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

nox-poetry crashes with TypeError: slice indices must be integers or None or have an __index__ method #1050

Closed
cjolowicz opened this issue Nov 8, 2021 · 7 comments · Fixed by #1051
Labels
bug Something isn't working

Comments

@cjolowicz
Copy link
Owner

cjolowicz commented Nov 8, 2021

nox-poetry crashes in the GA workflow when parsing requirements with packaging < 21.1 and pyparsing >= 3:

  File ".../python3.9/site-packages/packaging/requirements.py", line 81, in <lambda>
    lambda s, l, t: Marker(s[t._original_start : t._original_end])
TypeError: slice indices must be integers or None or have an __index__ method

The latest version for packaging is not installed because Poetry depends on packaging < 21.0.

There is a workaround for this, adding pyparsing < 3 to .github/workflows/constraints.txt.

A better fix would be to install Poetry and Nox in separate environments, using a tool like pipx.

Traceback
❯ nox -s mypy
nox > Running session mypy-3.9
nox > Creating virtual environment (virtualenv) using python3.9 in .nox/mypy-3-9
nox > poetry build --format=wheel
nox > pip uninstall --yes file:///Users/cjolowicz/Code/github.com/cjolowicz/cutty/dist/cutty-0.15.0-py3-none-any.whl
nox > poetry export --format=requirements.txt --dev --without-hashes
nox > Session mypy-3.9 raised exception TypeError('slice indices must be integers or None or have an __index__ method')
Traceback (most recent call last):
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/nox/sessions.py", line 626, in execute
    self.func(session)
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/nox/_decorators.py", line 54, in __call__
    return self.func(*args, **kwargs)
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/nox_poetry/sessions.py", line 43, in wrapper
    function(proxy, *_args, **_kwargs)
  File "/Users/cjolowicz/Code/github.com/cjolowicz/cutty/noxfile.py", line 128, in mypy
    session.install(".")
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/nox_poetry/sessions.py", line 290, in install
    return self.poetry.install(*args, **kwargs)
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/nox_poetry/sessions.py", line 149, in install
    requirements = self.export_requirements()
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/nox_poetry/sessions.py", line 224, in export_requirements
    constraints = to_constraints(self.poetry.export())
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/nox_poetry/sessions.py", line 90, in to_constraints
    return "\n".join(_to_constraints())
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/nox_poetry/sessions.py", line 86, in _to_constraints
    constraint = to_constraint(requirement, line)
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/nox_poetry/sessions.py", line 68, in to_constraint
    requirement = Requirement(requirement_string)
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/packaging/requirements.py", line 113, in __init__
    req = REQUIREMENT.parseString(requirement_string)
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/pyparsing/core.py", line 1100, in parse_string
    loc, tokens = self._parse(instring, 0)
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/pyparsing/core.py", line 790, in _parseNoCache
    loc, tokens = self.parseImpl(instring, pre_loc, doActions)
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/pyparsing/core.py", line 3810, in parseImpl
    loc, exprtokens = e._parse(instring, loc, doActions)
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/pyparsing/core.py", line 790, in _parseNoCache
    loc, tokens = self.parseImpl(instring, pre_loc, doActions)
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/pyparsing/core.py", line 4024, in parseImpl
    return e._parse(
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/pyparsing/core.py", line 790, in _parseNoCache
    loc, tokens = self.parseImpl(instring, pre_loc, doActions)
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/pyparsing/core.py", line 3810, in parseImpl
    loc, exprtokens = e._parse(instring, loc, doActions)
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/pyparsing/core.py", line 790, in _parseNoCache
    loc, tokens = self.parseImpl(instring, pre_loc, doActions)
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/pyparsing/core.py", line 4854, in parseImpl
    loc, tokens = self_expr._parse(instring, loc, doActions, callPreParse=False)
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/pyparsing/core.py", line 790, in _parseNoCache
    loc, tokens = self.parseImpl(instring, pre_loc, doActions)
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/pyparsing/core.py", line 3810, in parseImpl
    loc, exprtokens = e._parse(instring, loc, doActions)
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/pyparsing/core.py", line 827, in _parseNoCache
    tokens = fn(instring, tokens_start, ret_tokens)
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/pyparsing/core.py", line 283, in wrapper
    ret = func(*args[limit:])
  File "/Users/cjolowicz/.local/pipx/venvs/nox/lib/python3.9/site-packages/packaging/requirements.py", line 81, in <lambda>
    lambda s, l, t: Marker(s[t._original_start : t._original_end])
TypeError: slice indices must be integers or None or have an __index__ method
nox > Session mypy-3.9 failed.
@cjolowicz cjolowicz added the bug Something isn't working label Nov 8, 2021
@cjolowicz
Copy link
Owner Author

See pypa/packaging#482 for the upstream discussion.

@layday
Copy link

layday commented Nov 8, 2021

Just FYI the linked PR is unrelated. This is a regression in pyparsing 3.0.5 and cutting a new packaging release without excluding 3.0.5 will break packaging for everyone (!).

@cjolowicz
Copy link
Owner Author

Thanks for the heads up @layday

@heiderich
Copy link

heiderich commented Nov 8, 2021

I can confirm that the issue persists with release 2021.11.8. This does not surprise me, as #1051 only touches the CI).

@cjolowicz
Copy link
Owner Author

cjolowicz commented Nov 8, 2021

@heiderich Can you post the output of pip freeze in the environment where you see this error?

The latest release of packaging (21.2) depends on pyparsing < 3, so you should only see this if you have an older version of packaging. #1051 isolated the environments of Poetry and nox-poetry because Poetry forced the older version of packaging, triggering the crash in nox-poetry.

@heiderich
Copy link

It turned out that I did not follow the installation instructions closely and did not install the requirements (nox, poetry) in separate environments. Indeed I had an older version of packaging (20.9). Sorry for the noise!

@cjolowicz
Copy link
Owner Author

Thanks for reporting back @heiderich

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
3 participants