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.

Dataclasses solver failure with conditional python marker

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).

  • Linux (Fedora 32):

  • Poetry version:

$ poetry debug info

Poetry
Version: 1.0.5
Python:  3.8.2

Virtualenv
Python:         3.8.2
Implementation: CPython
Path:           /home/projects/poetry-dataclasses/poetry-demo/.venv
Valid:          True

System
Platform: linux
OS:       posix
Python:   /usr

pyproject.yaml

[tool.poetry]
name = "poetry-demo"
version = "0.1.0"
description = ""
authors = []

[tool.poetry.dependencies]
python = "^3.6.1"
dataclasses = {version = "^0.7", python = "~3.6.1"}
dacite = "^1.5.0"

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

Issue

Following on from #1413, the solution there seems to suggest user python version markers to specify when to install a conditional dependencty - in my case the dataclasses-backport on python 3.6.*. However this seems to result in a SolverProblemError resolving in certain cases even with the python specifier as indicated in my pyproject.yaml above .

Things seem to work fine until I also install the addional library dacite (https://github.com/konradhalas/dacite) - which also has a dependency on dataclasses when using python 3.6. The setup.py for it is as follows,

    install_requires=['dataclasses;python_version<"3.7"'],

Once this library is also installed, adding any other packages to my project results in the aforementioned SolverProblemError, e.g.

$ poetry add arrow
Using version ^0.15.6 for arrow

Updating dependencies
Resolving dependencies... (0.0s)

[SolverProblemError]
The current project's Python requirement (^3.6.1) is not compatible with some of the required packages Python requirement:
  - dataclasses requires Python >=3.6, <3.7

Because dataclasses (0.7) requires Python >=3.6, <3.7
 and no versions of dataclasses match >0.7,<0.8, dataclasses is forbidden.
So, because poetry-demo depends on dataclasses (^0.7), version solving failed.

Commenting then uncommenting out either my use of dataclasses or dacite in my pyproject.toml to add additional libraries works, but it seems that both my projects and dacite’s use of dataclasses with a conditional python marker conflict in poetry.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:6
  • Comments:22 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
mandscommented, Jul 9, 2020

As the original submitter, I can still reproduce this on the latest Poetry (1.0.9), when running poetry add <anypackage> within a Python 3.8 venv.

For more context, I’m building an application that runs on any Python from >= 3.6.1, and < 4.0.0 that requires the dataclasses library. As dataclasses is only required when developing using / when a user is running on Python >= 3.6.1 and < 3.7.0, I’ve set a conditional marker - however I develop myself within a Python 3.8 venv. I don’t believe that this is a user error, as I imagine Poetry supports such a configuration (Poetry’s own pyproject.toml has a similar dataclasses constraint) so I’m not sure what’s not working here.

The only way I can get it to work right now is by commenting the dataclasses package in my pyproject.toml, adding the additional package I want via poetry add, and then uncommenting dataclasses again.

My pyproject.toml is,

[tool.poetry.dependencies]
python = "^3.6.1"
dataclasses = {version = "0.7", python = "~3.6.1"}

The output from running poetry add <anypackage> -vvv is

   1: fact: dataclasses (0.7) requires Python >=3.6, <3.7
   1: conflict: dataclasses (0.7) requires Python >=3.6, <3.7
   1: ! dataclasses (0.7) is satisfied by dataclasses (0.7)
   1: ! which is caused by "datapane depends on dataclasses (0.7)"
   1: ! thus: version solving failed
   1: Version solving took 0.420 seconds.
   1: Tried 1 solutions.

[SolverProblemError]
The current project's Python requirement (^3.6.1) is not compatible with some of the required packages Python requirement:
  - dataclasses requires Python >=3.6, <3.7

Because datapane depends on dataclasses (0.7) which requires Python >=3.6, <3.7, version solving failed.
3reactions
cgarciaecommented, Sep 3, 2020

Having a lot of trouble with this. If a dependency itself depends on a restricted version of dataclasses you also get this error, even if you don’t depend on dataclasses yourself.

Read more comments on GitHub >

github_iconTop Results From Across the Web

requirements.txt: conditional on python version - Stack Overflow
Is there a way to make dataclasses only installed if it is necessary? python · dependency-management · requirements.txt · Share.
Read more >
dataclasses — Data Classes — Python 3.11.1 documentation
There is no general way for Data Classes to detect this condition. Instead, the dataclass() decorator will raise a TypeError if it detects...
Read more >
Python Type Hints: case study on parsy - lukeplant.me.uk
I have been trying to like static type checking in Python. For most of my Django projects, I get annoyed and give up,...
Read more >
Python - dataclasses — Data Classes | Docs4dev
It is an error to specify both default and default_factory . init : If true (the default), this field is included as a...
Read more >
Build a Hash Table in Python With TDD
To this day, it helps solve many real-life problems, such as indexing ... When the condition evaluates to True , then nothing happens, ......
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