Skip to content

Commit

Permalink
🔖 v1.1.5 Fixed some breaking bugs in virtual environment verification.
Browse files Browse the repository at this point in the history
  • Loading branch information
bmeares committed Jul 27, 2022
1 parent b4e42e1 commit e2504b5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion meerschaum/config/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Specify the Meerschaum release version.
"""

__version__ = "1.1.4"
__version__ = "1.1.5"
2 changes: 1 addition & 1 deletion meerschaum/utils/packages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ def need_update(
) if import_name is None else (
import_name.split('.')[0] if split else import_name
)
install_name = install_name or _import_to_install_name(import_name)
install_name = install_name or _import_to_install_name(root_name)
if install_name in _checked_for_updates:
return False
_checked_for_updates.add(install_name)
Expand Down
26 changes: 19 additions & 7 deletions meerschaum/utils/venv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,10 @@ def verify_venv(
if not bin_path.exists():
init_venv(venv, verify=False, debug=debug)

### Ensure the versions are symlinked correctly.
for filename in os.listdir(bin_path):
if not filename.startswith('python'):
continue
python_path = bin_path / filename
def get_python_version(python_path: pathlib.Path) -> Union[str, None]:
"""
Return the version for the python binary at the given path.
"""
try:
### It might be a broken symlink, so skip on errors.
proc = run_process(
Expand All @@ -184,18 +183,31 @@ def verify_venv(
)
stdout, stderr = proc.communicate(timeout=0.1)
except Exception as e:
### E.g. the symlink may be broken.
return None
return stdout.decode('utf-8').strip().replace('Python ', '')

### Ensure the versions are symlinked correctly.
for filename in os.listdir(bin_path):
if not filename.startswith('python'):
continue
python_path = bin_path / filename
version = get_python_version(python_path)
if version is None:
continue
version = stdout.decode('utf-8').strip().replace('Python ', '')
major_version = version.split('.', maxsplit=1)[0]
minor_version = version.split('.', maxsplit=2)[1]
python_versioned_name = (
'python' + major_version + '.' + minor_version
+ ('' if platform.system() != 'Windows' else '.exe')
)
python_versioned_path = bin_path / python_versioned_name
if filename == python_versioned_name:
continue
python_versioned_path = bin_path / python_versioned_name
if python_versioned_path.exists():
### Avoid circular symlinks.
if get_python_version(python_versioned_path) == version:
continue
python_versioned_path.unlink()
shutil.move(python_path, python_versioned_path)

Expand Down

0 comments on commit e2504b5

Please sign in to comment.