Tomas Aschan
Tomas Aschan

Reputation: 60584

Can I define a package extra that depends on another extra from the same package?

I am building a small Python package, for which I have configured a couple of extras; in my setup.cfg, I have the following:

[options.extras_require]
test =
    coverage>=5,<6
    pytest>=6,<7
    pytest-cov>=2.8.1,<3
lint =
    flake8

This works fine; I can do pip install ., pip install .[test], pip install .[lint] or pip install .[test,lint] in my package directory, and it will install the right things.

Now, I would like to create a new extra, dev, so that pip install .[dev] implies installing both the test and lint extras. Is this possible? How?

I have tried e.g.

dev =
    .[test]
    .[lint]

but this results in a parser error. I have also tried referring to my package name explicitly instead of . in the dependency list, but then it starts downloading old versions from PyPI instead of using the current directory.

Upvotes: 4

Views: 1052

Answers (1)

hoefling
hoefling

Reputation: 66261

Use interpolation:

[options.extras_require]
test =
  coverage>=5,<6
  pytest>=6,<7
  pytest-cov>=2.8.1,<3
lint =
  flake8
dev =
  %(test)s
  %(lint)s

Upvotes: 4

Related Questions