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

Set ROS_PYTHON_VERSION if unset #708

Merged
merged 8 commits into from
Oct 10, 2019
Merged

Set ROS_PYTHON_VERSION if unset #708

merged 8 commits into from
Oct 10, 2019

Conversation

sloretz
Copy link
Contributor

@sloretz sloretz commented Sep 25, 2019

Requires ros-infrastructure/rosdistro#145

This sets ROS_PYTHON_VERSION if it is unset. This enables rosdep to resolve conditional dependencies using ROS_PYTHON_VERSION before building a ROS distribution from source.

If --rosdistro is given, it tries to use the python_version field from the rosdistro index. Otherwise, it uses the same version of python used to invoke rosdep as mentioned in ros-infrastructure/rep#201

To try out the python_version attribute, update using a custom rosdistro index url

ROSDISTRO_INDEX_URL=https://raw.githubusercontent.com/ros/rosdistro/dirk-thomas/add-python_version-to-index/index-v4.yaml rosdep update

To test, get a package using conditional dependencies and run the commands below with no ROS workspace sourced.

git clone https://github.com/ros/urdf_parser_py.git -b py3-port

Before this PR

(env3) sloretz@7895d0788081:/tmp$ rosdep check --from-paths urdf_parser_py/ --ignore-src --skip-keys="rospy catkin"
All system dependencies have been satisfied

no rosdistro after this PR

sloretz@b0e9deb48a5e:~$ rosdep check --from-paths urdf_parser_py/ --ignore-src --skip-keys="rospy catkin"
WARNING: ROS_PYTHON_VERSION is unset. Defaulting to 3
System dependencies have not been satisfied:
apt	python3-lxml
apt	python3-mock

melodic

sloretz@b0e9deb48a5e:~$ rosdep check --rosdistro melodic --from-paths urdf_parser_py/ --ignore-src --skip-keys="rospy catkin"
System dependencies have not been satisfied:
apt	python-lxml
apt	python-yaml
apt	python-mock

noetic

sloretz@b0e9deb48a5e:~$ rosdep check --rosdistro noetic --from-paths urdf_parser_py/ --ignore-src --skip-keys="rospy catkin"
System dependencies have not been satisfied:
apt	python3-lxml
apt	python3-mock

wjwwood
wjwwood previously approved these changes Sep 26, 2019
Copy link
Contributor

@wjwwood wjwwood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Contributor

@nuclearsandwich nuclearsandwich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed this a bit offline today. My main concern is that I think many devs use the python2 or python3 versions of the tools exclusively since they cannot be co-installed system-wide. Which means that it's somewhat luck-of-the-draw whether a developer is using python2 or python3 tools with a python2 or python3 workspace. If this were a tool that operated inside a ROS workspace context, this would make a lot of sense, but since rosdep is system-wide I think that this default needs a warning since it has nearly a 50-50 chance of being the wrong choice.

@dirk-thomas
Copy link
Member

With ros-infrastructure/rep#207 in flight that information could be used here too.

@codecov-io
Copy link

codecov-io commented Oct 3, 2019

Codecov Report

Merging #708 into master will increase coverage by 0.31%.
The diff coverage is 82.05%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #708      +/-   ##
==========================================
+ Coverage   75.82%   76.14%   +0.31%     
==========================================
  Files          38       40       +2     
  Lines        3032     3106      +74     
==========================================
+ Hits         2299     2365      +66     
- Misses        733      741       +8
Impacted Files Coverage Δ
src/rosdep2/meta.py 100% <100%> (ø)
src/rosdep2/main.py 49.36% <50%> (+0.01%) ⬆️
src/rosdep2/sources_list.py 87.78% <66.66%> (+1.86%) ⬆️
src/rosdep2/cache_tools.py 73.46% <73.46%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 39cf725...dd4bf62. Read the comment docs.

@sloretz
Copy link
Contributor Author

sloretz commented Oct 3, 2019

@nuclearsandwich added warning in 88816ef

Copy link
Member

@dirk-thomas dirk-thomas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use the information from the updated REP 153.

@sloretz
Copy link
Contributor Author

sloretz commented Oct 3, 2019

This should use the information from the updated REP 153.

REP 153 python_version can be used instead of sys.version[0] when --rosdistro is set. That seems more like an enhancement than a blocker.

@dirk-thomas
Copy link
Member

REP 153 python_version can be used instead of sys.version[0] when --rosdistro is set. That seems more like an enhancement than a blocker.

it has nearly a 50-50 chance of being the wrong choice.

With the high probability of doing the wrong thing I wouldn't call this an enhancement. I think we should do it right when we can (when --rosdistro is available).

Warn when ROS_PYTHON_VERSION is being defaulted

Signed-off-by: Shane Loretz <[email protected]>
Import from new file cache_tools.py

Signed-off-by: Shane Loretz <[email protected]>
Adds a new cache directory for meta data.
Stores python version for each rosdistro in the metadata cache.

Signed-off-by: Shane Loretz<[email protected]>
Signed-off-by: Shane Loretz <[email protected]>
@sloretz sloretz force-pushed the sloretz/ros-python-version branch from 88816ef to d72c4a3 Compare October 3, 2019 18:55
@sloretz sloretz dismissed stale reviews from dirk-thomas, nuclearsandwich, and wjwwood October 3, 2019 19:01

Major changes since review

@sloretz sloretz requested review from dirk-thomas and wjwwood October 3, 2019 19:02
@sloretz
Copy link
Contributor Author

sloretz commented Oct 3, 2019

I think we should do it right when we can (when --rosdistro is available).

@dirk-thomas PR and PR description updated

Copy link
Contributor

@wjwwood wjwwood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, with one question.

