Motti
Motti

Reputation: 114795

Building package with 'build' does not exclude exclude-files (which setup.py does)

We're getting deprecation warnings when building with python3 setup.py sdist and after reading Why you shouldn't invoke setup.py directly? I see that the recomended alternative is to use build.

setup.py command New command
setup.py sdist python -m build (with build)
setup.py bdist_wheel

When comparing the outputs I see that the deprecated setup.py excludes the tests directory (as specified with packages=find_packages(exclude=['tests']), while python3 -m build does not exclude this directory.

My understanding was that build still uses setup.py, albeit not directly, am I missing something? What is the correct way to avoid packaging the tests directory?

Environment information

A minimal project behaves the same:

In my test sample project there is a lib directory with an empty __init__.py and hello.py with print("hello"), a tests directory with an empty test_hello.py file and the following setup.py:

from setuptools import find_packages, setup

setup(
  name="hello",
  version="0.1",
  author="myself",
  description="test package",
  packages=find_packages(exclude=["tests"]),
)

Edit: Opened issue on github https://github.com/pypa/setuptools/issues/3870

Upvotes: 0

Views: 586

Answers (1)

Motti
Motti

Reputation: 114795

After opening a defect on github the problem was resolved by adding the following pyproject.toml:

[build-system]
build-backend = "setuptools.build_meta"
requires = ["setuptools==65.5"]

Upvotes: 0

Related Questions