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

Errors building with poetry-core through tox #37

Closed
peterschutt opened this issue Jan 29, 2021 · 3 comments
Closed

Errors building with poetry-core through tox #37

peterschutt opened this issue Jan 29, 2021 · 3 comments
Labels
bug Something isn't working
Milestone

Comments

@peterschutt
Copy link

Hi,

Thanks for the tool, I'm looking forward to adopting it!

This looks similar to #35 in that I'm experiencing issues when tox tries to build my project using poetry-core.

Build system config:

[build-system]
requires = ["poetry-core>=1.0.0", "poetry-dynamic-versioning"]
build-backend = "poetry.core.masonry.api"

Here is the tox log showing the installed libs:

action: .package, msg: getenv
cwd: /home/peter/topsport-com-au/tmpl-package
cmd: /home/peter/topsport-com-au/tmpl-package/.tox/.package/bin/python -m pip install 'poetry-core>=1.0.0' poetry-dynamic-versioning
Collecting poetry-core>=1.0.0
  Using cached poetry_core-1.0.0-py2.py3-none-any.whl (409 kB)
Collecting poetry-dynamic-versioning
  Using cached poetry_dynamic_versioning-0.12.1-py3-none-any.whl (11 kB)
Collecting dunamai<2.0,>=1.5
  Using cached dunamai-1.5.4-py3-none-any.whl (16 kB)
Requirement already satisfied: setuptools>=8.0 in ./.tox/.package/lib/python3.9/site-packages (from dunamai<2.0,>=1.5->poetry-dynamic-versioning) (51.3.3)
Collecting jinja2<3.0.0,>=2.11.1
  Using cached Jinja2-2.11.2-py2.py3-none-any.whl (125 kB)
Collecting MarkupSafe>=0.23
  Using cached MarkupSafe-1.1.1-cp39-cp39-linux_x86_64.whl
Collecting tomlkit>=0.4
  Using cached tomlkit-0.7.0-py2.py3-none-any.whl (32 kB)
Installing collected packages: MarkupSafe, tomlkit, jinja2, dunamai, poetry-dynamic-versioning, poetry-core
Successfully installed MarkupSafe-1.1.1 dunamai-1.5.4 jinja2-2.11.2 poetry-core-1.0.0 poetry-dynamic-versioning-0.12.1 tomlkit-0.7.0
WARNING: You are using pip version 20.3.3; however, version 21.0 is available.
You should consider upgrading via the '/home/peter/topsport-com-au/tmpl-package/.tox/.package/bin/python -m pip install --upgrade pip' command.

And there are 2 log files with errors after tox fails to package the project:

action: .package, msg: get-build-requires
cwd: /home/peter/topsport-com-au/tmpl-package
cmd: /home/peter/topsport-com-au/tmpl-package/.tox/.package/bin/python /home/peter/.cache/pypoetry/virtualenvs/tmpl-package-yMfoEiUP-py3.9/lib/python3.9/site-packages/tox/helper/build_requires.py poetry.core.masonry.api '' ''
Error processing line 1 of /home/peter/topsport-com-au/tmpl-package/.tox/.package/lib/python3.9/site-packages/zzz_poetry_dynamic_versioning.pth:

  Traceback (most recent call last):
    File "/home/peter/.pyenv/versions/3.9.1/lib/python3.9/site.py", line 169, in addpackage
      exec(line)
    File "<string>", line 1, in <module>
    File "/home/peter/topsport-com-au/tmpl-package/.tox/.package/lib/python3.9/site-packages/poetry_dynamic_versioning/__init__.py", line 478, in activate
      _apply_patches()
    File "/home/peter/topsport-com-au/tmpl-package/.tox/.package/lib/python3.9/site-packages/poetry_dynamic_versioning/__init__.py", line 435, in _apply_patches
      from poetry import factory as factory_mod
    File "/home/peter/topsport-com-au/tmpl-package/.tox/.package/lib/python3.9/site-packages/poetry_dynamic_versioning/__init__.py", line 385, in alt_import
      _patch_poetry_create(module.factory)
  AttributeError: module 'poetry' has no attribute 'factory'

Remainder of file ignored
[]

... and this:

action: .package, msg: perform-isolated-build
cwd: /home/peter/topsport-com-au/tmpl-package
cmd: /home/peter/topsport-com-au/tmpl-package/.tox/.package/bin/python /home/peter/.cache/pypoetry/virtualenvs/tmpl-package-yMfoEiUP-py3.9/lib/python3.9/site-packages/tox/helper/build_isolated.py .tox/dist poetry.core.masonry.api '' ''
Error processing line 1 of /home/peter/topsport-com-au/tmpl-package/.tox/.package/lib/python3.9/site-packages/zzz_poetry_dynamic_versioning.pth:

  Traceback (most recent call last):
    File "/home/peter/.pyenv/versions/3.9.1/lib/python3.9/site.py", line 169, in addpackage
      exec(line)
    File "<string>", line 1, in <module>
    File "/home/peter/topsport-com-au/tmpl-package/.tox/.package/lib/python3.9/site-packages/poetry_dynamic_versioning/__init__.py", line 478, in activate
      _apply_patches()
    File "/home/peter/topsport-com-au/tmpl-package/.tox/.package/lib/python3.9/site-packages/poetry_dynamic_versioning/__init__.py", line 435, in _apply_patches
      from poetry import factory as factory_mod
    File "/home/peter/topsport-com-au/tmpl-package/.tox/.package/lib/python3.9/site-packages/poetry_dynamic_versioning/__init__.py", line 385, in alt_import
      _patch_poetry_create(module.factory)
  AttributeError: module 'poetry' has no attribute 'factory'

