Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove deprecated mypy_extensions and typing_extensions deps #863

Closed
wants to merge 1 commit into from

Conversation

nemith
Copy link
Contributor

@nemith nemith commented Sep 21, 2023

mypy_extensions and typing_extensions were decalred only as dev depenendencies. This means in a clean enviroment (like a fresh venv) nornir would fail to load.

Turns out the use for mypy_extensions was deprecated so we can remove that also Protocol is part of the base typing package so we can get rid of the typing_extensions package as well fixing both.

See: https://mypy.readthedocs.io/en/stable/additional_features.html?highlight=mypy_extensions#extended-callable-types

Fixes: #861

Testing

Before (on master)

$ git switch main
Switched to branch 'main'
Your branch is up to date with 'upstream/main'.
$ rm -rf /tmp/venv && python3 -m venv /tmp/venv && source /tmp/venv/bin/activate
$ pip install .
Processing /Volumes/Code/nornir
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Collecting ruamel.yaml>=0.17 (from nornir==3.4.0)
  Obtaining dependency information for ruamel.yaml>=0.17 from https://files.pythonhosted.org/packages/d9/0e/2a05efa11ea33513fbdf4a2e2576fe94fd8fa5ad226dbb9c660886390974/ruamel.yaml-0.17.32-py3-none-any.whl.metadata
  Using cached ruamel.yaml-0.17.32-py3-none-any.whl.metadata (17 kB)
Collecting ruamel.yaml.clib>=0.2.7 (from ruamel.yaml>=0.17->nornir==3.4.0)
  Obtaining dependency information for ruamel.yaml.clib>=0.2.7 from https://files.pythonhosted.org/packages/f5/23/b8ff333e40fa194678b01b66c1aced9dc5ecbc16a043b0d09beb6a37377c/ruamel.yaml.clib-0.2.7-cp311-cp311-macosx_13_0_arm64.whl.metadata
  Using cached ruamel.yaml.clib-0.2.7-cp311-cp311-macosx_13_0_arm64.whl.metadata (2.2 kB)
Using cached ruamel.yaml-0.17.32-py3-none-any.whl (112 kB)
Using cached ruamel.yaml.clib-0.2.7-cp311-cp311-macosx_13_0_arm64.whl (125 kB)
Building wheels for collected packages: nornir
  Building wheel for nornir (pyproject.toml) ... done
  Created wheel for nornir: filename=nornir-3.4.0-py3-none-any.whl size=30570 sha256=cff7a6cfbb4ba5d4d0427f78ae65d8275e2e30412d5e68ec54a210cab4371236
  Stored in directory: /private/var/folders/xv/k7lms_fn08972kd179h5j1zr0000gp/T/pip-ephem-wheel-cache-vl5mhvvm/wheels/97/89/d9/720bf7ca5f7e0b4e0392b119fd063d14f3782a0d72f9116fa3
