0

I'm installing my module with pip. The following is the setup.py:

from setuptools import setup, find_packages

with open('requirements.txt') as f:
    required = f.read().splitlines()

print(required)
setup(
    name='glm_plotter',
    packages=find_packages(),
    include_package_data=True,
    install_requires=required
)

and MANIFEST.in:

recursive-include glm_plotter/templates *
recursive-include glm_plotter/static *

When installing, the directories and files seem to get installed:

  ...
  creating build/lib/glm_plotter/templates
  copying glm_plotter/templates/index.html -> build/lib/glm_plotter/templates
...
  creating build/bdist.linux-x86_64/wheel/glm_plotter/templates
  copying build/lib/glm_plotter/templates/index.html -> build/bdist.linux-x86_64/wheel/glm_plotter/templates
 ...

When I go to import this module:

>>> import g_plotter
>>> dir(g_plotter)
['CORS', 'Flask', 'GLMparser', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'app', 'controllers', 'views']

I'm not seeing the static files. I'm not sure if this is the correct way to go about getting access to the static files.

user994165
  • 9,146
  • 30
  • 98
  • 165
  • Possible duplicate of [How to read a (static) file from inside a Python package?](https://stackoverflow.com/questions/6028000/how-to-read-a-static-file-from-inside-a-python-package) – phd Nov 09 '18 at 22:16
  • https://stackoverflow.com/search?q=%5Bpython%5D+package+static+files – phd Nov 09 '18 at 22:16

1 Answers1

1

dir() won't tell you anything about static files. The correct way (or one of them, at least) to get access to this data is with the resource_* functions in pkg_resources (part of setuptools), e.g.:

import pkg_resources

pkg_resource.resource_listdir('glm_plotter', 'templates')
# Returns a list of files in glm_plotter/templates

pkg_resource.resource_string('glm_plotter', 'templates/index.html')
# Returns the contents of glm_plotter/templates/index.html as a byte string
jwodder
  • 54,758
  • 12
  • 108
  • 124