Skip to content

Commit

Permalink
Rebase from 'release/noetic/catkin_virtualenv'
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbovbel committed Aug 24, 2020
1 parent 678b194 commit cb47e25
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 150 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -2,6 +2,18 @@
Changelog for package catkin_virtualenv
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0.6.1 (2020-08-24)
------------------
* Correct dependencies and autoformat (`#72 <https://github.com/locusrobotics/catkin_virtualenv/issues/72>`_)
* Remove python-virtualenv dep
* Add python2-dev
* Lint
* We're ok with any 44.x version of setuptools (`#71 <https://github.com/locusrobotics/catkin_virtualenv/issues/71>`_)
But not anything newer.
Older versions don't appear to work reliably with `pip==20.1`.
This helps when running a build of a package depending on catkin_virtualenv on OS which ship with an old version of setuptools (such as Ubuntu Xenial) when `USE_SYSTEM_PACKAGES` is not set to `FALSE`. In that situation, only specifying 'setuptools<45` will be true, as setuptools is installed (in the systems site packages), so pip will not upgrade it. Specifying a minimum version like this will force pip to always install an up-to-date version.
* Contributors: G.A. vd. Hoorn, Paul Bovbel

0.6.0 (2020-07-14)
------------------
* Don't require catkin_package to be called before catkin_generate_virtualenv (`#67 <https://github.com/locusrobotics/catkin_virtualenv/issues/67>`_)
Expand Down
4 changes: 2 additions & 2 deletions package.xml
Expand Up @@ -22,7 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<package format="2">
<name>catkin_virtualenv</name>
<version>0.6.0</version>
<version>0.6.1</version>
<description>Bundle python requirements in a catkin package via virtualenv.</description>

<maintainer email="pbovbel@locusrobotics.com">Paul Bovbel</maintainer>
Expand All @@ -31,7 +31,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

<buildtool_depend>catkin</buildtool_depend>

<build_export_depend>python-virtualenv</build_export_depend>
<build_export_depend>python-dev</build_export_depend>
<build_export_depend>python3-dev</build_export_depend>
<build_export_depend>python3-nose</build_export_depend>
<build_export_depend>python3-rospkg-modules</build_export_depend>
Expand Down
67 changes: 0 additions & 67 deletions rpm/template.spec.em

This file was deleted.

7 changes: 1 addition & 6 deletions setup.py
Expand Up @@ -19,11 +19,6 @@
from distutils.core import setup
from catkin_pkg.python_setup import generate_distutils_setup

d = generate_distutils_setup(
packages=[
'catkin_virtualenv',
],
package_dir={'': 'src'}
)
d = generate_distutils_setup(packages=["catkin_virtualenv"], package_dir={"": "src"})

setup(**d)
10 changes: 5 additions & 5 deletions src/catkin_virtualenv/__init__.py
Expand Up @@ -28,7 +28,7 @@

def configure_logging():
try:
with open(os.environ['ROS_PYTHON_LOG_CONFIG_FILE']) as config:
with open(os.environ["ROS_PYTHON_LOG_CONFIG_FILE"]) as config:
logging.config.dictConfig(yaml.safe_load(config))
except KeyError:
logging.basicConfig()
Expand All @@ -37,8 +37,8 @@ def configure_logging():


def run_command(cmd, *args, **kwargs):
logger.info(' '.join(cmd))
if kwargs.pop('capture_output', False):
kwargs['stdout'] = subprocess.PIPE
kwargs['stderr'] = subprocess.PIPE
logger.info(" ".join(cmd))
if kwargs.pop("capture_output", False):
kwargs["stdout"] = subprocess.PIPE
kwargs["stderr"] = subprocess.PIPE
return subprocess.run(cmd, *args, **kwargs)
9 changes: 3 additions & 6 deletions src/catkin_virtualenv/collect_requirements.py
Expand Up @@ -41,11 +41,7 @@ def parse_exported_requirements(package, package_dir):
def process_package(package_name, soft_fail=True):
# type: (str) -> List[str], List[str]
try:
package_path = find_in_workspaces(
project=package_name,
path="package.xml",
first_match_only=True,
)[0]
package_path = find_in_workspaces(project=package_name, path="package.xml", first_match_only=True,)[0]
except IndexError:
if not soft_fail:
raise RuntimeError("Unable to process package {}".format(package_name))
Expand All @@ -72,7 +68,8 @@ def collect_requirements(package_name, no_deps=False):
if queued_package not in processed_packages:
processed_packages.add(queued_package)
requirements, dependencies = process_package(
package_name=queued_package, soft_fail=(queued_package != package_name))
package_name=queued_package, soft_fail=(queued_package != package_name)
)
requirements_list = requirements + requirements_list

