Skip to content

Commit

Permalink
Adjust code for virtualenv 20.x
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile committed Feb 14, 2020
1 parent 5247e0c commit 2b95c7a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion tests/virtualenv_tools_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def test_verbose(venv, capsys):
run(venv.before, venv.after, args=('--verbose',))
out, _ = capsys.readouterr()
# Lots of output
assert len(out.splitlines()) > 25
assert len(out.splitlines()) > 10


def test_non_absolute_error(capsys):
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ envdir = venv-{[tox]project}
commands =

[pep8]
ignore = E265,E501
ignore = E265,E501,W504
16 changes: 11 additions & 5 deletions virtualenv_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
_pybin_match = re.compile(r'^python\d+\.\d+$')
_pypy_match = re.compile(r'^\d+.\d+$')
_activation_path_re = re.compile(
r'^(?:set -gx |setenv |)VIRTUAL_ENV[ =]"(.*?)"\s*$',
r'^(?:set -gx |setenv |)VIRTUAL_ENV[ =][\'"](.*?)[\'"]\s*$',
)
VERBOSE = False
MAGIC_LENGTH = 4 + 4 # magic length + 4 byte timestamp
Expand Down Expand Up @@ -169,7 +169,11 @@ def get_new_path(filename):

for dirname, dirnames, filenames in os.walk(lib_dir):
for filename in filenames:
if filename.endswith(('.pyc', '.pyo')):
if (
filename.endswith(('.pyc', '.pyo')) and
# python 2, virtualenv 20.x symlinks os.pyc
not os.path.islink(os.path.join(dirname, filename))
):
filename = os.path.join(dirname, filename)
local_path = get_new_path(filename)
update_pyc(filename, local_path)
Expand Down Expand Up @@ -236,11 +240,13 @@ def get_orig_path(venv_path):

with open(activate_path) as activate:
for line in activate:
if line.startswith('VIRTUAL_ENV="'):
return line.split('"', 2)[1]
# virtualenv 20 changes the position
for possible in ('VIRTUAL_ENV="', "VIRTUAL_ENV='"):
if line.startswith(possible):
return line.split(possible[-1], 2)[1]
else:
raise AssertionError(
'Could not find VIRTUAL_ENV=" in activation script: %s' %
'Could not find VIRTUAL_ENV= in activation script: %s' %
activate_path
)

Expand Down

0 comments on commit 2b95c7a

Please sign in to comment.