Skip to content

Commit

Permalink
formatting with black
Browse files Browse the repository at this point in the history
  • Loading branch information
kronos30 committed Jul 15, 2023
1 parent 6d5d19d commit 4f5a38a
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions catkin_virtualenv/src/catkin_virtualenv/venv.py
Expand Up @@ -26,6 +26,7 @@
import shutil
import subprocess
import tempfile

try:
from urllib.request import urlretrieve
except ImportError:
Expand All @@ -45,11 +46,11 @@

class Virtualenv:
def __init__(self, path):
""" Manage a virtualenv at the specified path. """
"""Manage a virtualenv at the specified path."""
self.path = path

def initialize(self, python, use_system_packages, extra_pip_args, clean=True):
""" Initialize a new virtualenv using the specified python version and extra arguments. """
"""Initialize a new virtualenv using the specified python version and extra arguments."""
if clean:
try:
shutil.rmtree(self.path)
Expand Down Expand Up @@ -83,36 +84,38 @@ def initialize(self, python, use_system_packages, extra_pip_args, clean=True):

without_pip = self._check_module(system_python, "ensurepip") is False
if without_pip:
virtualenv.append('--without-pip')
virtualenv.append("--without-pip")

virtualenv.append(self.path)
run_command(virtualenv, check=True)

if without_pip:
# install pip via get-pip.py
version_proc = run_command(
['python', "-cimport sys; print('{}.{}'.format(*sys.version_info))"],
capture_output=True)
["python", "-cimport sys; print('{}.{}'.format(*sys.version_info))"], capture_output=True
)
version = version_proc.stdout
if isinstance(version, bytes):
version = version.decode('utf-8')
version = version.decode("utf-8")
version = version.strip()
# download pip from https://bootstrap.pypa.io/pip/
get_pip_path, _ = urlretrieve("https://bootstrap.pypa.io/pip/get-pip.py")
run_command([self._venv_bin("python"), get_pip_path], check=True)

run_command([self._venv_bin("python"), "-m", "pip", "install", "-vvv"] + extra_pip_args + preinstall, check=True)
run_command(
[self._venv_bin("python"), "-m", "pip", "install", "-vvv"] + extra_pip_args + preinstall, check=True
)

def install(self, requirements, extra_pip_args):
""" Purge the cache first before installing. """ # (KLAD) testing to debug an issue on build farm
command = [self._venv_bin("python"), "-m", "pip", "cache", "purge"]
"""Purge the cache first before installing.""" # (KLAD) testing to debug an issue on build farm
command = [self._venv_bin("python"), "-m", "pip", "cache", "purge"]
""" Sync a virtualenv with the specified requirements. """
command = [self._venv_bin("python"), "-m", "pip", "install", "-vvv"] + extra_pip_args
for req in requirements:
run_command(command + ["-r", req], check=True)

def check(self, requirements, extra_pip_args):
""" Check if a set of requirements is completely locked. """
"""Check if a set of requirements is completely locked."""
with open(requirements, "r") as f:
existing_requirements = f.read()

Expand Down Expand Up @@ -140,7 +143,7 @@ def _format(content):
return diff

def lock(self, package_name, input_requirements, no_overwrite, extra_pip_args):
""" Create a frozen requirement set from a set of input specifications. """
"""Create a frozen requirement set from a set of input specifications."""
try:
output_requirements = collect_requirements(package_name, no_deps=True)[0]
except IndexError:
Expand Down Expand Up @@ -171,7 +174,7 @@ def lock(self, package_name, input_requirements, no_overwrite, extra_pip_args):
logger.info("Wrote new lock file to {}".format(output_requirements))

def relocate(self, target_dir):
""" Relocate a virtualenv to another directory. """
"""Relocate a virtualenv to another directory."""
self._delete_bytecode()
relocate.fix_shebangs(self.path, target_dir)
relocate.fix_activate_path(self.path, target_dir)
Expand Down Expand Up @@ -199,7 +202,7 @@ def _check_module(self, python_executable, module):
return False

def _delete_bytecode(self):
""" Remove all .py[co] files since they embed absolute paths. """
"""Remove all .py[co] files since they embed absolute paths."""
for root, _, files in os.walk(self.path):
for f in files:
if _BYTECODE_REGEX.match(f):
Expand Down

0 comments on commit 4f5a38a

Please sign in to comment.