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.

Optinal package install (mypy) raising "Could not parse version constraint: <empty>"

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: CentOS 7.

  • Poetry version: 0.12.17

  • Link of a Gist with the contents of your pyproject.toml file: NA

Issue

I have a package that needs running on Python 2 and 3. Therefore, I have

[tool.poetry.dependencies]
python = "^2.7 || ^3.6 ||  ^3.7"

in my pyproject.toml file.

I want some dependencies to be only Python 3, mostly for dev work – namely mypy and black. Reading the documentation, I found it is best practice to use poetry add … so that is what I did. However, I got a Could not parse version constraint: <empty>.

What am I doing wrong?

Could it be another manifestation of bug #1480?

usignals-py3.7(poetry ↑2|+3); poetry add -v -D --python ">=3.6" --optional mypy
Using virtualenv: /home/usr/.cache/pypoetry/virtualenvs/usignals-py3.7
Using version ^0.740.0 for mypy

Updating dependencies
Resolving dependencies... (0.9s)
                                               
[ValueError]                    
Could not parse version constraint: <empty>  
                                               
Exception trace:
 /home/usr/.poetry/lib/poetry/_vendor/py3.7/cleo/application.py in run() at line 94
   status_code = self.do_run(input_, output_)
 /home/usr/.poetry/lib/poetry/console/application.py in do_run() at line 88
   return super(Application, self).do_run(i, o)
 /home/usr/.poetry/lib/poetry/_vendor/py3.7/cleo/application.py in do_run() at line 197
   status_code = command.run(input_, output_)
 /home/usr/.poetry/lib/poetry/console/commands/command.py in run() at line 77
   return super(BaseCommand, self).run(i, o)
 /home/usr/.poetry/lib/poetry/_vendor/py3.7/cleo/commands/base_command.py in run() at line 146
   status_code = self.execute(input_, output_)
 /home/usr/.poetry/lib/poetry/_vendor/py3.7/cleo/commands/command.py in execute() at line 107
   return self.handle()
 /home/usr/.poetry/lib/poetry/console/commands/add.py in handle() at line 139
   status = installer.run()
 /home/usr/.poetry/lib/poetry/installation/installer.py in run() at line 73
   self._do_install(local_repo)
 /home/usr/.poetry/lib/poetry/installation/installer.py in _do_install() at line 165
   ops = solver.solve(use_latest=self._whitelist)
 /home/usr/.poetry/lib/poetry/puzzle/solver.py in solve() at line 38
   packages, depths = self._solve(use_latest=use_latest)
 /home/usr/.poetry/lib/poetry/puzzle/solver.py in _solve() at line 177
   e.constraints, use_latest=use_latest
 /home/usr/.poetry/lib/poetry/puzzle/solver.py in solve_in_compatibility_mode() at line 144
   _packages, _depths = self._solve(use_latest=use_latest)
 /home/usr/.poetry/lib/poetry/puzzle/solver.py in _solve() at line 171
   self._package, self._provider, locked=locked, use_latest=use_latest
 /home/usr/.poetry/lib/poetry/mixology/__init__.py in resolve_version() at line 7
   return solver.solve()
 /home/usr/.poetry/lib/poetry/mixology/version_solver.py in solve() at line 79
   next = self._choose_package_version()
 /home/usr/.poetry/lib/poetry/mixology/version_solver.py in _choose_package_version() at line 377
   version = self._provider.complete_package(version)
 /home/usr/.poetry/lib/poetry/puzzle/provider.py in complete_package() at line 592
   package.dependency.python_constraint
 /home/usr/.poetry/lib/poetry/packages/dependency.py in transitive_python_versions() at line 109
   self._transitive_python_constraint = parse_constraint(value)
 /home/usr/.poetry/lib/poetry/semver/__init__.py in parse_constraint() at line 31
   constraint_objects.append(parse_single_constraint(and_constraints[0]))
 /home/usr/.poetry/lib/poetry/semver/__init__.py in parse_single_constraint() at line 164
   raise ValueError("Could not parse version constraint: {}".format(constraint))

add [-D|--dev] [--git GIT] [--path PATH] [-E|--extras EXTRAS] [--optional] [--python PYTHON] [--platform PLATFORM] [--allow-prereleases] [--dry-run] [--] <name> (<name>)...

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
byronzcommented, Nov 11, 2019

I am having a similar problem with pytest-mock package

poetry add -v -D --python "^3.4" --optional pytest-mock
Using virtualenv: /Users/byron/Library/Caches/pypoetry/virtualenvs/demo-py2.7
Using version ^1.11 for pytest-mock

Updating dependencies
Resolving dependencies... (1.5s)

[ValueError]
Could not parse version constraint: <empty>

