home / github / issue_comments

Menu
  • GraphQL API

issue_comments: 1503832422

This data as json

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-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  
Powered by Datasette · Queries took 0.866ms