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.

dev-dependencies that are also extras

See original GitHub issue

I’ve got a somewhat weird requirement:

Project A provides a bunch of pytest fixtures, and uses pytest itself for testing. I want to provide an extra on the resulting distributable that is called “testing”.

So I created the following:

[tool.poetry.dependencies]
python = "*"
pyramid = "^1.9"
sqlalchemy = {version = "^1.2", extras = ["postgresql"]}
psycopg2 = {version = "^2.7", optional = true}
pytest = {version = "^3.5", optional = true}

[tool.poetry.dev-dependencies]
pytest = "^3.5"
pytest-cov = "^2.5"
coverage = "^4.5"

[tool.poetry.extras]
testing = ["pytest"]
postgresql = ["psycopg2"]

This will work correctly, however the dependency on pytest is specified twice. Once under tool.poetry.dependencies and another time under tool.poetry.dev-dependencies. What I would like to do is make sure that the same thing isn’t listed twice, so I tried the following:

[tool.poetry.dependencies]
python = "*"
pyramid = "^1.9"
sqlalchemy = {version = "^1.2", extras = ["postgresql"]}
psycopg2 = {version = "^2.7", optional = true}

[tool.poetry.dev-dependencies]
pytest = "^3.5"
pytest-cov = "^2.5"
coverage = "^4.5"

[tool.poetry.extras]
testing = ["pytest"]
postgresql = ["psycopg2"]

Hoping that the testing extra would pick up pytest from dev-dependencies. However this is not the case.

So I moved pytest back up, and made it optional:

[tool.poetry.dependencies]
python = "*"
pyramid = "^1.9"
sqlalchemy = {version = "^1.2", extras = ["postgresql"]}
psycopg2 = {version = "^2.7", optional = true}
pytest = {version = "^3.5", optional = true}

[tool.poetry.dev-dependencies]
pytest-cov = "^2.5"
coverage = "^4.5"

[tool.poetry.extras]
testing = ["pytest"]
postgresql = ["psycopg2"]

Now it is correctly picked up, but there is no way to specify that when installing dev-dependencies that the extra testing should be automatically installed too, since that now contains the pytest dependency.

Trying:

mypackage = { version = "*", extras = ["testing"]}

Did not work since it could not find mypackage, and I am sure that if it could find it, it would likely download it from pypi which is not intended.

Is there a way to refer to self somehow? Or would it be possible to add a dependency in one place (define its version and extras/requirements) without redefining it in dev-dependencies?

The goal ultimately is that a secondary package would have the following pyproject.toml:

[tool.poetry]
name = "B-package"
version = "0.2.0"
description = ""
authors = ["Your Name <you@example.com>"]

[tool.poetry.dependencies]
python = "*"
mypackage = {version = "^0.1"}

[tool.poetry.dev-dependencies]
mypackage = {version = "*", extras = ["testing"]}

And only if you are developing would it install mypackage[testing] but for production it would install mypackage. Using the version constraint from tool.poetry.dependencies vs the constraint specified in tool.poetry.dev-dependencies.

This is related to secondary issue: https://github.com/sdispater/poetry/issues/128

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:8
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
dmfigolcommented, Feb 26, 2019

I have similar use-cases for ReadTheDocs automatic builds: https://github.com/rtfd/readthedocs.org/issues/4912#issuecomment-457219385

0reactions
finswimmercommented, Mar 6, 2021

As @thejohnfreeman wrote, this will be possible with dependency groups which are planned for poetry 1.2. I’ll close this one in favor of #1644.

Read more comments on GitHub >

github_iconTop Results From Across the Web

An In-Depth Explanation of package.json's Dependencies
In the dev mode, lerna bootstrap creates a symlink to the plugin's installed devDependencies . We actually end up with the following tree...
Read more >
node.js - What's the difference between dependencies ...
Summary of important behavior differences: dependencies are installed on both: npm install from a directory that contains package.json ...
Read more >
fs-extra - npm
fs-extra contains methods that aren't included in the vanilla Node.js fs package. Such as recursive mkdir, copy, and remove.
Read more >
Managing dependencies | master | Documentation - Poetry
To declare a set of dependencies, which add additional functionality to the project during runtime, use extras instead. Extras can be installed by...
Read more >
Dependencies Management in Setuptools
Please note that you should also include here any other setuptools plugin (e.g., ... create a “variant” of your package with a set...
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