Exception trace:
 /Users/byron/.poetry/lib/poetry/_vendor/py2.7/cleo/application.py in run() at line 94
   status_code = self.do_run(input_, output_)
 /Users/byron/.poetry/lib/poetry/console/application.py in do_run() at line 88
   return super(Application, self).do_run(i, o)
 /Users/byron/.poetry/lib/poetry/_vendor/py2.7/cleo/application.py in do_run() at line 197
   status_code = command.run(input_, output_)
 /Users/byron/.poetry/lib/poetry/console/commands/command.py in run() at line 77
   return super(BaseCommand, self).run(i, o)
 /Users/byron/.poetry/lib/poetry/_vendor/py2.7/cleo/commands/base_command.py in run() at line 146
   status_code = self.execute(input_, output_)
 /Users/byron/.poetry/lib/poetry/_vendor/py2.7/cleo/commands/command.py in execute() at line 107
   return self.handle()
 /Users/byron/.poetry/lib/poetry/console/commands/add.py in handle() at line 139
   status = installer.run()
 /Users/byron/.poetry/lib/poetry/installation/installer.py in run() at line 73
   self._do_install(local_repo)
 /Users/byron/.poetry/lib/poetry/installation/installer.py in _do_install() at line 165
   ops = solver.solve(use_latest=self._whitelist)
 /Users/byron/.poetry/lib/poetry/puzzle/solver.py in solve() at line 38
   packages, depths = self._solve(use_latest=use_latest)
 /Users/byron/.poetry/lib/poetry/puzzle/solver.py in _solve() at line 177
   e.constraints, use_latest=use_latest
 /Users/byron/.poetry/lib/poetry/puzzle/solver.py in solve_in_compatibility_mode() at line 144
   _packages, _depths = self._solve(use_latest=use_latest)
 /Users/byron/.poetry/lib/poetry/puzzle/solver.py in _solve() at line 171
   self._package, self._provider, locked=locked, use_latest=use_latest
 /Users/byron/.poetry/lib/poetry/mixology/__init__.py in resolve_version() at line 7
   return solver.solve()
 /Users/byron/.poetry/lib/poetry/mixology/version_solver.py in solve() at line 79
   next = self._choose_package_version()
 /Users/byron/.poetry/lib/poetry/mixology/version_solver.py in _choose_package_version() at line 377
   version = self._provider.complete_package(version)
 /Users/byron/.poetry/lib/poetry/puzzle/provider.py in complete_package() at line 592
   package.dependency.python_constraint
 /Users/byron/.poetry/lib/poetry/packages/dependency.py in transitive_python_versions() at line 109
   self._transitive_python_constraint = parse_constraint(value)
 /Users/byron/.poetry/lib/poetry/semver/__init__.py in parse_constraint() at line 31
   constraint_objects.append(parse_single_constraint(and_constraints[0]))
 /Users/byron/.poetry/lib/poetry/semver/__init__.py in parse_single_constraint() at line 164
   raise ValueError("Could not parse version constraint: {}".format(constraint))

add [-D|--dev] [--git GIT] [--path PATH] [-E|--extras EXTRAS] [--optional] [--python PYTHON] [--platform PLATFORM] [--allow-prereleases] [--dry-run] [--] <name> (<name>)...

I found out that it adds an entry about typing module in the poetry.lock , and it seems to be the root cause with an invalid marker field marker = "<empty>"

[[package]]
category = "dev"
description = "Type Hints for Python"
marker = "<empty>"
name = "typing"
optional = true
python-versions = "*"
version = "3.7.4.1"

a reference toml file

[tool.poetry]
name = "demo"
authors = ["bz"]
version = "1.6"
description = ""

[tool.poetry.dependencies]
python = "~2.7 || ^3.3"

future = "^0.18.2"
requests = [
    {version = "^2.22", extras = ["security"], python="^3.5"},
    {version = "^2.0", extras = ["security"], python="<3.5"}
]
flask = [
    { version = "^1.0.0", python="^3.5" },
    { version = "<1.0", python = "<3.5" }
]
flask-compress = "^1.4"

pytest = [
    { version = "^5.0.0", optional = true, python = "^3.5" },
    { version = "^3.0.0", optional = true, python = "<3.5" }
]
pytest-mock = [
    { version = "^1.11.0", optional = true, python = "^3.4" },
    { version = "^1.6.0", optional = true, python = "<3.4" }
]
pytest-sugar = { version = "^0.9.2", optional = true }
selenium = { version = "^3.141.0", optional = true }
percy = { version = "^2.0", optional = true }

[tool.poetry.dev-dependencies]
flake8 = [
    { version = "^3.7", python = "^3.5", optional = true },
    { version = "^3.5.0 && < 3.7", python = "~2.7 || <3.5", optional = true }
]
pylint = [
    { version = "^1.0.0", python = "~2.7 || <3.5", optional = true },
    { version = "^2.0.0", python = "^3.5", optional = true }
]
astroid = { version = "^2.2.5", python = "^3.7", optional=true }
coloredlogs = "^10.0"
fire = "^0.2.1"
mock = [
    { version = "^2.0.0", python = "~2.7 || <3.5", optional = true },
    { version = "^3.0.0", python = "^3.5", optional = true }
]
pyyaml = "^5.1"
virtualenv = { version="^16", python = "~2.7", optional = true}

[tool.poetry.extras]
testing = ["pytest", "pytest-sugar", "pytest-mock", "selenium", "percy"]
dev = ["flake8", "mock", "coloredlogs", "fire", "pyyaml"]

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"

0reactions
neersightedcommented, Nov 21, 2022

"mypy" is not a valid version constraint. Poetry is telling you that you are feeding it a meaningless input. If you’re confused by this, please start a Discussion or reach out on Github instead of commenting on a resolved issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

poetry install - ParseConstraintError Could not parse version ...
In my case, this issue seems to have been triggered with the latest version of poetry, 1.2.1. Downgrading to 1.1.12 fixed it.
Read more >
Composer could not parse version constraint / could ... - Drupal
We've stuck in the following error in Drupal CI/CD (again). Composer require failure - View results on dispatcher --- Commands Executed ...
Read more >
Changelog - PDM
The local package is now treated specially during installation and locking. This means it will no longer be included in the lockfile, and...
Read more >
Cool Things You Can Do With Pydantic - Medium
Pydantic verifies that scores are not empty. Inputs that don't obey the constraints causes Pydantic to raise a ValidationError .
Read more >
What's New In Python 3.11 — Python 3.11.1 documentation
Summary – Release highlights¶ · Faster CPython New syntax features: · PEP 654: Exception Groups and except*. New built-in features: · PEP 678:...
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