IndexError during wheel build because of vcs ignoring entire project directory
See original GitHub issue-
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). -
OS version and name: Ubuntu 18.04, Ubuntu 19.10
-
Poetry version: 1.0.3
-
Link of a Gist with the contents of your pyproject.toml file: https://gist.github.com/jrandall/a24c6d608a8b57edc5dbad6fcb59ecdb
Issue
When the entire poetry project directory is within a vcs ignored directory tree and pyproject.toml specifies packages using include
, wheel build fails with an IndexError:
$ mkdir /tmp/repo
$ cd /tmp/repo
$ git init
$ mkdir build
$ cd build
$ poetry new project
$ cd project
$ perl -pi -e 's/^authors.*/authors = ["Example Author <example@example.com>"]\npackages = [\n { include = "project" }\n]\n/' pyproject.toml
$ poetry build -vvv
Using virtualenv: /tmp/venv
Building project (0.1.0)
- Building sdist
- Adding: project/__init__.py
- Adding: pyproject.toml
- Built project-0.1.0.tar.gz
- Building wheel
- Adding: /tmp/tmpcrix2209/project-0.1.0/project/__init__.py
- Built project-0.1.0-py3-none-any.whl
$ tar tvf dist/project-0.1.0.tar.gz
-rw-r--r-- 0/0 22 2020-02-19 19:00 project-0.1.0/project/__init__.py
-rw-r--r-- 0/0 326 2020-02-19 19:00 project-0.1.0/pyproject.toml
-rw-r--r-- 0/0 488 2020-02-19 19:05 project-0.1.0/setup.py
-rw-r--r-- 0/0 286 2020-02-19 19:05 project-0.1.0/PKG-INFO
$ echo build > ../../.gitignore
$ poetry build -vvv
Using virtualenv: /tmp/venv
Building project (0.1.0)
- Building sdist
- Adding: pyproject.toml
- Built project-0.1.0.tar.gz
[IndexError]
list index out of range
Traceback (most recent call last):
File "/tmp/venv/lib/python3.7/site-packages/clikit/console_application.py", line 131, in run
status_code = command.handle(parsed_args, io)
File "/tmp/venv/lib/python3.7/site-packages/clikit/api/command/command.py", line 120, in handle
status_code = self._do_handle(args, io)
File "/tmp/venv/lib/python3.7/site-packages/clikit/api/command/command.py", line 171, in _do_handle
return getattr(handler, handler_method)(args, io, self)
File "/tmp/venv/lib/python3.7/site-packages/cleo/commands/command.py", line 92, in wrap_handle
return self.handle()
File "/tmp/venv/lib/python3.7/site-packages/poetry/console/commands/build.py", line 30, in handle
builder.build(fmt)
File "/tmp/venv/lib/python3.7/site-packages/poetry/masonry/builder.py", line 21, in build
return builder.build()
File "/tmp/venv/lib/python3.7/site-packages/poetry/masonry/builders/complete.py", line 59, in build
original=self._poetry,
File "/tmp/venv/lib/python3.7/site-packages/poetry/masonry/builders/wheel.py", line 54, in make_in
wb = WheelBuilder(poetry, env, io, target_dir=directory, original=original)
File "/tmp/venv/lib/python3.7/site-packages/poetry/masonry/builders/wheel.py", line 44, in __init__
super(WheelBuilder, self).__init__(poetry, env, io)
File "/tmp/venv/lib/python3.7/site-packages/poetry/masonry/builders/builder.py", line 68, in __init__
includes=self._package.include,
File "/tmp/venv/lib/python3.7/site-packages/poetry/masonry/utils/module.py", line 72, in __init__
source=package.get('from'),
File "/tmp/venv/lib/python3.7/site-packages/poetry/masonry/utils/package_include.py", line 15, in __init__
self.check_elements()
File "/tmp/venv/lib/python3.7/site-packages/poetry/masonry/utils/package_include.py", line 37, in check_elements
root = self._elements[0]
$ tar tvf dist/project-0.1.0.tar.gz
-rw-r--r-- 0/0 326 2020-02-19 19:00 project-0.1.0/pyproject.toml
-rw-r--r-- 0/0 488 2020-02-19 19:00 project-0.1.0/setup.py
-rw-r--r-- 0/0 286 2020-02-19 19:00 project-0.1.0/PKG-INFO
The situation could be slightly improved by swapping the sanity check on line 39 (https://github.com/python-poetry/poetry/blob/master/poetry/masonry/utils/package_include.py#L39) with the assignment on line 37 that triggers the exception (https://github.com/python-poetry/poetry/blob/master/poetry/masonry/utils/package_include.py#L37).
It may also be worth considering adding an option to disable the VCS ignore setting in poetry config, or to detect if all of the files in the included files are being excluded by VCS and disable it automatically (perhaps with a warning).
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:8 (3 by maintainers)
Hello,
the correct way to this is to you use the
include
keyword, to define which files are allowed to include even if they are in the.gitignore
:The
packages
keyword is just used to tell poetry where it founds the packages data. If the name of that folder is the same as the asname
one can leave it out completely.fin swimmer
@mburszley no worries, just raise a new issue when you can and maybe tag
@python-poetry/triage
.