You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[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:
47
47
Apache-2.0
48
48
BSL-1.0
49
49
BSD-2.0
@@ -58,21 +58,25 @@ The folders/files, Mason, what do they mean?
58
58
--------------------------------------------
59
59
60
60
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`.
61
62
62
63
.. code-block:: console
63
-
:emphasize-lines: 1,2
64
+
:emphasize-lines: 1,3
64
65
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
76
80
77
81
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.
78
82
@@ -105,17 +109,24 @@ Overview of the library
105
109
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.
106
110
107
111
.. code-block:: console
108
-
:emphasize-lines: 4,5,6
112
+
:emphasize-lines: 6-8
109
113
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
119
130
120
131
With respect to the highlighted files, we will
121
132
@@ -152,35 +163,6 @@ Create a new file with the following contents and name.
152
163
:lines: 26-
153
164
154
165
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
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.
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/>`_.
0 commit comments