Skip to content

Commit

Permalink
pylint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Artturin authored and mergify[bot] committed Oct 20, 2023
1 parent c20b63f commit cfae4ff
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 27 deletions.
4 changes: 2 additions & 2 deletions nixpkgs_review/builddir.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def create_cache_directory(name: str) -> Union[Path, "TemporaryDirectory[str]"]:
if home is None:
# we are in a temporary directory
return TemporaryDirectory()
else:
xdg_cache = Path(home).joinpath(".cache")

xdg_cache = Path(home).joinpath(".cache")

counter = 0
while True:
Expand Down
14 changes: 7 additions & 7 deletions nixpkgs_review/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ def hub_config_path() -> Path:
raw_hub_path = os.environ.get("HUB_CONFIG", None)
if raw_hub_path:
return Path(raw_hub_path)

raw_config_home = os.environ.get("XDG_CONFIG_HOME", None)
if raw_config_home is None:
config_home = Path.home().joinpath(".config")
else:
raw_config_home = os.environ.get("XDG_CONFIG_HOME", None)
if raw_config_home is None:
config_home = Path.home().joinpath(".config")
else:
config_home = Path(raw_config_home)
return config_home.joinpath("hub")
config_home = Path(raw_config_home)
return config_home.joinpath("hub")


def read_github_token() -> str | None:
Expand Down Expand Up @@ -313,7 +313,7 @@ def parse_args(command: str, args: list[str]) -> argparse.Namespace:

if args == []:
main_parser.print_help()
exit(2)
sys.exit(2)

return main_parser.parse_args(args)

Expand Down
2 changes: 0 additions & 2 deletions nixpkgs_review/errors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
class NixpkgsReviewError(Exception):
"""Base class for exceptions in this module."""

pass
23 changes: 13 additions & 10 deletions nixpkgs_review/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def _request(
body = json.dumps(data).encode("ascii")

req = urllib.request.Request(url, headers=headers, method=method, data=body)
resp = urllib.request.urlopen(req)
return json.loads(resp.read())
with urllib.request.urlopen(req) as resp:
return json.loads(resp.read())

def get(self, path: str) -> Any:
return self._request(path, "GET")
Expand All @@ -42,15 +42,15 @@ def comment_issue(self, pr: int, msg: str) -> Any:
"Post a comment on a PR with nixpkgs-review report"
print(f"Posting result comment on {pr_url(pr)}")
return self.post(
f"/repos/NixOS/nixpkgs/issues/{pr}/comments", data=dict(body=msg)
f"/repos/NixOS/nixpkgs/issues/{pr}/comments", data={"body": msg}
)

def approve_pr(self, pr: int) -> Any:
"Approve a PR"
print(f"Approving {pr_url(pr)}")
return self.post(
f"/repos/NixOS/nixpkgs/pulls/{pr}/reviews",
data=dict(event="APPROVE"),
data={"event": "APPROVE"},
)

def merge_pr(self, pr: int) -> Any:
Expand All @@ -59,7 +59,7 @@ def merge_pr(self, pr: int) -> Any:
return self.put(f"/repos/NixOS/nixpkgs/pulls/{pr}/merge")

def graphql(self, query: str) -> dict[str, Any]:
resp = self.post("/graphql", data=dict(query=query))
resp = self.post("/graphql", data={"query": query})
if "errors" in resp:
raise RuntimeError(f"Expected data from graphql api, got: {resp}")
data: dict[str, Any] = resp["data"]
Expand Down Expand Up @@ -88,10 +88,13 @@ def get_borg_eval_gist(self, pr: dict[str, Any]) -> dict[str, set[str]] | None:
raw_gist_url = (
f"https://gist.githubusercontent.com/GrahamcOfBorg/{gist_hash}/raw/"
)
for line in urllib.request.urlopen(raw_gist_url):
if line == b"":
break
system, attribute = line.decode("utf-8").split()
packages_per_system[system].add(attribute)

with urllib.request.urlopen(raw_gist_url) as resp:
for line in resp:
if line == b"":
break
system, attribute = line.decode("utf-8").split()
packages_per_system[system].add(attribute)

return packages_per_system
return None
8 changes: 4 additions & 4 deletions nixpkgs_review/review.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import subprocess
import sys
import tempfile
import xml.etree.ElementTree as ElementTree
from dataclasses import dataclass, field
from enum import Enum
from pathlib import Path
from re import Pattern
from typing import IO
from xml.etree import ElementTree

from .allow import AllowedFeatures
from .builddir import Builddir
Expand Down Expand Up @@ -135,9 +135,9 @@ def git_merge(self, commit: str) -> None:
def apply_unstaged(self, staged: bool = False) -> None:
args = ["git", "--no-pager", "diff", "--no-ext-diff"]
args.extend(["--staged"] if staged else [])
diff_proc = subprocess.Popen(args, stdout=subprocess.PIPE)
assert diff_proc.stdout
diff = diff_proc.stdout.read()
with subprocess.Popen(args, stdout=subprocess.PIPE) as diff_proc:
assert diff_proc.stdout
diff = diff_proc.stdout.read()

if not diff:
info("No diff detected, stopping review...")
Expand Down
4 changes: 2 additions & 2 deletions nixpkgs_review/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,5 @@ def nix_nom_tool() -> str:
"Return `nom` if found in $PATH"
if shutil.which("nom"):
return "nom"
else:
return "nix"

return "nix"

0 comments on commit cfae4ff

Please sign in to comment.