Successfully built nornir
Installing collected packages: ruamel.yaml.clib, ruamel.yaml, nornir
Successfully installed nornir-3.4.0 ruamel.yaml-0.17.32 ruamel.yaml.clib-0.2.7
$ pip freeze
nornir @ file:///Volumes/Code/nornir
ruamel.yaml==0.17.32
ruamel.yaml.clib==0.2.7
$ python3
Python 3.11.5 (main, Aug 24 2023, 15:09:45) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from nornir.init_nornir import InitNornir
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Volumes/Code/nornir/nornir/__init__.py", line 3, in <module>
    from nornir.init_nornir import InitNornir
  File "/Volumes/Code/nornir/nornir/init_nornir.py", line 3, in <module>
    from nornir.core import Nornir
  File "/Volumes/Code/nornir/nornir/core/__init__.py", line 6, in <module>
    from nornir.core.inventory import Inventory
  File "/Volumes/Code/nornir/nornir/core/inventory.py", line 17, in <module>
    from nornir.core.plugins.connections import (
  File "/Volumes/Code/nornir/nornir/core/plugins/connections.py", line 6, in <module>
    from typing_extensions import Protocol
ModuleNotFoundError: No module named 'typing_extensions'
>>> print("sad elephant")
sad elephant
>>> 

After my fix

 rm -rf /tmp/venv && python3 -m venv /tmp/venv && source /tmp/venv/bin/activate
$ pip install .
Processing /Volumes/Code/nornir
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Collecting ruamel.yaml>=0.17 (from nornir==3.4.0)
  Obtaining dependency information for ruamel.yaml>=0.17 from https://files.pythonhosted.org/packages/d9/0e/2a05efa11ea33513fbdf4a2e2576fe94fd8fa5ad226dbb9c660886390974/ruamel.yaml-0.17.32-py3-none-any.whl.metadata
  Using cached ruamel.yaml-0.17.32-py3-none-any.whl.metadata (17 kB)
Collecting typing_extensions<5.0.0,>=4.7.1 (from nornir==3.4.0)
  Obtaining dependency information for typing_extensions<5.0.0,>=4.7.1 from https://files.pythonhosted.org/packages/24/21/7d397a4b7934ff4028987914ac1044d3b7d52712f30e2ac7a2ae5bc86dd0/typing_extensions-4.8.0-py3-none-any.whl.metadata
  Using cached typing_extensions-4.8.0-py3-none-any.whl.metadata (3.0 kB)
Collecting ruamel.yaml.clib>=0.2.7 (from ruamel.yaml>=0.17->nornir==3.4.0)
  Obtaining dependency information for ruamel.yaml.clib>=0.2.7 from https://files.pythonhosted.org/packages/f5/23/b8ff333e40fa194678b01b66c1aced9dc5ecbc16a043b0d09beb6a37377c/ruamel.yaml.clib-0.2.7-cp311-cp311-macosx_13_0_arm64.whl.metadata
  Using cached ruamel.yaml.clib-0.2.7-cp311-cp311-macosx_13_0_arm64.whl.metadata (2.2 kB)
Using cached ruamel.yaml-0.17.32-py3-none-any.whl (112 kB)
Using cached typing_extensions-4.8.0-py3-none-any.whl (31 kB)
Using cached ruamel.yaml.clib-0.2.7-cp311-cp311-macosx_13_0_arm64.whl (125 kB)
Building wheels for collected packages: nornir
  Building wheel for nornir (pyproject.toml) ... done
  Created wheel for nornir: filename=nornir-3.4.0-py3-none-any.whl size=30594 sha256=0d390bd2603b0cb2276eab8fcc0b2be8727fa60ddc90980964ac250a82bcd3f6
  Stored in directory: /private/var/folders/xv/k7lms_fn08972kd179h5j1zr0000gp/T/pip-ephem-wheel-cache-zsiapwf0/wheels/97/89/d9/720bf7ca5f7e0b4e0392b119fd063d14f3782a0d72f9116fa3
Successfully built nornir
Installing collected packages: typing_extensions, ruamel.yaml.clib, ruamel.yaml, nornir
Successfully installed nornir-3.4.0 ruamel.yaml-0.17.32 ruamel.yaml.clib-0.2.7 typing_extensions-4.8.0
$ pip freeze
nornir @ file:///Volumes/Code/nornir
ruamel.yaml==0.17.32
ruamel.yaml.clib==0.2.7
typing_extensions==4.8.0
$ python3
Python 3.11.5 (main, Aug 24 2023, 15:09:45) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from nornir.init_nornir import InitNornir
>>> print("awesome possum")
awesome possum
>>> ^D

@nemith nemith marked this pull request as ready for review September 21, 2023 19:55
@nemith
Copy link
Contributor Author

nemith commented Sep 21, 2023

And from looking at your code, I assume you did not use black for the formatting. The code must be formatted with black to pass the test.

nornir/Makefile

Lines 17 to 19 in 325c8ca

.PHONY: black
black:
poetry run black --check ${NORNIR_DIRS}

Just the opposite. My editor is setup to run black and isort and isort is formatting the imports (black doesn't)

@nemith
Copy link
Contributor Author

nemith commented Sep 21, 2023

It would be great not to add a dependency again. Luckily we removed Python 3.7 support, so we are fine to use typing.Protocol

I can update to use typing.Protocol. I am not ADDING a dependency but FIXING one. Fixed ALL the typing_extension imports as well in the latest update.

@nemith nemith changed the title remove deprecated mypy_dependency remove deprecated mypy_extensions and typing_extensions deps Sep 22, 2023
@ktbyers
Copy link
Collaborator

ktbyers commented Sep 22, 2023

Fix implemented here: #867

I created a separate issue related to the removal of mypy_extensions.

@ktbyers ktbyers closed this Sep 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mypy_extensions is only declared as a dev dependency but it directly imported
2 participants