Skip to content

Rework package structure and documentation

What does the code in the MR do ?

The overall objectives

This MR proposes to modernize the package structure and documentation:

  • Use an src layout for the package instead of a flat layout
  • Update the poetry.lock file with Poetry v2, which will be required to install Leaspy
  • Use the auto-api extension to generate automatically the API documentation
  • Remove all the RST files which were basically doing what auto-api is doing for free
  • Use the myst_nb extension to rely on Markdown rather than RST for writing documentation (it will be easier for contributors to write docs)
  • Rewrite the existing documentation pages from RST to Markdown (I need to check that I didn't do too many mistakes doing that...)
  • Run the formatting tools on all python files (it was the opportunity since the were all moved to the src folder...)

The package architectural changes

When moving to the src layout I faced a lot of circular import issues which are linked to the architecture of the package. Currently, these problems are masked by having some imports under an if TYPE_CHECKING block. In this MR, I removed all of these and had to restructure things a bit:

  • The AlgorithmSettings are now inside of the algo module and not in io.settings
  • The ModelSettings are now inside of the models module and not in io.settings (the latter was thus deleted)
  • The noise_models module was deleted as well as related tests which is why we went from 9 failing tests to 4
  • The public API of each module is declared in __all__ and imports have been made more straightforward
  • The Loader class in the module datasets have been replaced by simple functions
  • The algo and model class factories were replaced by functions with enumerations (a much simpler pattern that we use a lot in other projects, we can of course discuss this point if you disagree)

The public "API"

What is currently called the "API" (i.e. the Leaspy class as well as the quick imports) was modified a bit. In my opinion the Leaspy class is useless and misleading and I really think it should disappear at some point. In this MR I kept it (just do from leapsy.api import Leaspy instead of from leaspy import Leaspy). The quick imports (like from leapsy import Data or from leapsy import AlgorithmSettings have been deleted and users should import from the right module: from leapsy.io.data import Data or from leaps.algo import AlgorithmSettings).

Next steps

There is still a lot of work to make the package structure better (the io module for example could be refactored), but since this is already a huge MR, I think we can target those in follow-up MRs.

Where should the reviewer start ?

Honestly, the diff is almost impossible to make sense of. I think the easiest way is to get the branch locally and look at the code and structure in an IDE. The documentation changes can be analyzed by looking at the deployed doc and the new Markdown files.

How can the code be tested ?

The tests are passing, except 4 tests that are already broken on V2 due to the Ordinal models. We went from 9 broken tests to 4 because I removed the noise models and the related tests.

When is the MR due for? (review deadline)

What issues are linked to the MR ?

Edited by Nicolas Gensollen

Merge request reports

Loading