Skip to content

Commit

Permalink
Merge pull request #65 from pyros-dev/pipenv
Browse files Browse the repository at this point in the history
Pipenv
  • Loading branch information
asmodehn committed Jul 4, 2019
2 parents a83561a + d845a15 commit 97629c5
Show file tree
Hide file tree
Showing 14 changed files with 157 additions and 60 deletions.
2 changes: 2 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export PIPENV_SITE_PACKAGES=true
layout pipenv --site-packages
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,7 @@ ENV/

# Pycharm
.idea

# pipenv for multi version
Pipfile.lock

6 changes: 2 additions & 4 deletions .pyup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ search: False
# default: empty
# allowed: list
requirements:
- dev-requirements.txt:
update: True
- doc-requirements.txt:
update: True
- Pipfile
- Pipfile.lock

# add a label to pull requests, default is not set
# requires private repo permissions, even on public repos
Expand Down
18 changes: 8 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
sudo: required
language: generic
services:
- docker
Expand All @@ -18,18 +17,17 @@ env:
# This will check any ROS distro supported on this OS
# checking devel and install separately so that they don't influence each other (dependencies, path, env, etc.)
matrix:
- ROS_DISTRO=indigo PYTHON=2.7
- ROS_DISTRO=indigo PYTHON=3.4
# REMINDER : Python3 is NOT supported by ROS.

- ROS_DISTRO=jade PYTHON=2.7
- ROS_DISTRO=jade PYTHON=3.4
- ROS_DISTRO=indigo PYTHON=2.7
#- ROS_DISTRO=indigo PYTHON=3.4

- ROS_DISTRO=kinetic PYTHON=2.7
- ROS_DISTRO=kinetic PYTHON=3.5
#- ROS_DISTRO=kinetic PYTHON=3.5

- ROS_DISTRO=melodic PYTHON=2.7
#- ROS_DISTRO=melodic PYTHON=3.6

# docker image not available yet
#- ROS_DISTRO=lunar PYTHON=2.7
#- ROS_DISTRO=lunar PYTHON=3.5
# TODO : pypy + pypy3

before_install:
Expand All @@ -52,7 +50,7 @@ install:
# copying local clone to the running container (volume is currently broken)
- docker cp . ${CONTAINER_NAME}:/git_clone
# getting virtualenv setup with dependencies
- docker exec -ti ${CONTAINER_NAME} /bin/bash -c "source /usr/share/virtualenvwrapper/virtualenvwrapper.sh && mkvirtualenv --system-site-packages -i /git_clone -a /git_clone -q python_${PYTHON}_ros"
- docker exec -ti ${CONTAINER_NAME} /bin/bash -c "source /usr/share/virtualenvwrapper/virtualenvwrapper.sh && mkvirtualenv --python=/usr/bin/python${PYTHON} --system-site-packages -i pip -i \"setuptools>12\" -i /git_clone -a /git_clone -q python_${PYTHON}_ros"

# full ROS setup, build and test
script:
Expand Down
18 changes: 18 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
gitchangelog = "*"
twine = "==1.11.0"
wheel = "==0.30.0"

[packages]
six = ">=1.10.0"
pytest = ">=2.9.2"
pyros-config = ">=0.2.1"

[requires]
# ROS1 officially only supports python 2.7
python_version = "2.7"
66 changes: 59 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,27 @@ Pyros-setup
.. image:: https://travis-ci.org/asmodehn/pyros-setup.svg?branch=master
:target: https://travis-ci.org/asmodehn/pyros-setup

Toolsuite for running ROS environments directly from python code, without any specific requirements outside of usual python.
Toolsuite for using ROS environments directly from python code, without any specific requirements outside of usual python.

This is a pure python package, to be installed in your system, in order to allow easy ROS access from your python environment.