Remainder of file ignored
Traceback (most recent call last):
  File "/home/peter/.cache/pypoetry/virtualenvs/tmpl-package-yMfoEiUP-py3.9/lib/python3.9/site-packages/tox/helper/build_isolated.py", line 41, in <module>
    basename = backend.build_sdist(dist_folder, {"--global-option": ["--formats=gztar"]})
  File "/home/peter/topsport-com-au/tmpl-package/.tox/.package/lib/python3.9/site-packages/poetry/core/masonry/api.py", line 62, in build_sdist
    poetry = Factory().create_poetry(Path(".").resolve())
  File "/home/peter/topsport-com-au/tmpl-package/.tox/.package/lib/python3.9/site-packages/poetry_dynamic_versioning/__init__.py", line 287, in alt_poetry_create
    run_mod = _state.original_import_func("poetry.console.commands.run", fromlist=[None])
ModuleNotFoundError: No module named 'poetry.console'

If I remove "poetry-dynamic-versioning" from the build-system requirements tox is able to build the project and run tests etc.

I'm happy to provide more info if necessary, and apologies if I'm doing something stupid/missed something obvious!

@mtkennerly
Copy link
Owner

Thanks for this report! I think I've identified a fix for both errors (although I don't quite understand how the first one managed to happen). Would you mind trying this wheel?

poetry_dynamic_versioning-0.12.2a1-py3-none-any.zip

It has the changes from the commit that I just pushed.

@mtkennerly mtkennerly added the bug Something isn't working label Jan 30, 2021
@mtkennerly mtkennerly added this to the v0.12.2 milestone Jan 30, 2021
@peterschutt
Copy link
Author

Hi, thanks for looking at this so quickly! I can confirm the fix works. I couldn't work out how to tell tox to install a build dependency from a local version so I made a bash script that creates a minimal package/poetry/tox/git setup and makes the same set of calls that tox makes to generate the errors. If you pass in the location of the wheel as a positional argument it will install p-d-v from that and all runs fine. E.g.,

Fails with above errors:
$ /bin/bash script.sh

Outputs tmpl-package-0.1.0.tar.gz:
$ /bin/bash script.sh ~/Downloads/poetry_dynamic_versioning-0.12.2a1-py3-none-any.whl

It feels to me like the first error looks like an import side-effect, as seems to happen before anything has executed in the tox build_requires.py helper which is raising the error. I haven't looked at it in any depth though so might be way off the mark!

Here's the script:

#!/bin/bash

# get loc. of pdv from arg, or use pypi.
PDV=${1:-"poetry_dynamic_versioning"}

# Create a temporary directory and store its name in a variable ...
TMPDIR=$(mktemp -d)

# Bail out if the temp directory wasn't created successfully.
if [ ! -e $TMPDIR ]; then
    >&2 echo "Failed to create temp directory"
    exit 1
fi
# Make sure it gets removed even if the script exits abnormally.
trap "exit 1"           HUP INT PIPE QUIT TERM
trap 'rm -rf "$TMPDIR"' EXIT

echo "Created $TMPDIR"
cd $TMPDIR
mkdir -p src/tmpl-package
touch src/tmpl-package/__init__.py

# make pyproject.toml
cat >./pyproject.toml  <<EOL
[tool.poetry]
name = "tmpl-package"
version = "0.0.0"
description = "something"
authors = ["me <me@mail.com>"]
packages =[{include = "tmpl-package", from = "src"}]

[tool.poetry-dynamic-versioning]
enable = true

[build-system]
requires = ["poetry-core>=1.0.0", "poetry-dynamic-versioning"]
build-backend = "poetry.core.masonry.api"
EOL

# make tox.ini
cat >./tox.ini <<EOL
[tox]
envlist=py39
isolated_build=true
EOL

git init && git add . && git commit -m "testing" && git tag v0.1.0

python -m venv .venv
source .venv/bin/activate
PYTHON=$(which python)
SITE_PACKAGES=$(python -c 'import site; print(site.getsitepackages()[0])')
echo $PYTHON
echo $SITE_PACKAGES
python -m pip install tox

$PYTHON -m virtualenv --no-download --python $PYTHON .package
.package/bin/python -m pip install 'poetry-core>=1.0.0' $PDV
.package/bin/python /home/peter/.pyenv/versions/3.9.1/lib/python3.9/site-packages/tox/helper/build_requires.py poetry.core.masonry.api '' ''
.package/bin/python /home/peter/.pyenv/versions/3.9.1/lib/python3.9/site-packages/tox/helper/build_isolated.py .tox/dist poetry.core.masonry.api '' ''

@mtkennerly
Copy link
Owner

Excellent! I've just released the fix as v0.12.2 :D

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

2 participants