From a2eec781e44c5399e25b607df5dce828d68ac012 Mon Sep 17 00:00:00 2001 From: JP-Ellis Date: Tue, 19 Nov 2024 14:56:04 +1100 Subject: [PATCH] chore: remove CLI component As it is not very interesting, and not a useful test. Signed-off-by: JP-Ellis --- .github/workflows/test.yml | 2 +- .vscode/settings.json | 6 +- README.md | 9 +- pypacter-cli/LICENSE | 1 - pypacter-cli/README.md | 1 - pypacter-cli/pyproject.toml | 147 ---------------------- pypacter-cli/src/pypacter_cli/__init__.py | 106 ---------------- pypacter-cli/src/pypacter_cli/py.typed | 0 pypacter-cli/src/pypacter_cli/util.py | 40 ------ pypacter-cli/tests/ruff.toml | 11 -- pypacter-cli/tests/test_cli.py | 17 --- pyproject.toml | 11 +- 12 files changed, 8 insertions(+), 343 deletions(-) delete mode 100644 pypacter-cli/LICENSE delete mode 100644 pypacter-cli/README.md delete mode 100644 pypacter-cli/pyproject.toml delete mode 100644 pypacter-cli/src/pypacter_cli/__init__.py delete mode 100644 pypacter-cli/src/pypacter_cli/py.typed delete mode 100644 pypacter-cli/src/pypacter_cli/util.py delete mode 100644 pypacter-cli/tests/ruff.toml delete mode 100644 pypacter-cli/tests/test_cli.py diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cb6b79f..651bbff 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,7 +29,7 @@ jobs: matrix: os: [ubuntu-latest, windows-latest, macos-latest] python-version: ["3.11", "3.12"] - directory: [".", "pypacter-api", "pypacter-cli"] + directory: [".", "pypacter-api"] steps: - uses: actions/checkout@v4 diff --git a/.vscode/settings.json b/.vscode/settings.json index d720370..c9e2712 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,9 +1,5 @@ { - "python.testing.pytestArgs": [ - "tests", - "pypacter-api/tests", - "pypacter-cli/tests" - ], + "python.testing.pytestArgs": ["tests", "pypacter-api/tests"], "python.testing.pytestEnabled": true, "python.testing.unittestEnabled": false, "ruff.importStrategy": "fromEnvironment" diff --git a/README.md b/README.md index 4e0b50c..327fa01 100644 --- a/README.md +++ b/README.md @@ -32,11 +32,10 @@ code is tested. This project uses the [pytest](https://docs.pytest.org/en/stable ## Development This project uses [Hatch](https://hatch.pypa.io) for managing the development -environment. The code is split across three packages: +environment. The code is split across two packages: - `pypacter`: The core logic - `pypacter-api`: API wrapper -- `pypacter-cli`: CLI to interact with the API The structure of the project is as follows: @@ -47,16 +46,10 @@ pypacter/ │ ├── tests/ │ ├── pyproject.toml │ └── README.md -├── pypacter-cli/ <== CLI to interact with API -│ ├── src/pypacter_cli/ -│ ├── tests/ -│ ├── pyproject.toml -│ └── README.md ├── notebooks/ <== Jupyter notebooks (if any) ├── src/ │ └── pypacter/ <== Core logic ├── tests/ -├── mkdocs.yml ├── pyproject.toml └── README.md ``` diff --git a/pypacter-cli/LICENSE b/pypacter-cli/LICENSE deleted file mode 100644 index fc3b532..0000000 --- a/pypacter-cli/LICENSE +++ /dev/null @@ -1 +0,0 @@ -All rights reserved to SmartBear Software. diff --git a/pypacter-cli/README.md b/pypacter-cli/README.md deleted file mode 100644 index c79ca7a..0000000 --- a/pypacter-cli/README.md +++ /dev/null @@ -1 +0,0 @@ -# PyPacter CLI diff --git a/pypacter-cli/pyproject.toml b/pypacter-cli/pyproject.toml deleted file mode 100644 index 97b21c5..0000000 --- a/pypacter-cli/pyproject.toml +++ /dev/null @@ -1,147 +0,0 @@ -################################################################################ -## Project Configuration -################################################################################ -[project] -name = "pypacter-cli" -description = "CLI for PyPacter" -dynamic = ["version"] - -authors = [{ name = "JP-Ellis", email = "josh@jpellis.me" }] -maintainers = [{ name = "JP-Ellis", email = "josh@jpellis.me" }] - -readme = "README.md" -license = { file = "LICENSE" } -keywords = ["pactflow", "pypacter"] -classifiers = [ - "Development Status :: 3 - Alpha", - "Environment :: Console", - "Intended Audience :: Developers", - "License :: Other/Proprietary License", - "Natural Language :: English", - "Operating System :: OS Independent", - "Programming Language :: Python", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "Programming Language :: Python :: 3.12", - "Programming Language :: Python :: Implementation :: CPython", - "Topic :: Software Development :: Code Generators", -] - -requires-python = ">=3.8" - -dependencies = [ - "aiohttp[speedups]~=3.0", - "click~=8.0", - "pyyaml~=6.0", - "rich~=13.0", - "rich-click~=1.0", -] - -[project.urls] -Documentation = "https://github.com/pactflow/pactflow-python-coding-test/tree/main/pypacter-cli" -Issues = "https://github.com/pactflow/pactflow-python-coding-test/issues" -Source = "https://github.com/pactflow/pactflow-python-coding-test/tree/main/pypacter-cli" - -[project.scripts] -pypacter = "pypacter_cli:cli" - -[project.optional-dependencies] -devel-types = ["mypy==1.8.0", "pydantic~=1.0", "types-pyyaml"] -devel-test = ["pytest", "pytest-cov", "coverage[toml]"] -devel = ["pypacter-cli[devel-types,devel-test]", "ruff==0.2.2"] - -################################################################################ -## Build System Configuration -################################################################################ -[build-system] -requires = ["hatchling", "hatch-vcs"] -build-backend = "hatchling.build" - -[tool.hatch.version] -source = "vcs" -raw-options = { root = ".." } - -[tool.hatch.build.hooks.vcs] -version-file = "src/pypacter_cli/__version__.py" - -[tool.hatch.build.targets.sdist] -include = [ - # Source - "/src/pypacter_cli/**/*.py", - "/src/pypacter_cli/**/*.pyi", - "/src/pypacter_cli/py.typed", - # Metadata - "/LICENSE", -] - -[tool.hatch.build.targets.wheel] -packages = ["/src/pypacter_cli"] -include = [ - # Source - "/src/pypacter_cli/**/*.py", - "/src/pypacter_cli/**/*.pyi", - "/src/pypacter_cli/py.typed", -] - -[tool.hatch.envs.default] -features = ["devel"] - -[tool.hatch.envs.default.scripts] -lint = "ruff check --show-source --show-fixes {args} src tests" -typecheck = "mypy src tests {args}" -format = "ruff format src tests {args}" -test = "pytest tests/ {args}" -all = ["format", "lint", "typecheck", "test"] - -[tool.hatch.envs.test] -features = ["devel"] - -[[tool.hatch.envs.test.matrix]] -python = ["3.8", "3.9", "3.10", "3.11", "3.12"] - -################################################################################ -## Ruff Configuration -################################################################################ - -[tool.ruff] -extend = "../pyproject.toml" -target-version = "py38" - -[tool.ruff.format] -preview = true - -################################################################################ -## PyTest Configuration -################################################################################ - -[tool.pytest.ini_options] -addopts = [ - "--import-mode=importlib", - "--cov-config=pyproject.toml", - "--cov-report=xml", -] - -################################################################################ -## Mypy Configuration -################################################################################ - -[tool.mypy] -plugins = "pydantic.mypy" - -################################################################################ -## Coverage Configuration -################################################################################ - -[tool.coverage.paths] -pypacter_cli = ["/src/pypacter_cli"] -tests = ["tests"] - -[tool.coverage.report] -exclude_lines = [ - "if __name__ == .__main__.:", # Ignore non-runnable code - "if TYPE_CHECKING:", # Ignore typing - "raise NotImplementedError", # Ignore defensive assertions - "@(abc\\.)?abstractmethod", # Ignore abstract methods -] diff --git a/pypacter-cli/src/pypacter_cli/__init__.py b/pypacter-cli/src/pypacter_cli/__init__.py deleted file mode 100644 index 14bcdc9..0000000 --- a/pypacter-cli/src/pypacter_cli/__init__.py +++ /dev/null @@ -1,106 +0,0 @@ -""" -PyPacter CLI. - -Command line interface for PyPacter. - -We makes use of the [`click`][click] library for the defining and handling of -arguments, and uses the wrapper `rich_click` which leverages [`rich`][rich] to -provide rich text formatting for the CLI. - -The [`cli`][pypacter_cli.cli] function is the entry point for the CLI and handles -the parsing of arguments. -""" - -from __future__ import annotations - -import logging - -import click -import rich.traceback -import rich_click -from rich.logging import RichHandler - -from pypacter_cli.__version__ import __version__, __version_tuple__ -from pypacter_cli.util import make_sync - -__all__ = [ - "__version__", - "__version_tuple__", - "__author__", - "__email__", - "__url__", - "__license__", - "__copyright__", - "cli", - "get_version", -] - -__author__ = "Joshua Ellis" -__email__ = "joshua.ellis@smartbear.com" -__url__ = "https://github.com/pactflow/pactflow-python-coding-test" -__license__ = "Proprietary" -__copyright__ = "SmartBear Software and PactFlow" - - -logger = logging.getLogger("pypacter") -rich.traceback.install(suppress=[click, rich_click]) -rich_click.rich_click.USE_MARKDOWN = True - - -@rich_click.command() -@rich_click.option( - "-v", - "--verbose", - help="Increase the verbosity of the output. Can be specified multiple times.", - count=True, - metavar="", - envvar="ACCORD_VERBOSE", -) -@rich_click.option( - "-q", - "--quiet", - help="Decrease the verbosity of the output. Can be specified multiple times.", - count=True, - metavar="", - envvar="ACCORD_QUIET", -) -@rich_click.option( - "-V", - "--version", - help="Show the version and exit.", - is_flag=True, -) -@make_sync -async def cli( - verbose: int, - quiet: int, - version: bool, # noqa: FBT001 -) -> None: - """PyPacter CLI. - - Command line interface for PyPacter. - """ - if version: - rich_click.echo(f"PyPacter CLI v{get_version()}") - - logging.basicConfig( - level=logging.WARNING - 10 * (verbose - quiet), - format="%(message)s", - datefmt="[%X]", - handlers=[ - RichHandler( - rich_tracebacks=True, - tracebacks_suppress=[click, rich_click], - ), - ], - ) - - -def get_version() -> str: - """ - Get the version of PyPacter. - - Returns: - The version string. - """ - return __version__ diff --git a/pypacter-cli/src/pypacter_cli/py.typed b/pypacter-cli/src/pypacter_cli/py.typed deleted file mode 100644 index e69de29..0000000 diff --git a/pypacter-cli/src/pypacter_cli/util.py b/pypacter-cli/src/pypacter_cli/util.py deleted file mode 100644 index 8d05d00..0000000 --- a/pypacter-cli/src/pypacter_cli/util.py +++ /dev/null @@ -1,40 +0,0 @@ -""" -Utility functions for the CLI. -""" - -from __future__ import annotations - -import asyncio -import logging -import typing -from functools import wraps - -from typing_extensions import ParamSpec, TypeVar - -if typing.TYPE_CHECKING: - from collections.abc import Callable, Coroutine - -logger = logging.getLevelName(__name__) - - -_P = ParamSpec("_P") -_T = TypeVar("_T") - - -def make_sync(f: Callable[_P, Coroutine[None, None, _T]]) -> Callable[_P, _T]: - """ - Wrap a function to run it in an asyncio event loop. - - The click library does not support async functions, so we need to wrap the - async functions in a sync function that runs the async function in an - asyncio event loop. - - See [pallets/click#2033](https://github.com/pallets/click/issues/2033) for - the status of this issue. - """ - - @wraps(f) - def wrapper(*args: _P.args, **kwargs: _P.kwargs) -> _T: - return asyncio.run(f(*args, **kwargs)) - - return wrapper diff --git a/pypacter-cli/tests/ruff.toml b/pypacter-cli/tests/ruff.toml deleted file mode 100644 index 4d0a085..0000000 --- a/pypacter-cli/tests/ruff.toml +++ /dev/null @@ -1,11 +0,0 @@ -extend = "../pyproject.toml" - -[lint] -ignore = [ - "D100", # Required docstring in public module - "D103", # Require docstrings on public functions - "D104", # Require docstring in public package - "INP001", # Forbid implicit namespaces - "PLR2004", # Forbid magic numbers - "S101", # Disable assert -] diff --git a/pypacter-cli/tests/test_cli.py b/pypacter-cli/tests/test_cli.py deleted file mode 100644 index 1f1bddf..0000000 --- a/pypacter-cli/tests/test_cli.py +++ /dev/null @@ -1,17 +0,0 @@ -from click.testing import CliRunner - -from pypacter_cli import cli - - -def test_cli_help() -> None: - runner = CliRunner() - result = runner.invoke(cli, ["--help"]) - assert result.exit_code == 0 - assert "PyPacter" in result.output - - -def test_cli_version() -> None: - runner = CliRunner() - result = runner.invoke(cli, ["--version"]) - assert result.exit_code == 0 - assert "PyPacter" in result.output diff --git a/pyproject.toml b/pyproject.toml index cf135ad..852298e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,7 +39,6 @@ devel-types = ["mypy==1.8.0", "pydantic~=1.0", "types-pyyaml", "types-pygments"] devel = [ "pypacter[devel-test,devel-types]", "pypacter-api[devel]", - "pypacter-cli[devel]", "ruff==0.2.2", "ipykernel", ] @@ -75,11 +74,11 @@ include = [ ] [tool.hatch.envs.default] -python = "3.11" +installer = "uv" +python = "3.12" features = ["devel"] pre-install-commands = [ "pip install -q --disable-pip-version-check --no-deps --editable {root:uri}/pypacter-api[devel]", - "pip install -q --disable-pip-version-check --no-deps --editable {root:uri}/pypacter-cli[devel]", ] [tool.hatch.envs.default.scripts] @@ -90,14 +89,14 @@ test = "pytest tests/ {args}" all = ["format", "lint", "typecheck", "test"] [tool.hatch.envs.test] +installer = "uv" features = ["devel"] pre-install-commands = [ "pip install -q --disable-pip-version-check --no-deps --editable {root:uri}/pypacter-api[devel]", - "pip install -q --disable-pip-version-check --no-deps --editable {root:uri}/pypacter-cli[devel]", ] [[tool.hatch.envs.test.matrix]] -python = ["3.8", "3.9", "3.10", "3.11", "3.12"] +python = ["3.9", "3.10", "3.11", "3.12", "3.13"] ################################################################################ ## Ruff Configuration @@ -127,7 +126,7 @@ ignore = [ ] [tool.ruff.lint.isort] -known-first-party = ["pypacter", "pypacter_api", "pypacter_cli"] +known-first-party = ["pypacter", "pypacter_api"] [tool.ruff.lint.flake8-tidy-imports] ban-relative-imports = "all"