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

poetry install fails when tests are in a separate subdir from the main package #2450

Closed
3 tasks done
abadger opened this issue May 21, 2020 · 5 comments
Closed
3 tasks done
Labels
kind/bug Something isn't working as expected

Comments

@abadger
Copy link

abadger commented May 21, 2020

  • I am on the latest Poetry version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).

Issue

When a pyproject.toml has multiple include entries in the packages list and one of those entries is listed as format='sdist', poetry will mistakenly try to install that package into the virtualenv when doing poetry install. In conjunction with: #1811 this will lead to a traceback.

Reproducer:

$ wget https://toshio.fedorapeople.org/trees.tar.gz                                  (01:08:06)
$ tar -xzf trees.tar.gz                                                             (01:08:12)
$ cd trees                                                                           (01:08:16)
$ poetry install                                                               (01:08:20)
Installing dependencies from lock file

No dependencies to install or update

  - Installing trees (0.1.0)

[EnvCommandError]
Command ['/home/badger/.cache/pypoetry/virtualenvs/trees-qCG1GaiB-py3.7/bin/pip', 'install', '-e', '/var/tmp/trees'] errored with the following return code 1, and output: 
Obtaining file:///var/tmp/trees
    ERROR: Complete output from command python setup.py egg_info:
    ERROR: running egg_info
    writing src/trees.egg-info/PKG-INFO
    writing dependency_links to src/trees.egg-info/dependency_links.txt
    writing top-level names to src/trees.egg-info/top_level.txt
    error: package directory 'src/test' does not exist
    ----------------------------------------
ERROR: Command "python setup.py egg_info" failed with error code 1 in /var/tmp/trees/
WARNING: You are using pip version 19.1.1, however version 20.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.


Traceback (most recent call last):
  File "/home/badger/.local/lib/python3.7/site-packages/clikit/console_application.py", line 131, in run
    status_code = command.handle(parsed_args, io)
  File "/home/badger/.local/lib/python3.7/site-packages/clikit/api/command/command.py", line 120, in handle
    status_code = self._do_handle(args, io)
  File "/home/badger/.local/lib/python3.7/site-packages/clikit/api/command/command.py", line 171, in _do_handle
    return getattr(handler, handler_method)(args, io, self)
  File "/home/badger/.local/lib/python3.7/site-packages/cleo/commands/command.py", line 92, in wrap_handle
    return self.handle()
  File "/home/badger/.local/lib/python3.7/site-packages/poetry/console/commands/install.py", line 88, in handle
    builder.build()
  File "/home/badger/.local/lib/python3.7/site-packages/poetry/masonry/builders/editable.py", line 17, in build
    return self._setup_build()
  File "/home/badger/.local/lib/python3.7/site-packages/poetry/masonry/builders/editable.py", line 41, in _setup_build
    self._env.run_pip('install', '-e', str(self._path))
  File "/home/badger/.local/lib/python3.7/site-packages/poetry/utils/env.py", line 861, in run_pip
    return self._run(cmd, **kwargs)
  File "/home/badger/.local/lib/python3.7/site-packages/poetry/utils/env.py", line 1089, in _run
    return super(VirtualEnv, self)._run(cmd, **kwargs)
  File "/home/badger/.local/lib/python3.7/site-packages/poetry/utils/env.py", line 893, in _run
    raise EnvCommandError(e, input=input_)

Relevant portion of pyproject.toml from the reproducer tarball:

packages = [
        {include="apple", from="src"},
        {include="test", format="sdist"},
]

The problem is that poetry is generating a setup.py to be able to pip install -e. The setup.py entry for packages is wrong:

package_dir = \
{'': 'src'}

packages = \
['apple', 'test']

In this case, because {include="test"[..]} has format="sdist", test should not appear in the packages list.

@abadger abadger added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels May 21, 2020
@abadger
Copy link
Author

abadger commented May 24, 2020

