Skip to content

Refactoring C++ extension modules to make them more Pythonic

Juan F. Esteban Müller requested to merge refactoring_import into main

This MR should fix the issue that was causing some confusion to @yngvelevinsen and me, namely that one had to do import orbit.core before all extension modules became available.

With this MR, all extension modules are members of the orbit.core package. Importing modules is done in a more Pythonic way, e.g.:

  • import orbit.core will import all extension modules.
  • from orbit.core import bunch will import the bunch module.
  • from orbit.core.bunch import Bunch will import the Bunch class from the bunch module.
  • from orbit import core will also work to import all extension modules as subpackages of the core package.

This MR breaks compatibility with the previous intended usage of pyORBIT3. The following snippet will raise a ModuleNotFoundError:

import orbit.core
import bunch

However this MR keeps backward compatibility with previous pyORBIT scripts by adding a bash script that replicates the behavior of the pyORBIT executable. The script loads the pyORBIT dynamic library and makes the extension modules available for being imported.

When used without arguments, the pyORBIT script will launch an interactive Python interpreter with the pyORBIT shared library preloaded. For example, a user can do:

$ pyORBIT 
>>> import bunch
>>> 

When a pyORBIT script is passed as an argument, it will execute it as usual.

Edited by Juan F. Esteban Müller

Merge request reports

Loading