101 votes

Comment inclure des fichiers statiques à setuptools - paquet python

Je veux inclure le ./static/data.txt a setuptools Voici mon code :

# setup.py
import os,glob
from setuptools import setup,find_packages

setup(
    name = "PotatoProject",
    version = "0.1.1",
    author = "Master Splinter",
    author_email = "splinter@initech.com",
    description = ("The potatoproject!"),
    url = 'http://www.google.com',
    license = "BSD",

    # adding packages
    packages=find_packages('src'),
    package_dir = {'':'src'},

    # trying to add files...
    include_package_data = True,
    package_data = {
        '': ['*.txt'],
        '': ['static/*.txt'],
        'static': ['*.txt'],
    },

    scripts=['src/startPotato'],
    classifiers=[
        "Development Status :: 3 - Alpha",
        "Topic :: Utilities",
        "License :: OSI Approved :: BSD License",
    ],
)

Le système de fichiers :

.
 setup.py
 src
     distutils_setup.py
     Potato
        __init__.py
        potatoData.txt
        printer.py
     startPotato
     static
        data.txt
     Tomato
         big.py
         __init__.py

la sortie en cours d'exécution : python setup.py sdist

running sdist
running egg_info
creating src/PotatoProject.egg-info
writing src/PotatoProject.egg-info/PKG-INFO
writing top-level names to src/PotatoProject.egg-info/top_level.txt
writing dependency_links to src/PotatoProject.egg-info/dependency_links.txt
writing manifest file 'src/PotatoProject.egg-info/SOURCES.txt'
reading manifest file 'src/PotatoProject.egg-info/SOURCES.txt'
writing manifest file 'src/PotatoProject.egg-info/SOURCES.txt'
warning: sdist: standard file not found: should have one of README, README.txt

creating PotatoProject-0.1.1
creating PotatoProject-0.1.1/src
creating PotatoProject-0.1.1/src/Potato
creating PotatoProject-0.1.1/src/PotatoProject.egg-info
creating PotatoProject-0.1.1/src/Tomato
making hard links in PotatoProject-0.1.1...
hard linking setup.py -> PotatoProject-0.1.1
hard linking src/startPotato -> PotatoProject-0.1.1/src
hard linking src/Potato/__init__.py -> PotatoProject-0.1.1/src/Potato
hard linking src/Potato/printer.py -> PotatoProject-0.1.1/src/Potato
hard linking src/PotatoProject.egg-info/PKG-INFO -> PotatoProject-0.1.1/src/PotatoProject.egg-info
hard linking src/PotatoProject.egg-info/SOURCES.txt -> PotatoProject-0.1.1/src/PotatoProject.egg-info
hard linking src/PotatoProject.egg-info/dependency_links.txt -> PotatoProject-0.1.1/src/PotatoProject.egg-info
hard linking src/PotatoProject.egg-info/top_level.txt -> PotatoProject-0.1.1/src/PotatoProject.egg-info
hard linking src/Tomato/__init__.py -> PotatoProject-0.1.1/src/Tomato
hard linking src/Tomato/big.py -> PotatoProject-0.1.1/src/Tomato
Writing PotatoProject-0.1.1/setup.cfg
creating dist
Creating tar archive
removing 'PotatoProject-0.1.1' (and everything under it)

et aucun texte ajouté ! Non static/data.txt ni Potato/potatoData.txt ...

Qu'est-ce que je rate ?

160voto

JRicardo000 Points 591

Comme indiqué dans les commentaires, il y a deux façons d'ajouter les fichiers statiques :

1 - include_package_data=True + MANIFEST.in

A MANIFEST.in dans le même répertoire que le fichier setup.py qui ressemble à ça :

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

Avec include_package_data = True en setup.py .

2 - paquet_données dans setup.py

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

Spécifiez les fichiers dans le répertoire setup.py .


Ne pas utiliser les deux include_package_data y package_data en setup.py .

include_package_data annulera le package_data informations.

Documents officiels :
https://setuptools.readthedocs.io/en/latest/userguide/datafiles.html

31voto

Anton Danilchenko Points 1012

Inclure tous les fichiers de manière récursive :

recursive-include project_name/templates *
recursive-include project_name/static *

donde project_name est un dossier dans la même ligne où vous avez setup.py fichier.

11voto

emispowder Points 497

Selon les documents, il y a trois façons pour inclure les fichiers de données du paquet. Vous avez deux paquets : Potato et Tomato. Le répertoire static ne se trouve dans aucun de ces paquets, c'est pourquoi votre dictionnaire package_data dans setup.py ne fonctionnait pas. L'option manifest exige que la valeur True soit attribuée à include_package_data dans le fichier setup.py. L'accès aux fichiers de données hors paquetage peut être fait de la manière suivante aquí .

11voto

Dadaso Zanzane Points 5229

Utilisez les éléments suivants

packages = ['.','templates','static','docs'],

package_data={'templates':['*'],'static':['*'],'docs':['*'],},

Prograide.com

Prograide est une communauté de développeurs qui cherche à élargir la connaissance de la programmation au-delà de l'anglais.
Pour cela nous avons les plus grands doutes résolus en français et vous pouvez aussi poser vos propres questions ou résoudre celles des autres.

Powered by:

X