How do I modify a file in Python setup.py?
I created a
python package install with setup.py and I want it to copy a data file in the folder (created for this) ~/.did. The problem is that I have to call setup.py with sudo permissions because it is in /usr/local/… .
Then I decided to add a call to os.chmod() after the setup() function, but I was wondering if anyone had a more concise way to do that.
Here is my setup.py file:
#!/usr/bin/env python from distutils.core import setup import os home=os.path.expanduser('~') setup(name='did', version='1.0', description='Daily Image Downloader', author='Luc Mazon', author_email='[email protected]', url='', license='GNU GPL v3', scripts=['did'], packages=['didlib'], data_files=[ ('/usr/share/man/man1', ['doc/did.1.gz']), (home+'/.did', ['did.xml']) ] ) os.chmod(home+'/.did/did.xml', 0666)
Since did.xml is not a python file, I also created an MANIFEST.in file with the following line:
The global structure of my package is as follows:
did-1.0 | didlib | | __init__.py | | variouspyfiles.py | .doc | |-did.1.gz | MANIFEST.in | did.xml | did | setup.py
I think it would be better and more accustomed to not writing any config files to the installer’s home directory at all. What about other users? A better approach is to check your code at initialization time, add a new file if the file exists on the user running it, and if not, just add a new file.