diff --git a/.config/dictionary.txt b/.config/dictionary.txt index f7ec258..befe713 100644 --- a/.config/dictionary.txt +++ b/.config/dictionary.txt @@ -14,3 +14,4 @@ notest pycontribs pypa setuptools +typer diff --git a/.config/requirements.txt b/.config/requirements.txt index 3f382dd..fc06a9a 100644 --- a/.config/requirements.txt +++ b/.config/requirements.txt @@ -1 +1,4 @@ +pyyaml rich +typer-config +typing-extensions diff --git a/.config/test-requirements.txt b/.config/test-requirements.txt index e079f8a..742db7f 100644 --- a/.config/test-requirements.txt +++ b/.config/test-requirements.txt @@ -1 +1,2 @@ -pytest +pytest>=7.0 +coverage>=7.4.1 diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index 5e016b5..0fd63ad 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -30,6 +30,7 @@ jobs: with: min_python: "3.10" max_python: "3.12" + default_python: "3.10" other_names: | lint pkg @@ -95,11 +96,6 @@ jobs: - name: tox -e ${{ matrix.passed_name }} run: python3 -m tox -e ${{ matrix.passed_name }} - - name: Combine coverage data - if: ${{ startsWith(matrix.passed_name, 'py') }} - # produce a single .coverage file at repo root - run: tox -e coverage - - name: Upload coverage data if: ${{ startsWith(matrix.passed_name, 'py') }} uses: codecov/codecov-action@v3 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0557ad2..60b314e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -80,6 +80,8 @@ repos: additional_dependencies: - pytest - rich + - typer-config + - types-setuptools - repo: https://github.com/pycqa/pylint rev: v3.0.3 hooks: @@ -89,6 +91,7 @@ repos: additional_dependencies: - pytest - rich + - typer-config - repo: https://github.com/jazzband/pip-tools rev: 7.3.0 hooks: diff --git a/README.md b/README.md index 9854aff..6f3aa0a 100644 --- a/README.md +++ b/README.md @@ -10,13 +10,25 @@ gh extension install pycontribs/gh-pre Usage: -``` +```shell gh pre ``` -It can also be installed and executed as a python module: +It can also be installed and executed as a Python package: -``` +```shell pip install gh-pre pre ``` + +## Configuration + +Please create a `~/pre.yml` config file with content similar to: + +``` +repos: + - github-org/project1 + - github-org/project2 +``` + +This will tell it which repositories to check for draft releases. diff --git a/pyproject.toml b/pyproject.toml index 86ff24a..cd82bd4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,7 +37,7 @@ classifiers = [ keywords = ["gh", "github"] [project.scripts] -pre = "gh_pre.__main__:main" +pre = "gh_pre.__main__:app" [project.urls] homepage = "https://github.com/pycontribs/gh-pre" diff --git a/src/gh_pre/__main__.py b/src/gh_pre/__main__.py index 522b3af..861f2c7 100644 --- a/src/gh_pre/__main__.py +++ b/src/gh_pre/__main__.py @@ -4,27 +4,30 @@ import datetime from subprocess import run +import os +from typing import Optional +from typing_extensions import Annotated from rich.panel import Panel from rich import box from rich.console import Console +import typer +from typer_config.decorators import use_yaml_config -def main() -> None: - """Main entrypoint.""" +app = typer.Typer() + + +@app.command() +@use_yaml_config( + default_value=os.path.expanduser("~/pre.yml"), + param_help="Configuration file (~/pre.yml).", +) +def main(repos: Annotated[Optional[list[str]], typer.Option()] = None) -> None: + """Pre helps you chain releases on github.""" + if repos is None: + repos = [] console = Console() - repos = [ - "ansible/ansible-compat", - "ansible/ansible-lint", - "ansible/ansible-navigator", - "ansible/ansible-creator", - "ansible/molecule", - "ansible/tox-ansible", - "ansible/pytest-ansible", - "ansible/ansible-development-environment", - "ansible/ansible-dev-tools", - "ansible/creator-ee", - ] for repo in repos: repo_link = f"[markdown.link][link=https://github.com/{repo}]{repo}[/][/]" result = run( @@ -61,4 +64,4 @@ def main() -> None: if __name__ == "__main__": # execute only if run as a script - main() + app() diff --git a/tests/pre.yml b/tests/pre.yml new file mode 100644 index 0000000..124e4d7 --- /dev/null +++ b/tests/pre.yml @@ -0,0 +1,12 @@ +--- +repos: + - ansible/ansible-compat + - ansible/ansible-lint + - ansible/ansible-navigator + - ansible/ansible-creator + - ansible/molecule + - ansible/tox-ansible + - ansible/pytest-ansible + - ansible/ansible-development-environment + - ansible/ansible-dev-tools + - ansible/creator-ee diff --git a/tests/test_app.py b/tests/test_app.py index 3c62ee6..6b25f85 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -1,16 +1,14 @@ """Tests""" -from pytest import CaptureFixture -from gh_pre.__main__ import main +from typer.testing import CliRunner -__author__ = "Sorin Sbarnea" -__copyright__ = "Sorin Sbarnea" -__license__ = "MIT" +from gh_pre.__main__ import app -def test_main(capsys: CaptureFixture[str]) -> None: +runner = CliRunner() + + +def test_main() -> None: """CLI Tests""" - # capsys is a pytest fixture that allows asserts against stdout/stderr - # https://docs.pytest.org/en/stable/capture.html - main() - captured = capsys.readouterr() - assert "The 7-th Fibonacci number is 13" in captured.out + result = runner.invoke(app, ["--help", "--config=tests/pre.yml"]) + assert result.exit_code == 0, result.stdout + assert "Pre helps you chain releases on github." in result.stdout diff --git a/tox.ini b/tox.ini index adf7e17..447e090 100644 --- a/tox.ini +++ b/tox.ini @@ -3,25 +3,37 @@ # THIS SCRIPT IS SUPPOSED TO BE AN EXAMPLE. MODIFY IT ACCORDING TO YOUR NEEDS! [tox] -minversion = 4.0 +minversion = 4.6.3 envlist = pkg lint py -isolated_build = True - +isolated_build = true +requires = + tox >= 4.6.3 + setuptools >= 65.3.0 # editable installs [testenv] description = Invoke pytest to run automated tests setenv = TOXINIDIR = {toxinidir} passenv = + GH_TOKEN + GITHUB_TOKEN HOME + TERM + PYTHON* + PYTEST_* + PY_COLORS SETUPTOOLS_* + LANG + LC_* extras = test commands = - pytest {posargs} + coverage run -m pytest {posargs} + coverage xml + coverage report package = editable allowlist_externals = gh @@ -92,7 +104,7 @@ commands = # Install the wheel sh -c 'python3 -m pip install "gh-pre @ file://$(echo {toxinidir}/dist/*.whl)"' # call the tool - python3 -m gh_pre --help + sh -c "HOME=tests python3 -m gh_pre --help" # Uninstall it python3 -m pip uninstall -y gh-pre # Testing pipx compatibility @@ -101,4 +113,4 @@ commands = # Testing gh calling sh -c "gh extension remove gh-pre || true" gh extension install . - gh pre --version + gh pre --help --config=tests/pre.yml