Skip to content

Commit

Permalink
Finish dropping python<=3.9 support (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
kloczek authored Aug 27, 2024
1 parent 70bc5ad commit 5b7f0c7
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 83 deletions.
2 changes: 0 additions & 2 deletions crick/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

from ._version import get_versions
from .numpy_version import numpy_version
from .space_saving import SpaceSaving
Expand Down
64 changes: 32 additions & 32 deletions crick/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# This file helps to compute a version number in source trees obtained from
# git-archive tarball (such as those provided by githubs download-from-tag
# feature). Distribution tarballs (built by setup.py sdist) and build
Expand All @@ -16,11 +15,12 @@
import re
import subprocess
import sys
from typing import Any, Callable, Dict, List, Optional, Tuple
from typing import Any
from collections.abc import Callable
import functools


def get_keywords() -> Dict[str, str]:
def get_keywords() -> dict[str, str]:
"""Get the keywords needed to look up the version information."""
# these strings will be replaced by git during git-archive.
# setup.py/versioneer.py will grep for the variable names, so they must
Expand Down Expand Up @@ -62,8 +62,8 @@ class NotThisMethod(Exception):
"""Exception raised if a method is not valid for the current scenario."""


LONG_VERSION_PY: Dict[str, str] = {}
HANDLERS: Dict[str, Dict[str, Callable]] = {}
LONG_VERSION_PY: dict[str, str] = {}
HANDLERS: dict[str, dict[str, Callable]] = {}


def register_vcs_handler(vcs: str, method: str) -> Callable: # decorator
Expand All @@ -78,18 +78,18 @@ def decorate(f: Callable) -> Callable:


def run_command(
commands: List[str],
args: List[str],
cwd: Optional[str] = None,
commands: list[str],
args: list[str],
cwd: str | None = None,
verbose: bool = False,
hide_stderr: bool = False,
env: Optional[Dict[str, str]] = None,
) -> Tuple[Optional[str], Optional[int]]:
env: dict[str, str] | None = None,
) -> tuple[str | None, int | None]:
"""Call the given command(s)."""
assert isinstance(commands, list)
process = None

