question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
finswimmercommented, Sep 29, 2020

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:

[tool.poetry]
name = "project"
version = "0.1.0"
description = ""
authors = ["Example Author <example.com>"]
include = ["project/**/*"]

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 as name one can leave it out completely.

fin swimmer

0reactions
abncommented, Oct 4, 2020

@mburszley no worries, just raise a new issue when you can and maybe tag @python-poetry/triage.

Read more comments on GitHub >

github_iconTop Results From Across the Web

IndexError with my .gitignore file when trying to build a Python ...
I am trying to package my Python project/library. ... latest build version, I ran this command from within the root folder of my...
Read more >
Non-zero exit code (1) - unable to install packages in pycharm
i am unable to install any package! i get the error: Non-zero exit code (1)
Read more >
Changelog - pip documentation v21.1.dev0
The build step of pip wheel now builds all wheels to a cache first, then copies them to the wheel directory all at...
Read more >
pip Documentation - Read the Docs
To build wheels for your requirements and all their dependencies to a local directory: pip install wheel pip wheel --wheel-dir=/local/wheels ...
Read more >
How to Setup Your Python Environment for Machine Learning ...
Install Deep Learning Libraries. 1. Download Anaconda. In this step, we will download the Anaconda Python package for your platform. Anaconda is ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found