Skip to content

Commit

Permalink
Merge pull request #63 from jorenham/fix/60/--target
Browse files Browse the repository at this point in the history
fix broken `--target`
  • Loading branch information
jorenham authored Sep 28, 2024
2 parents 2ed7ca3 + d61792b commit 91b53ca
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion unpy/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ class PythonVersion(tuple[int, ...], enum.ReprEnum): # noqa: SLOT001
PY310 = (3, 10)
PY311 = (3, 11)
PY312 = (3, 12)
# PY313 = (3, 13)
PY313 = (3, 13)
21 changes: 16 additions & 5 deletions unpy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
from __future__ import annotations

import difflib
import enum
import fileinput
import sys
from pathlib import Path
from typing import Annotated, Final, TypeAlias
from typing import Annotated, Final, TypeAlias, cast

import typer

Expand All @@ -15,6 +16,17 @@
__all__ = ("app",)


class Target(enum.StrEnum):
PY310 = "3.10"
PY311 = "3.11"
PY312 = "3.12"
PY313 = "3.13"

@property
def version(self, /) -> PythonVersion:
return cast(PythonVersion, getattr(PythonVersion, self.name))


def _version_callback(*, value: bool) -> None:
if not value:
return
Expand Down Expand Up @@ -54,9 +66,8 @@ def _version_callback(*, value: bool) -> None:
help="Show the version and exit",
),
]

_OptionTarget: TypeAlias = Annotated[
PythonVersion,
Target,
typer.Option(
"--target",
help="The minimum Python version that should be supported.",
Expand All @@ -71,7 +82,7 @@ def _version_callback(*, value: bool) -> None:
]

_DEFAULT_OUTPUT: Final = Path("-")
_DEFAULT_TARGET: Final = PythonVersion.PY311
_DEFAULT_TARGET: Final = Target.PY311


def _read_source(source: Path, /) -> str:
Expand Down Expand Up @@ -157,7 +168,7 @@ def build(
assert not version

source_str = _read_source(source)
output_str = transform_source(source_str, target=target)
output_str = transform_source(source_str, target=target.version)

if diff:
_echo_diff(str(source), source_str, str(output), output_str)
Expand Down

0 comments on commit 91b53ca

Please sign in to comment.