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

Troubles with package with local dependencies #783

Open
Georacer opened this issue Jun 24, 2022 · 1 comment
Open

Troubles with package with local dependencies #783

Georacer opened this issue Jun 24, 2022 · 1 comment

Comments

@Georacer
Copy link

Georacer commented Jun 24, 2022

Hello there!

I'm having a hard time with the particular configuration of my project.
Here's what I have:

my_package/
├── src/my_package/
│   ├── some_code.py
│   ├── a_subrepo/
│       ├── src/a_subrepo/
│       │   ├── some_more_code.py
│       ├─ another_subprepo/
│       ├── pyproject.toml
├── pyproject.toml

my_package is a python package set-up with https://github.com/cjolowicz/cookiecutter-hypermodern-python.
a_subprepo is a python package made with a bare poetry init and added to my_package with poetry add src/my_package/a_subprepo.
The same deal with another_subprepo. It was added to a_subprepo (from its root directory) with poetry add another_subprepo.

The two subprepos are git submodules and I'd prefer to keep it that way, for faster development.

Now, I'm at the root directory of my_package and poetry install find the sub-repos as expected:

> poetry show
...
another_subrepo   0.1.0 src/my_package/a_subprepo/another_subrepo Another Subackage description
...
a_subrepo         1.0.0 src/my_package/a_subprepo               A Subpackage description.
...

The dependencies can be imported in the code and run just fine.
But opening a nox session does not work:

❯ nox -s pre-commit         
nox > Running session pre-commit
nox > Creating virtual environment (virtualenv) using python3.8 in .nox/pre-commit
nox > poetry export --format=requirements.txt --dev --without-hashes
nox > Session pre-commit raised exception RuntimeError('line 60: \'another_subrepo @ file://<abs_path_to_another_subprepo>; python_version >= "3.8" and python_version < "3.11"\': Parse error at "\'python_v\'": Expected stringEnd')
Traceback (most recent call last):
  File "/home/<user_name>/.local/lib/python3.8/site-packages/packaging/requirements.py", line 102, in __init__
    req = REQUIREMENT.parseString(requirement_string)
  File "/home/<user_name>/.local/lib/python3.8/site-packages/pyparsing.py", line 1955, in parseString
    raise exc
  File "/home/<user_name>/.local/lib/python3.8/site-packages/pyparsing.py", line 3814, in parseImpl
    raise ParseException(instring, loc, self.errmsg, self)
pyparsing.ParseException: Expected stringEnd, found 'p'  (at char 130), (line:1, col:131)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/<user_name>/.local/lib/python3.8/site-packages/nox_poetry/sessions.py", line 68, in to_constraint
    requirement = Requirement(requirement_string)
  File "/home/<user_name>/.local/lib/python3.8/site-packages/packaging/requirements.py", line 104, in __init__
    raise InvalidRequirement(
packaging.requirements.InvalidRequirement: Parse error at "'python_v'": Expected stringEnd

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/<user_name>/.local/lib/python3.8/site-packages/nox/sessions.py", line 695, in execute
    self.func(session)
  File "/home/<user_name>/.local/lib/python3.8/site-packages/nox/_decorators.py", line 68, in __call__
    return self.func(*args, **kwargs)
  File "/home/<user_name>/.local/lib/python3.8/site-packages/nox_poetry/sessions.py", line 43, in wrapper
    function(proxy, *_args, **_kwargs)
  File "/home/<user_name>/Dropbox/<user_name>/Projects/Avy/performance_models/noxfile.py", line 122, in precommit
    session.install(
  File "/home/<user_name>/.local/lib/python3.8/site-packages/nox_poetry/sessions.py", line 292, in install
    return self.poetry.install(*args, **kwargs)
  File "/home/<user_name>/.local/lib/python3.8/site-packages/nox_poetry/sessions.py", line 147, in install
    requirements = self.export_requirements()
  File "/home/<user_name>/.local/lib/python3.8/site-packages/nox_poetry/sessions.py", line 227, in export_requirements
    constraints = to_constraints(self.poetry.export())
  File "/home/<user_name>/.local/lib/python3.8/site-packages/nox_poetry/sessions.py", line 90, in to_constraints
    return "\n".join(_to_constraints())
  File "/home/<user_name>/.local/lib/python3.8/site-packages/nox_poetry/sessions.py", line 86, in _to_constraints
    constraint = to_constraint(requirement, line)
  File "/home/<user_name>/.local/lib/python3.8/site-packages/nox_poetry/sessions.py", line 70, in to_constraint
    raise RuntimeError(f"line {line}: {requirement_string!r}: {error}") from error
RuntimeError: line 60: 'another_subprepo @ file://<abs_path_to_another_subprepo>; python_version >= "3.8" and python_version < "3.11"': Parse error at "'python_v'": Expected stringEnd
nox > Session pre-commit failed.

And indeed the offending line in the requirements.txt file is

another_subrepo @ file://<abs_path_to_another_subrepo>; python_version >= "3.8" and python_version < "3.11"

I fear that pip does not support local dependencies, but I can't be sure; I find it weird, because pip install <path_to_another_subrepo> works just fine.

Any ideas?
Thanks in advance!

@jooh
Copy link

jooh commented Dec 27, 2022

I had the same issue and Poetry 1.3.1 solved it for me. I think the root cause was a missing space before the semi-colon as in pypa/packaging#529

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants