Skip to content
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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow a package to resolve its own resources simply #260

Merged
merged 4 commits into from
Oct 8, 2022

Conversation

jaraco
Copy link
Member

@jaraco jaraco commented Jul 23, 2022

Fixes #259.

@jaraco
Copy link
Member Author

jaraco commented Jul 23, 2022

An issue I found with this implementation is that a call to files(__main__) will result in an error because __main__.__spec__ is None... and while it's not common to call files(__main__) or files('__main__'), it would probably not be uncommon for someone to call files() from __main__.

@jaraco jaraco force-pushed the feature/implicit-here branch 2 times, most recently from cb223fd to 3b6fb35 Compare July 23, 2022 16:41
@jaraco jaraco force-pushed the feature/203-non-package-modules branch 2 times, most recently from 1f3c226 to 8c3edeb Compare October 5, 2022 14:30
@jaraco
Copy link
Member Author

jaraco commented Oct 5, 2022

An issue I found with this implementation is that a call to files(__main__) will result in an error because __main__.__spec__ is None... and while it's not common to call files(__main__) or files('__main__'), it would probably not be uncommon for someone to call files() from __main__.

I'm tempted to explicitly support __main__ to make that use-case easy and congruent to others.

@jaraco jaraco force-pushed the feature/implicit-here branch 6 times, most recently from 4561cd8 to 9cd57a6 Compare October 5, 2022 16:02
@jaraco
Copy link
Member Author

jaraco commented Oct 5, 2022

I'm tempted to explicitly support __main__ to make that use-case easy and congruent to others.

In the latest patch, I'm no longer able to replicate this issue, so I'm declaring it a non-issue:

 importlib_resources feature/implicit-here $ cat foo.py
import importlib_resources as res


def main():
    print(res.files())


__name__ == '__main__' and main()
 importlib_resources feature/implicit-here $ .tox/python/bin/python -m foo
/Users/jaraco/code/python/importlib_resources

@jaraco jaraco marked this pull request as ready for review October 5, 2022 16:20
@jaraco jaraco force-pushed the feature/implicit-here branch from 9cd57a6 to ef21c53 Compare October 5, 2022 17:26
Base automatically changed from feature/203-non-package-modules to main October 7, 2022 23:47
@jaraco jaraco force-pushed the feature/implicit-here branch from ef21c53 to cc1423f Compare October 7, 2022 23:53
@jaraco jaraco force-pushed the feature/implicit-here branch from cc1423f to e15a6b7 Compare October 8, 2022 00:17
@jaraco jaraco merged commit 4ff0b1b into main Oct 8, 2022
@jaraco jaraco deleted the feature/implicit-here branch October 8, 2022 00:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Provide a simple syntax to load resources from __here__
1 participant