github
html_url | issue_url | id | node_id | user | created_at | updated_at | author_association | body | reactions | issue | performed_via_github_app |
---|---|---|---|---|---|---|---|---|---|---|---|
https://github.com/simonw/datasette/issues/2057#issuecomment-1503838640 | https://api.github.com/repos/simonw/datasette/issues/2057 | 1503838640 | IC_kwDOBm6k_c5ZosGw | 9599 | 2023-04-11T17:48:23Z | 2023-04-11T17:48:23Z | OWNER | > This looks wrong to me - I would expect something like `is_directory()` not `is_file()` for telling if `static/` is a directory. I was right about that: ```pycon >>> importlib.resources.files('datasette_graphql') PosixPath('/Users/simon/.local/share/virtualenvs/datasette-big-local-6Yn-280V/lib/python3.11/site-packages/datasette_graphql') >>> importlib.resources.files('datasette_graphql').joinpath("static") PosixPath('/Users/simon/.local/share/virtualenvs/datasette-big-local-6Yn-280V/lib/python3.11/site-packages/datasette_graphql/static') >>> p = importlib.resources.files('datasette_graphql').joinpath("static") >>> p PosixPath('/Users/simon/.local/share/virtualenvs/datasette-big-local-6Yn-280V/lib/python3.11/site-packages/datasette_graphql/static') >>> p.is_ p.is_absolute() p.is_char_device() p.is_fifo() p.is_mount() p.is_reserved() p.is_symlink() p.is_block_device() p.is_dir() p.is_file() p.is_relative_to( p.is_socket() >>> p.is_dir() True >>> p.is_file() False ``` | { "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
1662951875 | |
https://github.com/simonw/datasette/issues/2057#issuecomment-1503832422 | https://api.github.com/repos/simonw/datasette/issues/2057 | 1503832422 | IC_kwDOBm6k_c5Zoqlm | 9599 | 2023-04-11T17:42:57Z | 2023-04-11T17:46:42Z | OWNER | I ran this prompt against ChatGPT with the Browsing alpha: > ```python > if pkg_resources.resource_isdir(plugin.__name__, "static"): > static_path = pkg_resources.resource_filename( > plugin.__name__, "static" > ) > if pkg_resources.resource_isdir(plugin.__name__, "templates"): > templates_path = pkg_resources.resource_filename( > plugin.__name__, "templates" > ) > ``` > This code gives a deprecation warning in Python 3.11 - fix it It looked up the fix for me: <img width="632" alt="image" src="https://user-images.githubusercontent.com/9599/231245259-af4d962c-e631-420b-8312-fd9657a23bbd.png"> And suggested: ```python import importlib.resources # Replace pkg_resources.resource_isdir with importlib.resources.files().is_file() if importlib.resources.files(plugin.__name__).joinpath("static").is_file(): static_path = importlib.resources.as_file( importlib.resources.files(plugin.__name__).joinpath("static") ) if importlib.resources.files(plugin.__name__).joinpath("templates").is_file(): templates_path = importlib.resources.as_file( importlib.resources.files(plugin.__name__).joinpath("templates") ) ``` This looks wrong to me - I would expect something like `is_directory()` not `is_file()` for telling if `static/` is a directory. | { "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
1662951875 | |
https://github.com/simonw/datasette/issues/2057#issuecomment-1503833906 | https://api.github.com/repos/simonw/datasette/issues/2057 | 1503833906 | IC_kwDOBm6k_c5Zoq8y | 9599 | 2023-04-11T17:44:16Z | 2023-04-11T17:45:45Z | OWNER | Another prompt: > How to fix this: > > `pkg_resources.get_distribution(package).version` Response: <img width="641" alt="image" src="https://user-images.githubusercontent.com/9599/231245559-dd943527-818a-45aa-9833-b9db8c7ca87e.png"> ```python import importlib.metadata # Get the version number of the specified package package_version = importlib.metadata.version(package) ``` That seems to work: ```pycon >>> import importlib.metadata >>> importlib.metadata.version("datasette") '0.64.2' >>> importlib.metadata.version("pluggy") '1.0.0' >>> importlib.metadata.version("not-a-package") ... importlib.metadata.PackageNotFoundError: No package metadata was found for not-a-package ``` | { "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
1662951875 |