A typical directory tree of a python project might look like this.
.
├── src
│?? ├── __init__.py
│?? ├── main.py
│?? ├── module1
│?? │?? ├── __init__.py
│?? │?? └── foo.py
│?? └── module2
│?? ├── __init__.py
│?? └── bar.py
├── setup.py
└── venv
└── ...
setup.py
contains package metadata like name, version, description, etc.
In some cases, it is useful to have these values inside the application code. For example with FastAPI, you can provide them to the constructor of the API object so that they are shown in the auto-generated docs. Or with Click, you can add a version option.
To avoid duplication, these values should be defined only once and used in both places. However, I have never found a good way, to share these values between setup.py
and application code.
Importing one from the other does not seem to work, because they are not part of the same package structure.
What is best practice in this case?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…