popen_kwargs: Dict[str, Any] = {}
popen_kwargs: dict[str, Any] = {}
if sys.platform == "win32":
# This hides the console window if pythonw.exe is used
startupinfo = subprocess.STARTUPINFO()
Expand All @@ -114,7 +114,7 @@ def run_command(
return None, None
else:
if verbose:
print("unable to find command, tried %s" % (commands,))
print("unable to find command, tried {}".format(commands))
return None, None
stdout = process.communicate()[0].strip().decode()
if process.returncode != 0:
Expand All @@ -129,7 +129,7 @@ def versions_from_parentdir(
parentdir_prefix: str,
root: str,
verbose: bool,
) -> Dict[str, Any]:
) -> dict[str, Any]:
"""Try to determine the version from the parent directory name.
Source tarballs conventionally unpack into a directory that includes both
Expand All @@ -154,15 +154,15 @@ def versions_from_parentdir(


@register_vcs_handler("git", "get_keywords")
def git_get_keywords(versionfile_abs: str) -> Dict[str, str]:
def git_get_keywords(versionfile_abs: str) -> dict[str, str]:
"""Extract version information from the given file."""
# the code embedded in _version.py can just fetch the value of these
# keywords. When used from setup.py, we don't want to import _version.py,
# so we do it with a regexp instead. This function is not used from
# _version.py.
keywords: Dict[str, str] = {}
keywords: dict[str, str] = {}
try:
with open(versionfile_abs, "r") as fobj:
with open(versionfile_abs) as fobj:
for line in fobj:
if line.strip().startswith("git_refnames ="):
mo = re.search(r'=\s*"(.*)"', line)
Expand All @@ -183,10 +183,10 @@ def git_get_keywords(versionfile_abs: str) -> Dict[str, str]:

@register_vcs_handler("git", "keywords")
def git_versions_from_keywords(
keywords: Dict[str, str],
keywords: dict[str, str],
tag_prefix: str,
verbose: bool,
) -> Dict[str, Any]:
) -> dict[str, Any]:
"""Get version information from git keywords."""
if "refnames" not in keywords:
raise NotThisMethod("Short version file found")
Expand Down Expand Up @@ -255,7 +255,7 @@ def git_pieces_from_vcs(
root: str,
verbose: bool,
runner: Callable = run_command
) -> Dict[str, Any]:
) -> dict[str, Any]:
"""Get version from 'git describe' in the root of the source tree.
This only gets called if the git-archive 'subst' keywords were *not*
Expand Down Expand Up @@ -295,7 +295,7 @@ def git_pieces_from_vcs(
raise NotThisMethod("'git rev-parse' failed")
full_out = full_out.strip()

pieces: Dict[str, Any] = {}
pieces: dict[str, Any] = {}
pieces["long"] = full_out
pieces["short"] = full_out[:7] # maybe improved later
pieces["error"] = None
Expand Down Expand Up @@ -387,14 +387,14 @@ def git_pieces_from_vcs(
return pieces


def plus_or_dot(pieces: Dict[str, Any]) -> str:
def plus_or_dot(pieces: dict[str, Any]) -> str:
"""Return a + if we don't already have one, else return a ."""
if "+" in pieces.get("closest-tag", ""):
return "."
return "+"


def render_pep440(pieces: Dict[str, Any]) -> str:
def render_pep440(pieces: dict[str, Any]) -> str:
"""Build up version string, with post-release "local version identifier".
Our goal: TAG[+DISTANCE.gHEX[.dirty]] . Note that if you
Expand All @@ -419,7 +419,7 @@ def render_pep440(pieces: Dict[str, Any]) -> str:
return rendered


def render_pep440_branch(pieces: Dict[str, Any]) -> str:
def render_pep440_branch(pieces: dict[str, Any]) -> str:
"""TAG[[.dev0]+DISTANCE.gHEX[.dirty]] .
The ".dev0" means not master branch. Note that .dev0 sorts backwards
Expand Down Expand Up @@ -449,7 +449,7 @@ def render_pep440_branch(pieces: Dict[str, Any]) -> str:
return rendered


def pep440_split_post(ver: str) -> Tuple[str, Optional[int]]:
def pep440_split_post(ver: str) -> tuple[str, int | None]:
"""Split pep440 version string at the post-release segment.
Returns the release segments before the post-release and the
Expand All @@ -459,7 +459,7 @@ def pep440_split_post(ver: str) -> Tuple[str, Optional[int]]:
return vc[0], int(vc[1] or 0) if len(vc) == 2 else None


def render_pep440_pre(pieces: Dict[str, Any]) -> str:
def render_pep440_pre(pieces: dict[str, Any]) -> str:
"""TAG[.postN.devDISTANCE] -- No -dirty.
Exceptions:
Expand All @@ -483,7 +483,7 @@ def render_pep440_pre(pieces: Dict[str, Any]) -> str:
return rendered


def render_pep440_post(pieces: Dict[str, Any]) -> str:
def render_pep440_post(pieces: dict[str, Any]) -> str:
"""TAG[.postDISTANCE[.dev0]+gHEX] .
The ".dev0" means dirty. Note that .dev0 sorts backwards
Expand All @@ -510,7 +510,7 @@ def render_pep440_post(pieces: Dict[str, Any]) -> str:
return rendered


def render_pep440_post_branch(pieces: Dict[str, Any]) -> str:
def render_pep440_post_branch(pieces: dict[str, Any]) -> str:
"""TAG[.postDISTANCE[.dev0]+gHEX[.dirty]] .
The ".dev0" means not master branch.
Expand Down Expand Up @@ -539,7 +539,7 @@ def render_pep440_post_branch(pieces: Dict[str, Any]) -> str:
return rendered


def render_pep440_old(pieces: Dict[str, Any]) -> str:
def render_pep440_old(pieces: dict[str, Any]) -> str:
"""TAG[.postDISTANCE[.dev0]] .
The ".dev0" means dirty.
Expand All @@ -561,7 +561,7 @@ def render_pep440_old(pieces: Dict[str, Any]) -> str:
return rendered


def render_git_describe(pieces: Dict[str, Any]) -> str:
def render_git_describe(pieces: dict[str, Any]) -> str:
"""TAG[-DISTANCE-gHEX][-dirty].
Like 'git describe --tags --dirty --always'.
Expand All @@ -581,7 +581,7 @@ def render_git_describe(pieces: Dict[str, Any]) -> str:
return rendered


def render_git_describe_long(pieces: Dict[str, Any]) -> str:
def render_git_describe_long(pieces: dict[str, Any]) -> str:
"""TAG-DISTANCE-gHEX[-dirty].
Like 'git describe --tags --dirty --always -long'.
Expand All @@ -601,7 +601,7 @@ def render_git_describe_long(pieces: Dict[str, Any]) -> str:
return rendered


def render(pieces: Dict[str, Any], style: str) -> Dict[str, Any]:
def render(pieces: dict[str, Any], style: str) -> dict[str, Any]:
"""Render the given version pieces into the requested style."""
if pieces["error"]:
return {"version": "unknown",
Expand Down Expand Up @@ -637,7 +637,7 @@ def render(pieces: Dict[str, Any], style: str) -> Dict[str, Any]:
"date": pieces.get("date")}


def get_versions() -> Dict[str, Any]:
def get_versions() -> dict[str, Any]:
"""Get version information or return default if unable to do so."""
# I am in _version.py, which lives at ROOT/VERSIONFILE_SOURCE. If we have
# __file__, we can work backwards from there to the root. Some
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def generate_code(templates):
# updated, then no need to generate
continue

with open(template, "r") as f:
with open(template) as f:
tmpl = f.read()
output = tempita.sub(tmpl)

Expand Down
Loading

0 comments on commit 5b7f0c7

Please sign in to comment.