Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/actions/python-poetry/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ runs:
# https://github.com/actions/runner-images/issues/6185
PYTHON_KEYRING_BACKEND: "keyring.backends.null.Keyring"
run: |
poetry install
poetry lock --check
poetry check --lock
poetry sync
PROJECT_VERSION=$(poetry version -s)
[ "${PROJECT_VERSION}" != "0.0.0" ] \
|| { echo "Versioning broken"; exit 1; }
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ env:
ENABLE_PYPI_PUBLISH: true
ENABLE_TEST_PYPI_PUBLISH: true
RELEASE_PYTHON_VERSION: "3.12"
RELEASE_POETRY_VERSION: "1.8"
RELEASE_POETRY_VERSION: "2.0"

on:
push:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ jobs:
os:
- Ubuntu
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
poetry-version:
- "1.8"
- "2.0"

runs-on: ${{ matrix.os }}-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ repos:
rev: v3.16.0
hooks:
- id: pyupgrade
args: ["--keep-runtime-typing"]
args: ["--py39-plus", "--keep-runtime-typing"]
- repo: local
hooks:
- id: mypy
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ Via [`pipx`][pipx]:
```console
pip install pipx
pipx install poetry
pipx inject poetry poetry-dynamic-versioning poetry-pre-commit-plugin
pipx inject poetry poetry-pre-commit-plugin
```

Via `pip`:

```console
pip install poetry
poetry self add poetry-dynamic-versioning poetry-pre-commit-plugin
poetry self add poetry-pre-commit-plugin
```

## New project creation
Expand Down
2 changes: 1 addition & 1 deletion cookie_python/manage/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
return subprocess.run(*popenargs, check=check, **kwargs)

def shell(self) -> None:
if sys.__stdin__.isatty():
if sys.__stdin__ and sys.__stdin__.isatty():

Check warning on line 120 in cookie_python/manage/repo.py

View check run for this annotation

Codecov / codecov/patch

cookie_python/manage/repo.py#L120

Added line #L120 was not covered by tests
self.logger.info('Starting shell. Run "exit 1" to abort.')
self.run([os.environ.get("SHELL", "/bin/bash")])

Expand Down
1 change: 1 addition & 0 deletions cookie_python/manage/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,4 @@ def update_action(repo: RepoSandbox) -> None:
repo.logger.info(f"Updated {actions_str}")
repo.commit_changes(message)
repo.open_pr(message)
repo.run(["poetry", "env", "remove", "--all"], check=False)
3 changes: 1 addition & 2 deletions cookie_python/new.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import subprocess
import time
from pathlib import Path
from typing import List, Tuple

TEMPLATE_REPOSITORY_URL = "https://github.com/smkent/cookie-python"


