Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ruff, black & isort configs #6382

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 35 additions & 24 deletions cylc/flow/pathutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,21 @@
import re
from shutil import rmtree
from time import sleep
from typing import Dict, Iterable, Set, Union, Optional, Any
from typing import (
Any,
Dict,
Iterable,
Optional,
Set,
Union,
)

from cylc.flow import LOG
from cylc.flow.cfgspec.glbl_cfg import glbl_cfg
from cylc.flow.exceptions import (
FileRemovalError, InputError, WorkflowFilesError
FileRemovalError,
InputError,
WorkflowFilesError,
)
from cylc.flow.platforms import get_localhost_install_target

Expand All @@ -40,7 +49,7 @@
^({re.escape(os.curdir)}|{re.escape(os.pardir)})
({re.escape(os.sep)}|$)
''',
re.VERBOSE
re.VERBOSE,
)
"""Matches relative paths that are explicit (starts with ./)"""

Expand All @@ -58,9 +67,9 @@
def expand_path(*args: Union[Path, str]) -> str:
"""Expand both vars and user in path and normalise it, joining any
extra args."""
return os.path.normpath(os.path.expanduser(os.path.expandvars(
os.path.join(*args)
)))
return os.path.normpath(
os.path.expanduser(os.path.expandvars(os.path.join(*args)))
)


def get_remote_workflow_run_dir(
Expand All @@ -87,7 +96,7 @@
def get_alt_workflow_run_dir(
alt_run_dir: Union[Path, str],
workflow_id: Union[Path, str],
*args: Union[Path, str]
*args: Union[Path, str],
) -> str:
"""Return alternate workflow run directory.

Expand Down Expand Up @@ -125,9 +134,7 @@

def get_workflow_file_install_log_dir(workflow, *args):
"""Return workflow file install log file dir, join any extra args."""
return get_workflow_run_dir(
workflow, 'log', 'remote-install', *args
)
return get_workflow_run_dir(workflow, 'log', 'remote-install', *args)

Check warning on line 137 in cylc/flow/pathutil.py

View check run for this annotation

Codecov / codecov/patch

cylc/flow/pathutil.py#L137

Added line #L137 was not covered by tests


def get_workflow_run_config_log_dir(workflow, *args):
Expand Down Expand Up @@ -173,7 +180,7 @@
def make_localhost_symlinks(
rund: Union[Path, str],
named_sub_dir: str,
symlink_conf: Optional[Dict[str, Dict[str, str]]] = None
symlink_conf: Optional[Dict[str, Dict[str, str]]] = None,
) -> Dict[str, Union[Path, str]]:
"""Creates symlinks for any configured symlink dirs from glbl_cfg.
Args:
Expand All @@ -189,7 +196,8 @@
symlinks_created = {}
dirs_to_symlink = get_dirs_to_symlink(
get_localhost_install_target(),
named_sub_dir, symlink_conf=symlink_conf
named_sub_dir,
symlink_conf=symlink_conf,
)
for key, value in dirs_to_symlink.items():
if value is None:
Expand All @@ -204,7 +212,8 @@
raise WorkflowFilesError(
f"Can't symlink to {target}\n"
"Undefined variables, check "
f"global config: {', '.join(env_vars)}")
f"global config: {', '.join(env_vars)}"
)

symlink_success = make_symlink_dir(symlink_path, target)
# Symlink info returned for logging purposes. Symlinks should be
Expand All @@ -217,7 +226,7 @@
def get_dirs_to_symlink(
install_target: str,
workflow_id: str,
symlink_conf: Optional[Dict[str, Dict[str, Any]]] = None
symlink_conf: Optional[Dict[str, Dict[str, Any]]] = None,
) -> Dict[str, str]:
"""Returns dictionary of directories to symlink.

Expand All @@ -241,13 +250,15 @@
base_dir = symlink_conf[install_target]['run']
if base_dir:
dirs_to_symlink['run'] = os.path.join(
base_dir, 'cylc-run', workflow_id)
base_dir, 'cylc-run', workflow_id
)
for dir_ in SYMLINKABLE_LOCATIONS:
link = symlink_conf[install_target].get(dir_, None)
if (not link) or link == base_dir:
continue
dirs_to_symlink[dir_] = os.path.join(
link, 'cylc-run', workflow_id, dir_)
link, 'cylc-run', workflow_id, dir_
)
return dirs_to_symlink


Expand Down Expand Up @@ -440,16 +451,17 @@
# This function unlikely to be called in circumstances where this will
# be a problem.
last_run_num = re_runX.search( # type: ignore
old_run_path).group(1)
old_run_path
).group(1)
last_run_num = int(last_run_num)
else:
# If the ``runN`` symlink has been removed, get next numbered run from
# file names:
paths = Path(run_path).glob('run[0-9]*')
run_numbers = (
int(m.group(1)) for m in (
re_runX.search(i.name) for i in paths
) if m
int(m.group(1))
for m in (re_runX.search(i.name) for i in paths)
if m
)
last_run_num = max(run_numbers, default=0)

Expand All @@ -473,8 +485,8 @@
if os.path.isabs(part):
raise InputError("--rm option cannot take absolute paths")
if (
part in {os.curdir, os.pardir} or
part.startswith(f"{os.pardir}{os.sep}") # '../'
part in {os.curdir, os.pardir}
or part.startswith(f"{os.pardir}{os.sep}") # '../'
):
raise InputError(
"--rm option cannot take paths that point to the "
Expand Down Expand Up @@ -504,8 +516,7 @@


def get_workflow_name_from_id(workflow_id: str) -> str:
"""Workflow name is the ID shorn of the runN directory name.
"""
"""Workflow name is the ID shorn of the runN directory name."""
cylc_run_dir = Path(get_cylc_run_dir())
if Path(workflow_id).is_absolute():
# this is a source directory, not an install dir:
Expand Down
25 changes: 25 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,28 @@ showcontent = true
directory = "fix"
name = "🔧 Fixes"
showcontent = true


# Not mandated to use these tools, but if you do:

[tool.ruff]
line-length = 79
target-version = "py37"

[tool.ruff.format]
quote-style = "preserve"


[tool.black]
line-length = 79
target-version = ['py37']
skip-string-normalization = true


[tool.isort]
profile = "black"
line_length = 79
force_grid_wrap = 2
lines_after_imports = 2
combine_as_imports = true
oliver-sanders marked this conversation as resolved.
Show resolved Hide resolved
force_sort_within_sections = true
Loading