typer 0.12.0 breaks django_typer 1.0.9
Closed this issue · 6 comments
I added django_typer to a fresh project and it pulled as a depedency typer 0.12.0. The result is, that my management commands that use django_typer show the following error message.
Traceback (most recent call last):
File "/Users/oa/tmp/example_project/./manage.py", line 23, in <module>
main()
File "/Users/oa/tmp/example_project/./manage.py", line 19, in main
execute_from_command_line(sys.argv)
File "/Users/oa/tmp/example_project/.venv/lib/python3.12/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
utility.execute()
File "/Users/oa/tmp/example_project/.venv/lib/python3.12/site-packages/django/core/management/__init__.py", line 436, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/oa/tmp/example_project/.venv/lib/python3.12/site-packages/django/core/management/__init__.py", line 275, in fetch_command
klass = load_command_class(app_name, subcommand)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/oa/tmp/example_project/.venv/lib/python3.12/site-packages/django/core/management/__init__.py", line 48, in load_command_class
module = import_module("%s.management.commands.%s" % (app_name, name))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/python@3.12/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/importlib/__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 995, in exec_module
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File "/Users/oa/tmp/example_project/.venv/lib/python3.12/site-packages/django_tailwind_cli/management/commands/tailwind.py", line 18, in <module>
from django_typer import TyperCommand, command, initialize
File "/Users/oa/tmp/example_project/.venv/lib/python3.12/site-packages/django_typer/__init__.py", line 84, in <module>
from django_typer import patch
File "/Users/oa/tmp/example_project/.venv/lib/python3.12/site-packages/django_typer/patch.py", line 132, in <module>
from typer import __version__ as typer_version
ImportError: cannot import name '__version__' from 'typer' (unknown location)
If I pin typer to 0.11.0 by calling poetry add typer==0.11.0
everything is fine again.
It seems as upstream has introduced changes that need to be reflected in django_typer.
Hey Oliver, took me a minute to reproduce this - the CI didnt catch it because it only effects virtual environments that are upgrading the typer version to 0.12.
This is a packaging bug introduced upstream. In 0.12.0 tiangolo split the typer package into three packages:
- typer-cli - this contains the typer command
- typer-slim - this contains all of the code
- typer - this package is empty, but depends on typer-cli and typer-slim
For whatever reason - may be a bug in pip - when upgrading from the single typer package to the three typer packages the files in the typer namespace in typer-slim are not written into the virtual environment. So the bug here is not an incompatibility - its just that the files are missing after the upgrade.
I'm experimenting to figure out if there is anything I can do in how django-typer specifies its dependencies to fix this. But to be clear - this bug is upstream that should hit everyone thats specified a dependency against typer.
Here is the workaround if you want to use typer 0.12+ If the virtual environment is fresh it will just work. If not and the typer package is upgrading from 0.11 you'll need to first uninstall 0.11:
pip uninstall typer
pip install --upgrade django-typer
If you've upgraded already and version 0.12 is broken - you'll need to uninstall all three packages and reinstall typer:
pip uninstall typer typer-cli typer-slim
pip install typer
Yes, that matches my analysis too. That is the reason why I pinned typer to 0.11.0 in our projects. May be it is a good idea to pin it in django_typer too? I expect others to have this issue too.
I would sugges to replace
typer = ">=0.9.0,<0.13.0"
with
typer = ">=0.9.0,<0.12.0"
in pyproject.toml for the moment.
I've yanked the 1.0.9 release so at least no one will accidentally fall on this until I can figure out what to do. At the very least going forward the dependency should be on typer-slim not typer. I'm bearish on this fixing the root issue for normal pip workflows, but it should at least fix it for projects that are using a package manager because it should first trigger an uninstall of typer when upgrading.
Specifying the dependency on typer-slim does seem to fix the issue for normal pip workflows as well.
I'm going to issue a 1.1.0 release with the dependency change to typer-slim>=0.12.0,<0.13.0. This should make the transition smooth.
I'm still being cautious in the dependency specifiers because tiangolo has been making lots of typer changes recently and as we've seen some of them have unexpected issues.
Hi @oliverandrich - I've tested the 1.1.0 pypi package in a number of different straight pip and poetry workflows and the upgrade runs smoothly now. Thanks for bringing this to my attention!
Thanks for the quick fix. It works in our projects also like a charm.