Skip to content

Allow a package to resolve its own resources simply - #260

Merged
jaraco merged 4 commits into
mainfrom
feature/implicit-here
Oct 8, 2022
Merged

Allow a package to resolve its own resources simply#260
jaraco merged 4 commits into
mainfrom
feature/implicit-here

Conversation

@jaraco

Copy link
Copy Markdown
Member

Fixes#259.

Comment threadimportlib_resources/_common.py Outdated
@jaraco

Copy link
Copy Markdown
MemberAuthor

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
jaracoforce-pushed the feature/implicit-here branch 2 times, most recently from cb223fd to 3b6fb35CompareJuly 23, 2022 16:41
@jaraco
jaracoforce-pushed the feature/203-non-package-modules branch 2 times, most recently from 1f3c226 to 8c3edebCompareOctober 5, 2022 14:30
@jaraco

Copy link
Copy Markdown
MemberAuthor

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
jaracoforce-pushed the feature/implicit-here branch 6 times, most recently from 4561cd8 to 9cd57a6CompareOctober 5, 2022 16:02
@jaraco

Copy link
Copy Markdown
MemberAuthor

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
jaracoforce-pushed the feature/implicit-here branch from 9cd57a6 to ef21c53CompareOctober 5, 2022 17:26
Base automatically changed from feature/203-non-package-modules to mainOctober 7, 2022 23:47
@jaraco
jaracoforce-pushed the feature/implicit-here branch from ef21c53 to cc1423fCompareOctober 7, 2022 23:53
@jaraco
jaracoforce-pushed the feature/implicit-here branch from cc1423f to e15a6b7CompareOctober 8, 2022 00:17
@jaraco
jaraco merged commit 4ff0b1b into mainOct 8, 2022
@jaraco
jaraco deleted the feature/implicit-here branch October 8, 2022 00:36
Sign up for freeto 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

@jaraco