From 0705b6792eb421d17e2a88319225f2856beaec3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 4 Apr 2024 11:32:39 -0500 Subject: [PATCH 01/17] =?UTF-8?q?=F0=9F=94=A7=20Make=20typer=20the=20main?= =?UTF-8?q?=20pyproject.toml=20and=20add=20typer-slim.pyproject.toml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 21 +++++------------ ...yproject.toml => typer-slim.pyproject.toml | 23 ++++++++++++------- 2 files changed, 21 insertions(+), 23 deletions(-) rename typer_package/pyproject.toml => typer-slim.pyproject.toml (81%) diff --git a/pyproject.toml b/pyproject.toml index f5abe95d3c..387cd19dd9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,15 +3,12 @@ requires = ["pdm-backend"] build-backend = "pdm.backend" [project] -# pip install typer-slim: is only the Typer library, without extras -# pip install typer: is typer-slim[standard], with extras and typer-cli -name = "typer-slim" +name = "typer" dynamic = ["version"] description = "Typer, build great CLIs. Easy to code. Based on Python type hints." authors = [ {name = "Sebastián Ramírez", email = "tiangolo@gmail.com"}, ] -readme = "README.md" requires-python = ">=3.7" classifiers = [ "Intended Audience :: Information Technology", @@ -35,23 +32,17 @@ classifiers = [ "License :: OSI Approved :: MIT License", ] dependencies = [ - "click >= 8.0.0", - "typing-extensions >= 3.7.4.3", + "typer-slim[standard]", + "typer-cli", ] - +readme = "README.md" [project.urls] Documentation = "https://typer.tiangolo.com/" homepage = "https://github.com/tiangolo/typer" [project.optional-dependencies] -all = [ - "shellingham >=1.3.0", - "rich >=10.11.0", -] -standard = [ - "shellingham >=1.3.0", - "rich >=10.11.0", -] +# For backwards compatibility +all = [] [tool.pdm] version = { source = "file", path = "typer/__init__.py" } diff --git a/typer_package/pyproject.toml b/typer-slim.pyproject.toml similarity index 81% rename from typer_package/pyproject.toml rename to typer-slim.pyproject.toml index c2f3f45bfa..d02bf2c929 100644 --- a/typer_package/pyproject.toml +++ b/typer-slim.pyproject.toml @@ -3,7 +3,7 @@ requires = ["pdm-backend"] build-backend = "pdm.backend" [project] -name = "typer" +name = "typer-slim" dynamic = ["version"] description = "Typer, build great CLIs. Easy to code. Based on Python type hints." authors = [ @@ -32,21 +32,28 @@ classifiers = [ "License :: OSI Approved :: MIT License", ] dependencies = [ - "typer-slim[standard]", - "typer-cli", + "click >= 8.0.0", + "typing-extensions >= 3.7.4.3", ] - +readme = "README.md" [project.urls] Documentation = "https://typer.tiangolo.com/" homepage = "https://github.com/tiangolo/typer" [project.optional-dependencies] -# For backwards compatibility -all = [] +standard = [ + "shellingham >=1.3.0", + "rich >=10.11.0", +] [tool.pdm] -version = { source = "file", path = "../typer/__init__.py" } +version = { source = "file", path = "typer/__init__.py" } distribution = true [tool.pdm.build] -excludes = ["*"] +source-includes = [ + "tests/", + "docs_src/", + "requirements*.txt", + "scripts/", + ] From 347f1983f24b338d4201def8fe7467405d265f16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 4 Apr 2024 12:22:09 -0500 Subject: [PATCH 02/17] =?UTF-8?q?=F0=9F=94=A7=20Use=20the=20same=20config?= =?UTF-8?q?=20for=20both=20typer=20and=20typer-slim?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 16 ++++++++--- typer-slim.pyproject.toml | 59 --------------------------------------- 2 files changed, 12 insertions(+), 63 deletions(-) delete mode 100644 typer-slim.pyproject.toml diff --git a/pyproject.toml b/pyproject.toml index 387cd19dd9..6faf2bc764 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,8 +32,8 @@ classifiers = [ "License :: OSI Approved :: MIT License", ] dependencies = [ - "typer-slim[standard]", - "typer-cli", + "click >= 8.0.0", + "typing-extensions >= 3.7.4.3", ] readme = "README.md" [project.urls] @@ -41,8 +41,10 @@ Documentation = "https://typer.tiangolo.com/" homepage = "https://github.com/tiangolo/typer" [project.optional-dependencies] -# For backwards compatibility -all = [] +standard = [ + "shellingham >=1.3.0", + "rich >=10.11.0", +] [tool.pdm] version = { source = "file", path = "typer/__init__.py" } @@ -56,6 +58,12 @@ source-includes = [ "scripts/", ] +[tool.typer._internal_build] +dependencies = [ + "typer-slim[standard]", + "typer-cli", +] + [tool.isort] profile = "black" known_third_party = ["typer", "click"] diff --git a/typer-slim.pyproject.toml b/typer-slim.pyproject.toml deleted file mode 100644 index d02bf2c929..0000000000 --- a/typer-slim.pyproject.toml +++ /dev/null @@ -1,59 +0,0 @@ -[build-system] -requires = ["pdm-backend"] -build-backend = "pdm.backend" - -[project] -name = "typer-slim" -dynamic = ["version"] -description = "Typer, build great CLIs. Easy to code. Based on Python type hints." -authors = [ - {name = "Sebastián Ramírez", email = "tiangolo@gmail.com"}, -] -requires-python = ">=3.7" -classifiers = [ - "Intended Audience :: Information Technology", - "Intended Audience :: System Administrators", - "Operating System :: OS Independent", - "Programming Language :: Python :: 3", - "Programming Language :: Python", - "Topic :: Software Development :: Libraries :: Application Frameworks", - "Topic :: Software Development :: Libraries :: Python Modules", - "Topic :: Software Development :: Libraries", - "Topic :: Software Development", - "Typing :: Typed", - "Development Status :: 4 - Beta", - "Intended Audience :: Developers", - "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "License :: OSI Approved :: MIT License", -] -dependencies = [ - "click >= 8.0.0", - "typing-extensions >= 3.7.4.3", -] -readme = "README.md" -[project.urls] -Documentation = "https://typer.tiangolo.com/" -homepage = "https://github.com/tiangolo/typer" - -[project.optional-dependencies] -standard = [ - "shellingham >=1.3.0", - "rich >=10.11.0", -] - -[tool.pdm] -version = { source = "file", path = "typer/__init__.py" } -distribution = true - -[tool.pdm.build] -source-includes = [ - "tests/", - "docs_src/", - "requirements*.txt", - "scripts/", - ] From a2638df00a7e3b3561785220d52ebda08edcd01c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 4 Apr 2024 12:22:58 -0500 Subject: [PATCH 03/17] =?UTF-8?q?=F0=9F=94=A8=20Add=20pdm=5Fbuild.py=20com?= =?UTF-8?q?patible=20with=20both=20typer=20and=20typer-cli=20from=20the=20?= =?UTF-8?q?same=20pyproject.toml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pdm_build.py | 34 ++++++++++++++++++++++++++ typer_package/pdm_build.py | 49 -------------------------------------- 2 files changed, 34 insertions(+), 49 deletions(-) create mode 100644 pdm_build.py delete mode 100644 typer_package/pdm_build.py diff --git a/pdm_build.py b/pdm_build.py new file mode 100644 index 0000000000..3d75f36c22 --- /dev/null +++ b/pdm_build.py @@ -0,0 +1,34 @@ +import os +from typing import List + +from pdm.backend.hooks import Context + +packages_to_sync = ["typer-slim", "typer-cli"] + +TYPER_SLIM_BUILD = os.getenv("TYPER_SLIM_BUILD") + + +def pdm_build_hook_enabled(context: Context): + return context.target == "sdist" + + +def pdm_build_initialize(context: Context): + metadata = context.config.metadata + # Get main version + version = metadata["version"] + if TYPER_SLIM_BUILD: + metadata["name"] = "typer-slim" + else: + typer_config_data = context.config.data["tool"]["typer"]["_internal_build"] + typer_dependencies: List[str] = typer_config_data["dependencies"] + + new_dependencies = [] + for dep in typer_dependencies: + if any(dep.startswith(name) for name in packages_to_sync): + new_dep = f"{dep}=={version}" + new_dependencies.append(new_dep) + else: + new_dependencies.append(dep) + if new_dependencies != typer_dependencies: + metadata["dependencies"] = new_dependencies + metadata["optional-dependencies"] = {} diff --git a/typer_package/pdm_build.py b/typer_package/pdm_build.py deleted file mode 100644 index b670aa9504..0000000000 --- a/typer_package/pdm_build.py +++ /dev/null @@ -1,49 +0,0 @@ -from pathlib import Path -from typing import List - -from pdm.backend.hooks import Context - -packages_to_sync = ["typer-slim", "typer-cli"] - -readme_name = "README.md" -license_name = "LICENSE" -readme_path = Path("..") / readme_name -license_path = Path("..") / license_name - - -def pdm_build_hook_enabled(context: Context): - return context.target == "sdist" - - -def pdm_build_initialize(context: Context): - metadata = context.config.metadata - # Get main version - version = metadata["version"] - # Update version in dependencies to sync them - dependencies: List[str] = metadata["dependencies"] - new_dependencies = [] - for dep in dependencies: - if any(dep.startswith(name) for name in packages_to_sync): - new_dep = f"{dep}=={version}" - new_dependencies.append(new_dep) - else: - new_dependencies.append(dep) - if new_dependencies != dependencies: - metadata["dependencies"] = new_dependencies - # README.md and LICENSE - readme_content = readme_path.read_text() - license_content = license_path.read_text() - metadata["readme"] = readme_name - context.ensure_build_dir() - # Copy README.md and LICENSE to build directory - # (context.build_dir / readme_name).write_text(readme_content) - # (context.build_dir / license_name).write_text(license_content) - # # Workaround, copy README.md and LICENSE to package_dir during build - Path(readme_name).write_text(readme_content) - Path(license_name).write_text(license_content) - - -def pdm_build_finalize(context: Context, artifact: Path): - # Workaround, remove README.md and LICENSE from package_dir after build - Path(readme_name).unlink() - Path(license_name).unlink() From b9c10f34641c5dc480ad369613a42c5ab63d01fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 4 Apr 2024 16:52:06 -0500 Subject: [PATCH 04/17] =?UTF-8?q?=F0=9F=93=9D=20Move=20README=20for=20Type?= =?UTF-8?q?r-CLI=20to=20typer-cli,=20remove=20extra=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- {typer_cli_package => typer-cli}/README.md | 0 typer_cli_package/pdm_build.py | 40 ---------------- typer_cli_package/pyproject.toml | 55 ---------------------- 3 files changed, 95 deletions(-) rename {typer_cli_package => typer-cli}/README.md (100%) delete mode 100644 typer_cli_package/pdm_build.py delete mode 100644 typer_cli_package/pyproject.toml diff --git a/typer_cli_package/README.md b/typer-cli/README.md similarity index 100% rename from typer_cli_package/README.md rename to typer-cli/README.md diff --git a/typer_cli_package/pdm_build.py b/typer_cli_package/pdm_build.py deleted file mode 100644 index cca6d59a75..0000000000 --- a/typer_cli_package/pdm_build.py +++ /dev/null @@ -1,40 +0,0 @@ -from pathlib import Path -from typing import List - -from pdm.backend.hooks import Context - -packages_to_sync = ["typer-slim"] - -license_name = "LICENSE" -license_path = Path("..") / license_name - - -def pdm_build_hook_enabled(context: Context): - return context.target == "sdist" - - -def pdm_build_initialize(context: Context): - metadata = context.config.metadata - # Get main version - version = metadata["version"] - # Update version in dependencies to sync them - dependencies: List[str] = metadata["dependencies"] - new_dependencies = [] - for dep in dependencies: - if any(dep.startswith(name) for name in packages_to_sync): - new_dep = f"{dep}=={version}" - new_dependencies.append(new_dep) - else: - new_dependencies.append(dep) - if new_dependencies != dependencies: - metadata["dependencies"] = new_dependencies - # LICENSE - license_content = license_path.read_text() - context.ensure_build_dir() - # # Workaround, copy LICENSE to package_dir during build - Path(license_name).write_text(license_content) - - -def pdm_build_finalize(context: Context, artifact: Path): - # Workaround, remove LICENSE from package_dir after build - Path(license_name).unlink() diff --git a/typer_cli_package/pyproject.toml b/typer_cli_package/pyproject.toml deleted file mode 100644 index 2bb4f8d26c..0000000000 --- a/typer_cli_package/pyproject.toml +++ /dev/null @@ -1,55 +0,0 @@ -[build-system] -requires = ["pdm-backend"] -build-backend = "pdm.backend" - -[project] -name = "typer-cli" -dynamic = ["version"] -description = "Typer, build great CLIs. Easy to code. Based on Python type hints." -authors = [ - {name = "Sebastián Ramírez", email = "tiangolo@gmail.com"}, -] -readme = "README.md" -requires-python = ">=3.7" -classifiers = [ - "Intended Audience :: Information Technology", - "Intended Audience :: System Administrators", - "Operating System :: OS Independent", - "Programming Language :: Python :: 3", - "Programming Language :: Python", - "Topic :: Software Development :: Libraries :: Application Frameworks", - "Topic :: Software Development :: Libraries :: Python Modules", - "Topic :: Software Development :: Libraries", - "Topic :: Software Development", - "Typing :: Typed", - "Development Status :: 4 - Beta", - "Intended Audience :: Developers", - "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "License :: OSI Approved :: MIT License", -] -dependencies = [ - "typer-slim[standard]", -] - -[project.urls] -Documentation = "https://typer.tiangolo.com/" -homepage = "https://github.com/tiangolo/typer" - -[project.optional-dependencies] -# For backwards compatibility -all = [] - -[project.scripts] -typer = "typer.cli:main" - -[tool.pdm] -version = { source = "file", path = "../typer/__init__.py" } -distribution = true - -[tool.pdm.build] -excludes = ["*"] From 232d246a0e28925ecafb326662f4df91cc9fcf7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 4 Apr 2024 16:52:45 -0500 Subject: [PATCH 05/17] =?UTF-8?q?=F0=9F=94=A7=20Update=20pyproject.toml=20?= =?UTF-8?q?custom=20build=20config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 6faf2bc764..ca4369627c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,11 +58,49 @@ source-includes = [ "scripts/", ] -[tool.typer._internal_build] +[tool.tiangolo._internal_slim_build] +sync_dependencies = [ + "typer-slim[standard]", + "typer-cli", +] + +[tool.tiangolo._internal_slim_build.packages.typer-slim.project] +name = "typer-slim" + +[tool.tiangolo._internal_slim_build.packages.typer.project] dependencies = [ "typer-slim[standard]", "typer-cli", ] +optional-dependencies = {} + +[tool.tiangolo._internal_slim_build.packages.typer-cli.project] +name = "typer-cli" +readme = "typer-cli/README.md" +dependencies = [ + "typer-slim[standard]", +] +optional-dependencies = {} + +[tool.tiangolo._internal_slim_build.packages.typer-cli.project.scripts] +typer = "typer.cli:main" + +[tool.tiangolo._internal_slim_build.packages.typer-cli.tool.pdm.build] +# excludes needs to explicitly exclude the top level python packages, +# otherwise PDM includes them by default +# A "*" glob pattern can't be used here because in PDM internals, the patterns are put +# in a set (unordered, order varies) and each excluded file is assigned one of the +# glob patterns that matches, as the set is unordered, the matched pattern could be "*" +# independent of the order here. And then the internal code would give it a lower score +# than the one for a default included file. +# By not using "*" and explicitly excluding the top level packages, they get a higher +# score than the default inclusion +excludes = ["typer", "tests", "pdm_build.py"] +# source-includes needs to explicitly define some value because PDM will check the +# truthy value of the list, and if empty, will include some defaults, including "tests", +# an empty string doesn't match anything, but makes the list truthy, so that PDM +# doesn't override it during the build. +source-includes = [""] [tool.isort] profile = "black" From 76639e7e4f6a5fe03a258f9934cf7f6c4eb2e69b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 4 Apr 2024 16:53:10 -0500 Subject: [PATCH 06/17] =?UTF-8?q?=F0=9F=94=A8=20Update=20pdm=5Fbuild.py=20?= =?UTF-8?q?script=20to=20make=20it=20more=20generic,=20reading=20from=20py?= =?UTF-8?q?project.toml=20configs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pdm_build.py | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/pdm_build.py b/pdm_build.py index 3d75f36c22..7bc05aebbc 100644 --- a/pdm_build.py +++ b/pdm_build.py @@ -1,34 +1,36 @@ import os -from typing import List +from typing import Any, Dict, List from pdm.backend.hooks import Context -packages_to_sync = ["typer-slim", "typer-cli"] - -TYPER_SLIM_BUILD = os.getenv("TYPER_SLIM_BUILD") - - -def pdm_build_hook_enabled(context: Context): - return context.target == "sdist" +TIANGOLO_BUILD_PACKAGE = os.getenv("TIANGOLO_BUILD_PACKAGE", "typer") def pdm_build_initialize(context: Context): metadata = context.config.metadata # Get main version version = metadata["version"] - if TYPER_SLIM_BUILD: - metadata["name"] = "typer-slim" - else: - typer_config_data = context.config.data["tool"]["typer"]["_internal_build"] - typer_dependencies: List[str] = typer_config_data["dependencies"] - - new_dependencies = [] - for dep in typer_dependencies: - if any(dep.startswith(name) for name in packages_to_sync): - new_dep = f"{dep}=={version}" - new_dependencies.append(new_dep) - else: - new_dependencies.append(dep) - if new_dependencies != typer_dependencies: - metadata["dependencies"] = new_dependencies - metadata["optional-dependencies"] = {} + sync_dependencies: List[str] = context.config.data["tool"]["tiangolo"][ + "_internal_slim_build" + ]["sync_dependencies"] + config: Dict[str, Any] = context.config.data["tool"]["tiangolo"][ + "_internal_slim_build" + ]["packages"][TIANGOLO_BUILD_PACKAGE] + project_config: Dict[str, Any] = config["project"] + for key, value in project_config.items(): + metadata[key] = value + build_config: Dict[str, Any] = ( + config.get("tool", {}).get("pdm", {}).get("build", {}) + ) + for key, value in build_config.items(): + context.config.build_config[key] = value + dependencies: List[str] = metadata.get("dependencies", []) + new_dependencies = [] + for dep in dependencies: + if dep in sync_dependencies: + new_dep = f"{dep}=={version}" + new_dependencies.append(new_dep) + else: + new_dependencies.append(dep) + if new_dependencies != dependencies: + metadata["dependencies"] = new_dependencies From 4721337b1d91445323a340e9fc619c5118423132 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 4 Apr 2024 16:55:43 -0500 Subject: [PATCH 07/17] =?UTF-8?q?=F0=9F=91=B7=20Refactor=20and=20simplify?= =?UTF-8?q?=20publish=20GitHub=20Action=20workflow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/publish.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 1a842c4ea7..80cae43a7f 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -14,8 +14,6 @@ jobs: - typer-slim - typer - typer-cli - env: - dir: ${{ matrix.package == 'typer-slim' && './' || matrix.package == 'typer' && 'typer_package' || matrix.package == 'typer-cli' && 'typer_cli_package' }} permissions: id-token: write steps: @@ -34,9 +32,8 @@ jobs: - name: Install build dependencies run: pip install build - name: Build distribution - working-directory: ${{ env.dir }} + env: + TIANGOLO_BUILD_PACKAGE: ${{ matrix.package }} run: python -m build - name: Publish uses: pypa/gh-action-pypi-publish@v1.8.11 - with: - packages-dir: ${{ env.dir }}/dist/ From 195c62425b78e0116510295b5d8fe8d0f91bc5d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 4 Apr 2024 16:57:42 -0500 Subject: [PATCH 08/17] =?UTF-8?q?=F0=9F=91=B7=20Re-sructure=20test-redistr?= =?UTF-8?q?ibute=20GitHub=20Action?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test-redistribute.yml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test-redistribute.yml b/.github/workflows/test-redistribute.yml index c16d19d7b4..d2a33d30e2 100644 --- a/.github/workflows/test-redistribute.yml +++ b/.github/workflows/test-redistribute.yml @@ -18,8 +18,6 @@ jobs: - typer-slim - typer - typer-cli - env: - dir: ${{ matrix.package == 'typer-slim' && './' || matrix.package == 'typer' && 'typer_package' || matrix.package == 'typer-cli' && 'typer_cli_package' }} steps: - name: Dump GitHub context env: @@ -36,25 +34,24 @@ jobs: - name: Install build dependencies run: pip install build - name: Build source distribution - working-directory: ${{ env.dir }} + env: + TIANGOLO_BUILD_PACKAGE: ${{ matrix.package }} run: python -m build --sdist - name: Decompress source distribution - working-directory: ${{ env.dir }} run: | cd dist tar xvf typer*.tar.gz - name: Install test dependencies - if: ${{ matrix.package == 'typer-slim' }} + if: ${{ matrix.package != 'typer-cli' }} run: | cd dist/typer*/ pip install -r requirements-tests.txt - name: Run source distribution tests - if: ${{ matrix.package == 'typer-slim' }} + if: ${{ matrix.package != 'typer-cli' }} run: | cd dist/typer*/ bash scripts/test.sh - name: Build wheel distribution - working-directory: ${{ env.dir }} run: | cd dist pip wheel --no-deps typer*.tar.gz From e7cb85f1654d308ca3907eee32f5d69feaed0eff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 4 Apr 2024 18:43:42 -0500 Subject: [PATCH 09/17] =?UTF-8?q?=F0=9F=94=A7=20Re-structure=20custom=20bu?= =?UTF-8?q?ild=20so=20that=20typer=20and=20typer-slim=20are=20independent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ca4369627c..b648d38ad4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,34 +58,34 @@ source-includes = [ "scripts/", ] -[tool.tiangolo._internal_slim_build] -sync_dependencies = [ +[tool.tiangolo._internal-slim-build] +sync-dependencies = [ "typer-slim[standard]", "typer-cli", + "typer" ] -[tool.tiangolo._internal_slim_build.packages.typer-slim.project] +[tool.tiangolo._internal-slim-build.packages.typer-slim.project] name = "typer-slim" -[tool.tiangolo._internal_slim_build.packages.typer.project] -dependencies = [ - "typer-slim[standard]", - "typer-cli", -] +[tool.tiangolo._internal-slim-build.packages.typer] +include-optional-dependencies = ["standard"] + +[tool.tiangolo._internal-slim-build.packages.typer.project] optional-dependencies = {} -[tool.tiangolo._internal_slim_build.packages.typer-cli.project] +[tool.tiangolo._internal-slim-build.packages.typer.project.scripts] +typer = "typer.cli:main" + +[tool.tiangolo._internal-slim-build.packages.typer-cli.project] name = "typer-cli" readme = "typer-cli/README.md" dependencies = [ - "typer-slim[standard]", + "typer", ] optional-dependencies = {} -[tool.tiangolo._internal_slim_build.packages.typer-cli.project.scripts] -typer = "typer.cli:main" - -[tool.tiangolo._internal_slim_build.packages.typer-cli.tool.pdm.build] +[tool.tiangolo._internal-slim-build.packages.typer-cli.tool.pdm.build] # excludes needs to explicitly exclude the top level python packages, # otherwise PDM includes them by default # A "*" glob pattern can't be used here because in PDM internals, the patterns are put From 7212e9c9e94674acb83eff7730a823d18a3f86ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 4 Apr 2024 18:44:19 -0500 Subject: [PATCH 10/17] =?UTF-8?q?=F0=9F=94=A8=20Update=20PDM=20build=20hoo?= =?UTF-8?q?k=20to=20support=20including=20the=20default=20extras=20to=20ex?= =?UTF-8?q?tend,=20make=20packages=20independent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pdm_build.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/pdm_build.py b/pdm_build.py index 7bc05aebbc..4629801f0e 100644 --- a/pdm_build.py +++ b/pdm_build.py @@ -10,21 +10,40 @@ def pdm_build_initialize(context: Context): metadata = context.config.metadata # Get main version version = metadata["version"] + # Get package names to keep in sync with the same main version sync_dependencies: List[str] = context.config.data["tool"]["tiangolo"][ - "_internal_slim_build" - ]["sync_dependencies"] + "_internal-slim-build" + ]["sync-dependencies"] + # Get custom config for the current package, from the env var config: Dict[str, Any] = context.config.data["tool"]["tiangolo"][ - "_internal_slim_build" + "_internal-slim-build" ]["packages"][TIANGOLO_BUILD_PACKAGE] project_config: Dict[str, Any] = config["project"] + # Get main optional dependencies, extras + optional_dependencies: Dict[str, List[str]] = metadata.get( + "optional-dependencies", {} + ) + # Get custom optional dependencies name to always include in this (non-slim) package + include_optional_dependencies: List[str] = config.get( + "include-optional-dependencies", [] + ) + # Override main [project] configs with custom configs for this package for key, value in project_config.items(): metadata[key] = value + # Get custom build config for the current package build_config: Dict[str, Any] = ( config.get("tool", {}).get("pdm", {}).get("build", {}) ) + # Override PDM build config with custom build config for this package for key, value in build_config.items(): context.config.build_config[key] = value + # Get main dependencies dependencies: List[str] = metadata.get("dependencies", []) + # Add optional dependencies to the default dependencies for this (non-slim) package + for include_optional in include_optional_dependencies: + optional_dependencies_group = optional_dependencies.get(include_optional, []) + dependencies.extend(optional_dependencies_group) + # Sync versions in dependencies new_dependencies = [] for dep in dependencies: if dep in sync_dependencies: From 8f3632afb4b9c6209226940a312747a6575e166d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 4 Apr 2024 18:49:56 -0500 Subject: [PATCH 11/17] =?UTF-8?q?=F0=9F=94=96=20Release=20version=200.12.1?= =?UTF-8?q?.dev1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- typer/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typer/__init__.py b/typer/__init__.py index 4fa2de27f2..73b426180b 100644 --- a/typer/__init__.py +++ b/typer/__init__.py @@ -1,6 +1,6 @@ """Typer, build great CLIs. Easy to code. Based on Python type hints.""" -__version__ = "0.12.0" +__version__ = "0.12.1.dev1" from shutil import get_terminal_size as get_terminal_size From 0f3fb313b2240eef6464dce1d4438906fedf5837 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 4 Apr 2024 18:50:34 -0500 Subject: [PATCH 12/17] =?UTF-8?q?=F0=9F=91=B7=20Deploy=20dev=20release=20i?= =?UTF-8?q?n=20CI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/publish.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 80cae43a7f..60f7766ebb 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -4,6 +4,10 @@ on: release: types: - created + # TODO: remove this + push: + branches: + - fix-typer-package-src jobs: publish: From 83d1db5c99d0185d0be4278893e509a20f07f68e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 4 Apr 2024 19:08:35 -0500 Subject: [PATCH 13/17] =?UTF-8?q?=F0=9F=93=9D=20Update=20README=20for=20Ty?= =?UTF-8?q?per-CLI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- typer-cli/README.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/typer-cli/README.md b/typer-cli/README.md index dba1a0dcf7..728d7c017d 100644 --- a/typer-cli/README.md +++ b/typer-cli/README.md @@ -30,9 +30,13 @@ Typer is a library for building shellingham: to automatically detect the current shell when installing completion. * With `shellingham` you can just use `--install-completion`. * Without `shellingham`, you have to pass the name of the shell to install completion for, e.g. `--install-completion bash`. -* `typer-cli`: adds the `typer` command to your shell: - * Quickly run scripts (that don't have to use Typer) with shell completion. - * Generate docs for your Typer applications. ### `typer-slim` -If you don't want the extra dependencies, install `typer-slim` instead. +If you don't want the extra standard optional dependencies, install `typer-slim` instead. When you install with: @@ -369,15 +366,15 @@ When you install with: pip install typer ``` -...it's the equivalent of: +...it includes the same code and dependencies as: ```bash pip install "typer-slim[standard]" ``` -The `standard` extra dependencies are `rich`, `shellingham`, `typer-cli`. +The `standard` extra dependencies are `rich` and `shellingham`. -**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`. +**Note**: The `typer` command is only included in the `typer` package. ## License diff --git a/docs/index.md b/docs/index.md index 0d4d824aa1..6bb4983a9f 100644 --- a/docs/index.md +++ b/docs/index.md @@ -37,7 +37,7 @@ The key features are: * **Short**: Minimize code duplication. Multiple features from each parameter declaration. Fewer bugs. * **Start simple**: The simplest example adds only 2 lines of code to your app: **1 import, 1 function call**. * **Grow large**: Grow in complexity as much as you want, create arbitrarily complex trees of commands and groups of subcommands, with options and arguments. -* **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. +* **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. ## FastAPI of CLIs @@ -355,13 +355,10 @@ By default it also comes with extra standard dependencies: * shellingham: to automatically detect the current shell when installing completion. * With `shellingham` you can just use `--install-completion`. * Without `shellingham`, you have to pass the name of the shell to install completion for, e.g. `--install-completion bash`. -* `typer-cli`: adds the `typer` command to your shell: - * Quickly run scripts (that don't have to use Typer) with shell completion. - * Generate docs for your Typer applications. ### `typer-slim` -If you don't want the extra dependencies, install `typer-slim` instead. +If you don't want the extra standard optional dependencies, install `typer-slim` instead. When you install with: @@ -369,15 +366,15 @@ When you install with: pip install typer ``` -...it's the equivalent of: +...it includes the same code and dependencies as: ```bash pip install "typer-slim[standard]" ``` -The `standard` extra dependencies are `rich`, `shellingham`, `typer-cli`. +The `standard` extra dependencies are `rich` and `shellingham`. -**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`. +**Note**: The `typer` command is only included in the `typer` package. ## License diff --git a/docs/tutorial/index.md b/docs/tutorial/index.md index 6fb8075c87..6cec65fe23 100644 --- a/docs/tutorial/index.md +++ b/docs/tutorial/index.md @@ -68,12 +68,12 @@ The first step is to install **Typer**: ```console $ pip install typer ---> 100% -Successfully installed typer click shellingham rich typer-cli +Successfully installed typer click shellingham rich ``` -By default, `typer` comes with `rich`, `shellingham`, and `typer-cli`. +By default, `typer` comes with `rich` and `shellingham`. !!! note If you are an advanced user and want to opt out of these default extra dependencies, you can instead install `typer-slim`. @@ -82,7 +82,7 @@ By default, `typer` comes with `rich`, `shellingham`, and `typer-cli`. pip install typer ``` - ...is the equivalent of: + ...includes the same optional dependencies as: ```bash pip install "typer-slim[standard]" From 4051ad12388ec59867a79ea11d72d26bcd1546dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 4 Apr 2024 19:20:19 -0500 Subject: [PATCH 15/17] =?UTF-8?q?=F0=9F=94=96=20Release=20version=200.12.1?= =?UTF-8?q?.dev2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- typer/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typer/__init__.py b/typer/__init__.py index 73b426180b..53a450970e 100644 --- a/typer/__init__.py +++ b/typer/__init__.py @@ -1,6 +1,6 @@ """Typer, build great CLIs. Easy to code. Based on Python type hints.""" -__version__ = "0.12.1.dev1" +__version__ = "0.12.1.dev2" from shutil import get_terminal_size as get_terminal_size From 8222efe348ba1fa09c45c2d232a4b16f93fa7e9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 4 Apr 2024 19:23:18 -0500 Subject: [PATCH 16/17] =?UTF-8?q?=F0=9F=93=9D=20Update=20Typer-CLI=20READM?= =?UTF-8?q?E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- typer-cli/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typer-cli/README.md b/typer-cli/README.md index 728d7c017d..0ebe65102c 100644 --- a/typer-cli/README.md +++ b/typer-cli/README.md @@ -36,7 +36,7 @@ This package, `typer-cli`, does nothing other than depend on `typer`. All the functionality has been integrated into `typer`. -The only reason this package exists is as a migration path for old projects that used to depend on `typer-cli`, so that they can notice they can upgrade it to just use `typer`. +The 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`. You probably **should not** install this package. From b3b823bc552a083bb1a5f5143d29fb4d96521eac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 4 Apr 2024 19:24:10 -0500 Subject: [PATCH 17/17] =?UTF-8?q?=F0=9F=91=B7=20Disable=20publishing=20fro?= =?UTF-8?q?m=20dev=20branch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/publish.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 60f7766ebb..80cae43a7f 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -4,10 +4,6 @@ on: release: types: - created - # TODO: remove this - push: - branches: - - fix-typer-package-src jobs: publish: