KowaiiNeko
KowaiiNeko

Reputation: 327

including folder and files inside a Python package

I'm trying to make a python package and I have most of the things already setup by when I try to install the library from Github here, it installs everything except for the folder called champs and it's files

This is my File directory structure

LeagueYue
   champs
      -Lname_num.json
      -Lname_Uname.json
      -num_Uname.json
   -__init__.py
   -champion_files.py
   -external.py
   -match.py
   -rank.py
   -status.py
   -summoner.py
-requirements.txt
-setup.py

All the files are installed except for the folder and the files inside champs

Upvotes: 2

Views: 5187

Answers (2)

Augusto A
Augusto A

Reputation: 306

As this question answers:

There are 2 ways to add the static files:

1) Include_package_data=True + MANIFEST.in

A MANIFEST.in file in the same directory of setup.py, that looks like this:

include src/static/*
include src/Potato/*.txt

2) Package_data in setup.py

package_data = {
    'static': ['*'],
    'Potato': ['*.txt']
}

Specify the files inside the setup.py.

Upvotes: 4

J_H
J_H

Reputation: 20611

Two of the files could probably be derived at runtime from num_Uname.json, but that's fine.

I do not yet see a data_files directive in https://github.com/CharmingMother/LeagueLib/blob/async/setup.py

Thomas Cokelaer suggests using an expression like

datafiles = [(datadir, list(glob.glob(os.path.join(datadir, '*'))))]

and then

setup(
    ...
    data_files = datafiles,
)

in http://thomas-cokelaer.info/blog/2012/03/how-to-embedded-data-files-in-python-using-setuptools/

In your case this could be as simple as:

data_files = [('', ['champs/num_Uname.json'])],

Martin Thoma explains you should access them using filepath = pkg_resources.resource_filename(__name__, path) in How to read a (static) file from inside a Python package?

When I Read The Fine Manual, this setup.cfg alternative surfaces:

[options.data_files]
...
data = data/img/logo.png, data/svg/icon.svg

suggesting a line like . = champs/num_Uname.json or champs = num_Uname.json

Upvotes: 2

Related Questions