Skip to content

Commit

Permalink
Testing with pip cache purge prior to install pip packages (#103)
Browse files Browse the repository at this point in the history
* Testing with pip cache purge prior to install pip packages

* Tailor: Updating Jenkinsfile

* Adding verbose logging to attempt to catch pypi issue

* Fixing typo

* typos

* formatting with black

* Updating pip version to 22.2.2 as a potential fix for pypa/pip#11340

* Testing with no-cache-dir during install

* Moving option

* Add --no-cache-dir

* Fixing formatting with black

* Tailor: Updating Jenkinsfile

* Tailor: Updating Jenkinsfile

* Tailor: Updating Jenkinsfile

---------

Co-authored-by: locus-services <33065330+locus-services@users.noreply.github.com>
Co-authored-by: Gary Servin <gservin@locusrobotics.com>
  • Loading branch information
3 people committed Feb 2, 2024
1 parent 4af9970 commit eb06c95
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
8 changes: 4 additions & 4 deletions Jenkinsfile
@@ -1,5 +1,5 @@
#!/usr/bin/env groovy
@Library('tailor-meta@0.1.21')_
@Library('tailor-meta@0.1.24')_
tailorTestPipeline(
// Name of job that generated this test definition.
rosdistro_job: '/ci/rosdistro/master',
Expand All @@ -10,11 +10,11 @@ tailorTestPipeline(
// Release label to pull test images from.
release_label: 'hotdog',
// OS distributions to test.
distributions: ['focal', 'jammy'],
distributions: ['jammy'],
// Version of tailor_meta to build against
tailor_meta: '0.1.21',
tailor_meta: '0.1.24',
// Master or release branch associated with this track
source_branch: 'master',
source_branch: 'test_pip_cache_purge',
// Docker registry where test image is stored
docker_registry: 'https://084758475884.dkr.ecr.us-east-1.amazonaws.com/locus-tailor'
)
35 changes: 21 additions & 14 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 All @@ -65,7 +66,7 @@ def initialize(self, python, use_system_packages, extra_pip_args, clean=True):
raise RuntimeError(error_msg)

preinstall = [
"pip==22.0.2",
"pip==22.2.2",
"pip-tools==6.10.0",
]

Expand All @@ -83,34 +84,40 @@ 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"] + extra_pip_args + preinstall, check=True)
# (gservin): test --no-cache-dir
run_command(
[self._venv_bin("python"), "-m", "pip", "install", "--no-cache-dir", "-vvv"] + extra_pip_args + preinstall,
check=True,
)

def install(self, requirements, extra_pip_args):
""" Sync a virtualenv with the specified requirements. """
command = [self._venv_bin("python"), "-m", "pip", "install"] + 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"]
""" Sync a virtualenv with the specified requirements.""" # (KLAD) testing no-cache-dir
command = [self._venv_bin("python"), "-m", "pip", "install", "-vvv", "--no-cache-dir"] + 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 @@ -138,7 +145,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 @@ -169,7 +176,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 @@ -197,7 +204,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 eb06c95

Please sign in to comment.