Skip to content

Commit 0be2e1c

Browse files
committed
[create_python_library.rst] Adjusted for Jazzy.
1 parent 74478bd commit 0be2e1c

1 file changed

Lines changed: 36 additions & 54 deletions

File tree

docs/source/create_python_library.rst

Lines changed: 36 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ which outputs the forever beautiful wall of text we're now used to, with a minor
1717
1818
going to create a new package
1919
package name: python_package_with_a_library
20-
destination directory: /home/murilo/git/ROS2_Tutorial/ros2_tutorial_workspace/src
20+
destination directory: /root/ros2_tutorial_workspace/src
2121
package format: 3
2222
version: 0.0.0
2323
description: TODO: Package description
24-
maintainer: ['murilo <murilomarinho@ieee.org>']
24+
maintainer: ['root <murilo.marinho@manchester.ac.uk>']
2525
licenses: ['TODO: License declaration']
2626
build type: ament_python
2727
dependencies: []
@@ -43,7 +43,7 @@ which outputs the forever beautiful wall of text we're now used to, with a minor
4343
creating ./python_package_with_a_library/python_package_with_a_library/sample_python_library/__init__.py
4444
4545
[WARNING]: Unknown license 'TODO: License declaration'. This has been set in the package.xml, but no LICENSE file has been created.
46-
It is recommended to use one of the ament license identitifers:
46+
It is recommended to use one of the ament license identifiers:
4747
Apache-2.0
4848
BSL-1.0
4949
BSD-2.0
@@ -58,21 +58,25 @@ The folders/files, Mason, what do they mean?
5858
--------------------------------------------
5959

6060
The ROS2 package created from the template has a structure like so. In particular, we can see that :file:`python_package_with_a_library` is repeated twice in a row. This is a common source of error, so don't forget!
61+
The first is the name of the :program:`ROS2` package, and the second is the name of Python package that will be installed by :program:`ROS2`.
6162

6263
.. code-block:: console
63-
:emphasize-lines: 1,2
64+
:emphasize-lines: 1,3
6465
65-
python_package_with_a_library
66-
└── python_package_with_a_library
67-
└── sample_python_library
68-
__init__.py
69-
__init__.py
70-
└── resource
71-
python_package_with_a_library
72-
└── test
73-
package.xml
74-
setup.cfg
75-
setup.py
66+
python_package_with_a_library/
67+
|-- package.xml
68+
|-- python_package_with_a_library
69+
| |-- __init__.py
70+
| `-- sample_python_library
71+
| `-- __init__.py
72+
|-- resource
73+
| `-- python_package_with_a_library
74+
|-- setup.cfg
75+
|-- setup.py
76+
`-- test
77+
|-- test_copyright.py
78+
|-- test_flake8.py
79+
`-- test_pep257.py
7680
7781
We learned the meaning of most of those in the preamble, namely :ref:`Python Best Practices`. To quickly clarify a few things, see the table below.
7882

@@ -105,17 +109,24 @@ Overview of the library
105109
For the sake of the example, let us create a library with a Python :code:`function` and another one with a :code:`class`. To guide our next steps, we first draw a quick overview of what our :code:`python_package_with_a_library` will look like.
106110

107111
.. code-block:: console
108-
:emphasize-lines: 4,5,6
112+
:emphasize-lines: 6-8
109113
110-
python_package_with_a_library
111-
└── python_package_with_a_library
112-
└── sample_python_library
113-
__init__.py
114-
_sample_class.py
115-
_sample_function.py
116-
__init__.py
117-
└── resource
118-
└── test
114+
python_package_with_a_library/
115+
|-- package.xml
116+
|-- python_package_with_a_library
117+
| |-- __init__.py
118+
| `-- sample_python_library
119+
| |-- __init__.py
120+
| |-- _sample_class.py
121+
| `-- _sample_function.py
122+
|-- resource
123+
| `-- python_package_with_a_library
124+
|-- setup.cfg
125+
|-- setup.py
126+
`-- test
127+
|-- test_copyright.py
128+
|-- test_flake8.py
129+
`-- test_pep257.py
119130
120131
With respect to the highlighted files, we will
121132

@@ -152,35 +163,6 @@ Create a new file with the following contents and name.
152163
:lines: 26-
153164

154165
The class is quite simple with a `private data member <https://docs.python.org/3/tutorial/classes.html#private-variables>`_ and a method to retrieve it.
155-
156-
Modify the :code:`__init__.py` to export the symbols
157-
----------------------------------------------------
158-
159-
With the necessary files created and properly organized, the last step is to :code:`import` the function and the class. We modify proper :file:`__init__.py` file with the following contents.
160-
161-
:download:`~/ros2_tutorial_workspace/src/python_package_with_a_library/python_package_with_a_library/sample_python_library/__init__.py <../../ros2_tutorial_workspace/src/python_package_with_a_library/python_package_with_a_library/sample_python_library/__init__.py>`
162-
163-
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_with_a_library/python_package_with_a_library/sample_python_library/__init__.py
164-
:language: python
165-
:linenos:
166-
:lines: 24-
167-
168-
Modify the :code:`setup.py` to export the packages
169-
--------------------------------------------------
170-
171-
.. warning::
172-
This step might be unnecessary after `this fix <https://github.com/ros2/ros2cli/issues/833>`_.
173-
174-
.. note::
175-
176-
This is a *one-size-fits-most* solution, which might not work for certain Python package structures. As a generic solution, we will export all Python packages in the ROS2 package excluding the `test` directory. For more information on :program:`setuptools`, see the `official Python packaging docs <https://packaging.python.org/en/latest/guides/distributing-packages-using-setuptools/>`_.
177-
178-
:download:`~/ros2_tutorial_workspace/src/python_package_with_a_library/setup.py <../../ros2_tutorial_workspace/src/python_package_with_a_library/setup.py>`
179-
180-
.. literalinclude:: ../../ros2_tutorial_workspace/src/python_package_with_a_library/setup.py
181-
:language: python
182-
:linenos:
183-
:emphasize-lines: 1,8
184166

185167
Build and source
186168
----------------

0 commit comments

Comments
 (0)