Add static files in PyPI package?

The minimal example code snippet provided in the Documentation, as shown below, doesn’t work when the package is installed from PyPI.

from commonroad_reach.data_structure.configuration_builder import ConfigurationBuilder
from commonroad_reach.data_structure.reach.reach_interface import ReachableSetInterface
from commonroad_reach.utility import visualization as util_visual

# ==== specify scenario
name_scenario = "ARG_Carcarana-1_1_T-1"

# ==== build configuration
config = ConfigurationBuilder.build_configuration(name_scenario)
config.update_configuration()
config.print_configuration_summary()

# ==== compute reachable sets using reachability interface
reach_interface = ReachableSetInterface(config)
reach_interface.compute_reachable_sets()

# ==== plot computation results
util_visual.plot_scenario_with_reachable_sets(reach_interface)

Other than the interface having slightly changed, not all static files are installed. As shown below, I only found configurations_default in my installation directory.

$ ls /opt/anaconda/envs/creach-pypi/lib/python3.8/site-packages/commonroad_reach
configurations_default  data_structure  __init__.py  __pycache__  pycrreach.cpython-38-x86_64-linux-gnu.so  utility  __version__.py

For me to be able to run the example, I had to

builder = ConfigurationBuilder(
    path_root='/absolute-path-cloned-repo',
    dir_config_default='commonroad_reach/configurations_default',
)
builder.build_configuration(name_scenario)

One solution might be to extend MANIFEST.in to include those files and use pkgutil to retrieve the paths in configuration_builder.py. This stackoverflow answer can be useful.


Thanks for sharing your code! Can I help?

I don’t know if you are open to contributions, I couldn’t find any guidelines or a place to open a pull request. If that’s the case, I would be happy to help.

Hi Boyan,

thanks for your post. Yes you are right, the interface for ConfigurationBuilder needs to be updated in the minimal example, thanks for spotting that!

However, I don’t fully understand the issue. The static files (i.e., the default configuration yaml files) are included in the PyPi package and can also be detected correctly. If, a custom config file should be specified (e.g., for scenario ARG_Carcarana-1_1_T-1), then the user would need to provide that explictly. Otherwise, the COnfigurationBuilder simply retreives the default values from the configurations_default folder in the package. Similarly, any values not specified in a custom config file are retrieved from there. We could, however make it more clear to the user in the minimal example, how a custom configuration file would be passed. Let me know if that would help.

Regarding contributing: Currently we are hosting the code on our TUM Gitlab platform, which unfortunately makes it hard for external users to contribute. For that reason we decided to migrate our CommonRoad Repos to Github, then you could contribute via issues/pull requests. I will notify you again in this post, once we this is done. In any case, we are always very happy about any contributions and help to improve the code :slight_smile:

Regards,
Gerald

Hi Gerald,

I am happy to hear about the migration. It’s also amazing to see you not only open sourced, but are also actively maintaining the project, great work! :+1:

More documentation on working with custom scenarios and configurations would be great, but I don’t believe it’s necessary for the minimal example. I find it less intimidating when I can get something up and running with the fewest lines possible :grin:

There is nothing wrong with the default configurations, my issue was that other static files are missing. More specifically:

  1. Lookup tables for longitudinal enlargement
  2. Scenarios
    • Perhaps just add commonroad-scenarios as dependency and load them from there?
  3. Scenario configurations

If I currently run the minimal example by having the package installed via pip, but not cloned locally, I get

from commonroad_reach.data_structure.configuration_builder import ConfigurationBuilder

config = ConfigurationBuilder().build_configuration('ARG_Carcarana-1_1_T-1')
# As in example. This is what causes the error.
config.update()
FileNotFoundError: [Errno 2] No such file or directory: 'scenarios/ARG_Carcarana-1_1_T-1.xml'

Once all files are available on PyPI, they should be loaded from the site-packages directory when path_root is not specified. I suspect there might be issues with that, as the current working directory is used by default, see configuration_builder.py.

Best regards,
Boyan