I saw that there had been some changes in the develop branch to installing the root package. (Is that the right jargon for the package that I'm using poetry to build?) I installed the develop branch and gave this another try. The good news is that on the develop branch poetry install will complete.

The bad news is that it doesn't install correctly. It seems that it still only knows about one of the from entries in the package list. When it installs, it creates a .pth file in the virtualenv. But it can contain the wrong path:

$ cat /home/badger/.cache/pypoetry/virtualenvs/trees-qCG1GaiB-py3.8/lib/python3.8/site-packages/trees.pth
/var/tmp/trees

For this test case, the .pth file should contain /var/tmp/trees/src

Poetry commit hash on develop: abee30f

abadger added a commit to abadger/antsibull that referenced this issue May 24, 2020
By moving the tests into the subdirectory as well.

Hold off on merging this, though, as the current code in what will be
1.1.0 can't seem to handle this either.
python-poetry/poetry#2450 (comment)
jaharkes added a commit to jaharkes/poetry-core that referenced this issue Nov 16, 2020
When we define multiple packages from different source locations,
Poetry currently only uses the last specified from=. This patch adds
explicit paths to package_dir for any additional packages.

This fixes python-poetry/poetry#1811, python-poetry/poetry#2354

And possibly python-poetry/poetry#2450
jaharkes added a commit to jaharkes/poetry-core that referenced this issue Nov 16, 2020
When we define multiple packages from different source locations,
Poetry currently only uses the last specified from=. This patch adds
explicit paths to package_dir for any additional packages.

This fixes python-poetry/poetry#1811 python-poetry/poetry#2354
And possibly python-poetry/poetry#2450
jaharkes added a commit to jaharkes/poetry-core that referenced this issue Nov 16, 2020
When we define multiple packages from different source locations,
Poetry currently only uses the last specified from= location.
This patch adds explicit paths to package_dir for additional packages.

This fixes python-poetry/poetry#1811, fixes python-poetry/poetry#2354,
and possibly even python-poetry/poetry#2450.
jaharkes added a commit to jaharkes/poetry-core that referenced this issue Jun 3, 2021
When we define multiple packages from different source locations,
Poetry currently only uses the last specified from= location.
This patch adds explicit paths to package_dir for additional packages.

This fixes python-poetry/poetry#1811, fixes python-poetry/poetry#2354,
and possibly even python-poetry/poetry#2450.
jaharkes added a commit to jaharkes/poetry-core that referenced this issue Nov 10, 2021
When we define multiple packages from different source locations,
Poetry currently only uses the last specified from= location.
This patch adds explicit paths to package_dir for additional packages.

This fixes python-poetry/poetry#1811, fixes python-poetry/poetry#2354,
and possibly even python-poetry/poetry#2450.
neersighted pushed a commit to python-poetry/poetry-core that referenced this issue Nov 10, 2021
* Fix for including modules from different locations

When we define multiple packages from different source locations,
Poetry currently only uses the last specified from= location.
This patch adds explicit paths to package_dir for additional packages.

This fixes python-poetry/poetry#1811, fixes python-poetry/poetry#2354,
and possibly even python-poetry/poetry#2450.

* Test the fix for including modules from different locations

When we try to include moduleA from libA and moduleB from libB then
package_dir in the generated setup.py must to contain either one or
both `"moduleA": "libA/moduleA"` or `"moduleB": "libB/moduleB"`
so we are able to find both modules when building the source dist.

`ns["package_dir"].keys() == {"", "module_b"}`
should always be true, so we don't have to test for module_a in
`ns["package_dir"]`.
@neersighted
Copy link
Member

I saw that there had been some changes in the develop branch to installing the root package. (Is that the right jargon for the package that I'm using poetry to build?) I installed the develop branch and gave this another try. The good news is that on the develop branch poetry install will complete.

The bad news is that it doesn't install correctly. It seems that it still only knows about one of the from entries in the package list. When it installs, it creates a .pth file in the virtualenv. But it can contain the wrong path:

$ cat /home/badger/.cache/pypoetry/virtualenvs/trees-qCG1GaiB-py3.8/lib/python3.8/site-packages/trees.pth
/var/tmp/trees

For this test case, the .pth file should contain /var/tmp/trees/src

Poetry commit hash on develop: abee30f

Hey @abadger -- would you be willing to try with the latest poetry-core? I do believe that the from= issue should be fixed and that hopefully will solve the second half of this issue.

@abadger
Copy link
Author

abadger commented Nov 10, 2021 via email

abadger added a commit to abadger/antsibull that referenced this issue Nov 14, 2021
poetry has been split into poetry and poetry-core.  The core is a small
subset of functionality that is what is necessary to build python
packages.  Changing from poetry to poetry-core should improve the
`pip install antsibull` experience since all of poetry and its
dependencis won't be needed.

The update to a newer version is also needed to solve:

> python-poetry/poetry#2450

and allow us to put the source in a subdirectory
@abadger
Copy link
Author

abadger commented Nov 14, 2021

I have tested and it seems to work now! Thanks!

@abadger abadger closed this as completed Nov 14, 2021
felixfontein pushed a commit to abadger/antsibull that referenced this issue Nov 15, 2021
poetry has been split into poetry and poetry-core.  The core is a small
subset of functionality that is what is necessary to build python
packages.  Changing from poetry to poetry-core should improve the
`pip install antsibull` experience since all of poetry and its
dependencis won't be needed.

The update to a newer version is also needed to solve:

> python-poetry/poetry#2450

and allow us to put the source in a subdirectory
felixfontein pushed a commit to ansible-community/antsibull-build that referenced this issue Nov 15, 2021
* Use poetry-core as the build backend.

poetry has been split into poetry and poetry-core.  The core is a small
subset of functionality that is what is necessary to build python
packages.  Changing from poetry to poetry-core should improve the
`pip install antsibull` experience since all of poetry and its
dependencis won't be needed.

The update to a newer version is also needed to solve:

> python-poetry/poetry#2450

and allow us to put the source in a subdirectory

* Move source of ansibulled to a subdir.

pyre prefers to be given the directory which holds your python package
as the source-directory rather than the directory which is your python
package.  However, if the directory given is the toplevel, pyre tends to
get slow for me.  (I believe since it scans temporary directories that
I have accumulated [downloads of all those ansible collections...]).
Putting the source code in its own subdirectory is the way to fix that.

* Change the source dir path in github workflows too
@abn abn removed the status/triage This issue needs to be triaged label Mar 3, 2022
Copy link

github-actions bot commented Mar 2, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Something isn't working as expected
Projects
None yet
Development

No branches or pull requests

3 participants