mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-10-03 13:30:36 +00:00
python3Packages.nixpkgs-plugin-update: fix ruff checks
This commit is contained in:
@@ -12,6 +12,7 @@ buildPythonPackage {
|
||||
pname = "nixpkgs-plugin-update";
|
||||
version = "0.1.0";
|
||||
pyproject = true;
|
||||
__structuredAttrs = true;
|
||||
|
||||
src = ./nixpkgs-plugin-update;
|
||||
|
||||
|
||||
@@ -18,17 +18,19 @@ import traceback
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
import xml.etree.ElementTree as ET
|
||||
from collections.abc import Callable
|
||||
from dataclasses import asdict, dataclass, replace
|
||||
from datetime import datetime, date
|
||||
from datetime import UTC, datetime
|
||||
from functools import wraps
|
||||
from multiprocessing.dummy import Pool
|
||||
from pathlib import Path
|
||||
from tempfile import NamedTemporaryFile
|
||||
from typing import Any, Callable
|
||||
from typing import Any
|
||||
from urllib.parse import unquote, urljoin, urlparse, urlsplit
|
||||
|
||||
import git
|
||||
from packaging.version import InvalidVersion, parse as parse_version
|
||||
from packaging.version import InvalidVersion
|
||||
from packaging.version import parse as parse_version
|
||||
|
||||
ATOM_ENTRY = "{http://www.w3.org/2005/Atom}entry" # " vim gets confused here
|
||||
ATOM_LINK = "{http://www.w3.org/2005/Atom}link" # "
|
||||
@@ -44,7 +46,7 @@ RELEASE_VERSION_PATTERN = re.compile(r"^[^\d]*(\d[\w.@+-]*)$")
|
||||
|
||||
LOG_LEVELS = {
|
||||
logging.getLevelName(level): level
|
||||
for level in [logging.DEBUG, logging.INFO, logging.WARN, logging.ERROR]
|
||||
for level in [logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR]
|
||||
}
|
||||
|
||||
log = logging.getLogger()
|
||||
@@ -70,7 +72,7 @@ def retry(ExceptionToCheck: Any, tries: int = 4, delay: float = 3, backoff: floa
|
||||
try:
|
||||
return f(*args, **kwargs)
|
||||
except ExceptionToCheck as e:
|
||||
print(f"{str(e)}, Retrying in {mdelay} seconds...")
|
||||
print(f"{e!s}, Retrying in {mdelay} seconds...")
|
||||
time.sleep(mdelay)
|
||||
mtries -= 1
|
||||
mdelay *= backoff
|
||||
@@ -159,7 +161,7 @@ class Repo:
|
||||
"""Url to the repo"""
|
||||
self._branch = branch
|
||||
# Redirect is the new Repo to use
|
||||
self.redirect: "Repo | None" = None
|
||||
self.redirect: Repo | None = None
|
||||
self.token: str | None = None
|
||||
|
||||
@property
|
||||
@@ -231,7 +233,7 @@ class Repo:
|
||||
except subprocess.CalledProcessError as e:
|
||||
log.debug("Failed to fetch tags for %s: %s", self.uri, e)
|
||||
return None
|
||||
except Exception as e:
|
||||
except Exception as e: # noqa: BLE001
|
||||
log.warning("Unexpected error fetching tags for %s: %s", self.uri, e)
|
||||
return None
|
||||
|
||||
@@ -322,7 +324,9 @@ class RepoGitHub(Repo):
|
||||
assert updated_tag is not None and updated_tag.text is not None, (
|
||||
f"No updated tag found feed entry {xml!r}"
|
||||
)
|
||||
updated = datetime.strptime(updated_tag.text, "%Y-%m-%dT%H:%M:%SZ")
|
||||
updated = datetime.strptime(
|
||||
updated_tag.text, "%Y-%m-%dT%H:%M:%SZ"
|
||||
).replace(tzinfo=UTC)
|
||||
return Path(str(url.path)).name, updated
|
||||
|
||||
@retry(urllib.error.URLError, tries=4, delay=3, backoff=2)
|
||||
@@ -713,14 +717,14 @@ def select_plugin_target(
|
||||
f"{GIT_TAGS_PREFIX}{latest_tag}"
|
||||
)
|
||||
|
||||
if current_plugin is not None:
|
||||
if (
|
||||
current_plugin.date is not None
|
||||
and current_plugin.tag is None
|
||||
and current_plugin.date.date() > release_date.date()
|
||||
):
|
||||
latest_tag = newer_version_tag(current_plugin.last_tag, latest_tag)
|
||||
return get_commit_target(plugin_desc.repo, "HEAD", latest_tag)
|
||||
if (
|
||||
current_plugin is not None
|
||||
and current_plugin.date is not None
|
||||
and current_plugin.tag is None
|
||||
and current_plugin.date.date() > release_date.date()
|
||||
):
|
||||
latest_tag = newer_version_tag(current_plugin.last_tag, latest_tag)
|
||||
return get_commit_target(plugin_desc.repo, "HEAD", latest_tag)
|
||||
|
||||
return release_commit, release_date, release_version, latest_tag
|
||||
|
||||
@@ -780,7 +784,7 @@ class Editor:
|
||||
deprecated: Path | None = None,
|
||||
cache_file: str | None = None,
|
||||
):
|
||||
log.debug("get_plugins:", get_plugins)
|
||||
log.debug("get_plugins: %s", get_plugins)
|
||||
self.name = name
|
||||
self.root = root
|
||||
self.get_plugins = get_plugins
|
||||
@@ -821,10 +825,7 @@ class Editor:
|
||||
if autocommit:
|
||||
assert editor.nixpkgs_repo is not None
|
||||
|
||||
commit_message = "{drv_name}: init at {version}".format(
|
||||
drv_name=editor.get_drv_name(plugin.normalized_name),
|
||||
version=plugin.version,
|
||||
)
|
||||
commit_message = f"{editor.get_drv_name(plugin.normalized_name)}: init at {plugin.version}"
|
||||
|
||||
if isinstance(pdesc.repo, RepoGitHub):
|
||||
github_url = (
|
||||
@@ -1098,7 +1099,7 @@ class Editor:
|
||||
"--debug",
|
||||
"-d",
|
||||
choices=LOG_LEVELS.keys(),
|
||||
default=logging.getLevelName(logging.WARN),
|
||||
default=logging.getLevelName(logging.WARNING),
|
||||
help="Adjust log level",
|
||||
)
|
||||
|
||||
@@ -1160,7 +1161,7 @@ class Editor:
|
||||
getattr(self, command)(args)
|
||||
|
||||
|
||||
class CleanEnvironment(object):
|
||||
class CleanEnvironment:
|
||||
def __init__(self, nixpkgs):
|
||||
self.local_pkgs = nixpkgs
|
||||
|
||||
@@ -1174,7 +1175,7 @@ class CleanEnvironment(object):
|
||||
self.empty_config.flush()
|
||||
return f"localpkgs={self.local_pkgs}"
|
||||
|
||||
def __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None:
|
||||
def __exit__(self, exc_type: object, exc_value: object, traceback: object) -> None:
|
||||
os.environ.update(self.old_environ)
|
||||
self.empty_config.close()
|
||||
|
||||
@@ -1264,7 +1265,6 @@ def print_download_error(plugin: PluginDesc, ex: Exception):
|
||||
def check_results(
|
||||
results: list[tuple[PluginDesc, Exception | Plugin, Repo | None]],
|
||||
) -> tuple[list[tuple[PluginDesc, Plugin]], Redirects]:
|
||||
""" """
|
||||
failures: list[tuple[PluginDesc, Exception]] = []
|
||||
plugins = []
|
||||
redirects: Redirects = {}
|
||||
@@ -1387,7 +1387,7 @@ def prefetch(
|
||||
plugin, redirect = prefetch_plugin(pluginDesc, cache, current_plugin)
|
||||
cache[target_cache_key(pluginDesc.repo.uri, plugin.commit, plugin.tag)] = plugin
|
||||
return (pluginDesc, plugin, redirect)
|
||||
except Exception as e:
|
||||
except Exception as e: # noqa: BLE001
|
||||
return (pluginDesc, e, None)
|
||||
|
||||
|
||||
@@ -1396,9 +1396,14 @@ def rewrite_input(
|
||||
input_file: Path,
|
||||
deprecated: Path,
|
||||
# old pluginDesc and the new
|
||||
redirects: Redirects = {},
|
||||
append: list[PluginDesc] = [],
|
||||
redirects: Redirects | None = None,
|
||||
append: list[PluginDesc] | None = None,
|
||||
):
|
||||
if redirects is None:
|
||||
redirects = {}
|
||||
if append is None:
|
||||
append = []
|
||||
|
||||
log.info("Rewriting input file %s", input_file)
|
||||
plugins = load_plugins_from_csv(config, input_file)
|
||||
|
||||
@@ -1407,7 +1412,7 @@ def rewrite_input(
|
||||
if redirects:
|
||||
log.debug("Dealing with deprecated plugins listed in %s", deprecated)
|
||||
|
||||
cur_date_iso = datetime.now().strftime("%Y-%m-%d")
|
||||
cur_date_iso = datetime.now(tz=UTC).strftime("%Y-%m-%d")
|
||||
with open(deprecated, "r") as f:
|
||||
deprecations = json.load(f)
|
||||
# TODO parallelize this step
|
||||
@@ -1493,7 +1498,7 @@ def update_plugins(editor: Editor, args):
|
||||
name, old_ver, new_ver = updated_plugins[0]
|
||||
message = f"{editor.attr_path}.{name}: {old_ver} -> {new_ver}"
|
||||
else:
|
||||
message = f"{editor.attr_path}: update on {date.today()}"
|
||||
message = f"{editor.attr_path}: update on {datetime.now(tz=UTC).date()}"
|
||||
|
||||
print(args.outfile)
|
||||
commit(repo, message, [args.outfile])
|
||||
|
||||
Reference in New Issue
Block a user