Skip to content

Commit

Permalink
feat: add ruff config flake8-builtins
Browse files Browse the repository at this point in the history
  • Loading branch information
seyLu committed Oct 23, 2023
1 parent 3f7f492 commit ceaeae3
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 103 deletions.
8 changes: 4 additions & 4 deletions src/ghlabel/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def setup_labels(
show_default=False,
),
] = None,
dir: Annotated[
labels_dir: Annotated[
str,
typer.Option(
"--dir",
Expand Down Expand Up @@ -148,7 +148,7 @@ def setup_labels(
GithubConfig.set_REPO_NAME(repo_name)
github_config = GithubConfig()

github_label = GithubLabel(github_config=github_config, dir=dir)
github_label = GithubLabel(github_config=github_config, labels_dir=labels_dir)

with Progress(
SpinnerColumn(style="[magenta]"),
Expand Down Expand Up @@ -184,7 +184,7 @@ def app_dump(
help="Deletes all files in labels dir.",
),
] = True,
dir: Annotated[
labels_dir: Annotated[
str,
typer.Option(
"--dir",
Expand Down Expand Up @@ -218,7 +218,7 @@ def app_dump(
) as progress:
progress.add_task(description="Dumping...", total=None)
time.sleep(0.5)
DumpLabel.dump(dir=dir, new=new, ext=ext.value, app=app.value)
DumpLabel.dump(labels_dir=labels_dir, new=new, ext=ext.value, app=app.value)
time.sleep(0.5)


Expand Down
16 changes: 8 additions & 8 deletions src/ghlabel/utils/dump_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,31 +265,31 @@ class GameDevLabels(Labels):

class DumpLabel:
@staticmethod
def _init_dir(dir: str = "labels") -> None:
logging.info(f"Initializing {dir} dir.")
Path(dir).mkdir(exist_ok=True)
for filename in os.listdir(dir):
file_path: str = os.path.join(dir, filename)
def _init_labels_dir(labels_dir: str = "labels") -> None:
logging.info(f"Initializing {labels_dir} dir.")
Path(labels_dir).mkdir(exist_ok=True)
for filename in os.listdir(labels_dir):
file_path: str = os.path.join(labels_dir, filename)
if os.path.isfile(file_path):
os.remove(file_path)

@staticmethod
def dump(
dir: str = "labels",
labels_dir: str = "labels",
new: bool = True,
ext: str = "yaml",
app: str = "app",
) -> None:
if new:
DumpLabel._init_dir(dir)
DumpLabel._init_labels_dir(labels_dir)

label_cls: Labels = LABELS_CLS_MAP.get(app, "app") # type: ignore[assignment]

for field in label_cls.__dataclass_fields__:
labels: tuple[dict[str, str], ...] | tuple[str, ...] = getattr(
label_cls, field
)
label_file: str = os.path.join(dir, f"{field.lower()}_labels.{ext}")
label_file: str = os.path.join(labels_dir, f"{field.lower()}_labels.{ext}")

with open(label_file, "w+") as f:
logging.info(f"Dumping to {f.name}.")
Expand Down
34 changes: 19 additions & 15 deletions src/ghlabel/utils/setup_github_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class GithubLabel:
def __init__(
self,
github_config: GithubConfig | None = None,
dir: str = "labels",
labels_dir: str = "labels",
) -> None:
if github_config is None:
github_config = GithubConfig()
Expand All @@ -84,7 +84,7 @@ def __init__(
"Accept": "application/vnd.github+json",
"X-GitHub-Api-Version": "2022-11-28",
}
self._dir: str = dir
self._labels_dir: str = labels_dir
self._github_labels: list[dict[str, str]] = self._fetch_github_labels(
github_config
)
Expand All @@ -97,8 +97,8 @@ def __init__(
)

@property
def dir(self) -> str:
return self._dir
def labels_dir(self) -> str:
return self._labels_dir

@property
def url(self) -> str:
Expand Down Expand Up @@ -172,27 +172,27 @@ def _fetch_github_labels(self, github_config: GithubConfig) -> list[dict[str, st
def _load_labels_from_config(self) -> list[dict[str, str]]:
use_labels: list[dict[str, str]] = []
labels: list[dict[str, str]] = []
files_in_dir: list[str] = []
files_in_labels_dir: list[str] = []

try:
files_in_dir = os.listdir(self.dir)
files_in_labels_dir = os.listdir(self.labels_dir)
except FileNotFoundError:
logging.error(
f"No {self.dir} dir found. To solve this issue, first run `ghlabel dump`."
f"No {self.labels_dir} dir found. To solve this issue, first run `ghlabel dump`."
)
sys.exit()

yaml_filenames: list[str] = list(
filter(
lambda f: (f.endswith(".yaml") or f.endswith(".yml"))
and not f.startswith("_remove"),
files_in_dir,
files_in_labels_dir,
)
)
json_filenames: list[str] = list(
filter(
lambda f: f.endswith(".json") and not f.startswith("_remove"),
files_in_dir,
files_in_labels_dir,
)
)

Expand All @@ -215,7 +215,7 @@ def _load_labels_from_config(self) -> list[dict[str, str]]:

for label_filename in label_filenames:
logging.info(f"Loading labels from {label_filename}.")
label_file: str = os.path.join(self.dir, label_filename)
label_file: str = os.path.join(self.labels_dir, label_filename)

with open(label_file, "r") as f:
if label_ext == "yaml":
Expand Down Expand Up @@ -243,30 +243,34 @@ def _load_labels_from_config(self) -> list[dict[str, str]]:
def _load_labels_to_remove_from_config(self) -> list[str]:
labels_to_remove: list[str] = []

files_in_dir: list[str] = os.listdir(self.dir)
files_in_labels_dir: list[str] = os.listdir(self.labels_dir)

label_to_remove_yaml: list[str] = list(
filter(
lambda f: (f.endswith(".yaml") or f.endswith("yml"))
and f.startswith("_remove"),
files_in_dir,
files_in_labels_dir,
)
)
label_to_remove_json: list[str] = list(
filter(
lambda f: f.endswith(".json") and f.startswith("_remove"),
files_in_dir,
files_in_labels_dir,
)
)

label_to_remove_file: str = ""
label_to_remove_ext: str = ""

if label_to_remove_yaml:
label_to_remove_file = os.path.join(self.dir, label_to_remove_yaml[0])
label_to_remove_file = os.path.join(
self.labels_dir, label_to_remove_yaml[0]
)
label_to_remove_ext = "yaml"
elif label_to_remove_json:
label_to_remove_file = os.path.join(self.dir, label_to_remove_json[0])
label_to_remove_file = os.path.join(
self.labels_dir, label_to_remove_json[0]
)
label_to_remove_ext = "json"

logging.info(f"Deleting labels from {label_to_remove_file}")
Expand Down
8 changes: 4 additions & 4 deletions src/labels/affects_labels.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- name: 'Affects: Infra'
color: '#fbbc9d'
- name: "Affects: Infra"
color: "#fbbc9d"
description: Related to configuration, automation, CI, etc.
- name: 'Affects: Project Management'
color: '#fbbc9d'
- name: "Affects: Project Management"
color: "#fbbc9d"
27 changes: 14 additions & 13 deletions src/labels/close_labels.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
- name: 'Close: Answered'
color: '#cdd1d5'
- name: 'Close: Backlog'
color: '#cdd1d5'
- name: "Close: Answered"
color: "#cdd1d5"
- name: "Close: Backlog"
color: "#cdd1d5"
description: Issues are stale/expired; sent to backlog for later re-evaluation.
- name: 'Close: Duplicate'
color: '#cdd1d5'
description: This issue or pull request already exists (see comments for pointer
- name: "Close: Duplicate"
color: "#cdd1d5"
description:
This issue or pull request already exists (see comments for pointer
to it).
- name: 'Close: Not Actionable'
color: '#cdd1d5'
- name: 'Close: Not Reproducible'
color: '#cdd1d5'
- name: "Close: Not Actionable"
color: "#cdd1d5"
- name: "Close: Not Reproducible"
color: "#cdd1d5"
description: Closed because we cannot reproduce the issue.
- name: 'Close: Will Not Fix'
color: '#cdd1d5'
- name: "Close: Will Not Fix"
color: "#cdd1d5"
description: Closed because we have decided not to address this (e.g. out of scope).
2 changes: 1 addition & 1 deletion src/labels/default_labels.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
- name: good first issue
color: '#7057ff'
color: "#7057ff"
description: Good for newcomers.
66 changes: 36 additions & 30 deletions src/labels/needs_labels.yaml
Original file line number Diff line number Diff line change
@@ -1,40 +1,46 @@
- name: 'Needs: Breakdown'
color: '#0052cc'
description: This big issue needs a checklist or subissues to describe a breakdown
- name: "Needs: Breakdown"
color: "#0052cc"
description:
This big issue needs a checklist or subissues to describe a breakdown
of work.
- name: 'Needs: Designs'
color: '#0052cc'
- name: 'Needs: Detail'
color: '#0052cc'
description: Submitter needs to provide more detail for this issue to be assessed
- name: "Needs: Designs"
color: "#0052cc"
- name: "Needs: Detail"
color: "#0052cc"
description:
Submitter needs to provide more detail for this issue to be assessed
(see comments).
- name: 'Needs: Feedback'
color: '#0052cc'
description: A proposed feature or bug resolution needs feedback prior to forging
- name: "Needs: Feedback"
color: "#0052cc"
description:
A proposed feature or bug resolution needs feedback prior to forging
ahead.
- name: 'Needs: Help'
color: '#0052cc'
description: Issues, typically substantial ones, that need a dedicated developer
- name: "Needs: Help"
color: "#0052cc"
description:
Issues, typically substantial ones, that need a dedicated developer
to take them on.
- name: 'Needs: Investigation'
color: '#0052cc'
- name: "Needs: Investigation"
color: "#0052cc"
description: This issue/PR needs a root-cause analysis to determine a solution.
- name: 'Needs: Response'
color: '#0052cc'
- name: "Needs: Response"
color: "#0052cc"
description: Issues which require feedback from staff members.
- name: 'Needs: Review'
color: '#0052cc'
description: This issue/PR needs to be reviewed in order to be closed or merged
- name: "Needs: Review"
color: "#0052cc"
description:
This issue/PR needs to be reviewed in order to be closed or merged
(see comments)
- name: 'Needs: Revisiting'
color: '#0052cc'
- name: "Needs: Revisiting"
color: "#0052cc"
description: Archived (usually noisy dependencies).
- name: 'Needs: Submitter Input'
color: '#0052cc'
- name: "Needs: Submitter Input"
color: "#0052cc"
description: Waiting on input from the creator of the issue/pr.
- name: 'Needs: Testing'
color: '#0052cc'
- name: 'Needs: Triage'
color: '#0052cc'
description: This issue needs triage. The team needs to decide who should own it,
- name: "Needs: Testing"
color: "#0052cc"
- name: "Needs: Triage"
color: "#0052cc"
description:
This issue needs triage. The team needs to decide who should own it,
what to do, by when.
16 changes: 8 additions & 8 deletions src/labels/priority_labels.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
- name: 'Priority: Critical'
color: '#7c0a02'
- name: 'Priority: High'
color: '#b22222'
- name: 'Priority: Medium'
color: '#ff8597'
- name: 'Priority: Low'
color: '#ffccc9'
- name: "Priority: Critical"
color: "#7c0a02"
- name: "Priority: High"
color: "#b22222"
- name: "Priority: Medium"
color: "#ff8597"
- name: "Priority: Low"
color: "#ffccc9"
15 changes: 8 additions & 7 deletions src/labels/state_labels.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
- name: 'State: Blocked'
color: '#e07bf9'
description: Work has stopped, waiting for something (Info, Dependent fix, etc.
- name: "State: Blocked"
color: "#e07bf9"
description:
Work has stopped, waiting for something (Info, Dependent fix, etc.
See comments).
- name: 'State: In Review'
color: '#e07bf9'
- name: "State: In Review"
color: "#e07bf9"
description: This issue is waiting for review to finish.
- name: 'State: Work In Progress'
color: '#e07bf9'
- name: "State: Work In Progress"
color: "#e07bf9"
description: This issue is being actively worked on.
27 changes: 14 additions & 13 deletions src/labels/type_labels.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
- name: 'Type: Bug'
color: '#ff9900'
- name: "Type: Bug"
color: "#ff9900"
description: Something isn't working.
- name: 'Type: Documentation'
color: '#ff9900'
- name: "Type: Documentation"
color: "#ff9900"
description: Improvements or additions to documentation.
- name: 'Type: Feature Request'
color: '#ff9900'
- name: "Type: Feature Request"
color: "#ff9900"
description: Issue describes a feature or enhancement we'd like to implement.
- name: 'Type: Question'
color: '#ff9900'
- name: "Type: Question"
color: "#ff9900"
description: This issue doesn't require code. A question needs an answer.
- name: 'Type: Refactor/Clean-up'
color: '#ff9900'
description: Issues related to reorganization/clean-up of data or code (e.g. for
- name: "Type: Refactor/Clean-up"
color: "#ff9900"
description:
Issues related to reorganization/clean-up of data or code (e.g. for
maintainability).
- name: 'Type: Suggestion'
color: '#ff9900'
- name: "Type: Suggestion"
color: "#ff9900"

0 comments on commit ceaeae3

Please sign in to comment.