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

Sdist build fails in projects with build.py #1188

Open
gitonthescene opened this issue Sep 5, 2023 · 4 comments
Open

Sdist build fails in projects with build.py #1188

gitonthescene opened this issue Sep 5, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@gitonthescene
Copy link

Hi, I recently upgraded poetry to the latest release and I'm having issues running nox tests. I haven't changed anything other than upgrading poetry and nox.

➜  csv-reconcile git:(develop) ✗ nox --version
 2023.4.22
➜  csv-reconcile git:(develop) ✗ 

Here's my noxfile.py. (Last edited two years ago...)

It looks like the SDIST usage varies from what I found in current documentation, but changing that to use the string didn't seem to help.

Here's the error I'm seeing:

nox > Command python -m pip install --constraint=.nox/test_geo-3-9/tmp/requirements.txt 'file:///Users/xxx/Python/wikidata/csv-reconcile/dist/%280.3.2%29#egg=csv-reconcile' failed with exit code 1:
Processing ./dist/(0.3.2)
ERROR: Could not install packages due to an OSError: [Errno 2] No such file or directory: '/Users/xxxx/Python/wikidata/csv-reconcile/dist/(0.3.2)'

As a wild guess It looks like maybe that (0.3.2) comes from processing poetry output which might have changed??

Using poetry build manually produces the following files:

➜  csv-reconcile git:(develop) ✗ ls dist 
csv_reconcile-0.3.2-cp37-cp37m-macosx_12_0_x86_64.whl csv_reconcile-0.3.2.tar.gz
➜  csv-reconcile git:(develop) ✗ 

I'm not sure where to start debugging this. Any advice you can offer would be greatly appreciated.

Regards

@gitonthescene
Copy link
Author

gitonthescene commented Sep 5, 2023

I think this might confirm my guess.

This is what the output looks like with the latest poetry release:

➜  csv-reconcile git:(develop) ✗ poetry build
Preparing build environment with build-system requirements poetry>=0.12, cython, setuptools!=50.0, wheel
Building csv-reconcile (0.3.2)
➜  csv-reconcile git:(develop) ✗ 

@cjolowicz cjolowicz added the bug Something isn't working label Sep 9, 2023
@cjolowicz
Copy link
Owner

cjolowicz commented Sep 17, 2023

This is only triggered in Poetry projects using the undocumented build script support.

Here's a minimal repro:

# pyproject.toml
[tool.poetry]
name = "example"
version = "0.1.0"
description = ""
authors = ["your name <you@example.com>"]
build = "build.py"

[tool.poetry.dependencies]
python = "^3.11"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
# build.py
def build(setup_kwargs):
    pass
# noxfile.py
from nox_poetry import session

@session
def test(session):
    session.poetry.installroot(distribution_format="sdist")

The rest of the files as generated by poetry new and poetry lock.

Running nox:

❯ nox
nox > Running session test
nox > Creating virtual environment (virtualenv) using python in .nox/test
nox > poetry build --format=sdist --no-ansi

Preparing build environment with build-system requirements poetry-corenox > poetry --version --no-ansi
nox > poetry export --format=requirements.txt --without-hashes
nox > pip uninstall --yes 'file:///private/var/folders/x1/jpjk1s6n39qbb5wxldt5ms6c0000gn/T/tmp.i3TGU7yXyi/example/dist/%280.1.0%29#egg=example'
nox > pip cache remove example
nox > python -m pip install --constraint=.nox/test/tmp/requirements.txt 'file:///private/var/folders/x1/jpjk1s6n39qbb5wxldt5ms6c0000gn/T/tmp.i3TGU7yXyi/example/dist/%280.1.0%29#egg=example'
nox > Command python -m pip install --constraint=.nox/test/tmp/requirements.txt 'file:///private/var/folders/x1/jpjk1s6n39qbb5wxldt5ms6c0000gn/T/tmp.i3TGU7yXyi/example/dist/%280.1.0%29#egg=example' failed with exit code 1:
Processing ./dist/(0.1.0)
ERROR: Could not install packages due to an OSError: [Errno 2] No such file or directory: '/private/var/folders/x1/jpjk1s6n39qbb5wxldt5ms6c0000gn/T/tmp.i3TGU7yXyi/example/dist/(0.1.0)'

nox > Session test failed.

Running Poetry:

❯ poetry build
Preparing build environment with build-system requirements poetry-core
Building example (0.1.0)

Running Poetry without build script:

❯ poetry build
Building example (0.1.0)
  - Building sdist
  - Built example-0.1.0.tar.gz
  - Building wheel
  - Built example-0.1.0-py3-none-any.whl

@cjolowicz cjolowicz changed the title Incompatible with latest poetry release? Sdist build fails in projects with build.py Sep 17, 2023
@cjolowicz
Copy link
Owner

Nox currently doesn't have a good way to invoke PEP 517 build hooks like build_sdist (which would take the build directory and return the name of the generated file). So I'd suggest the following, less appealing fix in the nox_poetry.poetry.Poetry.build method:

  • Extract the filename from the output of poetry build, as before.
  • If the file exists in the dist directory, return it.
  • Otherwise, construct a glob from the name and version in pyproject.toml (using nox_poetry.poetry.Config)
  • If the glob matches a unique existing file in the dist directory, return it.
  • Otherwise, raise a friendly error.

Note that tool.poetry.version may not match the version component in the sdist filename. The version could be computed dynamically, and it could be non-PEP 440 format. So this is not perfect, but likely good enough for now?

I'm open for better suggestions. Calling the build hook in a robust, cross-platform way would be great, but I don't really see how. If there was a mechanism to invoke poetry build in a pristine build directory (rather than cleaning out files ourselves), that would also be a great option. Again, this doesn't seem to be supported.

@drhagen
Copy link
Contributor

drhagen commented Feb 15, 2024

The poetry version --short command gives the version for the current Poetry project. Might that work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants