-
-
Notifications
You must be signed in to change notification settings - Fork 7
Add a test of .pth handling. #118
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
700b15f
Add a test of .pth handling.
freakboy3742 221fe76
Pre-compile the wheel so that it can be found on platforms that use r…
freakboy3742 c789a0e
Fix typos
mhsmith d18d4c0
Install x-pth-tester unconditionally
mhsmith a3d96cf
Add a test of stdlib availability during .pth handling.
freakboy3742 adf3eb1
Simplify logic for android special case test.
freakboy3742 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| __pycache__/ | ||
| .idea | ||
| *.dist-info/ | ||
| *.egg-info/ | ||
| build/ | ||
| logs/ | ||
| .DS_Store |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # pth-tester | ||
|
|
||
| This is a package that tests whether `.pth` files are correctly process on | ||
| import. It is not designed to be published; it is only useful in the context of | ||
| the testbed app. | ||
|
|
||
| When installed, it includes `.pth` file that invokes the `pth_tester.init()` method. | ||
|
mhsmith marked this conversation as resolved.
Outdated
|
||
| This sets the `initialized` attribute of the module to `True`. In this way, it is | ||
| possible to tell if `.pth` handling has occurred on app startup. | ||
|
|
||
| This project has been compiled into a wheel, stored in the `wheels` directory | ||
| of the top-level directory. The wheel can be rebuilt using: | ||
|
|
||
| $ pip install build | ||
| $ python -m build --wheel --outdir ../wheels | ||
|
|
||
| If you make any modifications to the code for this project, you will need to | ||
| rebuild the wheel. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| initialized = False | ||
|
|
||
|
|
||
| # The pth_tester module should be initalized by processing the `.pth` file | ||
| # created on installation. | ||
| def init(): | ||
| global initialized | ||
| initialized = True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| [build-system] | ||
| requires = ["setuptools==78.0.2", "wheel"] | ||
| build-backend = "setuptools.build_meta" | ||
|
|
||
| [project] | ||
| name = "x-pth-tester" | ||
| version = "1.0.0" | ||
| classifiers = ["Private :: Do Not Upload"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import os | ||
|
|
||
| import setuptools | ||
| from setuptools.command.install import install | ||
|
|
||
|
|
||
| # Copied from setuptools: | ||
| # (https://github.com/pypa/setuptools/blob/7c859e017368360ba66c8cc591279d8964c031bc/setup.py#L40C6-L82) | ||
| class install_with_pth(install): | ||
| """ | ||
| Custom install command to install a .pth file. | ||
|
|
||
| This hack is necessary because there's no standard way to install behavior | ||
| on startup (and it's debatable if there should be one). This hack (ab)uses | ||
| the `extra_path` behavior in Setuptools to install a `.pth` file with | ||
| implicit behavior on startup. | ||
|
|
||
| The original source strongly recommends against using this behavior. | ||
| """ | ||
|
|
||
| _pth_name = "_pth_tester" | ||
| _pth_contents = "import pth_tester; pth_tester.init()" | ||
|
|
||
| def initialize_options(self): | ||
| install.initialize_options(self) | ||
| self.extra_path = self._pth_name, self._pth_contents | ||
|
|
||
| def finalize_options(self): | ||
| install.finalize_options(self) | ||
| self._restore_install_lib() | ||
|
|
||
| def _restore_install_lib(self): | ||
| """ | ||
| Undo secondary effect of `extra_path` adding to `install_lib` | ||
| """ | ||
| suffix = os.path.relpath(self.install_lib, self.install_libbase) | ||
|
|
||
| if suffix.strip() == self._pth_contents.strip(): | ||
| self.install_lib = self.install_libbase | ||
|
|
||
|
|
||
| setuptools.setup( | ||
| cmdclass={"install": install_with_pth}, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.