Skip to content

Commit

Permalink
feat: Support Python 3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Oct 18, 2023
1 parent 1d405aa commit fc81d43
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 275 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
Expand Down
5 changes: 1 addition & 4 deletions copier_template/{{library_name}}/extension.py.jinja
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
"""Meltano {{ extension_name }} extension."""
from __future__ import annotations

import os
import pkgutil
import subprocess
import sys
from pathlib import Path
from typing import Any

import structlog
Expand Down Expand Up @@ -54,5 +51,5 @@ class {{ extension_name }}(ExtensionBase):
models.InvokerCommand(
name="{{ cli_prefix }}_invoker", description="pass through invoker"
),
]
],
)
16 changes: 12 additions & 4 deletions copier_template/{{library_name}}/main.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ def invoke(ctx: typer.Context, command_args: List[str]) -> None:
@app.command()
def describe(
output_format: DescribeFormat = typer.Option(
DescribeFormat.text, "--format", help="Output format"
DescribeFormat.text,
"--format",
help="Output format",
)
) -> None:
"""Describe the available commands of this extension."""
Expand All @@ -76,13 +78,19 @@ def main(
ctx: typer.Context,
log_level: str = typer.Option("INFO", envvar="LOG_LEVEL"),
log_timestamps: bool = typer.Option(
False, envvar="LOG_TIMESTAMPS", help="Show timestamp in logs"
False,
envvar="LOG_TIMESTAMPS",
help="Show timestamp in logs",
),
log_levels: bool = typer.Option(
False, "--log-levels", envvar="LOG_LEVELS", help="Show log levels"
False,
"--log-levels",
envvar="LOG_LEVELS",
help="Show log levels",
),
meltano_log_json: bool = typer.Option(
False, "--meltano-log-json",
False,
"--meltano-log-json",
envvar="MELTANO_LOG_JSON",
help="Log in the meltano JSON log format"
),
Expand Down
2 changes: 1 addition & 1 deletion copier_template/{{library_name}}/pass_through.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ def pass_through_cli() -> None:
ext = {{extension_name}}()
ext.pass_through_invoker(
structlog.getLogger("{{ cli_prefix }}_invoker"),
*sys.argv[1:] if len(sys.argv) > 1 else []
*sys.argv[1:] if len(sys.argv) > 1 else [],
)
299 changes: 78 additions & 221 deletions poetry.lock

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ classifiers = [
"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 :: Libraries :: Application Frameworks",
"Typing :: Typed",
Expand Down Expand Up @@ -68,13 +69,11 @@ docs = [
copier = ">=8.1.0,<9.0"
pytest = "^7.4.2"
types-pyyaml = "^6.0.12.4"

# Cookiecutter tests
mypy = "^1.4"
black = "^23.3"
darglint = "^1.8.0"
flake8 = "^3.9.0"
flake8-annotations = "^2.9.1"
flake8-docstrings = "^1.7.0"
mypy = "^1.6"
ruff = "~=0.1.0"
typer = "^0.6.1"

[tool.ruff]
ignore = [
Expand Down
63 changes: 25 additions & 38 deletions tests/copier_template/test_generated.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
"""Test copier_template template."""

import logging
import os
import shutil
import subprocess
from logging import getLogger
from pathlib import Path

import black
import pytest
from copier import run_copy
from flake8.api import legacy as flake8
from mypy import api

getLogger("flake8").propagate = False
Expand All @@ -31,17 +28,6 @@ def outdir() -> str:

def test_copier_output(outdir: str):
"""Generate and validate the resulting copier managed template."""
style_guide_easy = flake8.get_style_guide(
ignore=["E302", "E303", "E305", "F401", "W391"]
)
style_guide_strict = flake8.get_style_guide(
ignore=[
"F401", # "imported but unused"
"W292", # "no newline at end of file"
"W391", # "blank line at end of file"
]
)

template_path = os.path.join(
os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "copier_template/"
)
Expand All @@ -62,26 +48,27 @@ def test_copier_output(outdir: str):
quiet=True,
)

for outfile in Path(outdir).glob("**/*.py"):
filepath = str(outfile.absolute())
report = style_guide_easy.check_files([filepath])
errors = report.get_statistics("E")
assert (
not errors
), f"Flake8 found violations in first pass of {filepath}: {errors}"
mypy_out = api.run([filepath, "--config", str(Path(outdir) / Path("tox.ini"))])
mypy_msg = str(mypy_out[0])
if not mypy_msg.startswith("Success:"):
logging.exception(f"MyPy validation failed: {mypy_msg}")
assert not mypy_msg, f"MyPy validation failed for file {filepath}"
report = style_guide_strict.check_files([filepath])
errors = report.get_statistics("E")
assert (
not errors
), f"Flake8 found violations in second pass of {filepath}: {errors}"
black.format_file_in_place(
Path(filepath),
fast=False,
mode=black.FileMode(),
write_back=black.WriteBack.NO,
)
# Use mypy to check the generated code
mypy_stdout, mypy_stderr, mypy_exit_status = api.run([outdir])
assert not mypy_exit_status, mypy_stdout

# Use ruff to check the generated code
ruff_check = [
"ruff",
"check",
outdir,
"--select",
"E,F,W,Q",
]
p = subprocess.run(ruff_check, capture_output=True)
assert p.returncode == 0, p.stdout.decode("utf-8")

# Use ruff to format the generated code
ruff_format = [
"ruff",
"format",
outdir,
# "--check",
]
p = subprocess.run(ruff_format, capture_output=True)
assert p.returncode == 0, p.stdout.decode("utf-8")

0 comments on commit fc81d43

Please sign in to comment.