New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Keep support for ICO formats by defaulting to PNG if necessary #4343
Merged
willhuang1997
merged 10 commits into
streamlit:develop
from
willhuang1997:fix/icon-files
Feb 4, 2022
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0bcc897
Keep support for ICO formats by defaulting to PNG if necessary
willhuang1997 484cf14
Reformatting
willhuang1997 de18938
Adding in attempt to find the ico file based on path
willhuang1997 a2d718d
Reformat
willhuang1997 0bd5522
Changing script to just check everything 2 levels above no matter what
willhuang1997 b0f02ae
Forgot reformatting
willhuang1997 0551095
Reformat
willhuang1997 f1eecf2
Reformatting again
willhuang1997 ebdbb0b
Addressing PR comments
willhuang1997 38b63ca
refactoring
willhuang1997 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import streamlit as st | ||
import os, fnmatch | ||
|
||
|
||
def is_assets_favicon_path(path): | ||
if "assets/favicon.ico" in path: | ||
return path | ||
|
||
|
||
def filter_nones(l): | ||
return list(filter(None, l)) | ||
|
||
|
||
def find(pattern, path): | ||
result = [] | ||
for root, dirs, files in os.walk(path): | ||
for name in files: | ||
if fnmatch.fnmatch(name, pattern): | ||
result.append(os.path.join(root, name)) | ||
return result | ||
|
||
|
||
# We want to find the file from 2 directories behind for circle ci | ||
# and for local testing if you are in the e2e/scripts folder | ||
# if you are in the root streamlit directory, | ||
# this script still work but will be slower likely. | ||
paths = find("favicon.ico", "../..") | ||
filtered_paths = filter_nones(list(map(is_assets_favicon_path, paths))) | ||
|
||
if len(filtered_paths) != 1: | ||
print("Can't seem to find assets/favicon.ico in the directory you're in.") | ||
else: | ||
st.set_page_config( | ||
page_icon=filtered_paths[0], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* @license | ||
* Copyright 2018-2022 Streamlit Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
describe("st.set_page_config", () => { | ||
before(() => { | ||
cy.loadApp("http://localhost:3000/"); | ||
}); | ||
|
||
it("sets the page favicon with ico file", () => { | ||
cy.get("link[rel='shortcut icon']") | ||
.should("have.attr", "href") | ||
.should( | ||
"contain", | ||
"92018b2805266c4cb9a98e90c849ce5b5e7ba6d1af423bd7b7c345da.png" | ||
); | ||
}); | ||
}); |
Binary file not shown.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -207,6 +207,9 @@ def _normalize_to_bytes(data, width, output_format): | |
if output_format.lower() == "auto": | ||
ext = imghdr.what(None, data) | ||
mimetype = mimetypes.guess_type("image.%s" % ext)[0] | ||
# if no other options, attempt to convert | ||
if mimetype is None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I realize I wrote this, but I would just add a comment that suggests that there's no other options, just try to convert it (would require Pillow support). |
||
mimetype = "image/" + format.lower() | ||
else: | ||
mimetype = "image/" + format.lower() | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha this code got complicated, I would just add a comment on the reason why this is happening (we should note that this later can be a e2e_test_util library