I have a web application that displays the ABOUT.md file of the project. The project has the following file tree:
project_folder/
main_package/
assets/icon.png
__init__.py
app.py
.gitignore # And other files
README.md
ABOUT.md
setup.cfg
setup.py
In app.py I have a webserver that renders and provides the contents of the file README.md
. It has a code like this:
from main_package import __file__ as mpfile
# First parent is just the folder where __init__.py is located.
ABOUT_MD = Path(mpfile).parent.parent / 'ABOUT.md'
This works without building, but if I build the wheel and install it in other environment, it stops working.
I modified the config in setup.cfg
so it includes the ABOUT.md
[options.package_data]
main_package =
../ABOUT.md
assets/*
But this copies the file to the root of site_packages
, which I think is a bit dirty.
I want to keep the ABOUT.md
file available in the root folder, so it remains very accessible through GitHub, but I also want to be able to build and publish my package.
Idea:
Modify the build system to copy the ABOUT.md from the root to main_package/assets/ABOUT.md
while creating the wheel. Then, add an if inside app.py
that loads the correct file depending on where it is. The problem is that I don't know how to make the build system copy the file to this path.
Update 2022-07-18: Why not linking?
In response to @Leander
If we use a Hard Link, that info is not propagated through the version control system (git), so It will appear to be two different files in every other computer, and we would have to sync the data somehow (with hooks or any kind of system), plus it would take double space in disk.
If we use a Symlink, the used space is reduced, but the web view of the repositories can't follow symlinks, so the ABOUT.md ends unusable (it just displays the plaintext path of the symlink).