3

I am creating a Python package which wraps (and bundles) a DLL. I'm planning on shipping prebuilt sphinx based docs within the wheel and perhaps add an entry point as a convenience to launch a browser to view them.

After some googling I haven't found much information on this approach.

Is this not a recommended approach? Note that this is for an in house package that is not for public consumption and I want the package user to always have the appropriate version of the docs for the DLL release.

What I'm looking for is a way to include the built html files by referencing them within the setup.py file. I know that I can use package_data and include_package_data keyword arguments to setup within setup.py but I believe that these work with packages as the name implies so I think using this approach would be messy for this application.

If this is not the right approach, I'm keen to hear of better alternatives!

pjs
  • 18,696
  • 4
  • 27
  • 56
Gregory Kuhn
  • 1,627
  • 2
  • 22
  • 34
  • [This answer](https://stackoverflow.com/a/5423147/1671693) describes one possibility: `data_files`. What I want is probably closer to `package_data` but `package_data` requires sub folders to also be packages, i.e. contain an `__init__.py` – Gregory Kuhn Sep 06 '18 at 10:31
  • I recommend to use a MANIFEST.in file. – ninja_zx9r Aug 11 '23 at 08:59

1 Answers1

1

I have settled on a solution which seems to work ok using data_files but it's ugly as sin. The solution is based on this answer.

In my setup.py I have this:

def get_data_files(docs_root):
    data_files = []
    for dirname, dirs, files in os.walk(docs_root):
        for f in files:
            data_files.append(os.path.join(dirname, f))
    return data_files

which I call as part of the data_files keyword argument:

data_files = [('Lib/site-packages/<module_name>/docs', get_data_files('module_name/docs'))],

I have my reservations of the portability of this but it seems to be the only viable option that works for me that allows a clean uninstall as well.

Gregory Kuhn
  • 1,627
  • 2
  • 22
  • 34
  • According to https://packaging.python.org/guides/distributing-packages-using-setuptools/#package-data documentation can be shipped as data_files: "Often, additional files need to be installed into a package. These files are often data that’s closely related to the package’s implementation, or text files containing documentation that might be of interest to programmers using the package. These files are called “package data”." – Adriano Oct 06 '20 at 15:46