-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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 missing .py files if .pyc is present #1714
Conversation
src/virtualenv/create/via_global_ref/builtin/python2/python2.py
Outdated
Show resolved
Hide resolved
Can you describe a use case for this? Why would anyone want this? |
Custom systems may want to maximize available storage or obfuscate source code by removing |
Did this worked with old virtualenv or would this be a new feature here 🤔 |
I cannot reproduce the issue with |
I don't think this is an issue but feature 🤔 did it work to create virtual environments with virtualenv 16.x when you did not have the source file? I don't think so. |
Yes, if I downgrade to |
I'm surprised. Can you post a tree view of the result with old virtualenv and the output of -vvv 😲 |
How's this (with
|
I'm having a tough time making a test for this because writes to diff --git a/tests/unit/create/test_creator.py b/tests/unit/create/test_creator.py
index 70e0e6a..4091689 100644
--- a/tests/unit/create/test_creator.py
+++ b/tests/unit/create/test_creator.py
@@ -19,6 +19,7 @@ import pytest
from virtualenv.__main__ import run, run_with_catch
from virtualenv.create.creator import DEBUG_SCRIPT, Creator, get_env_debug_info
+from virtualenv.create.via_global_ref.builtin.cpython.cpython2 import CPython2
from virtualenv.discovery.builtin import get_interpreter
from virtualenv.discovery.py_info import PythonInfo
from virtualenv.info import IS_PYPY, IS_WIN, PY3, fs_is_case_sensitive, fs_supports_symlink
@@ -448,3 +449,23 @@ def test_python_path(monkeypatch, tmp_path, python_path_on):
assert non_python_path == [i for i in base if i not in extra_as_python_path]
else:
assert base == extra_all
+
+
+@pytest.fixture
+def creator_patched_modules(monkeypatch, current_creators):
+ creator = current_creators[2]
+ module_name = "CPython2_patch_modules_module"
+ module_path = Path(CURRENT.system_stdlib) / "{}.pyc".format(module_name)
+ module_path.touch()
+ @classmethod
+ def modules(cls):
+ return [module_name]
+ monkeypatch.setattr(CPython2, 'modules', modules)
+ yield creator
+ module_path.unlink()
+
+
+@pytest.mark.skipif(PY3, reason=".py files are only checked for in py2.")
+def test_pyc_only(creator_patched_modules):
+ assert creator_patched_modules.can_create(CURRENT) is not None
|
As a test I'd recommend building a mock python by copying the system files without the py files and running on that 👍 |
Dumb question: why isn't this logic (before/after) using By the way, the current code is technically code broken with .pyo-only files, as well as compressed eggs. There are some other custom formats like .par and .xar, that might not work with this either. I think it makes a lot more sense to rely on the python interpreter when it comes to import logic. |
src/virtualenv/create/via_global_ref/builtin/python2/python2.py
Outdated
Show resolved
Hide resolved
It's because the python executing the code here is not the same as the target python. Importing it here would not give you the modules you're expecting. Those modes are not supported by virtualenv, and would require case by case judgment if we should support them or not. |
I'm fairly sure compressed eggs are not supported by the ecosystem, e.g. setuptools anymore. They work for backwards compatibility reasons but they should not be used. |
I'm not entirely sure how to do this 😅 I was able to get something working, though. |
Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net>
Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net>
Awesome 😎 Thanks for that!
|
Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net>
Yeah, pushed a fixed commit just now, seems PyPy does not support not having the source file for a standard library module. |
I'll do a release tomorrow 👍 |
Hello, a fix for this issue has been released via virtualenv 20.0.11; see https://pypi.org/project/virtualenv/20.0.11/ (https://virtualenv.pypa.io/en/latest/changelog.html#v20-0-11-2020-03-18). Please give a try and report back if your issue has not been addressed; if not, please comment here, and we'll reopen the ticket. We want to apologize for the inconvenience this has caused you and say thanks for having patience while we resolve the unexpected bugs with this new major release. |
@gaborbernat Thank YOU for all your help with this 😊 No worries I suspect this is fixed; however, I'm unable to verify due to #1738! edit: Suspicion confirmed: 20.0.13 seems to work! Thanks again 🎉 |
Python can run with just
.pyc
files; however, if only a.pyc
file is present (e.g.os.pyc
),virtualenv
will throw aRuntimeError: No virtualenv implementation for PythonInfo(...)
.This makes it so the
.py
file is checked if it exists or if neither it nor the.pyc
file exists (so as to preserve the current behavior when both are missing).Thanks for contributing, make sure you address all the checklists (for details on how see
development documentation)!
tox -e fix_lint
)docs/changelog
folder