Skip to content

Commit

Permalink
style: fix add black line length configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
k4black committed Dec 27, 2023
1 parent bebd2d0 commit cd06474
Show file tree
Hide file tree
Showing 18 changed files with 109 additions and 306 deletions.
44 changes: 11 additions & 33 deletions checker/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@
from .exceptions import BadConfig, TestingError

Check warning on line 15 in checker/__main__.py

View check run for this annotation

Codecov / codecov/patch

checker/__main__.py#L14-L15

Added lines #L14 - L15 were not covered by tests


ClickReadableFile = click.Path(
exists=True, file_okay=True, readable=True, path_type=Path
)
ClickReadableDirectory = click.Path(
exists=True, file_okay=False, readable=True, path_type=Path
)
ClickReadableFile = click.Path(exists=True, file_okay=True, readable=True, path_type=Path)
ClickReadableDirectory = click.Path(exists=True, file_okay=False, readable=True, path_type=Path)
ClickWritableDirectory = click.Path(file_okay=False, writable=True, path_type=Path)

Check warning on line 20 in checker/__main__.py

View check run for this annotation

Codecov / codecov/patch

checker/__main__.py#L18-L20

Added lines #L18 - L20 were not covered by tests


Expand Down Expand Up @@ -54,9 +50,7 @@ def cli(

@cli.command()
@click.argument("root", type=ClickReadableDirectory, default=".")
@click.option(
"-v/-s", "--verbose/--silent", is_flag=True, default=True, help="Verbose output"
)
@click.option("-v/-s", "--verbose/--silent", is_flag=True, default=True, help="Verbose output")
@click.pass_context
def validate(

Check warning on line 55 in checker/__main__.py

View check run for this annotation

Codecov / codecov/patch

checker/__main__.py#L51-L55

Added lines #L51 - L55 were not covered by tests
ctx: click.Context,
Expand Down Expand Up @@ -159,9 +153,7 @@ def validate(
default=True,
help="Verbose tests output",
)
@click.option(
"--dry-run", is_flag=True, help="Do not execute anything, only log actions"
)
@click.option("--dry-run", is_flag=True, help="Do not execute anything, only log actions")

Check warning on line 156 in checker/__main__.py

View check run for this annotation

Codecov / codecov/patch

checker/__main__.py#L156

Added line #L156 was not covered by tests
@click.pass_context
def check(
ctx: click.Context,
Expand Down Expand Up @@ -244,15 +236,9 @@ def check(
@cli.command()
@click.argument("root", type=ClickReadableDirectory, default=".")
@click.argument("reference_root", type=ClickReadableDirectory, default=".")
@click.option(
"--submit-score", is_flag=True, help="Submit score to the Manytask server"
)
@click.option(
"--timestamp", type=str, default=None, help="Timestamp to use for the submission"
)
@click.option(
"--username", type=str, default=None, help="Username to use for the submission"
)
@click.option("--submit-score", is_flag=True, help="Submit score to the Manytask server")
@click.option("--timestamp", type=str, default=None, help="Timestamp to use for the submission")
@click.option("--username", type=str, default=None, help="Username to use for the submission")
@click.option("--no-clean", is_flag=True, help="Clean or not check tmp folders")
@click.option(

Check warning on line 243 in checker/__main__.py

View check run for this annotation

Codecov / codecov/patch

checker/__main__.py#L236-L243

Added lines #L236 - L243 were not covered by tests
"-v/-s",
Expand All @@ -261,9 +247,7 @@ def check(
default=False,
help="Verbose tests output",
)
@click.option(
"--dry-run", is_flag=True, help="Do not execute anything, only log actions"
)
@click.option("--dry-run", is_flag=True, help="Do not execute anything, only log actions")

Check warning on line 250 in checker/__main__.py

View check run for this annotation

Codecov / codecov/patch

checker/__main__.py#L250

Added line #L250 was not covered by tests
@click.pass_context
def grade(
ctx: click.Context,
Expand Down Expand Up @@ -305,9 +289,7 @@ def grade(
# detect changes to test
filesystem_tasks: list[FileSystemTask] = list()

Check warning on line 290 in checker/__main__.py

View check run for this annotation

Codecov / codecov/patch

checker/__main__.py#L290

Added line #L290 was not covered by tests
# TODO: detect changes
filesystem_tasks = [
task for task in course.get_tasks(enabled=True) if task.name == "hello_world"
]
filesystem_tasks = [task for task in course.get_tasks(enabled=True) if task.name == "hello_world"]

Check warning on line 292 in checker/__main__.py

View check run for this annotation

Codecov / codecov/patch

checker/__main__.py#L292

Added line #L292 was not covered by tests

# create tester to... to test =)
tester = Tester(course, checker_config, verbose=verbose, dry_run=dry_run)

Check warning on line 295 in checker/__main__.py

View check run for this annotation

Codecov / codecov/patch

checker/__main__.py#L295

Added line #L295 was not covered by tests
Expand All @@ -334,12 +316,8 @@ def grade(
@cli.command()
@click.argument("reference_root", type=ClickReadableDirectory, default=".")
@click.argument("export_root", type=ClickWritableDirectory, default="./export")
@click.option(
"--commit", is_flag=True, help="Commit and push changes to the repository"
)
@click.option(
"--dry-run", is_flag=True, help="Do not execute anything, only log actions"
)
@click.option("--commit", is_flag=True, help="Commit and push changes to the repository")
@click.option("--dry-run", is_flag=True, help="Do not execute anything, only log actions")

Check warning on line 320 in checker/__main__.py

View check run for this annotation

Codecov / codecov/patch

checker/__main__.py#L316-L320

Added lines #L316 - L320 were not covered by tests
@click.pass_context
def export(

Check warning on line 322 in checker/__main__.py

View check run for this annotation

Codecov / codecov/patch

checker/__main__.py#L322

Added line #L322 was not covered by tests
ctx: click.Context,
Expand Down
26 changes: 6 additions & 20 deletions checker/configs/deadlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,12 @@ def check_dates(self) -> "DeadlinesGroupConfig":
if isinstance(self.end, timedelta) and self.end < timedelta():
raise ValueError(f"end timedelta <{self.end}> should be positive")

Check warning on line 95 in checker/configs/deadlines.py

View check run for this annotation

Codecov / codecov/patch

checker/configs/deadlines.py#L95

Added line #L95 was not covered by tests
if isinstance(self.end, datetime) and self.end < self.start:
raise ValueError(
f"end datetime <{self.end}> should be after the start <{self.start}>"
)
raise ValueError(f"end datetime <{self.end}> should be after the start <{self.start}>")

Check warning on line 97 in checker/configs/deadlines.py

View check run for this annotation

Codecov / codecov/patch

checker/configs/deadlines.py#L97

Added line #L97 was not covered by tests

# check steps
last_step_date_or_delta: datetime | timedelta = self.start
for _, date_or_delta in self.steps.items():
step_date = (
self.start + date_or_delta
if isinstance(date_or_delta, timedelta)
else date_or_delta
)
step_date = self.start + date_or_delta if isinstance(date_or_delta, timedelta) else date_or_delta
last_step_date = (

Check warning on line 103 in checker/configs/deadlines.py

View check run for this annotation

Codecov / codecov/patch

checker/configs/deadlines.py#L102-L103

Added lines #L102 - L103 were not covered by tests
self.start + last_step_date_or_delta
if isinstance(last_step_date_or_delta, timedelta)
Expand All @@ -115,9 +109,7 @@ def check_dates(self) -> "DeadlinesGroupConfig":
if isinstance(date_or_delta, timedelta) and date_or_delta < timedelta():
raise ValueError(f"step timedelta <{date_or_delta}> should be positive")
if isinstance(date_or_delta, datetime) and date_or_delta <= self.start:
raise ValueError(
f"step datetime <{date_or_delta}> should be after the start {self.start}"
)
raise ValueError(f"step datetime <{date_or_delta}> should be after the start {self.start}")

Check warning on line 112 in checker/configs/deadlines.py

View check run for this annotation

Codecov / codecov/patch

checker/configs/deadlines.py#L109-L112

Added lines #L109 - L112 were not covered by tests

if step_date <= last_step_date:
raise ValueError(

Check warning on line 115 in checker/configs/deadlines.py

View check run for this annotation

Codecov / codecov/patch

checker/configs/deadlines.py#L114-L115

Added lines #L114 - L115 were not covered by tests
Expand Down Expand Up @@ -154,9 +146,7 @@ def get_tasks(
self,
enabled: bool | None = None,
) -> list[DeadlinesTaskConfig]:
tasks = [
task for group in self.get_groups(enabled=enabled) for task in group.tasks
]
tasks = [task for group in self.get_groups(enabled=enabled) for task in group.tasks]

if enabled is not None:
tasks = [task for task in tasks if task.enabled == enabled]
Expand All @@ -174,9 +164,7 @@ def check_version(cls, data: int) -> int:

@field_validator("schedule")
@classmethod
def check_group_names_unique(
cls, data: list[DeadlinesGroupConfig]
) -> list[DeadlinesGroupConfig]:
def check_group_names_unique(cls, data: list[DeadlinesGroupConfig]) -> list[DeadlinesGroupConfig]:
groups = [group.name for group in data]
duplicates = [name for name in groups if groups.count(name) > 1]
if duplicates:
Expand All @@ -185,9 +173,7 @@ def check_group_names_unique(

@field_validator("schedule")
@classmethod
def check_task_names_unique(
cls, data: list[DeadlinesGroupConfig]
) -> list[DeadlinesGroupConfig]:
def check_task_names_unique(cls, data: list[DeadlinesGroupConfig]) -> list[DeadlinesGroupConfig]:
tasks_names = [task.name for group in data for task in group.tasks]
duplicates = [name for name in tasks_names if tasks_names.count(name) > 1]
if duplicates:
Expand Down
19 changes: 4 additions & 15 deletions checker/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,8 @@ def __init__(
self.repository_root = repository_root
self.reference_root = reference_root or repository_root

self.potential_groups = {
group.name: group
for group in self._search_potential_groups(self.repository_root)
}
self.potential_tasks = {
task.name: task
for group in self.potential_groups.values()
for task in group.tasks
}
self.potential_groups = {group.name: group for group in self._search_potential_groups(self.repository_root)}
self.potential_tasks = {task.name: task for group in self.potential_groups.values() for task in group.tasks}

def validate(self) -> None:
# check all groups and tasks mentioned in deadlines exists
Expand All @@ -62,9 +55,7 @@ def validate(self) -> None:
deadlines_tasks = self.deadlines.get_tasks(enabled=True)
for deadlines_task in deadlines_tasks:
if deadlines_task.name not in self.potential_tasks:
raise BadConfig(
f"Task {deadlines_task.name} of not found in repository"
)
raise BadConfig(f"Task {deadlines_task.name} of not found in repository")

def get_groups(
self,
Expand Down Expand Up @@ -107,9 +98,7 @@ def _search_potential_groups(root: Path) -> list[FileSystemGroup]:
try:
task_config = TaskConfig.from_yaml(task_config_path)
except BadConfig as e:
raise BadConfig(
f"Task config {task_config_path} is invalid:\n{e}"
)
raise BadConfig(f"Task config {task_config_path} is invalid:\n{e}")

potential_tasks.append(
FileSystemTask(
Expand Down
55 changes: 17 additions & 38 deletions checker/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,19 @@ def export_public(
"*",
*(
task_ignore
if (task_ignore := task.config.structure.public_patterns)
is not None
if (task_ignore := task.config.structure.public_patterns) is not None
else global_public_patterns
),
],
[
*(
task_ignore
if (task_ignore := task.config.structure.private_patterns)
is not None
if (task_ignore := task.config.structure.private_patterns) is not None
else global_private_patterns
),
*(
task_ignore
if (task_ignore := task.config.structure.ignore_patterns)
is not None
if (task_ignore := task.config.structure.ignore_patterns) is not None
else global_ignore_patterns
),
],
Expand Down Expand Up @@ -134,20 +131,17 @@ def export_for_testing(
[
*(
task_ignore
if (task_ignore := task.config.structure.ignore_patterns)
is not None
if (task_ignore := task.config.structure.ignore_patterns) is not None
else global_ignore_patterns
),
*(
task_public
if (task_public := task.config.structure.public_patterns)
is not None
if (task_public := task.config.structure.public_patterns) is not None
else global_public_patterns
),
*(
task_private
if (task_private := task.config.structure.private_patterns)
is not None
if (task_private := task.config.structure.private_patterns) is not None
else global_private_patterns
),
],
Expand Down Expand Up @@ -176,22 +170,19 @@ def export_for_testing(
[
*(
task_public
if (task_public := task.config.structure.public_patterns)
is not None
if (task_public := task.config.structure.public_patterns) is not None
else global_public_patterns
),
*(
task_private
if (task_private := task.config.structure.private_patterns)
is not None
if (task_private := task.config.structure.private_patterns) is not None
else global_private_patterns
),
],
[
*(
task_ignore
if (task_ignore := task.config.structure.ignore_patterns)
is not None
if (task_ignore := task.config.structure.ignore_patterns) is not None
else global_ignore_patterns
),
],
Expand All @@ -211,9 +202,7 @@ def export_for_contribution(

global_ignore_patterns = self.structure_config.ignore_patterns or []
global_public_patterns = self.structure_config.public_patterns or []
global_private_patterns = ( # noqa: F841
self.structure_config.private_patterns or []
)
global_private_patterns = self.structure_config.private_patterns or [] # noqa: F841

print("REPO")
print(f"Copy files from {self.repository_root} to {target}")
Expand All @@ -233,16 +222,14 @@ def export_for_contribution(
[
*(
task_public
if (task_public := task.config.structure.public_patterns)
is not None
if (task_public := task.config.structure.public_patterns) is not None
else global_public_patterns
),
],
[
*(
task_ignore
if (task_ignore := task.config.structure.ignore_patterns)
is not None
if (task_ignore := task.config.structure.ignore_patterns) is not None
else global_ignore_patterns
),
],
Expand Down Expand Up @@ -270,14 +257,12 @@ def export_for_contribution(
[
*(
task_ignore
if (task_ignore := task.config.structure.public_patterns)
is not None
if (task_ignore := task.config.structure.public_patterns) is not None
else global_public_patterns
),
*(
task_ignore
if (task_ignore := task.config.structure.ignore_patterns)
is not None
if (task_ignore := task.config.structure.ignore_patterns) is not None
else global_ignore_patterns
),
],
Expand Down Expand Up @@ -317,9 +302,7 @@ def _copy_files_accounting_sub_rules(
relative_filename = str(path.relative_to(root))
if path.is_dir():
if path in sub_rules:
print(
f" - Check Dir {path} to {destination / relative_filename} with sub rules (rec)"
)
print(f" - Check Dir {path} to {destination / relative_filename} with sub rules (rec)")
self._copy_files_accounting_sub_rules(
path,
destination / relative_filename,
Expand All @@ -329,9 +312,7 @@ def _copy_files_accounting_sub_rules(
sub_rules=sub_rules,
)
else:
print(
f" - Check Dir {path} to {destination / relative_filename} (rec)"
)
print(f" - Check Dir {path} to {destination / relative_filename} (rec)")
self._copy_files_accounting_sub_rules(
path,
destination / relative_filename,
Expand All @@ -342,9 +323,7 @@ def _copy_files_accounting_sub_rules(
)
else:
if any(path.match(copy_pattern) for copy_pattern in copy_patterns):
print(
f" - Copy File {path} to {destination / relative_filename}"
)
print(f" - Copy File {path} to {destination / relative_filename}")
destination.mkdir(parents=True, exist_ok=True)
shutil.copyfile(
path,
Expand Down
Loading

0 comments on commit cd06474

Please sign in to comment.