def parse_args() -> Tuple[argparse.Namespace, List[str]]:
def parse_args() -> tuple[argparse.Namespace, list[str]]:
ap = argparse.ArgumentParser()
ap.add_argument(
"project_dir", help="New project parent directory", type=str
Expand Down
3 changes: 1 addition & 2 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
import os
import shutil
import subprocess
from typing import Dict, List

import yaml

TEMPLATE_ONLY_DATA = "cookiecutter_template_data"


def _run(call: List[str], env: Dict[str, str]) -> None:
def _run(call: list[str], env: dict[str, str]) -> None:
subprocess.run(call, env=env).check_returncode()


Expand Down
529 changes: 300 additions & 229 deletions poetry.lock

Large diffs are not rendered by default.

39 changes: 24 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
[build-system]
requires = ["poetry-core>=1.2.0", "poetry-dynamic-versioning"]
build-backend = "poetry_dynamic_versioning.backend"
requires = ["poetry-core>=2.0.0,<3.0.0", "poetry-dynamic-versioning"]
build-backend = "poetry.core.masonry.api"

[tool.poetry]
[project]
name = "cookie-python"
version = "0.0.0"
description = ""
license = "MIT"
authors = ["Stephen Kent <smkent@smkent.net>"]
authors = [ { name = "Stephen Kent", email = "smkent@smkent.net" } ]
readme = "README.md"
repository = "https://github.com/smkent/cookie-python"
classifiers = [
Expand All @@ -17,19 +16,31 @@ classifiers = [
"Topic :: Software Development :: Libraries :: Python Modules",
"Typing :: Typed",
]
requires-python = ">=3.9"
dynamic = [ "version" ]
dependencies = [
"loguru",
"pygithub",
"pyyaml",
"semver",
"toml ; python_version < '3.11'",
]

[project.scripts]
new-cookie = "cookie_python.new:main"
manage-cookie = "cookie_python.manage.main:main"

[tool.poetry]
packages = [
{ include = "{{cookiecutter.project_name}}" }
]
requires-poetry = ">=2.0"
version = "0.0.0"

[tool.poetry.dependencies]
python = "^3.8"
loguru = "*"
poetry-dynamic-versioning = "*"
pygithub = "*"
pyyaml = "*"
semver = "*"
[tool.poetry.requires-plugins]
poetry-dynamic-versioning = { version = ">=1.0.0,<2.0.0", extras = ["plugin"] }

[tool.poetry.dev-dependencies]
[tool.poetry.group.dev.dependencies]
bandit = {extras = ["toml"], version = "*"}
black = "*"
build = "*"
Expand All @@ -51,8 +62,6 @@ pytest-sugar = "*"
types-PyYAML = "*"

[tool.poetry.scripts]
new-cookie = "cookie_python.new:main"
manage-cookie = "cookie_python.manage.main:main"

[tool.poetry-dynamic-versioning]
enable = true
Expand Down
71 changes: 68 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,41 @@
import json
import os
import subprocess
import sys
from pathlib import Path
from tempfile import TemporaryDirectory
from typing import Iterator
from collections.abc import Iterator
from unittest.mock import patch

import pytest

from cookie_python.new import main as new_cookie_main

AUTHOR_NAME = "Ness"
AUTHOR_EMAIL = "ness@onett.example"
PROJECT_NAME = "unit-test-1"


@pytest.fixture
def project_environment() -> Iterator[None]:
add_values = dict(
GIT_AUTHOR_NAME=AUTHOR_NAME,
GIT_AUTHOR_EMAIL=AUTHOR_EMAIL,
GIT_COMMITTER_NAME=AUTHOR_NAME,
GIT_COMMITTER_EMAIL=AUTHOR_EMAIL,
GITHUB_API_TOKEN="unittest_token",
)
with patch.dict(os.environ, add_values):
yield


@pytest.fixture(scope="session", autouse=True)
def subprocess_environment() -> Iterator[None]:
with patch.dict(os.environ, {}) as patched_env:
if "VIRTUAL_ENV" in patched_env:
del patched_env["VIRTUAL_ENV"]
yield


def pytest_addoption(parser: pytest.Parser) -> None:
group = parser.getgroup("cookie", "python-cookie test helpers")
Expand All @@ -23,6 +55,39 @@ def opt_update_expected_outputs(request: pytest.FixtureRequest) -> bool:


@pytest.fixture
def temp_dir() -> Iterator[str]:
def temp_dir() -> Iterator[Path]:
with TemporaryDirectory(prefix="cookie-python.unittest.") as td:
yield os.path.join(td)
yield Path(td)


@pytest.fixture(params=["@"])
def new_cookie(
request: pytest.FixtureRequest, project_environment: None, temp_dir: Path
) -> Iterator[Path]:
testargs = [
"new-cookie",
"--local",
str(temp_dir),
"--",
"-d",
"-y",
"--extra-context",
json.dumps(
{
"author_email": AUTHOR_EMAIL,
"author_name": AUTHOR_NAME,
"github_user": "ness.unittest.example",
"project_description": "Unit test project",
"project_name": PROJECT_NAME,
"enable_container_publish": "yes",
}
),
"-c",
request.param,
]
with patch.object(sys, "argv", testargs):
new_cookie_main()
project_dir = temp_dir / PROJECT_NAME
yield project_dir
if (project_dir / "pyproject.toml").is_file():
subprocess.run(["poetry", "env", "remove", "--all"], cwd=project_dir)
4 changes: 2 additions & 2 deletions tests/data/readme-github_user_only.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ Via [`pipx`][pipx]:
```console
pip install pipx
pipx install poetry
pipx inject poetry poetry-dynamic-versioning poetry-pre-commit-plugin
pipx inject poetry poetry-pre-commit-plugin
```

Via `pip`:

```console
pip install poetry
poetry self add poetry-dynamic-versioning poetry-pre-commit-plugin
poetry self add poetry-pre-commit-plugin
```

### Development tasks
Expand Down
4 changes: 2 additions & 2 deletions tests/data/readme-github_user_with_container.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ Via [`pipx`][pipx]:
```console
pip install pipx
pipx install poetry
pipx inject poetry poetry-dynamic-versioning poetry-pre-commit-plugin
pipx inject poetry poetry-pre-commit-plugin
```

Via `pip`:

```console
pip install poetry
poetry self add poetry-dynamic-versioning poetry-pre-commit-plugin
poetry self add poetry-pre-commit-plugin
```

### Development tasks
Expand Down
4 changes: 2 additions & 2 deletions tests/data/readme-github_user_with_coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ Via [`pipx`][pipx]:
```console
pip install pipx
pipx install poetry
pipx inject poetry poetry-dynamic-versioning poetry-pre-commit-plugin
pipx inject poetry poetry-pre-commit-plugin
```

Via `pip`:

```console
pip install poetry
poetry self add poetry-dynamic-versioning poetry-pre-commit-plugin
poetry self add poetry-pre-commit-plugin
```

### Development tasks
Expand Down
4 changes: 2 additions & 2 deletions tests/data/readme-github_user_with_coverage_and_container.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ Via [`pipx`][pipx]:
```console
pip install pipx
pipx install poetry
pipx inject poetry poetry-dynamic-versioning poetry-pre-commit-plugin
pipx inject poetry poetry-pre-commit-plugin
```

Via `pip`:

```console
pip install poetry
poetry self add poetry-dynamic-versioning poetry-pre-commit-plugin
poetry self add poetry-pre-commit-plugin
```

### Development tasks
Expand Down
4 changes: 2 additions & 2 deletions tests/data/readme-github_user_with_coverage_and_pypi.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ Via [`pipx`][pipx]:
```console
pip install pipx
pipx install poetry
pipx inject poetry poetry-dynamic-versioning poetry-pre-commit-plugin
pipx inject poetry poetry-pre-commit-plugin
```

Via `pip`:

```console
pip install poetry
poetry self add poetry-dynamic-versioning poetry-pre-commit-plugin
poetry self add poetry-pre-commit-plugin
```

### Development tasks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ Via [`pipx`][pipx]:
```console
pip install pipx
pipx install poetry
pipx inject poetry poetry-dynamic-versioning poetry-pre-commit-plugin
pipx inject poetry poetry-pre-commit-plugin
```

Via `pip`:

```console
pip install poetry
poetry self add poetry-dynamic-versioning poetry-pre-commit-plugin
poetry self add poetry-pre-commit-plugin
```

### Development tasks
Expand Down
4 changes: 2 additions & 2 deletions tests/data/readme-github_user_with_pypi.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ Via [`pipx`][pipx]:
```console
pip install pipx
pipx install poetry
pipx inject poetry poetry-dynamic-versioning poetry-pre-commit-plugin
pipx inject poetry poetry-pre-commit-plugin
```

Via `pip`:

```console
pip install poetry
poetry self add poetry-dynamic-versioning poetry-pre-commit-plugin
poetry self add poetry-pre-commit-plugin
```

### Development tasks
Expand Down
4 changes: 2 additions & 2 deletions tests/data/readme-github_user_with_pypi_and_container.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ Via [`pipx`][pipx]:
```console
pip install pipx
pipx install poetry
pipx inject poetry poetry-dynamic-versioning poetry-pre-commit-plugin
pipx inject poetry poetry-pre-commit-plugin
```

Via `pip`:

```console
pip install poetry
poetry self add poetry-dynamic-versioning poetry-pre-commit-plugin
poetry self add poetry-pre-commit-plugin
```

### Development tasks
Expand Down
Loading
Loading