Note : If instead you prefer doing things the other way around, to embed existing python packages in the ROS environment, this is possible thanks to [catkin_pip](https://github.com/asmodehn/catkin_pip)

Prerequisites
^^^^^^^^^^^^^

ROS should be installed on your system.
Example with ROS melodic on Ubuntu Bionic::

sudo apt install ros-melodic-ros-base

This will setup everything you need for using ROS with python2.7
More information there : http://wiki.ros.org/melodic/Installation/Ubuntu

Then you need to make sure the Python2 virtual environment in which you are working allows access to system packages.
More information there : https://virtualenv.pypa.io/en/latest/userguide/#the-system-site-packages-option


HowTo install
^^^^^^^^^^^^^

Expand Down Expand Up @@ -47,10 +64,18 @@ This is useful for development along with ROS packages::
$ py.test -s --pyargs pyros_setup --distro=indigo


HowTo code
^^^^^^^^^^
HowTo develop
^^^^^^^^^^^^^

After cloning the repository, you can use pipenv to setup your development environment.
Be careful to allow access to system packages::

pipenv --two --system-packages

HowTo use
^^^^^^^^^

Basically it allows you to do this::
Basically pyros_setup allows you to do this::

try:
import rospy
Expand All @@ -77,17 +102,44 @@ Note: If you know any easier / less tricky / more pythonic way of handling confi
HowTo deploy
^^^^^^^^^^^^

If you want to use pyros-setup, you should use the pip package, since the whole point is to provide access to ROS from pure python environment.
This is now possible thanks to [catkin_pip](https://github.com/asmodehn/catkin_pip)
If you want to use pyros-setup as a dependency of your package, you should depend on the pip package.
Afterall, the whole point is to provide access to ROS from a pure python environment.


Python3
^^^^^^^

DISCLAIMER: This is not compatible with catkin_pip usage. Also NOT SUPPORTED.
Attempt this at your own risk.

But since python2 is almost dead, we might want to move to python3 already.
Just remember that ROS does not support python3 out of the box, and significant tinkering is required.

For python3, you will need to install dependent python packages in your python3 virtual environment.
For example, pyros-setup itself only requires rospkg and pyyaml for the tests to pass::

pip3 install pyyaml rospkg


More information there : https://answers.ros.org/question/237613/how-to-define-ros-kinetic-to-use-python3-instead-of-python27/


Remarks
^^^^^^^

Although it would technically be possible to build a ROS package from this source, this will NOT be done.
The catkin build system is only here to help having pyros-setup in a source workspace while developing on it.
The catkin_pip build system that was here once, was only here to help having pyros-setup in a source workspace while developing on it.
When using ROS directly this package is not needed, and having it installed among ROS packages would cause much useless confusion with python import mechanism.


Roadmap
^^^^^^^

- The way forward seems to build a ROS wheel from source, with the basic packages inside...
This will make it compatible with any python environment, easily installable, and isolate it from the operating system.

- This code might eventually be migrated into rosimport, which, as a larger scope, focuses on python environments interoparability with ROS.

Troubleshooting
^^^^^^^^^^^^^^^

Expand Down
6 changes: 0 additions & 6 deletions dev-requirements.txt

This file was deleted.

6 changes: 0 additions & 6 deletions doc-requirements.txt

This file was deleted.

12 changes: 4 additions & 8 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.

## get catkin package information
import os
import catkin_pkg.package
catkin_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
catkin_package = catkin_pkg.package.parse_package(
os.path.join(catkin_dir, catkin_pkg.package.PACKAGE_MANIFEST_FILENAME))
with open('../pyros_setup/_version.py') as vf:
exec(vf.read())

# -- General configuration ---------------------------------------------------

Expand Down Expand Up @@ -57,9 +53,9 @@
# built documents.
#
# The short X.Y version.
version = catkin_package.version
version = __version__
# The full version, including alpha/beta/rc tags.
release = catkin_package.version
release = __version__

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
28 changes: 28 additions & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.. _index:

Pyros-Setup
===========

Toolsuite for running ROS environments directly from python code, without any specific requirements outside of usual python.

This is a pure python package, to be installed in your system, in order to allow easy ROS access from your python environment.

.. include:: weblinks.rst


Contents:

.. toctree::
:maxdepth: 2

readme_link
overview
develop
changelog_link

Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`

19 changes: 19 additions & 0 deletions example_usage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
try:
import rospy
import roslaunch
import rosgraph
import rosnode
except ImportError: # if ROS environment is not setup, we emulate it.
print("!!! Original import failed. Attempting Pyros-Setup...")
import pyros_setup
pyros_setup.configurable_import().configure('mysetup.cfg').activate() # this will use mysetup.cfg from pyros-setup instance folder

import rospy
import roslaunch
import rosgraph
import rosnode

print("rospy from: " + rospy.__file__)
print("roslaunch from: " + roslaunch.__file__)
print("rosgraph from: " + rosgraph.__file__)
print("rosnode from: " + rosnode.__file__)
8 changes: 5 additions & 3 deletions pyros_setup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
from pyros_config import ConfigHandler

#: Smart Default distro detection (as early as possible)
if os.path.exists('/opt/ros/lunar'):

if os.path.exists('/opt/ros/melodic'):
DETECTED_DISTRO = 'melodic'
elif os.path.exists('/opt/ros/lunar'):
DETECTED_DISTRO = 'lunar'
elif os.path.exists('/opt/ros/kinetic'):
DETECTED_DISTRO = 'kinetic'
Expand Down Expand Up @@ -55,8 +58,7 @@ def configurable_import(instance_path=None, instance_relative_config=True, root_
class PyrosSetup(object):
def __init__(self, instance_path=None, instance_relative_config=True, root_path=None):

# TODO : when used from system : use (default) instance path to /opt/ros/DETECTED_DISTRO/pyros
# TODO : when used from venv : use calculated instance path (inside venv)
# TODO : use calculated instance path (inside venv)

# we delegate config related behavior (including defaults)
self.config_handler = ConfigHandler(
Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,15 @@ def run(self):
install_requires=[
'six>=1.10.0', # to be compatible with latest pkg_resources requirements
'pyros_config>=0.2.0',
'pytest>=2.5.1'
'pytest>=2.9.2'
],
setup_requires=[
'pytest-runner',
# 'twine' # this requires requests >= 2.5.0, which breaks on trusty...
],
tests_require=[
'pyyaml',
'rospkg'
],
cmdclass={
'prepare_release': PrepareReleaseCommand,
Expand Down
20 changes: 5 additions & 15 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
# content of: tox.ini , put in same dir as setup.py
# This requires tox-pipenv to use the pipfile to populate the tox virtualenvs
[tox]
skip_missing_interpreters = true
envlist = py27
# Test fails ! requires pyros_config >1.2
#, py34
#, py35

# NOT SUPPORTED, because we dont want to merge packages for different interpreters.
#, py34, py35, py36, py37

#, pypy
#, pypy3

[tox:travis]
2.7 = py27

# This requires pyros_config >1.2
#3.4 = py34
# TODO : link ROS distro and python3 version...

# not tested yet
#pypy = pypy
#pypy3 = pypy3

[testenv]
# to always force recreation and avoid unexpected side effects
recreate=True
Expand Down

0 comments on commit 97629c5

Please sign in to comment.