Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log errors for incorrect pyproject.toml #1860

Closed
nikhilweee opened this issue May 4, 2023 · 4 comments
Closed

Log errors for incorrect pyproject.toml #1860

nikhilweee opened this issue May 4, 2023 · 4 comments
Labels
bug Something is not working duplicate Duplicate of an existing issue/PR pyproject.toml Related to pyproject.toml support

Comments

@nikhilweee
Copy link

My Problem

I'm using pip-tools to manage the requirements of a project that I don't indend to distribute. My pyproject.toml looks like this.

# pyproject.toml
[project]
name = "name"
version = "1.0"
dependencies = ["name==1.0"]

When I try to run pip-compile, I get a very unhelpful error.

$ pip-compile pyproject.toml
Backend subprocess exited when trying to invoke get_requires_for_build_wheel
Failed to parse /path/to/pyproject.toml

To add to my problems, validate-pyproject does not discover any errors either

$ validate-pyproject pyproject.toml
Valid file: pyproject.toml

The Solution

In my particular case, the solution was to add the following section to pyproject.toml

[tool.setuptools]
py-modules = []

I was able to figure this out by changing the following line to remove the stderr argument.

# file: site-packages/pyproject_hooks/_impl.py
...
def quiet_subprocess_runner(...):
    ...
    check_output(cmd, cwd=cwd, env=env, stderr=STDOUT)

Once I do that, I can run pip-compile and immediately find the error:

error: Multiple top-level packages discovered in a flat-layout: ['static', 'project', 'app'].

To avoid accidental inclusion of unwanted files or directories,
setuptools will not proceed with this build.

If you are trying to create a single distribution with multiple packages
on purpose, you should not rely on automatic discovery.
Instead, consider the following options:

1. set up custom discovery (`find` directive with `include` or `exclude`)
2. use a `src-layout`
3. explicitly set `py_modules` or `packages` with a list of names

To find more information, look for "package discovery" on setuptools docs.

Future Work

I don't think we should deprive users of such a helpful message.

Right now the build library defaults to using a quiet subprocess runner. In a future release, build will allow the option to specify the runner explicitly (pypa/build#566). When the next version of build is released, we should consider changing the following lines to use pyproject_hooks.default_subprocess_runner so that errors are also printed to the terminal.

metadata = project_wheel_metadata(
os.path.dirname(os.path.abspath(src_file)),
isolated=build_isolation,
)

@nikhilweee nikhilweee changed the title Log errors for incorrect pyproject.toml in the future Log errors for incorrect pyproject.toml May 4, 2023
@nikhilweee
Copy link
Author

Turns out this is being actively tracked in #1711 . For those who stumble upon this issue, an easier way to see the error message is to simply try pip install . or python -m build as described in #1711 (comment)

@nikhilweee
Copy link
Author

Fun fact: pypa/build#566 was a result of pypa/build#553 which originated out of #1711 so we've come a full circle here.

@atugushev
Copy link
Member

we've come a full circle here.

Yeah, we're waiting now for build release to fix the bug on pip-tools side.

@atugushev
Copy link
Member

atugushev commented May 4, 2023

I'll close this as duplicate of #1711. Nonetheless, thanks for the issue and analysis!

@atugushev atugushev added bug Something is not working duplicate Duplicate of an existing issue/PR pyproject.toml Related to pyproject.toml support labels May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is not working duplicate Duplicate of an existing issue/PR pyproject.toml Related to pyproject.toml support
Projects
None yet
Development

No branches or pull requests

2 participants