@@ -391,6 +392,18 @@ def _rosdep_main(args):
check_for_sources_list_init(options.sources_cache_dir)
elif command not in ['fix-permissions']:
setup_proxy_opener()

if 'ROS_PYTHON_VERSION' not in os.environ and options.ros_distro:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't options.ros_distro take precedence over the environment variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

options.ros_distro overriding ROS_PYTHON_VERSION might be a problem for Arch Linux users. They seem to be using Python 3: https://aur.archlinux.org/packages/ros-melodic-catkin/ with melodic. If options.ros_distro takes precedence then with #709 pip dependencies would be installed with Python 2 using Melodic on Arch.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #708 (comment) why on other platforms the rosdistro configured value must have precedence.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wjwwood I think this is resolved by dd4bf62 (explanation in #708 (comment)). Would you mind having another look at this PR?

Copy link
Member

@dirk-thomas dirk-thomas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't looked at the added MetaDatabase logic. I will leave that up to the maintainer(s) of rosdep.

src/rosdep2/main.py Outdated Show resolved Hide resolved
src/rosdep2/sources_list.py Show resolved Hide resolved
Signed-off-by: Shane Loretz <[email protected]>
Signed-off-by: Shane Loretz <[email protected]>
Python 2 compatibility
Missing imports

Signed-off-by: Shane Loretz<[email protected]>
Signed-off-by: Shane Loretz <[email protected]>
@sloretz
Copy link
Contributor Author

sloretz commented Oct 7, 2019

I haven't looked at the added MetaDatabase logic. I will leave that up to the maintainer(s) of rosdep.

Added tests in 830db97. They pass in Python 2 and Python 3 as of 8a2f954.

Signed-off-by: Shane Loretz <[email protected]>
This allows users with a melodic workspace sourced to install
dependencies for a noetic workspace, while still allowing users on
community supported platforms to override the python version.

Signed-off-by: Shane Loretz<[email protected]>
Signed-off-by: Shane Loretz <[email protected]>
@sloretz sloretz requested a review from wjwwood October 10, 2019 17:36
@sloretz
Copy link
Contributor Author

sloretz commented Oct 10, 2019

CI failure looks like a temporary network issue

======================================================================

ERROR: test.test_rosdep_source.test_install_source

----------------------------------------------------------------------

Traceback (most recent call last):

  File "/opt/python/3.6.7/lib/python3.6/urllib/request.py", line 1318, in do_open

    encode_chunked=req.has_header('Transfer-encoding'))

  File "/opt/python/3.6.7/lib/python3.6/http/client.py", line 1239, in request

    self._send_request(method, url, body, headers, encode_chunked)

  File "/opt/python/3.6.7/lib/python3.6/http/client.py", line 1285, in _send_request

    self.endheaders(body, encode_chunked=encode_chunked)

  File "/opt/python/3.6.7/lib/python3.6/http/client.py", line 1234, in endheaders

    self._send_output(message_body, encode_chunked=encode_chunked)

  File "/opt/python/3.6.7/lib/python3.6/http/client.py", line 1026, in _send_output

    self.send(msg)

  File "/opt/python/3.6.7/lib/python3.6/http/client.py", line 964, in send

    self.connect()

  File "/opt/python/3.6.7/lib/python3.6/http/client.py", line 1392, in connect

    super().connect()

  File "/opt/python/3.6.7/lib/python3.6/http/client.py", line 936, in connect

    (self.host,self.port), self.timeout, self.source_address)

  File "/opt/python/3.6.7/lib/python3.6/socket.py", line 724, in create_connection

    raise err

  File "/opt/python/3.6.7/lib/python3.6/socket.py", line 713, in create_connection

    sock.connect(sa)

TimeoutError: [Errno 110] Connection timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/nose/case.py", line 198, in runTest

    self.test(*self.arg)

  File "/home/travis/build/ros-infrastructure/rosdep/test/test_rosdep_source.py", line 318, in test_install_source

    install_source(resolved)

  File "/home/travis/build/ros-infrastructure/rosdep/src/rosdep2/platforms/source.py", line 278, in install_source

    f = urlretrieve(resolved.tarball, filename)

  File "/opt/python/3.6.7/lib/python3.6/urllib/request.py", line 248, in urlretrieve

    with contextlib.closing(urlopen(url, data)) as fp:

  File "/opt/python/3.6.7/lib/python3.6/urllib/request.py", line 223, in urlopen

    return opener.open(url, data, timeout)

  File "/opt/python/3.6.7/lib/python3.6/urllib/request.py", line 526, in open

    response = self._open(req, data)

  File "/opt/python/3.6.7/lib/python3.6/urllib/request.py", line 544, in _open

    '_open', req)

  File "/opt/python/3.6.7/lib/python3.6/urllib/request.py", line 504, in _call_chain

    result = func(*args)

  File "/opt/python/3.6.7/lib/python3.6/urllib/request.py", line 1361, in https_open

    context=self._context, check_hostname=self._check_hostname)

  File "/opt/python/3.6.7/lib/python3.6/urllib/request.py", line 1320, in do_open

    raise URLError(err)

urllib.error.URLError: <urlopen error [Errno 110] Connection timed out>

@sloretz sloretz merged commit 42c8fed into master Oct 10, 2019
@sloretz sloretz deleted the sloretz/ros-python-version branch October 10, 2019 18:38

if 'ROS_PYTHON_VERSION' not in os.environ and 'ROS_DISTRO' in os.environ:
# Set python version to version used by ROS distro
python_versions = MetaDatabase().get('ROS_PYTHON_VERSION')
Copy link

@acarrillo acarrillo Oct 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like MetaDatabase().get('ROS_PYTHON_VERSION') can return None here, it's causing my CI builds to fail after I upgraded to rosdep 0.16.2: #720

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix proposed in #721

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants