pythonpython-3.xsetuptoolspyproject.toml

Building a PyPi package using setuptools & pyproject.toml with a custom directory tree


I have a custom directory structure which is not the traditional "src" or "flat" layouts setuptools expects.

This is a sample of the directory tree:

my_git_repo/
├── Dataset/
│ ├── __init__.py
│ ├── data/
│ │ └── some_csv_file.csv
│ ├── some_ds1_script.py
│ └── some_ds2_script.py
└── Model/
├── __init__.py
├── utils/
│ ├── __init__.py
│ ├── some_utils1_script.py
│ └── some_utils2_script.py
└── some_model/
├── __init__.py
├── some_model_script.py
└── trained_models/
├── __init__.py
└── model_weights.pkl

Lets say that my package name inside the pyproject.toml is "my_ai_package" and the current packages configuration is:

[tools.setuptools.packages.find]
include = ["*"]
namespaces = false

After building the package, what I currently get is inside my site-packages directory I have the Dataset & Model directories

What I want is a main directory called "my_ai_package" and inside it the Dataset & Model directories, I want to be able to do "from my_ai_package import Dataset.some_ds1_script"

I can't re-structure my directory tree to match src/flat layouts, I need some custom configuration in pyptoject.toml

Thanks!


Solution

  • I ended up re-structuring my project in a "src" layout where "src" is replaced by my package name