I have a template file in my package file named config_template.json
I want to copy the file from the root directory of the repository into the package directory, where it is accessed by a submodule. The original file config.json
is on my gitignore file. I want to do this to give access to the template which would work with the final code and don't confuse any user by paths I have set in my personal file. All this should be done while calling python setup.py
. I now the MANIFEST file allows inserting other files but I am not shure how to rename them. I am open for better approaches.
Asked
Active
Viewed 236 times
0

MaKaNu
- 762
- 8
- 25
-
Why not move it there permanently? – phd Dec 02 '21 at 20:51
-
because I want to have the template pushed to the repo but the actual config not. So I am enable to tinker around with my own copy of the config (and also other users) while the template stays intact. I actually saw many PRs (mostly datascientists) which want to change the paths to their personal one. I am mostly shure this happen with ```git add .``` – MaKaNu Dec 03 '21 at 09:16
-
Use `.gitignore` to ignore the actual config. Anyway your repo should include the root with `setup.py`, `MANIFEST.in` and all the packaging files so it doesn't matter if the template is inside the root or deep down in the package. Putting it in the package makes `setup.py` simpler. – phd Dec 03 '21 at 11:32
-
Okay I see no problem with putting the template inside the package. As I understand MANIFEST.in it is responsible for putting files into the installed packaged which are not python files. This is the behaviour I want to create but additional to that, I want that while setup a renamed copy of the template is created, which is then put inside the installed package. So By setting up the MANIFEST.in with the config.json inside and wrapping around the solution from @Alexandru DuDu inside the setup.py I would create the wanted behaviour? – MaKaNu Dec 03 '21 at 13:51
-
[`MANIFEST.in` tells Distutils what files to include in the **source distribution**](https://stackoverflow.com/a/3597263/7976758) (`sdist`) See also https://stackoverflow.com/search?q=%5Bsetuptools%5D+MANIFEST.in) esp. https://stackoverflow.com/a/14159430/7976758 – phd Dec 03 '21 at 14:11
1 Answers
0
You can use this example:
import shutil
inputFilePath = "C:/User/admin/Desktop/config.json"
outputFilePath = "D:/output/config_template.json"
shutil.copy(inputFilePath, outputLocationPath)
Include this code in your setup.py
and configure the path to the original file and the path to output. shutil.copy
can take different names for input and output and will write the input file to output file

Alexandru DuDu
- 998
- 1
- 7
- 19
-
is it realy that simple? I thought I need to put it some special manner. I test this later thanks so far – MaKaNu Dec 03 '21 at 09:16