Title: Replace `DegenerateFiles` with `CompatibilityFiles` · Issue #226 · python/importlib_resources · GitHub
Open Graph Title: Replace `DegenerateFiles` with `CompatibilityFiles` · Issue #226 · python/importlib_resources
X Title: Replace `DegenerateFiles` with `CompatibilityFiles` · Issue #226 · python/importlib_resources
Description: When reimplementing the lagacy api with files() in preparation for the legacy API deprecation, as discussed in #80, I uncovered that it does not have proper support for the legacy ResourceReader API. We implement DegenerateFiles, which t...
Open Graph Description: When reimplementing the lagacy api with files() in preparation for the legacy API deprecation, as discussed in #80, I uncovered that it does not have proper support for the legacy ResourceReader AP...
X Description: When reimplementing the lagacy api with files() in preparation for the legacy API deprecation, as discussed in #80, I uncovered that it does not have proper support for the legacy ResourceReader AP...
Opengraph URL: https://github.com/python/importlib_resources/issues/226
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Replace `DegenerateFiles` with `CompatibilityFiles`","articleBody":"When reimplementing the lagacy api with `files()` in preparation for the legacy API deprecation, as discussed in #80, I uncovered that it does not have proper support for the legacy `ResourceReader` API.\r\n\r\nWe implement `DegenerateFiles`, which takes a module spec and implements a degenerate object to be used as a fallback if no better `TraversableReader` is available.\r\n\r\nhttps://github.com/python/importlib_resources/blob/a024adf2c5235218aeb6d90817fe93b4e63496b9/importlib_resources/_adapters.py#L31-L74\r\nhttps://github.com/python/importlib_resources/blob/a024adf2c5235218aeb6d90817fe93b4e63496b9/importlib_resources/_compat.py#L64-L77\r\n\r\nIn some of the cases where it is used, we actually have a valid `ResourceReader` that we can use. We have one example in the tests.\r\n\r\nhttps://github.com/python/importlib_resources/blob/a024adf2c5235218aeb6d90817fe93b4e63496b9/importlib_resources/tests/util.py#L54-L61\r\n\r\nThe `files()` api won't work here, even though the legacy API does. If we deprecate the legacy api, users in these situations won't have any good alternative. I expect some of them to be in situations where they are not the ones that provide the reader, and so they are not able to fix it by adopting `TraversableReader`.\r\n\r\nTo solve this I propose replacing `DegenerateFiles` with a new implementation, `CompatibilityFiles`. It would adapt the `ResourceReader` api to provide a `TraversableReader`, essentially the oposite of `TraversableResources`, which implements a `ResourceReader` from a `TraversableReader`.\r\n\r\nI have a working implementation in #221. Though, when changing the leagcy api to use `files()`, in order to make sure it supports all the use cases in the legacy api tests, I ran into some failures.\r\n\r\nhttps://github.com/FFY00/importlib_resources/blob/7cb935e1defc995c24a63e8a08453e9f55d0fef2/importlib_resources/_adapters.py#L32-L113\r\n\r\n---\r\n\r\n@brettcannon you wrote the two tests that are now failing when you added support for the `ResourceReader` api, so I was hoping maybe you would be able to clarify some things.\r\n\r\n`test_resource_path` does not set `contents` in `create_package` and then tries to open the file. This worked in the legacy api, but raises `FileNotFoundError` in `files()`. I would guess that it was simply ommited because it worked, but that might not be necessarily true. Do you remember?\r\n\r\nI have set `contents` so that it includes `utf-8.file` in my PR, which fixes the issue. I think it is reasonable to fail reading a resource if that resource is not listed by `ResourceReader.contents`, that's actually what I would expect.\r\n\r\nhttps://github.com/python/importlib_resources/blob/a024adf2c5235218aeb6d90817fe93b4e63496b9/importlib_resources/tests/util.py#L121-L126\r\n\r\nThe other test, which is the one that is giving me trouble, is `test_resource_opener`. As far as I can tell, it essentially tests if we can still read a resource when `resource_path`, `is_resource` and `contents` (from `ResourceReader`) raise an exception, which does not seem very correct to me.\r\n\r\nThose methods are writen to raise an exception if `Reader.path` is an exception. This test specifically triggers that and then atempts to read the file.\r\n\r\n@brettcannon do you have any more context on this? Does it seems right? Or should it be removed?\r\n\r\nhttps://github.com/python/importlib_resources/blob/a024adf2c5235218aeb6d90817fe93b4e63496b9/importlib_resources/tests/util.py#L115-L119\r\n\r\nhttps://github.com/python/importlib_resources/blob/a024adf2c5235218aeb6d90817fe93b4e63496b9/importlib_resources/tests/util.py#L17-L51\r\n\r\nHopefully I have provided here all the context needed to understand the issue without having to go dig through the code, but let me know if there is still something I could clarify.","author":{"url":"https://github.com/FFY00","@type":"Person","name":"FFY00"},"datePublished":"2021-05-20T23:54:51Z","url":"https://github.com/python/importlib_resources/issues/226"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:89f7fd87-ac92-92c1-a585-379aabd60b7e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BCF0:A70A9:1A80F41:230056D:6B0219B2 |
| html-safe-nonce | b5aaaa66094de58a67ee63933fc0f5967a0ae912885938f332f65e2d5ce400fe |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQ0YwOkE3MEE5OjFBODBGNDE6MjMwMDU2RDo2QjAyMTlCMiIsInZpc2l0b3JfaWQiOiI4MzU2NjQ4MDc2NDAzOTM5NzYyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 932b892de90df30c63137bb994d0ca5253d299c097d224c1e20691c5a333545d |
| hovercard-subject-tag | issue:897558682 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/importlib_resources/226/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6fb5bd50e258a9984fc885ab7ab9befb4baf095aaca5350a6317c804fd38063d/python/importlib_resources/issues/226 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6fb5bd50e258a9984fc885ab7ab9befb4baf095aaca5350a6317c804fd38063d/python/importlib_resources/issues/226 |
| og:image:alt | When reimplementing the lagacy api with files() in preparation for the legacy API deprecation, as discussed in #80, I uncovered that it does not have proper support for the legacy ResourceReader AP... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | FFY00 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/importlib_resources git https://github.com/python/importlib_resources.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 306147182 |
| octolytics-dimension-repository_nwo | python/importlib_resources |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 306147182 |
| octolytics-dimension-repository_network_root_nwo | python/importlib_resources |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width