Search code examples
pythonpipsetuptools

Install static files in Python egg sdist install directory


I am creating a Python3 application that depends on a directory of static files in the project.

Project structure:

myBlanky
  \__blankys
        \__bootstrap
         |__google_app_engine
  \__my_blanky
       \____init__.py
        |__my_blanky.py
        |__file_system_utils.py
  setup.py
  MANIFEST.in
  README.md
  LICENSE
  .travis.yml
  setup.cfg

So, in my root directory, I have 1 Python module (my_blanky), various Python project files (manifest, setup.py, etc) and 1 directory full of static data (blankys).

I was having troubles creating a .tar.gz package for my application earlier, but after creating a MANIFEST.in file and editing my setup.py file, I was able to create a .tar.gz successfully with command: python3 setup.py sdist.

My setup.py:

from setuptools import setup
from my_blanky import version

setup(name="myBlanky",
      ...url, author, etc info here...
      packages=["my_blanky"],
      include_package_data=True,
      package_data={'blankys': ['blankys/*']},
      zip_safe=False,
      entry_points={"console_scripts": ["myblanky = my_blanky.my_blanky:main"]},
      install_requires=['docopt==0.6.1'])

My MANIFEST.in:

recursive-include blankys *
include *.md
include LICENSE
include setup.cfg

After I run python3 setup.py sdist, I open up the created .tar.gz file and it includes all the data that I need (blankys directory, my_blanky module, all root dir static files) so it includes all my static files that I need, great.

Then I move onto installing the .tar.gz with pip: find ./dist -iname "*.tar.gz" -print0 | xargs -0 pip install and it runs successfully with no errors. (The output of installing it does not display any information regarding the static files but didn't think it would do that any way.)

Now here is the issue. My python project should now be installed on my machine. I can run myblanky on my machine or myblanky -v and it all works great. Everything runs. But when I try to run any code like myblanky list that tries to access the static files directory "blankys", it breaks saying there is no such directory in /usr/local/lib/python3.4/dist-packages/my_blanky/. I browse to that location manually and the only files there is my Python module my_blanky source files. The parent directory: /usr/local/lib/python3.4/dist-packages/ also does not include any static files at all.

I am expecting the static directory blankys gets copied over to the dist-packages location when I pip install my project. I am expecting the directory to live with my my_blanky module directory so I can use that static files directory my relative path searching in my program.


So if the static files install great into my .tar.gz package and installation seems to succeed on my machine, where are my static files in the installed dist-package? I am installing the project on my machine from the .tar.gz which has the static files/directory in it, so why are those not copied over in the installation? Only the python module my_blanky gets copied over.

UPDATE (2020): For future readers of this question, some people have commented that the original question and answer I gave in 2014 does not make sense or help solve their problem. Sorry, but I have not touched this code since 2014 and I am not able to improve this question or answer. I am leaving it here in case it's helpful, but I am not able to help any further on this.


Solution

  • UPDATE (2020): For future readers of this answer, some people have commented that the original question and answer I gave in 2014 does not make sense or help solve their problem. Sorry, but I have not touched this code since 2014 and I am not able to improve this question or answer. I am leaving it here in case it's helpful, but I am not able to help any further on this.


    I feel I have solved this issue.

    Essentially my problem is that I have a "settings.config" file that I want to be able to access system wide on the user's machine. So instead of having the settings.config file located in some random directory that my program cannot find, I wanted to have one single settings.config file on the system that it can find and manipulate so I was asking in my question how you go about doing this in distutils.

    While I was cleaning out my machine's home directory today I realized that I was going at the idea all wrong. Applications do this idea all the time where it has one config file somewhere in the system it can access. It is located in ~/.config or /etc or on Windows: %APPDATA%. I was asking in my question above how I can install a settings.config file inside of /usr/local/lib/python3 but that is wrong. That is not what I should be doing, just do like what every other program does.

    So to answer my question: you can't install a data file in /usr/local/lib/python3 and for good reason. Instead use ~/.config or /etc or %APPDATA%.