chore(cli): fix some ruff preview rules (#32803)

This commit is contained in:
Christophe Bornet
2025-09-07 22:53:19 +02:00
committed by GitHub
parent 4e39c164bb
commit 5bf0b218c8
5 changed files with 15 additions and 29 deletions

View File

@@ -72,9 +72,7 @@ def new(
name_str = name
pip_bool = bool(pip) # None should be false
else:
name_str = (
name if name else typer.prompt("What folder would you like to create?")
)
name_str = name or typer.prompt("What folder would you like to create?")
if not has_packages:
package = []
package_prompt = "What package would you like to add? (leave blank to skip)"

View File

@@ -34,7 +34,7 @@ def new(
package_name_split = computed_name.split("/")
package_name = (
package_name_split[-2]
if len(package_name_split) > 1 and package_name_split[-1] == ""
if len(package_name_split) > 1 and not package_name_split[-1]
else package_name_split[-1]
)
module_name = re.sub(

View File

@@ -138,8 +138,8 @@ def parse_dependencies(
if (
(dependencies and len(dependencies) != num_deps)
or (api_path and len(api_path) != num_deps)
or (repo and len(repo) not in [1, num_deps])
or (branch and len(branch) not in [1, num_deps])
or (repo and len(repo) not in {1, num_deps})
or (branch and len(branch) not in {1, num_deps})
):
msg = (
"Number of defined repos/branches/api_paths did not match the "
@@ -151,15 +151,15 @@ def parse_dependencies(
inner_repos = _list_arg_to_length(repo, num_deps)
inner_branches = _list_arg_to_length(branch, num_deps)
return [
parse_dependency_string(iter_dep, iter_repo, iter_branch, iter_api_path)
for iter_dep, iter_repo, iter_branch, iter_api_path in zip(
return list(
map(
parse_dependency_string,
inner_deps,
inner_repos,
inner_branches,
inner_api_paths,
)
]
)
def _get_repo_path(gitstring: str, ref: Optional[str], repo_dir: Path) -> Path:
@@ -167,7 +167,7 @@ def _get_repo_path(gitstring: str, ref: Optional[str], repo_dir: Path) -> Path:
ref_str = ref if ref is not None else ""
hashed = hashlib.sha256((f"{gitstring}:{ref_str}").encode()).hexdigest()[:8]
removed_protocol = gitstring.split("://")[-1]
removed_protocol = gitstring.split("://", maxsplit=1)[-1]
removed_basename = re.split(r"[/:]", removed_protocol, maxsplit=1)[-1]
removed_extras = removed_basename.split("#")[0]
foldername = re.sub(r"\W", "_", removed_extras)