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.

How are you supposed to install optionals?

See original GitHub issue
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have searched the documentation and believe that my question is not covered.

Question

I’ve got something similar to poetry’s pyproject.toml file.

You can see my file here: aiohttp_session_ws

The problem is, now that black is optional, I can’t get it to install. Should I only be using optional for packages that are “extras”. And if so, why doesn’t poetry install -E development then install black?

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
mikeneronecommented, Aug 2, 2020

As it appears to be the case that the use of extras is required for all optional dependencies in order in order to be able to opt-in, I think the phrasing of this comment in the docs at https://python-poetry.org/docs/pyproject/ need to be changed. Note the word “some”, which implies “not all”.

# A list of all of the optional dependencies, some of which are included in the
# below `extras`. They can be opted into by apps.

It’s confusing at best.

1reaction
nickprestacommented, Nov 7, 2018

EDIT I’ve submitted a PR that fixes the issue.

I have the same (or similar) issue:

pyproject.toml

[tool.poetry]
name = "mything"
version = "0.1.0"
description = "description"
authors = ["nick"]

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

[tool.poetry.dev-dependencies]
pytest = "^3"
black = { version = "^18.9b0", optional = true }
mypy = { version = "^0.641.0", optional = true }
typing-extensions = { version = "^3.6", optional = true }

[tool.poetry.extras]
developer = ["black", "mypy", "typing-extensions"]

When I run poetry install -v, I get:

$ poetry install -v
Creating virtualenv mything-py3.7 in /Users/npresta/Library/Caches/pypoetry/virtualenvs
Using virtualenv: /Users/npresta/Library/Caches/pypoetry/virtualenvs/mything-py3.7
Updating dependencies
Resolving dependencies... (0.6s)


Package operations: 7 installs, 0 updates, 0 removals

Writing lock file

  - Installing six (1.11.0)
  - Installing atomicwrites (1.2.1)
  - Installing attrs (18.2.0)
  - Installing more-itertools (4.3.0)
  - Installing pluggy (0.8.0)
  - Installing py (1.7.0)
  - Installing pytest (3.10.0)

When I run poetry show -v:

$ poetry show -v
Using virtualenv: /Users/npresta/Library/Caches/pypoetry/virtualenvs/mything-py3.7
appdirs           1.4.3  A small Python module for determining appropriate platform-specific dirs, e.g. a "user data dir".
atomicwrites      1.2.1  Atomic file writes.
attrs             18.2.0 Classes Without Boilerplate
black             18.9b0 The uncompromising code formatter.
click             7.0    Composable command line interface toolkit
more-itertools    4.3.0  More routines for operating on iterables, beyond itertools
mypy              0.641  Optional static typing for Python
mypy-extensions   0.4.1  Experimental type system extensions for programs checked with the mypy typechecker.
pluggy            0.8.0  plugin and hook calling mechanisms for python
py                1.7.0  library with cross-python path, ini-parsing, io, code, log facilities
pytest            3.10.0 pytest: simple powerful testing with Python
six               1.11.0 Python 2 and 3 compatibility utilities
toml              0.10.0 Python Library for Tom's Obvious, Minimal Language
typed-ast         1.1.0  a fork of Python 2 and 3 ast modules with type comment support
typing            3.6.6  Type Hints for Python
typing-extensions 3.6.6  Backported and Experimental Type Hints for Python 3.5+

The packages appdirs, black, click, mypy, mypy-extensions, toml, typed-ast, typing, typing-extensions` are red instead of green.

When I run poetry install -v -E developer I get:

$ poetry install -v -E developer
Using virtualenv: /Users/npresta/Library/Caches/pypoetry/virtualenvs/mything-py3.7
Installing dependencies from lock file

Nothing to install or update

and poetry run pip freeze shows:

$ poetry run pip freeze
atomicwrites==1.2.1
attrs==18.2.0
more-itertools==4.3.0
pluggy==0.8.0
py==1.7.0
pytest==3.10.0
six==1.11.0

HOWEVER, I found a manual fix. When I look at poetry.lock, there is a section that looks like this:

[extras]
developer = []

When I change that list to:

[extras]
developer = ["mypy", "black", "typing-extensions"]

and run poetry install -v -E developer I get:

$ poetry install -v -E developer
Using virtualenv: /Users/npresta/Library/Caches/pypoetry/virtualenvs/mything-py3.7
Installing dependencies from lock file


Package operations: 9 installs, 0 updates, 0 removals

  - Installing appdirs (1.4.3)
  - Installing click (7.0)
  - Installing mypy-extensions (0.4.1)
  - Installing toml (0.10.0)
  - Installing typed-ast (1.1.0)
  - Installing typing (3.6.6)
  - Installing black (18.9b0)
  - Installing mypy (0.641)

and poetry show works as expected (all 9 packages are green).

It seems the initial extras are not being written to the lock file when the dependencies appear as part of dev-dependencies.

When I move the requirements from dev-dependencies to dependencies, things work as expected:

$ cat pyproject.toml
[tool.poetry]
name = "mything"
version = "0.1.0"
description = "description"
authors = ["nick"]

[tool.poetry.dependencies]
python = "^3.6 || ^3.7"
black = { version = "^18.9b0", optional = true }
mypy = { version = "^0.641.0", optional = true }
typing_extensions = { version = "^3.6", optional = true }

[tool.poetry.dev-dependencies]
pytest = "^3"

[tool.poetry.extras]
developer = ["black", "mypy", "typing_extensions"]

$ poetry install -v -E developer
Using virtualenv: /Users/npresta/Library/Caches/pypoetry/virtualenvs/mything-py3.7
Installing dependencies from lock file


Package operations: 9 installs, 0 updates, 0 removals

  - Installing appdirs (1.4.3)
  - Installing click (7.0)
  - Installing mypy-extensions (0.4.1)
  - Installing toml (0.10.0)
  - Installing typed-ast (1.1.0)
  - Installing typing (3.6.6)
  - Installing black (18.9b0)
  - Installing mypy (0.641)
  - Installing typing-extensions (3.6.6)

I believe this is a bug. We should be able to define extras that depend on packages only in dev-dependencies. I have a straightforward fix that I’m working on and expect to submit today.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What Are NPM's Optional Dependencies and When Should ...
Execute npm install someDependency --save-optional to install a package as an optional dependency. The installed package will be put into ...
Read more >
What are Optional Dependencies and when should we use them
How to install a dependency as an optional dependency: We can install a dependency as an optional dependency using the following command:
Read more >
What Are Windows Optional Updates, and How Do You Install ...
Not all Windows updates are mandatory. Check out our guide on optional updates, what they do, and if you should download them or...
Read more >
Python poetry - how to install optional dependencies?
You need to add a tool.poetry.extras group to your pyproject.toml if you want to use the -E flag during install, as described in...
Read more >
Should I Install Optional Updates In Windows ... - YouTube
Should I Install Optional Updates In Windows? How To Install Optional Updates Windows 11 [Tutorial]We'll explain what's going on in more ...
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