pip-tools: Mysterious error with optional dependencies in pyproject.toml
I have been following the guide in the README file on how to use pip-tools with pyproject.toml. Unfortunately, if I add a project.optional-dependencies section to pyproject.toml, regardless of what its contents are, I get the following error:
(base) PS C:\Users\adewar\code\Solidity-GUI> pip-compile -v pyproject.toml
C:\ProgramData\Miniconda3\lib\site-packages\_distutils_hack\__init__.py:33: UserWarning: Setuptools is replacing distutils.
warnings.warn("Setuptools is replacing distutils.")
Creating virtualenv isolated environment...
find interpreter for spec PythonSpec(path=C:\ProgramData\Miniconda3\python.exe)
proposed PythonInfo(spec=CPython3.9.13.final.0-64, exe=C:\ProgramData\Miniconda3\python.exe, platform=win32, version='3.9.13 (main, Oct 13 2022, 21:23:06) [MSC v.1916 64 bit (AMD64)]', encoding_fs_io=utf-8-utf-8)
create virtual environment via CPython3Windows(dest=C:\Users\adewar\AppData\Local\Temp\build-env-m1awcc93, clear=False, no_vcs_ignore=False, global=False)
add seed packages via FromAppData(download=False, pip=bundle, via=copy, app_data_dir=C:\Users\adewar\AppData\Local\pypa\virtualenv)
Installing packages in isolated environment... (setuptools >= 40.8.0, wheel)
Getting build dependencies for wheel...
Backend subprocess exited when trying to invoke get_requires_for_build_wheel
Failed to parse C:\Users\adewar\code\Solidity-GUI\pyproject.toml
Environment Versions
- Windows 10 (replicated on Arch Linux)
- Python version:
python 3.9.13 - pip version:
pip 22.2.2 from C:\ProgramData\Miniconda3\lib\site-packages\pip (python 3.9) - pip-tools version:
pip-compile, version 6.9.0
Steps to replicate
- Add a
project.optional-dependenciessection to yourpyproject.toml - Run
pip-compile pyproject.toml
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 26 (13 by maintainers)
Commits related to this issue
- requirements.txt: Generate package lock file - Use pip-tools' pip-compile command via '.venv/bin/pip-compile' - Note: For pip-compile to work for this project we have to add: ``` [tool.setuptools] py... — committed to letam/python-django-app-starter by letam a year ago
- requirements.txt: Generate package lock file - Use pip-tools' pip-compile command via '.venv/bin/pip-compile' - Note: For pip-compile to work for this project we have to add: ``` [tool.setuptools] py... — committed to letam/python-django-app-starter by letam a year ago
- requirements.txt: Generate package lock file - Use pip-tools' pip-compile command via '.venv/bin/pip-compile' - Note: For pip-compile to work for this project we have to add: ``` [tool.setuptools] py... — committed to letam/python-django-app-starter by letam a year ago
- Use pyproject.toml in all services - Add tool.setuptools section to avoid this mysterious issue: https://github.com/jazzband/pip-tools/issues/1711 — committed to City-of-Helsinki/mittaridatapumppu by laurigates a year ago
- Merge branch 'main' into gh-1711-use-default-subprocess-runner — committed to szobov/pip-tools by atugushev 10 months ago
- Use pyproject.toml in all services - Add tool.setuptools section to avoid this mysterious issue: https://github.com/jazzband/pip-tools/issues/1711 — committed to City-of-Helsinki/mittaridatapumppu-parser by laurigates a year ago
- Use pyproject.toml in all services - Add tool.setuptools section to avoid this mysterious issue: https://github.com/jazzband/pip-tools/issues/1711 — committed to City-of-Helsinki/mittaridatapumppu-endpoint by laurigates a year ago
Regarding that last example, it seems to be about the way setuptools auto-discovers the project structure, and can be avoided with
Aside from that I’ll note that the alternative runner selection is now in
build, but there has not yet been a release including it.I’ve stumbled upon this issue a couple of times in the last month. Here is the error I see:
Setup
Environment:
The
pyproject.tomlfile itself is super simple and passes validation using thevalidate-pyprojectpackage:What causes it
It’s definitely not a
pip-compileproblem as it just callsproject_wheel_metadatafrom thebuildpackage and then catches the error and reports.https://github.com/jazzband/pip-tools/blob/eff84765725fc15579d6626851910350d580ec8b/piptools/scripts/compile.py#L474-L476
The
buildpackage, in turn, does lots of stuff and ends up calling a Python script called_in_process.pyfrom the pep517 package.I have no idea how it is supposed to work, but it looks like the
buildpackage create a one-time temporary virtual environment in which this_in_process.pyscript is then invoked. Here is the command with whichbuildpackage tries to call a subprocess in my case:Obviously, when something wrong happens in that subprocess script all we get at the end is:
But in reality, the real error does not ever get propagated to the parent process and we don’t see it. I’ve caught it by instrumenting the
_in_process.pyfile in my virtual environment (lib/python3.11/site-packages/pep517/in_process/_in_process.py) with print statements.Now I can see that the underlying error actually comes from the
flitpackage, complaining about lack of thedescriptionfield in the[project]section of mypyproject.tomlfile.How to get the same output
Here is what I manually added to the
_in_process.pyfile inpep517package in my venvhttps://github.com/pypa/pyproject-hooks/blob/4c9325f4e594bfc7178452d0d01eb8da6c3dbbdb/src/pyproject_hooks/_in_process/_in_process.py#L322
Fixing the issue
I can address the complaints of
flitby adding missing things:descriptionfieldopensearch_loggerexists in the same directory wherepyproject.tomlis placedAnd voila:
Alternatively, should I swap the build system to classic setuptools, it compiles successfully even without said fixes.
Conclusion
I don’t understand why such system was chosen by creators of build system (not pip-tools). This is the reason we don’t see an underlying problem from the chosen build system. It just does not get propagated to higher level tools, such as
buildorpip-tools.P.S. was so happy to see @atugushev in the comments of this issue. Cheers!
I also experienced this problem. I have a valid
pyproject.tomlwith no syntax errors, running python 3.11 on Ubuntu 22.04. @AndydeCleyre’s solution above is what worked for me. Thanks @AndydeCleyre!FTR: tracking issue https://github.com/pypa/build/issues/553 for
project_wheel_metadataimprovement.@vduseev thanks for chiming in and for the additional context!
Digging into the issue I found that
build.utils.project_wheel_metadatausespep517.quiet_subprocess_runnerwhich suppresses output. Withpep517.default_subprocess_runnerIt shows the actual error.Patched
build:pip-compileoutput:@pradyunsg I wonder if would it be okay to introduce one of the following params in
build.utils. project_wheel_metadata()? For example:project_wheel_metadata(quiet=False)- do not suppress the outputproject_wheel_metadata(runner=my_runner)- use my runnerA colleague has tracked down the source of the problem. If you check
pyproject.tomlwith validate-pyproject you get:Putting the
authorsfield into the correct format fixes things, i.e.:I’ve dug in a bit more and it’s weirder than I thought. This following pyproject.toml doesn’t work:
However, if you remove the
authorsline, it works fine again:How odd is that?!
I found another case today where this error can occur:. I started with a working
pyproject.toml, then I created two subdirectories.The clue for me was that
pip install --editable .gave an error “multiple top-level packages discovered in a flat-layout”.Running validate-projected returned no errors.
Ouch, sorry. This is the pip-tools’ message:
https://github.com/jazzband/pip-tools/blob/eff84765725fc15579d6626851910350d580ec8b/piptools/scripts/compile.py#L479
pip install .:python -m build:this also solved the problem for me.
So the errors come because pip-compile swallows output of
pip install -e .Running the command will reveal the error.In the case of a flatlayout with multiple packages, mentioned by @cout one can explicitly specify which folders in the flat layout must be included as packages
for the record,
buildhas implemented switching runner from the defaultquietone, but it’s not yet included in any releases ofbuild.pip-compile omitted all error logs, I have to use
pip install -e .to see what went wrong with the pyproject.toml file. My problem was wrong syntax for fieldslicenseandrequires-pythonAgreed. Feel free to open a separate issue on the pip-tools tracker.