if not no_deps:
Expand Down
46 changes: 19 additions & 27 deletions src/catkin_virtualenv/relocate.py
Expand Up @@ -24,62 +24,54 @@

from . import run_command

PYTHON_INTERPRETERS = ['python', 'pypy', 'ipy', 'jython']
_PYTHON_INTERPRETERS_REGEX = r'\(' + r'\|'.join(PYTHON_INTERPRETERS) + r'\)'
PYTHON_INTERPRETERS = ["python", "pypy", "ipy", "jython"]
_PYTHON_INTERPRETERS_REGEX = r"\(" + r"\|".join(PYTHON_INTERPRETERS) + r"\)"


def find_script_files(venv_dir):
"""Find list of files containing python shebangs in the bin directory. """
command = [
'grep', '-l', '-r',
'-e', r'^#!.*bin/\(env \)\?{0}'.format(_PYTHON_INTERPRETERS_REGEX),
'-e', r"^'''exec.*bin/{0}".format(_PYTHON_INTERPRETERS_REGEX),
os.path.join(venv_dir, 'bin')]
"grep",
"-l",
"-r",
"-e",
r"^#!.*bin/\(env \)\?{0}".format(_PYTHON_INTERPRETERS_REGEX),
"-e",
r"^'''exec.*bin/{0}".format(_PYTHON_INTERPRETERS_REGEX),
os.path.join(venv_dir, "bin"),
]
files = run_command(command, check=True, capture_output=True).stdout
return {f for f in files.decode('utf-8').strip().split('\n') if f}
return {f for f in files.decode("utf-8").strip().split("\n") if f}


def fix_shebangs(venv_dir, target_dir):
"""Translate /usr/bin/python and /usr/bin/env python shebang
lines to point to our virtualenv python.
"""
pythonpath = os.path.join(target_dir, 'bin/python')
pythonpath = os.path.join(target_dir, "bin/python")
for f in find_script_files(venv_dir):
regex = (
r's-^#!.*bin/\(env \)\?{names}\"\?-#!{pythonpath}-;'
r"s-^'''exec'.*bin/{names}-'''exec' {pythonpath}-"
r"s-^#!.*bin/\(env \)\?{names}\"\?-#!{pythonpath}-;" r"s-^'''exec'.*bin/{names}-'''exec' {pythonpath}-"
).format(names=_PYTHON_INTERPRETERS_REGEX, pythonpath=re.escape(pythonpath))
run_command(['sed', '-i', regex, f], check=True)
run_command(["sed", "-i", regex, f], check=True)


def fix_activate_path(venv_dir, target_dir):
"""Replace the `VIRTUAL_ENV` path in bin/activate to reflect the
post-install path of the virtualenv.
"""
activate_settings = [
[
'VIRTUAL_ENV="{0}"'.format(target_dir),
r'^VIRTUAL_ENV=.*$',
"activate"
],
[
'setenv VIRTUAL_ENV "{0}"'.format(target_dir),
r'^setenv VIRTUAL_ENV.*$',
"activate.csh"
],
[
'set -gx VIRTUAL_ENV "{0}"'.format(target_dir),
r'^set -gx VIRTUAL_ENV.*$',
"activate.fish"
],
['VIRTUAL_ENV="{0}"'.format(target_dir), r"^VIRTUAL_ENV=.*$", "activate"],
['setenv VIRTUAL_ENV "{0}"'.format(target_dir), r"^setenv VIRTUAL_ENV.*$", "activate.csh"],
['set -gx VIRTUAL_ENV "{0}"'.format(target_dir), r"^set -gx VIRTUAL_ENV.*$", "activate.fish"],
]

for activate_args in activate_settings:
virtualenv_path = activate_args[0]
pattern = re.compile(activate_args[1], flags=re.M)
activate_file = activate_args[2]

with open(os.path.join(venv_dir, 'bin', activate_file), 'r+') as fh:
with open(os.path.join(venv_dir, "bin", activate_file), "r+") as fh:
content = pattern.sub(virtualenv_path, fh.read())
fh.seek(0)
fh.truncate()
Expand Down

0 comments on commit cb47e25

Please sign in to comment.