Including data files in a package - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Including data files in a package (/thread-35364.html) |
Including data files in a package - ChrisOfBristol - Oct-24-2021 I want to create a binary package (Wheel) and possibly also a source package (tarball). I need to include a reference file and a help file. I believe I can do this for the source package just by stating them in MANIIFEST.in, but all the information I have found on the Web states that for a binary package I need to use setup.py. This Python tutorial states Static metadata (setup.cfg) should be preferred. Dynamic metadata (setup.py) should be used only as an escape hatch when absolutely necessary. setup.py used to be required, but can be omitted with newer versions of setuptools and pip. I would prefer to follow the official recommendation, is there a way to include my files with a statement in setup.cfg perhaps? RE: Including data files in a package - snippsat - Oct-24-2021 (Oct-24-2021, 07:33 PM)ChrisOfBristol Wrote: but all the information I have found on the Web states that for a binary package I need to use setup.py.To do most setup from setup.cfg is relative new,so most tutorial/demo you find on web will be for setup.py .Can still use setup.py it will work fine or can rewrite it to use setup.cfg Look at Configuring setup() using setup.cfg files A sample Python project And look my answer in your last post. in setup.cfg to add files eg .dat use [options.data_files] (same as package_data ).In link you see for setup.py is this way. # If there are data files included in your packages that need to be # installed, specify them here. package_data={ # Optional 'sample': ['package_data.dat'], }, RE: Including data files in a package - ChrisOfBristol - Oct-25-2021 (Oct-24-2021, 09:11 PM)snippsat Wrote: Look at Configuring setup() using setup.cfg filesThe above states the following without any explanation of what the elements are: [options.data_files] /etc/my_package = site.d/00_default.conf host.d/00_default.conf data = data/img/logo.png, data/svg/icon.svg fonts = data/fonts/*.ttf, data/fonts/*.otf I've no idea what site.d... or host.d... mean. I imagine that the line starting data means create a directory called "data" and copy the following files into it. I'll try: [options.data_files] data = reference.dat, help.html RE: Including data files in a package - snippsat - Oct-25-2021 Can just use [options.package_data] this will add .dat and .rst files,work for me when i test[options.package_data] * = *.dat, *.rstSo same setup as this,but added somefile.dat And importlib.resources sa shown here packaging_tutorial/ └── src/ └── example_package/ ├── __init__.py └── example.py └── somefile.dat # Build (pack_tut) G:\div_code\pack_tut\packaging_tutorial λ python -m build * Creating venv isolated environment.. ..... ect Successfully installed example-pkg-YOUR-USERNAME-HERE-0.0.1 # install (pack_tut) G:\div_code\pack_tut\packaging_tutorial\dist λ pip install example_pkg_YOUR_USERNAME_HERE-0.0.1-py3-none-any.whl --force-reinstall ..... Successfully installed example-pkg-YOUR-USERNAME-HERE-0.0.1 # Test that it work (pack_tut) G:\div_code\pack_tut\packaging_tutorial λ python Python 3.9.5 (tags/v3.9.5:0a7dcbd, May 3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from example_package import example >>> >>> example.add_one(2) 3 # Can now use somefile.dat here >>> example.add_one(int(example.number)) 43 RE: Including data files in a package - ChrisOfBristol - Oct-27-2021 The documentation on this is very confusing and the statements conflict in certain circumstances. A bug report/enhancement request has been made. This works: [options] package_dir = = src packages = find: python_requires = >=3.7 include_package_data = True [options.packages.find] where = src With this in MANIFEST.in: include src/mymodules/myapp.dat src/mymodules/myapp.html src/mymodules/myapp.hlp The package has now been published. |