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

Avoid use of __file__ #7011

Closed
jayvdb opened this issue Nov 9, 2019 · 14 comments
Closed

Avoid use of __file__ #7011

jayvdb opened this issue Nov 9, 2019 · 14 comments

Comments

@jayvdb
Copy link

jayvdb commented Nov 9, 2019

It appears the use of __file__ here is mostly unnecessary, and can easily be replaced with importlib.resources/pkgutil. See indygreg/PyOxidizer#69 for more info about why, but the tl;dr version is __file__ is an optional attribute and should not be relied upon.

Loading of resources from the runtime package should ideally be done using importlib.resources and backport importlib_resources, however pkgutil could be used to avoid the need for the backport. Using pkgutil doesn't work under PyOxidizer 0.4, however I expect that will be fixed soon.

@stale
Copy link

stale bot commented May 17, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label May 17, 2020
@jayvdb
Copy link
Author

jayvdb commented May 19, 2020

This is still valid:

The first two are runtime use of __file__.

git grep __file__
compose/cli/utils.py:    filename = os.path.join(os.path.dirname(compose.__file__), 'GITSHA')
compose/config/validation.py:    return os.path.dirname(os.path.abspath(__file__))
script/release/const.py:REPO_ROOT = os.path.join(os.path.dirname(__file__), '..', '..')
setup.py:    path = os.path.join(os.path.dirname(__file__), *parts)

@stale
Copy link

stale bot commented May 19, 2020

This issue has been automatically marked as not stale anymore due to the recent activity.

@stale stale bot removed the stale label May 19, 2020
@stale
Copy link

stale bot commented Nov 15, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Nov 15, 2020
@stale
Copy link

stale bot commented Nov 22, 2020

This issue has been automatically closed because it had not recent activity during the stale period.

@stale stale bot closed this as completed Nov 22, 2020
@jayvdb
Copy link
Author

jayvdb commented Nov 22, 2020

ping @ndeloof , can you re-open

@thaJeztah
Copy link
Member

Let me reopen.

Looks like you have a fair understanding of what changes need to be made; were you considering opening a pull request with those changes?

@thaJeztah thaJeztah reopened this Nov 22, 2020
@stale
Copy link

stale bot commented Nov 22, 2020

This issue has been automatically marked as not stale anymore due to the recent activity.

1 similar comment
@stale
Copy link

stale bot commented Nov 22, 2020

This issue has been automatically marked as not stale anymore due to the recent activity.

@stale stale bot removed the stale label Nov 22, 2020
@stale
Copy link

stale bot commented Jun 2, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jun 2, 2021
@jayvdb
Copy link
Author

jayvdb commented Jun 2, 2021

Still a problem

git grep __file__
compose/cli/utils.py:    filename = os.path.join(os.path.dirname(compose.__file__), 'GITSHA')
compose/config/validation.py:    return os.path.dirname(os.path.abspath(__file__))
script/release/const.py:REPO_ROOT = os.path.join(os.path.dirname(__file__), '..', '..')
setup.py:    path = os.path.join(os.path.dirname(__file__), *parts)

However PyOxidizer now supports pkgutil, so that is now an easy and backwards compatible way to solve these

https://github.com/indygreg/PyOxidizer/blob/f5aecad5bf5123e5910a9ebb552815c6fa524edd/pyembed/docs/oxidized_importer_behavior_and_compliance.rst#pkgutil-compatibility

@stale
Copy link

stale bot commented Jun 2, 2021

This issue has been automatically marked as not stale anymore due to the recent activity.

@stale stale bot removed the stale label Jun 2, 2021
@stale
Copy link

stale bot commented Apr 16, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Apr 16, 2022
@jayvdb
Copy link
Author

jayvdb commented Apr 16, 2022

Issue now redundant.

@jayvdb jayvdb closed this as completed Apr 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants