Use new type annotations introduced in Python 3.10
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
d48daaab10
commit
d6c0673a1d
@ -4,6 +4,7 @@ PYTHON_VERSIONS = [
|
|||||||
"3.7",
|
"3.7",
|
||||||
"3.8",
|
"3.8",
|
||||||
"3.9",
|
"3.9",
|
||||||
|
"3.10",
|
||||||
"latest",
|
"latest",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -13,17 +13,12 @@ from subprocess import check_output
|
|||||||
from tarfile import TarFile
|
from tarfile import TarFile
|
||||||
from tarfile import TarInfo
|
from tarfile import TarInfo
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from typing import Optional
|
|
||||||
from typing import Union
|
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
|
||||||
# Extract metadata from repo
|
|
||||||
|
|
||||||
|
|
||||||
class UnsupportedContentTypeError(ValueError):
|
class UnsupportedContentTypeError(ValueError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -52,6 +47,8 @@ def removesuffix(s: str, suf: str) -> str:
|
|||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class GitRemoteInfo:
|
class GitRemoteInfo:
|
||||||
|
"""Extracts information about a repository"""
|
||||||
|
|
||||||
hostname: str
|
hostname: str
|
||||||
owner: str
|
owner: str
|
||||||
repo: str
|
repo: str
|
||||||
@ -89,7 +86,7 @@ class GitRemoteInfo:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def parse_git_remote(git_url: Optional[str] = None) -> GitRemoteInfo:
|
def parse_git_remote(git_url: str | None = None) -> GitRemoteInfo:
|
||||||
"""Extract Github repo info from a git remote url"""
|
"""Extract Github repo info from a git remote url"""
|
||||||
if not git_url:
|
if not git_url:
|
||||||
git_url = (
|
git_url = (
|
||||||
@ -128,7 +125,7 @@ def parse_cargo_version(p: Path) -> str:
|
|||||||
raise ValueError(f"No version found in {p}")
|
raise ValueError(f"No version found in {p}")
|
||||||
|
|
||||||
|
|
||||||
def read_git_tag(fetch: bool = True) -> Optional[str]:
|
def read_git_tag(fetch: bool = True) -> str | None:
|
||||||
"""Get local git tag for current repo
|
"""Get local git tag for current repo
|
||||||
|
|
||||||
fetch: optionally fetch tags with depth of 1 from remote"""
|
fetch: optionally fetch tags with depth of 1 from remote"""
|
||||||
@ -139,7 +136,7 @@ def read_git_tag(fetch: bool = True) -> Optional[str]:
|
|||||||
return git_tag or None
|
return git_tag or None
|
||||||
|
|
||||||
|
|
||||||
def read_version(from_tags: bool = False, fetch: bool = False) -> Optional[str]:
|
def read_version(from_tags: bool = False, fetch: bool = False) -> str | None:
|
||||||
"""Read version information from file or from git"""
|
"""Read version information from file or from git"""
|
||||||
if from_tags:
|
if from_tags:
|
||||||
return read_git_tag(fetch)
|
return read_git_tag(fetch)
|
||||||
@ -158,12 +155,9 @@ def read_version(from_tags: bool = False, fetch: bool = False) -> Optional[str]:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
# Fetch release and assets from Github
|
|
||||||
|
|
||||||
|
|
||||||
def fetch_release(
|
def fetch_release(
|
||||||
remote: GitRemoteInfo,
|
remote: GitRemoteInfo,
|
||||||
version: Optional[str] = None
|
version: str | None = None
|
||||||
# TODO: Accept an argument for pre-release
|
# TODO: Accept an argument for pre-release
|
||||||
) -> dict[Any, Any]:
|
) -> dict[Any, Any]:
|
||||||
"""Fetches a release object from a Github repo
|
"""Fetches a release object from a Github repo
|
||||||
@ -193,9 +187,9 @@ def fetch_release(
|
|||||||
def match_asset(
|
def match_asset(
|
||||||
release: dict[Any, Any],
|
release: dict[Any, Any],
|
||||||
format: str,
|
format: str,
|
||||||
version: Optional[str] = None,
|
version: str | None = None,
|
||||||
system_mapping: Optional[dict[str, str]] = None,
|
system_mapping: dict[str, str] | None = None,
|
||||||
arch_mapping: Optional[dict[str, str]] = None,
|
arch_mapping: dict[str, str] | None = None,
|
||||||
) -> dict[Any, Any]:
|
) -> dict[Any, Any]:
|
||||||
"""Accepts a release and searches for an appropriate asset attached using
|
"""Accepts a release and searches for an appropriate asset attached using
|
||||||
a provided template and some alternative mappings for version, system, and machine info
|
a provided template and some alternative mappings for version, system, and machine info
|
||||||
@ -273,7 +267,7 @@ class PackageAdapter:
|
|||||||
"""Adapts the names and extractall methods from ZipFile and TarFile classes"""
|
"""Adapts the names and extractall methods from ZipFile and TarFile classes"""
|
||||||
|
|
||||||
def __init__(self, content_type: str, response: requests.Response):
|
def __init__(self, content_type: str, response: requests.Response):
|
||||||
self._package: Union[TarFile, ZipFile]
|
self._package: TarFile | ZipFile
|
||||||
if content_type in (
|
if content_type in (
|
||||||
"application/zip",
|
"application/zip",
|
||||||
"application/x-zip-compressed",
|
"application/x-zip-compressed",
|
||||||
@ -306,8 +300,8 @@ class PackageAdapter:
|
|||||||
|
|
||||||
def extractall(
|
def extractall(
|
||||||
self,
|
self,
|
||||||
path: Optional[Path],
|
path: Path | None,
|
||||||
members: Optional[list[str]],
|
members: list[str] | None,
|
||||||
) -> list[str]:
|
) -> list[str]:
|
||||||
"""Extract all or a subset of files from the package
|
"""Extract all or a subset of files from the package
|
||||||
|
|
||||||
@ -351,8 +345,8 @@ def get_asset_package(
|
|||||||
|
|
||||||
def download_asset(
|
def download_asset(
|
||||||
asset: dict[Any, Any],
|
asset: dict[Any, Any],
|
||||||
extract_files: Optional[list[str]] = None,
|
extract_files: list[str] | None = None,
|
||||||
destination: Optional[Path] = None,
|
destination: Path | None = None,
|
||||||
) -> list[Path]:
|
) -> list[Path]:
|
||||||
"""Download asset from entity passed in
|
"""Download asset from entity passed in
|
||||||
|
|
||||||
@ -388,8 +382,8 @@ class MapAddAction(argparse.Action):
|
|||||||
self,
|
self,
|
||||||
_: argparse.ArgumentParser,
|
_: argparse.ArgumentParser,
|
||||||
namespace: argparse.Namespace,
|
namespace: argparse.Namespace,
|
||||||
values: Union[str, Sequence[Any], None],
|
values: str | Sequence[Any] | None,
|
||||||
option_string: Optional[str] = None,
|
option_string: str | None = None,
|
||||||
):
|
):
|
||||||
# Validate that required value has something
|
# Validate that required value has something
|
||||||
if self.required and not values:
|
if self.required and not values:
|
||||||
@ -419,7 +413,7 @@ class MapAddAction(argparse.Action):
|
|||||||
setattr(namespace, self.dest, dest)
|
setattr(namespace, self.dest, dest)
|
||||||
|
|
||||||
|
|
||||||
def _parse_args(args: Optional[list[str]] = None) -> argparse.Namespace:
|
def _parse_args(args: list[str] | None = None) -> argparse.Namespace:
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"format",
|
"format",
|
||||||
@ -529,10 +523,10 @@ def download_release(
|
|||||||
remote_info: GitRemoteInfo,
|
remote_info: GitRemoteInfo,
|
||||||
destination: Path,
|
destination: Path,
|
||||||
format: str,
|
format: str,
|
||||||
version: Optional[str] = None,
|
version: str | None = None,
|
||||||
system_mapping: Optional[dict[str, str]] = None,
|
system_mapping: dict[str, str] | None = None,
|
||||||
arch_mapping: Optional[dict[str, str]] = None,
|
arch_mapping: dict[str, str] | None = None,
|
||||||
extract_files: Optional[list[str]] = None,
|
extract_files: list[str] | None = None,
|
||||||
) -> list[Path]:
|
) -> list[Path]:
|
||||||
"""Convenience method for fetching, downloading and extracting a release"""
|
"""Convenience method for fetching, downloading and extracting a release"""
|
||||||
release = fetch_release(remote_info)
|
release = fetch_release(remote_info)
|
||||||
|
1
setup.py
1
setup.py
@ -26,6 +26,7 @@ setup(
|
|||||||
"Programming Language :: Python :: 3.7",
|
"Programming Language :: Python :: 3.7",
|
||||||
"Programming Language :: Python :: 3.8",
|
"Programming Language :: Python :: 3.8",
|
||||||
"Programming Language :: Python :: 3.9",
|
"Programming Language :: Python :: 3.9",
|
||||||
|
"Programming Language :: Python :: 3.10",
|
||||||
],
|
],
|
||||||
keywords="",
|
keywords="",
|
||||||
py_modules=["release_gitter", "pseudo_builder"],
|
py_modules=["release_gitter", "pseudo_builder"],
|
||||||
|
Loading…
Reference in New Issue
Block a user