Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge repeated requirements #32

Merged
merged 6 commits into from
Dec 4, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ It's possible to bundle all of a catkin package's python requirements, as well a
into a virtualenv. This process will also override the standard `catkin_install_python` macro to wrap a virtualenv
loader around the specified python scripts.

This operation does not do any dependency resolution - similar to how `pip` operates, the topmost dependency declaration
'wins' (https://github.com/pypa/pip/issues/988).

Add an build dependency to `package.xml`:

```
Expand Down
13 changes: 4 additions & 9 deletions catkin_virtualenv/cmake/combine_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import re
import sys

from catkin_virtualenv import requirements
from packaging.requirements import Requirement

comment_regex = re.compile('\s*#.*')
comment_regex = re.compile(r'\s*#.*')


def combine_requirements(requirements_list, output_file):
Expand All @@ -36,14 +36,9 @@ def combine_requirements(requirements_list, output_file):
contents = comment_regex.sub('', contents)
for requirement_string in contents.splitlines():
if requirement_string and not requirement_string.isspace():
requirement = requirements.Requirement(requirement_string)
try:
combined_requirements[requirement.name] = combined_requirements[requirement.name] + requirement
except KeyError:
requirement = Requirement(requirement_string)
if requirement.name not in combined_requirements:
combined_requirements[requirement.name] = requirement
except requirements.ReqMergeException as e:
print("In files {}: {}".format(requirements_list, e), file=sys.stderr)
raise

for requirement in combined_requirements.values():
output_file.write("{}\n".format(requirement))
Expand Down
1 change: 1 addition & 0 deletions catkin_virtualenv/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<buildtool_depend>catkin</buildtool_depend>

<build_export_depend>python-enum34</build_export_depend>
<build_export_depend>python-packaging</build_export_depend>
<build_export_depend>python-virtualenv</build_export_depend>
<build_export_depend>python3-dev</build_export_depend>

Expand Down
2 changes: 1 addition & 1 deletion test_catkin_virtualenv/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
wrapt>=1.10.11
requests==2.20.1
3 changes: 2 additions & 1 deletion test_catkin_virtualenv/test/test_virtualenv_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@
class TestVirtualenv(unittest.TestCase):

def test_import_wrapt(self):
paulbovbel marked this conversation as resolved.
Show resolved Hide resolved
importlib.import_module("wrapt")
requests = importlib.import_module("requests")
self.assertEquals(requests.__version__, "2.20.1")
3 changes: 2 additions & 1 deletion test_catkin_virtualenv/test/test_virtualenv_script
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import unittest
class TestVirtualenv(unittest.TestCase):

def test_import_wrapt(self):
paulbovbel marked this conversation as resolved.
Show resolved Hide resolved
importlib.import_module("wrapt")
requests = importlib.import_module("requests")
self.assertEquals(requests.__version__, "2.20.1")


if __name__ == '__main__':
Expand Down
29 changes: 29 additions & 0 deletions test_catkin_virtualenv_inherited/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
cmake_minimum_required(VERSION 2.8.3)
project(test_catkin_virtualenv_inherited)

find_package(catkin REQUIRED COMPONENTS catkin_virtualenv)

catkin_package()

catkin_generate_virtualenv()

install(FILES requirements.txt
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})

if(CATKIN_ENABLE_TESTING)
find_package(rostest REQUIRED)

catkin_install_python(
PROGRAMS
test/test_virtualenv_script
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})

catkin_add_nosetests(test
DEPENDENCIES ${PROJECT_NAME}_generate_virtualenv
)

add_rostest(test/virtualenv_script.test
DEPENDENCIES ${PROJECT_NAME}_generate_virtualenv
)

endif()
44 changes: 44 additions & 0 deletions test_catkin_virtualenv_inherited/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<!--
Software License Agreement (GPL)

\file package.xml
\authors Paul Bovbel <pbovbel@locusrobotics.com>
\copyright Copyright (c) (2017,), Locus Robotics, All rights reserved.

This program is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 2 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<package format="2">
<name>test_catkin_virtualenv_inherited</name>
<version>0.2.1</version>
<description>Package to test inherited requirements.</description>

<maintainer email="pbovbel@locusrobotics.com">Paul Bovbel</maintainer>
<license>GPL</license>
<author email="pbovbel@locusrobotics.com">Paul Bovbel</author>

<buildtool_depend>catkin</buildtool_depend>

<build_depend>catkin_virtualenv</build_depend>

<depend>test_catkin_virtualenv</depend>

<test_depend>rostest</test_depend>

<export>
<pip_requirements>requirements.txt</pip_requirements>
</export>

</package>
1 change: 1 addition & 0 deletions test_catkin_virtualenv_inherited/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests==2.19.1
27 changes: 27 additions & 0 deletions test_catkin_virtualenv_inherited/test/test_virtualenv_library.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Software License Agreement (GPL)
#
# \file test_virtualenv_library.py
# \authors Paul Bovbel <pbovbel@locusrobotics.com>
# \copyright Copyright (c) (2017,), Locus Robotics, All rights reserved.
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import importlib
import unittest


class TestVirtualenv(unittest.TestCase):

def test_import_wrapt(self):
paulbovbel marked this conversation as resolved.
Show resolved Hide resolved
requests = importlib.import_module("requests")
self.assertEquals(requests.__version__, "2.19.1")
34 changes: 34 additions & 0 deletions test_catkin_virtualenv_inherited/test/test_virtualenv_script
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python
# Software License Agreement (GPL)
#
# \file test_virtualenv_script
# \authors Paul Bovbel <pbovbel@locusrobotics.com>
# \copyright Copyright (c) (2017,), Locus Robotics, All rights reserved.
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import importlib
import rostest
import sys
import unittest


class TestVirtualenv(unittest.TestCase):

def test_import_wrapt(self):
requests = importlib.import_module("requests")
self.assertEquals(requests.__version__, "2.19.1")


if __name__ == '__main__':
rostest.rosrun('test_catkin_virtualenv_inherited', 'test_virtualenv_script', TestVirtualenv, sys.argv)
24 changes: 24 additions & 0 deletions test_catkin_virtualenv_inherited/test/virtualenv_script.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<!--
Software License Agreement (GPL)

\file virtualenv_script.test
\authors Paul Bovbel <pbovbel@locusrobotics.com>
\copyright Copyright (c) (2017,), Locus Robotics, All rights reserved.

This program is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 2 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<launch>
<test test-name="virtualenv_script" pkg="test_catkin_virtualenv_inherited" type="test_virtualenv_script" />
</launch>
2 changes: 1 addition & 1 deletion test_catkin_virtualenv_py3/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
wrapt>=1.10.11
requests==2.20.1
3 changes: 2 additions & 1 deletion test_catkin_virtualenv_py3/test/test_virtualenv_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@
class TestVirtualenv(unittest.TestCase):

def test_import_wrapt(self):
importlib.import_module("wrapt")
requests = importlib.import_module("requests")
self.assertEquals(requests.__version__, "2.20.1")
5 changes: 3 additions & 2 deletions test_catkin_virtualenv_py3/test/test_virtualenv_script
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ import unittest
class TestVirtualenv(unittest.TestCase):

def test_import_wrapt(self):
importlib.import_module("wrapt")
requests = importlib.import_module("requests")
self.assertEquals(requests.__version__, "2.20.1")


if __name__ == '__main__':
rostest.rosrun('test_catkin_virtualenv', 'test_virtualenv_script', TestVirtualenv, sys.argv)
rostest.rosrun('test_catkin_virtualenv_py3', 'test_virtualenv_script', TestVirtualenv, sys.argv)
2 changes: 1 addition & 1 deletion test_catkin_virtualenv_py3/test/virtualenv_script.test
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<launch>
<test test-name="test_virtualenv_script_py3" pkg="test_catkin_virtualenv_py3" type="test_virtualenv_script" />
<test test-name="virtualenv_script" pkg="test_catkin_virtualenv_py3" type="test_virtualenv_script" />
</launch>