Performing a `colcon build` is neccessary after every change to the `src` directory. This must be performed in the `root` of the _colcon_ workspace (eg. `cd ~/colcon_ws`).
In order to avoid this procedure after every change made to a Python script you must run `colcon build --symlink-install` once. This links the files created in `/build` and `/install` to your source files in `/src`. However, after creating a new Python script this procedure must be repeated in order to also link this new script.
The source directory holds your ROS2 packages in the form of directories. In this example the `src` directory contains the exemplary packages `pubsub` and `pubsub_msg`:
The next chapters will describe the content of the files inside a package directory. However, the occuring files depend on the type of package (`ament_cmake` for C++ scripts or `ament_python` for Python scripts). This is described in detail [here](https://docs.ros.org/en/foxy/Tutorials/Creating-Your-First-ROS2-Package.html). The following chapters only describe Python packages (eg. `pubsub/`).
The file _setup.py_ is used to create entry points, meaning you link your python scripts to names which you can be called through `ros2 run ...`. In order for this to work your python scripts must be written using the following mechanism
The _setup.py_-excerp above links the the function `main()` from the scripts _talker.py_ and _listener.py_ from inside `/pubsub` to the names _talker_ and _listener_. This way they can be called using `ros2 run pubsub talker` or `ros2 run pubsub listener`.
From this you can see that you need to follow the Python programming style of creating a _main()_ procedure, in order for the entry points to work.
The file _package.xml_ is used to link dependencies to this package. For example, if this package requires a _*.msg_ file which is located inside a different package this is defined in _package.xml_, eg.
The example package `pubsub/` contains a directory of the same name as the package. This is where you place your Python scripts. Inside this directory you are free to do as you please, however keep in mind that you need to link your main script (eg. `listener.py`) to a name later on (using _setup.py_).