Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

Commit

Permalink
Add config file
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Jan 29, 2024
1 parent c1bebc6 commit 7282e31
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 37 deletions.
1 change: 1 addition & 0 deletions .config/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ notest
pycontribs
pypa
setuptools
typer
3 changes: 3 additions & 0 deletions .config/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
pyyaml
rich
typer-config
typing-extensions
3 changes: 2 additions & 1 deletion .config/test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pytest
pytest>=7.0
coverage>=7.4.1
1 change: 1 addition & 0 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
with:
min_python: "3.10"
max_python: "3.12"
default_python: "3.10"
other_names: |
lint
pkg
Expand Down
3 changes: 3 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ repos:
additional_dependencies:
- pytest
- rich
- typer-config
- types-setuptools
- repo: https://github.com/pycqa/pylint
rev: v3.0.3
hooks:
Expand All @@ -89,6 +91,7 @@ repos:
additional_dependencies:
- pytest
- rich
- typer-config
- repo: https://github.com/jazzband/pip-tools
rev: 7.3.0
hooks:
Expand Down
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
33 changes: 18 additions & 15 deletions src/gh_pre/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -61,4 +64,4 @@ def main() -> None:

if __name__ == "__main__":
# execute only if run as a script
main()
app()
12 changes: 12 additions & 0 deletions tests/pre.yml
Original file line number Diff line number Diff line change
@@ -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
20 changes: 9 additions & 11 deletions tests/test_app.py
Original file line number Diff line number Diff line change
@@ -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
22 changes: 16 additions & 6 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,35 @@
# 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 =
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
Expand Down Expand Up @@ -92,7 +102,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
Expand All @@ -101,4 +111,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

0 comments on commit 7282e31

Please sign in to comment.