[Python] How to select packaging files in pyproject.toml?

Discussão em 'Python' iniciado por Stack, Junho 14, 2025.

  1. Stack

    Stack Membro Participativo

    What I am trying to do


    I am trying to build a python package. I want the build package to contain only the necessary files.

    I make the build with following command: python -m build

    What I have


    My package files structure looks more or less like this:

    project_root_directory
    ├── .gitignore
    ├── .github
    ├── pyproject.toml
    ├── README.rst
    ├── LICENSE
    └── mypkg
    ├── __init__.py
    └── file.py


    Packaging essentials from my pyproject.toml file:

    [build-system]
    requires = [
    "setuptools >= 65.5.1",
    "setuptools-scm",
    "wheel"
    ]
    build-backend = "setuptools.build_meta"

    [tool.setuptools.package-data]
    "*" = [
    "README.rst",
    "LICENSE"
    ]

    [tool.setuptools.packages.find]
    include = [
    "mypkg.*"
    ]

    What is my current outcome


    The problem is that both .gitignore and .github are part of SOURCES.txt and therefore are in dist files (e.g. when I unpack mypkg-0.0.0.tar.gz it contains .github directory and .gitignore files).

    SOURCES.txt entries:

    .gitignore
    LICENSE
    README.rst
    pyproject.toml
    .github/dependabot.yml
    .github/pull_request_template.md
    .github/ISSUE_TEMPLATE/99_any.md
    .github/workflows/testing.yml
    mypkg.egg-info/PKG-INFO
    mypkg.egg-info/SOURCES.txt
    mypkg.egg-info/dependency_links.txt
    mypkg.egg-info/requires.txt
    mypkg.egg-info/top_level.txt
    mypkg/__init__.py
    mypkg/file.py

    What I want to achieve


    I want my SOURCES.txt to contain following entries after build command:

    LICENSE
    README.rst
    mypkg.egg-info/PKG-INFO
    mypkg.egg-info/SOURCES.txt
    mypkg.egg-info/dependency_links.txt
    mypkg.egg-info/requires.txt
    mypkg.egg-info/top_level.txt
    mypkg/__init__.py
    mypkg/file.py


    and have my dist files to be build accordingly.

    Continue reading...

Compartilhe esta Página