Skip to content

Commit

Permalink
Refactor ruff configuration and enhance feedback in cloud_copy.py and…
Browse files Browse the repository at this point in the history
… installer.py
  • Loading branch information
Alex Al-Saffar committed Feb 12, 2025
1 parent 9794643 commit 3fa7cbd
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 78 deletions.
67 changes: 0 additions & 67 deletions .ruff.toml

This file was deleted.

7 changes: 4 additions & 3 deletions src/machineconfig/scripts/python/cloud_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@ def arg_parser() -> None:
rel2home=args_obj.rel2home, root=args_obj.root, os_specific=args_obj.os_specific, strict=False,
share=args_obj.share)
if args_obj.share:
if P(source).is_dir(): share_url_path = P(source).joinpath(".share_url")
else: share_url_path = P(source).with_suffix(".share_url")
fname = f".share_url_{cloud}"
if P(source).is_dir(): share_url_path = P(source).joinpath(fname)
else: share_url_path = P(source).with_suffix(fname)
share_url_path.write_text(res.as_url_str())
print(f"🔗 Share url saved to {share_url_path}")
print(f"🔗 share url saved to {share_url_path}")
print(f"🌍 {res.as_url_str()}")
else: raise ValueError(f"Cloud `{cloud}` not found in source or target.")

Expand Down
8 changes: 5 additions & 3 deletions src/machineconfig/settings/linters/.ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ indent-width = 4
# McCabe complexity (`C901`) by default.
select = ["E4", "E7", "E9", "F"]

ignore = ["E701", # multiple statements in one line.
"E702",
"E721", # don't compare types use isinstance
ignore = [
"E701", # multiple statements in one line.
"E702",
"E721", # don't compare types use isinstance
]

# Allow fix for all enabled rules (when `--fix`) is provided.
Expand All @@ -62,6 +63,7 @@ indent-style = "space"
# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false


# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"

8 changes: 4 additions & 4 deletions src/machineconfig/utils/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def find_move_delete_linux(downloaded: P, tool_name: str, delete: Optional[bool]
exe.chmod(0o777)
# exe.move(folder=LINUX_INSTALL_PATH, overwrite=False)
if "/usr" in LINUX_INSTALL_PATH:
Terminal().run(f"sudo mv {exe} {LINUX_INSTALL_PATH}/").print_if_unsuccessful(desc=f"MOVING executable `{exe}` to {LINUX_INSTALL_PATH}", strict_err=True, strict_returncode=True)
Terminal().run(f"sudo mv {exe} {LINUX_INSTALL_PATH}/").capture().print_if_unsuccessful(desc=f"MOVING executable `{exe}` to {LINUX_INSTALL_PATH}", strict_err=True, strict_returncode=True)
else:
exe.move(folder=LINUX_INSTALL_PATH, overwrite=True)
if delete: downloaded.delete(sure=True)
Expand Down Expand Up @@ -140,12 +140,12 @@ def install(self, version: Optional[str]):
elif "npm " in self.repo_url or "pip " in self.repo_url or "winget " in self.repo_url:
desc = self.repo_url.split(" ", maxsplit=1)[0] + "installation"
version_to_be_installed = self.repo_url.split(" ", maxsplit=1)[0] + "Latest"
Terminal().run(self.repo_url, shell="default").print_if_unsuccessful(desc=desc, strict_err=True, strict_returncode=True)
Terminal().run(self.repo_url, shell="default").capture().print_if_unsuccessful(desc=desc, strict_err=True, strict_returncode=True)
else:
downloaded, version_to_be_installed = self.download(version=version)
if downloaded.to_str().endswith(".deb"):
assert platform.system() == "Linux"
Terminal().run(f"sudo apt install -y {downloaded}").print_if_unsuccessful(desc="Installing .deb", strict_err=True, strict_returncode=True)
Terminal().run(f"sudo apt install -y {downloaded}").capture().print_if_unsuccessful(desc="Installing .deb", strict_err=True, strict_returncode=True)
downloaded.delete(sure=True)
else:
if platform.system() == "Windows":
Expand Down Expand Up @@ -338,7 +338,7 @@ def install_all(installers: L[Installer], safe: bool=False, jobs: int = 10, fres
if platform.system().lower() == "windows":
apps_dir.search("*").apply(lambda app: app.move(folder=P.get_env().WindowsPaths().WindowsApps))
elif platform.system().lower() == "linux":
Terminal().run(f"sudo mv {apps_dir.as_posix()}/* {LINUX_INSTALL_PATH}/").print_if_unsuccessful(desc=f"MOVING executable to {LINUX_INSTALL_PATH}", strict_err=True, strict_returncode=True)
Terminal().run(f"sudo mv {apps_dir.as_posix()}/* {LINUX_INSTALL_PATH}/").capture().print_if_unsuccessful(desc=f"MOVING executable to {LINUX_INSTALL_PATH}", strict_err=True, strict_returncode=True)
else: raise NotImplementedError(f"I don't know this system {platform.system()}")
apps_dir.delete(sure=True)
return None
Expand Down
2 changes: 1 addition & 1 deletion src/machineconfig/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def write_shell_script(program: str, desc: str, preserve_cwd: bool, display: boo
print_code(code=program, lexer="shell", desc=desc)
PROGRAM_PATH.create(parents_only=True).write_text(program)
if execute:
Terminal().run(f". {PROGRAM_PATH}", shell="powershell").print_if_unsuccessful(desc="🛠️ Executing shell script", strict_err=True, strict_returncode=True)
Terminal().run(f". {PROGRAM_PATH}", shell="powershell").capture().print_if_unsuccessful(desc="🛠️ Executing shell script", strict_err=True, strict_returncode=True)
return None


Expand Down

0 comments on commit 3fa7cbd

Please sign in to comment.