Skip to content
Myr

🐛 Fix broken installation when upgrading from `typer <0.12.0` to `typer >=0.12.0`, make `typer` independent of `typer-slim`, include `typer` command in `typer` package (#791)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Sebastián Ramírez · committed by GitHub · parent 8bac821 · Browse files · 14 files+174 added−286 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

14 files+174 added−286 removed

  • other:+174 added−286 removed

14 files+174 added−286 removed

modified:.github/workflows/publish.yml+2 added-5 removed
modified:.github/workflows/test-redistribute.yml+4 added-7 removed
modified:docs/tutorial/index.md+3 added-3 removed
modified:docs/index.md+5 added-8 removed
35 unmodified lines
36* **Easy to use**: It's easy to use for the final users. Automatic help, and automatic completion for all shells.37* **Short**: Minimize code duplication. Multiple features from each parameter declaration. Fewer bugs.38* **Start simple**: The simplest example adds only 2 lines of code to your app: **1 import, 1 function call**.39* **Grow large**: Grow in complexity as much as you want, create arbitrarily complex trees of commands and groups of subcommands, with options and arguments.40* **Run scripts**: Typer includes a `typer` command that you can use to run scripts, automatically converting them to CLIs, even if they don't use Typer internally.40* **Run scripts**: Typer includes a `typer` command/program that you can use to run scripts, automatically converting them to CLIs, even if they don't use Typer internally.4142## FastAPI of CLIs4344**Typer** is <a href="https://fastapi.tiangolo.com" class="external-link" target="_blank">FastAPI</a>'s little sibling, it's the FastAPI of CLIs.
309 unmodified lines
354* <a href="https://rich.readthedocs.io/en/stable/index.html" class="external-link" target="_blank"><code>rich</code></a>: to show nicely formatted errors automatically.355* <a href="https://github.com/sarugaku/shellingham" class="external-link" target="_blank"><code>shellingham</code></a>: to automatically detect the current shell when installing completion.356 * With `shellingham` you can just use `--install-completion`.357 * Without `shellingham`, you have to pass the name of the shell to install completion for, e.g. `--install-completion bash`.358* `typer-cli`: adds the `typer` command to your shell:359 * Quickly run scripts (that don't have to use Typer) with shell completion.360 * Generate docs for your Typer applications.358359### `typer-slim`360364If you don't want the extra dependencies, install `typer-slim` instead.361If you don't want the extra standard optional dependencies, install `typer-slim` instead.362363When you install with:364365```bash366pip install typer367```368372...it's the equivalent of:369...it includes the same code and dependencies as:370371```bash372pip install "typer-slim[standard]"373```374378The `standard` extra dependencies are `rich`, `shellingham`, `typer-cli`.375The `standard` extra dependencies are `rich` and `shellingham`.376380**Note**: even if you don't install `typer-cli` you can still use it's functionality by calling `typer` as a module, e.g. `python -m typer`.377**Note**: The `typer` command is only included in the `typer` package.378379## License380381This project is licensed under the terms of the MIT license.
modified:typer/__init__.py+1 added-1 removed
1"""Typer, build great CLIs. Easy to code. Based on Python type hints."""23__version__ = "0.12.0"3__version__ = "0.12.1.dev2"45from shutil import get_terminal_size as get_terminal_size67from click.exceptions import Abort as Abort
32 unmodified lines
deleted:typer_cli_package/pdm_build.py-40 removed
1from pathlib import Path2from typing import List34from pdm.backend.hooks import Context56packages_to_sync = ["typer-slim"]78license_name = "LICENSE"9license_path = Path("..") / license_name101112def pdm_build_hook_enabled(context: Context):13 return context.target == "sdist"141516def pdm_build_initialize(context: Context):17 metadata = context.config.metadata18 # Get main version19 version = metadata["version"]20 # Update version in dependencies to sync them21 dependencies: List[str] = metadata["dependencies"]22 new_dependencies = []23 for dep in dependencies:24 if any(dep.startswith(name) for name in packages_to_sync):25 new_dep = f"{dep}=={version}"26 new_dependencies.append(new_dep)27 else:28 new_dependencies.append(dep)29 if new_dependencies != dependencies:30 metadata["dependencies"] = new_dependencies31 # LICENSE32 license_content = license_path.read_text()33 context.ensure_build_dir()34 # # Workaround, copy LICENSE to package_dir during build35 Path(license_name).write_text(license_content)363738def pdm_build_finalize(context: Context, artifact: Path):39 # Workaround, remove LICENSE from package_dir after build40 Path(license_name).unlink()
deleted:typer_cli_package/pyproject.toml-55 removed
1[build-system]2requires = ["pdm-backend"]3build-backend = "pdm.backend"45[project]6name = "typer-cli"7dynamic = ["version"]8description = "Typer, build great CLIs. Easy to code. Based on Python type hints."9authors = [10 {name = "Sebastián Ramírez", email = "tiangolo@gmail.com"},11]12readme = "README.md"13requires-python = ">=3.7"14classifiers = [15 "Intended Audience :: Information Technology",16 "Intended Audience :: System Administrators",17 "Operating System :: OS Independent",18 "Programming Language :: Python :: 3",19 "Programming Language :: Python",20 "Topic :: Software Development :: Libraries :: Application Frameworks",21 "Topic :: Software Development :: Libraries :: Python Modules",22 "Topic :: Software Development :: Libraries",23 "Topic :: Software Development",24 "Typing :: Typed",25 "Development Status :: 4 - Beta",26 "Intended Audience :: Developers",27 "Programming Language :: Python :: 3 :: Only",28 "Programming Language :: Python :: 3.7",29 "Programming Language :: Python :: 3.8",30 "Programming Language :: Python :: 3.9",31 "Programming Language :: Python :: 3.10",32 "Programming Language :: Python :: 3.11",33 "License :: OSI Approved :: MIT License",34]35dependencies = [36 "typer-slim[standard]",37]3839[project.urls]40Documentation = "https://typer.tiangolo.com/"41homepage = "https://github.com/tiangolo/typer"4243[project.optional-dependencies]44# For backwards compatibility45all = []4647[project.scripts]48typer = "typer.cli:main"4950[tool.pdm]51version = { source = "file", path = "../typer/__init__.py" }52distribution = true5354[tool.pdm.build]55excludes = ["*"]
deleted:typer_cli_package/README.md-49 removed
1<p align="center">2 <a href="https://typer.tiangolo.com"><img src="https://typer.tiangolo.com/img/logo-margin/logo-margin-vector.svg" alt="Typer"></a>3</p>4<p align="center">5 <em>Typer, build great CLIs. Easy to code. Based on Python type hints.</em>6</p>7<p align="center">8<a href="https://github.com/tiangolo/typer/actions?query=workflow%3ATest" target="_blank">9 <img src="https://github.com/tiangolo/typer/workflows/Test/badge.svg" alt="Test">10</a>11<a href="https://github.com/tiangolo/typer/actions?query=workflow%3APublish" target="_blank">12 <img src="https://github.com/tiangolo/typer/workflows/Publish/badge.svg" alt="Publish">13</a>14<a href="https://coverage-badge.samuelcolvin.workers.dev/redirect/tiangolo/typer" target="_blank">15 <img src="https://coverage-badge.samuelcolvin.workers.dev/tiangolo/typer.svg" alt="Coverage">16<a href="https://pypi.org/project/typer" target="_blank">17 <img src="https://img.shields.io/pypi/v/typer?color=%2334D058&label=pypi%20package" alt="Package version">18</a>19</p>2021---2223**Documentation**: <a href="https://typer.tiangolo.com" target="_blank">https://typer.tiangolo.com/tutorial/typer-command/</a>2425**Source Code**: <a href="https://github.com/tiangolo/typer" target="_blank">https://github.com/tiangolo/typer</a>2627---2829Typer is a library for building <abbr title="command line interface, programs executed from a terminal">CLI</abbr> applications that users will **love using** and developers will **love creating**. Based on Python type hints.3031## Typer CLI3233This package, `typer-cli`, only provides a command `typer` in the shell with the same functionality of `python -m typer`.3435The only reason why this is a separate package is to allow developers to opt out of the `typer` command by installing `typer-slim`, that doesn't include `typer-cli`.3637You probably **should not** install this package.3839Install instead:4041```bash42pip install typer43```4445That includes this package, `typer-cli`, with the `typer` command.4647## License4849This project is licensed under the terms of the MIT license.
deleted:typer_package/pdm_build.py-49 removed
1from pathlib import Path2from typing import List34from pdm.backend.hooks import Context56packages_to_sync = ["typer-slim", "typer-cli"]78readme_name = "README.md"9license_name = "LICENSE"10readme_path = Path("..") / readme_name11license_path = Path("..") / license_name121314def pdm_build_hook_enabled(context: Context):15 return context.target == "sdist"161718def pdm_build_initialize(context: Context):19 metadata = context.config.metadata20 # Get main version21 version = metadata["version"]22 # Update version in dependencies to sync them23 dependencies: List[str] = metadata["dependencies"]24 new_dependencies = []25 for dep in dependencies:26 if any(dep.startswith(name) for name in packages_to_sync):27 new_dep = f"{dep}=={version}"28 new_dependencies.append(new_dep)29 else:30 new_dependencies.append(dep)31 if new_dependencies != dependencies:32 metadata["dependencies"] = new_dependencies33 # README.md and LICENSE34 readme_content = readme_path.read_text()35 license_content = license_path.read_text()36 metadata["readme"] = readme_name37 context.ensure_build_dir()38 # Copy README.md and LICENSE to build directory39 # (context.build_dir / readme_name).write_text(readme_content)40 # (context.build_dir / license_name).write_text(license_content)41 # # Workaround, copy README.md and LICENSE to package_dir during build42 Path(readme_name).write_text(readme_content)43 Path(license_name).write_text(license_content)444546def pdm_build_finalize(context: Context, artifact: Path):47 # Workaround, remove README.md and LICENSE from package_dir after build48 Path(readme_name).unlink()49 Path(license_name).unlink()
deleted:typer_package/pyproject.toml-52 removed
1[build-system]2requires = ["pdm-backend"]3build-backend = "pdm.backend"45[project]6name = "typer"7dynamic = ["version"]8description = "Typer, build great CLIs. Easy to code. Based on Python type hints."9authors = [10 {name = "Sebastián Ramírez", email = "tiangolo@gmail.com"},11]12requires-python = ">=3.7"13classifiers = [14 "Intended Audience :: Information Technology",15 "Intended Audience :: System Administrators",16 "Operating System :: OS Independent",17 "Programming Language :: Python :: 3",18 "Programming Language :: Python",19 "Topic :: Software Development :: Libraries :: Application Frameworks",20 "Topic :: Software Development :: Libraries :: Python Modules",21 "Topic :: Software Development :: Libraries",22 "Topic :: Software Development",23 "Typing :: Typed",24 "Development Status :: 4 - Beta",25 "Intended Audience :: Developers",26 "Programming Language :: Python :: 3 :: Only",27 "Programming Language :: Python :: 3.7",28 "Programming Language :: Python :: 3.8",29 "Programming Language :: Python :: 3.9",30 "Programming Language :: Python :: 3.10",31 "Programming Language :: Python :: 3.11",32 "License :: OSI Approved :: MIT License",33]34dependencies = [35 "typer-slim[standard]",36 "typer-cli",37]3839[project.urls]40Documentation = "https://typer.tiangolo.com/"41homepage = "https://github.com/tiangolo/typer"4243[project.optional-dependencies]44# For backwards compatibility45all = []4647[tool.pdm]48version = { source = "file", path = "../typer/__init__.py" }49distribution = true5051[tool.pdm.build]52excludes = ["*"]
added:typer-cli/README.md+53 added
1<p align="center">2 <a href="https://typer.tiangolo.com"><img src="https://typer.tiangolo.com/img/logo-margin/logo-margin-vector.svg" alt="Typer"></a>3</p>4<p align="center">5 <em>Typer, build great CLIs. Easy to code. Based on Python type hints.</em>6</p>7<p align="center">8<a href="https://github.com/tiangolo/typer/actions?query=workflow%3ATest" target="_blank">9 <img src="https://github.com/tiangolo/typer/workflows/Test/badge.svg" alt="Test">10</a>11<a href="https://github.com/tiangolo/typer/actions?query=workflow%3APublish" target="_blank">12 <img src="https://github.com/tiangolo/typer/workflows/Publish/badge.svg" alt="Publish">13</a>14<a href="https://coverage-badge.samuelcolvin.workers.dev/redirect/tiangolo/typer" target="_blank">15 <img src="https://coverage-badge.samuelcolvin.workers.dev/tiangolo/typer.svg" alt="Coverage">16<a href="https://pypi.org/project/typer" target="_blank">17 <img src="https://img.shields.io/pypi/v/typer?color=%2334D058&label=pypi%20package" alt="Package version">18</a>19</p>2021---2223**Documentation**: <a href="https://typer.tiangolo.com" target="_blank">https://typer.tiangolo.com/tutorial/typer-command/</a>2425**Source Code**: <a href="https://github.com/tiangolo/typer" target="_blank">https://github.com/tiangolo/typer</a>2627---2829Typer is a library for building <abbr title="command line interface, programs executed from a terminal">CLI</abbr> applications that users will **love using** and developers will **love creating**. Based on Python type hints.3031## Typer CLI3233⚠️ Do not install this package. ⚠️3435This package, `typer-cli`, does nothing other than depend on `typer`.3637All the functionality has been integrated into `typer`.3839The only reason this package exists is as a migration path for old projects that used to depend on `typer-cli`, so that they can get the latest version of `typer`.4041You probably **should not** install this package.4243Install instead:4445```bash46pip install typer47```4849That includes the `typer` command.5051## License5253This project is licensed under the terms of the MIT license.
added:pdm_build.py+55 added
1import os2from typing import Any, Dict, List34from pdm.backend.hooks import Context56TIANGOLO_BUILD_PACKAGE = os.getenv("TIANGOLO_BUILD_PACKAGE", "typer")789def pdm_build_initialize(context: Context):10 metadata = context.config.metadata11 # Get main version12 version = metadata["version"]13 # Get package names to keep in sync with the same main version14 sync_dependencies: List[str] = context.config.data["tool"]["tiangolo"][15 "_internal-slim-build"16 ]["sync-dependencies"]17 # Get custom config for the current package, from the env var18 config: Dict[str, Any] = context.config.data["tool"]["tiangolo"][19 "_internal-slim-build"20 ]["packages"][TIANGOLO_BUILD_PACKAGE]21 project_config: Dict[str, Any] = config["project"]22 # Get main optional dependencies, extras23 optional_dependencies: Dict[str, List[str]] = metadata.get(24 "optional-dependencies", {}25 )26 # Get custom optional dependencies name to always include in this (non-slim) package27 include_optional_dependencies: List[str] = config.get(28 "include-optional-dependencies", []29 )30 # Override main [project] configs with custom configs for this package31 for key, value in project_config.items():32 metadata[key] = value33 # Get custom build config for the current package34 build_config: Dict[str, Any] = (35 config.get("tool", {}).get("pdm", {}).get("build", {})36 )37 # Override PDM build config with custom build config for this package38 for key, value in build_config.items():39 context.config.build_config[key] = value40 # Get main dependencies41 dependencies: List[str] = metadata.get("dependencies", [])42 # Add optional dependencies to the default dependencies for this (non-slim) package43 for include_optional in include_optional_dependencies:44 optional_dependencies_group = optional_dependencies.get(include_optional, [])45 dependencies.extend(optional_dependencies_group)46 # Sync versions in dependencies47 new_dependencies = []48 for dep in dependencies:49 if dep in sync_dependencies:50 new_dep = f"{dep}=={version}"51 new_dependencies.append(new_dep)52 else:53 new_dependencies.append(dep)54 if new_dependencies != dependencies:55 metadata["dependencies"] = new_dependencies
modified:pyproject.toml+46 added-9 removed
1 unmodified line
2requires = ["pdm-backend"]3build-backend = "pdm.backend"45[project]6# pip install typer-slim: is only the Typer library, without extras7# pip install typer: is typer-slim[standard], with extras and typer-cli8name = "typer-slim"6name = "typer"7dynamic = ["version"]8description = "Typer, build great CLIs. Easy to code. Based on Python type hints."9authors = [10 {name = "Sebastián Ramírez", email = "tiangolo@gmail.com"},11]14readme = "README.md"12requires-python = ">=3.7"13classifiers = [14 "Intended Audience :: Information Technology",15 "Intended Audience :: System Administrators",
18 unmodified lines
34dependencies = [35 "click >= 8.0.0",36 "typing-extensions >= 3.7.4.3",37]4138readme = "README.md"39[project.urls]40Documentation = "https://typer.tiangolo.com/"41homepage = "https://github.com/tiangolo/typer"4243[project.optional-dependencies]47all = [48 "shellingham >=1.3.0",49 "rich >=10.11.0",50]44standard = [45 "shellingham >=1.3.0",46 "rich >=10.11.0",47]
9 unmodified lines
57 "requirements*.txt",58 "scripts/",59 ]6061[tool.tiangolo._internal-slim-build]62sync-dependencies = [63 "typer-slim[standard]",64 "typer-cli",65 "typer"66]6768[tool.tiangolo._internal-slim-build.packages.typer-slim.project]69name = "typer-slim"7071[tool.tiangolo._internal-slim-build.packages.typer]72include-optional-dependencies = ["standard"]7374[tool.tiangolo._internal-slim-build.packages.typer.project]75optional-dependencies = {}7677[tool.tiangolo._internal-slim-build.packages.typer.project.scripts]78typer = "typer.cli:main"7980[tool.tiangolo._internal-slim-build.packages.typer-cli.project]81name = "typer-cli"82readme = "typer-cli/README.md"83dependencies = [84 "typer",85]86optional-dependencies = {}8788[tool.tiangolo._internal-slim-build.packages.typer-cli.tool.pdm.build]89# excludes needs to explicitly exclude the top level python packages,90# otherwise PDM includes them by default91# A "*" glob pattern can't be used here because in PDM internals, the patterns are put92# in a set (unordered, order varies) and each excluded file is assigned one of the93# glob patterns that matches, as the set is unordered, the matched pattern could be "*"94# independent of the order here. And then the internal code would give it a lower score95# than the one for a default included file.96# By not using "*" and explicitly excluding the top level packages, they get a higher97# score than the default inclusion98excludes = ["typer", "tests", "pdm_build.py"]99# source-includes needs to explicitly define some value because PDM will check the100# truthy value of the list, and if empty, will include some defaults, including "tests",101# an empty string doesn't match anything, but makes the list truthy, so that PDM102# doesn't override it during the build.103source-includes = [""]104105[tool.isort]106profile = "black"107known_third_party = ["typer", "click"]108skip_glob = [
103 unmodified lines
modified:README.md+5 added-8 removed
35 unmodified lines
36* **Easy to use**: It's easy to use for the final users. Automatic help, and automatic completion for all shells.37* **Short**: Minimize code duplication. Multiple features from each parameter declaration. Fewer bugs.38* **Start simple**: The simplest example adds only 2 lines of code to your app: **1 import, 1 function call**.39* **Grow large**: Grow in complexity as much as you want, create arbitrarily complex trees of commands and groups of subcommands, with options and arguments.40* **Run scripts**: Typer includes a `typer` command that you can use to run scripts, automatically converting them to CLIs, even if they don't use Typer internally.40* **Run scripts**: Typer includes a `typer` command/program that you can use to run scripts, automatically converting them to CLIs, even if they don't use Typer internally.4142## FastAPI of CLIs4344**Typer** is <a href="https://fastapi.tiangolo.com" class="external-link" target="_blank">FastAPI</a>'s little sibling, it's the FastAPI of CLIs.
309 unmodified lines
354* <a href="https://rich.readthedocs.io/en/stable/index.html" class="external-link" target="_blank"><code>rich</code></a>: to show nicely formatted errors automatically.355* <a href="https://github.com/sarugaku/shellingham" class="external-link" target="_blank"><code>shellingham</code></a>: to automatically detect the current shell when installing completion.356 * With `shellingham` you can just use `--install-completion`.357 * Without `shellingham`, you have to pass the name of the shell to install completion for, e.g. `--install-completion bash`.358* `typer-cli`: adds the `typer` command to your shell:359 * Quickly run scripts (that don't have to use Typer) with shell completion.360 * Generate docs for your Typer applications.358359### `typer-slim`360364If you don't want the extra dependencies, install `typer-slim` instead.361If you don't want the extra standard optional dependencies, install `typer-slim` instead.362363When you install with:364365```bash366pip install typer367```368372...it's the equivalent of:369...it includes the same code and dependencies as:370371```bash372pip install "typer-slim[standard]"373```374378The `standard` extra dependencies are `rich`, `shellingham`, `typer-cli`.375The `standard` extra dependencies are `rich` and `shellingham`.376380**Note**: even if you don't install `typer-cli` you can still use it's functionality by calling `typer` as a module, e.g. `python -m typer`.377**Note**: The `typer` command is only included in the `typer` package.378379## License380381This project is licensed under the terms of the MIT license.