-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
Move path-based bootstrap code to a separate frozen file. #68099
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
Comments
The bootstrap code has a clear division between the core import functionality and the path-based import machinery. The attached patch makes that division explicit by moving the latter into its own module. The module is also frozen, necessarily. In addition to clearly distinguishing the two parts, this division will help with some later work that I'd like to do later with an encapsulated import system abstraction. The patch uses the name "pathy" throughout, which I'll change to something more descriptive later. I'll also add the news entry then. |
Here's an updated patch, with the PEP-489 changes merged in. Only one test isn't passing and it is due to something in the pip that is bundled into ensurepip. I'll work on fixing that when I have some time. I'm sure there's documentation near the bundle that explains how to update it. |
s/PEP 489/PEP 488/ |
Nice, this ties directly into one of the thornier problems in the PEP-432 bootstrapping work, which needs to set up the core import system in Py_BeginInitialization, but delay setting up the rest of it until Py_EndInitialization. Your patch achieves this by moving everything that belongs in the latter part of the operation to the "import _frozen_path_importer" step. As far as naming goes, I'd suggest referring to the two import subsystems as "internal imports" and "external imports". The key aspect of builtin and frozen modules is that they're an inherent part of the interpreter itself - if you have an interpreter, you have all of its buitin and frozen modules natively available. By contrast, setting up the external import machinery requires that the interpreter first be configured to appropriately communicate with the host system. |
Glad to hear the patch is conceptually consistent with other components. :) And the "internal"/"external" suggestion is a good one. I'll update the patch when I have a minute. |
Here's an updated patch with "_pathy.py" changed to "_bootstrap_external.py" (and similar changes with freezing). The patch does not include fixing the venv test (i.e. the bundled pip). Also, I'll be adding a note to NEWS. |
As I mentioned, I'm pretty sure that the failing venv test is due to the bundled pip. Here's the test output: test test_venv failed -- Traceback (most recent call last):
File "/home/esnow/projects/cpython/Lib/test/test_venv.py", line 356, in test_with_pip
with_pip=True)
subprocess.CalledProcessError: Command '['/tmp/tmphxh1zztf/bin/python', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/esnow/projects/cpython/Lib/test/test_venv.py", line 362, in test_with_pip
self.fail(msg.format(exc, details))
AssertionError: Command '['/tmp/tmphxh1zztf/bin/python', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1
**Subprocess Output**
Traceback (most recent call last):
File "/home/esnow/projects/cpython/Lib/runpy.py", line 170, in _run_module_as_main
"__main__", mod_spec)
File "/home/esnow/projects/cpython/Lib/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/esnow/projects/cpython/Lib/ensurepip/__main__.py", line 4, in <module>
ensurepip._main()
File "/home/esnow/projects/cpython/Lib/ensurepip/__init__.py", line 209, in _main
default_pip=args.default_pip,
File "/home/esnow/projects/cpython/Lib/ensurepip/__init__.py", line 116, in bootstrap
_run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
File "/home/esnow/projects/cpython/Lib/ensurepip/__init__.py", line 40, in _run_pip
import pip
File "<frozen importlib._bootstrap>", line 958, in _find_and_load
File "<frozen importlib._bootstrap>", line 947, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap>", line 625, in _load_backward_compatible
File "/tmp/tmp57j9vkrt/pip-6.1.1-py2.py3-none-any.whl/pip/__init__.py", line 13, in <module>
File "<frozen importlib._bootstrap>", line 958, in _find_and_load
File "<frozen importlib._bootstrap>", line 947, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap>", line 625, in _load_backward_compatible
File "/tmp/tmp57j9vkrt/pip-6.1.1-py2.py3-none-any.whl/pip/utils/__init__.py", line 22, in <module>
File "<frozen importlib._bootstrap>", line 958, in _find_and_load
File "<frozen importlib._bootstrap>", line 947, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap>", line 625, in _load_backward_compatible
File "/tmp/tmp57j9vkrt/pip-6.1.1-py2.py3-none-any.whl/pip/_vendor/pkg_resources/__init__.py", line 1712, in <module>
AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader' |
Looks like setuptool's pkg_resources is directly importing importlib._bootstrap. I've filed a bug: https://bitbucket.org/pypa/setuptools/issue/378. In the meantime, what are our options for getting that test passing? |
Here's the correct patch. |
As a compatibility hack for setuptools versions with the issue, I'd suggest |
Gah. I had tried exactly that but did it in the wrong spot. Here's an updated patch which fixes the test. |
New changeset 02e3bf65b2f8 by Eric Snow in branch 'default': |
This checkin broke the buildbots. If you build trunk then run ./python -bb -m test test_site the test fails. "-bb" is used by the normal test runner ("make test"). The problem is in the lines
os__file__ and os__cached__ are bytes but you're passing them into .format() on a str. |
New changeset 36b902bbc992 by Eric Snow in branch 'default': |
Thanks for pointing this out, Ned. Early on I ran into a problem when running _freeze_importlib without the flag set. However, I expect that it was not necessary after a certain point (e.g. once I had a valid _importlib_external.h). I'll remove the flag as suggested. |
changeset: 95887:3bea670c9830 |
New changeset cc2e52878393 by Zachary Ware in branch 'default': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: