2

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

KowaiiNeko
  • 327
  • 6
  • 17
  • 1
    I believe this [question](https://stackoverflow.com/questions/11848030/how-include-static-files-to-setuptools-python-package) can solve your problem. – Augusto A Mar 27 '19 at 02:23
  • Thank you, it worked amazingly! As for the bounty, I think you will have to post it as an "answer "and not a comment even though it is the answer. – KowaiiNeko Mar 27 '19 at 02:45
  • Does this answer your question? [How include static files to setuptools - python package](https://stackoverflow.com/questions/11848030/how-include-static-files-to-setuptools-python-package) – ankostis Apr 13 '20 at 09:10

2 Answers2

4

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.

Augusto A
  • 306
  • 1
  • 2
1

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

J_H
  • 17,926
  • 4
  • 24
  • 44
  • Thank you for your answer and insight, I wish I could also give you a bounty reward as well but `Augusto A` has already answered before you – KowaiiNeko Mar 27 '19 at 03:55