From 909e652f0d5d915231fffa2f6a9b47a18a012cad Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sat, 14 Sep 2024 15:23:06 +0200 Subject: [PATCH 01/18] os/debian --- rwx/os/__init__.py | 17 +++++++++++++++-- rwx/os/debian.py | 17 +++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 rwx/os/debian.py diff --git a/rwx/os/__init__.py b/rwx/os/__init__.py index 70ca05c..3bd3c15 100644 --- a/rwx/os/__init__.py +++ b/rwx/os/__init__.py @@ -2,10 +2,23 @@ from pathlib import Path +from rwx.err import Error +from rwx.os.debian import Debian + class OS: """Operating System.""" - def __init__(self, path: str) -> None: + def __init__(self, path: Path) -> None: """Set root.""" - self.root = Path(path) + self.root = path + self.name = self.get_name() + + def get_name(self) -> str: + """Return mandatory name.""" + raise Error + + +def from_path(path: Path) -> OS: + """Initialize from an already existing path.""" + return Debian(path) diff --git a/rwx/os/debian.py b/rwx/os/debian.py new file mode 100644 index 0000000..f8b5fdd --- /dev/null +++ b/rwx/os/debian.py @@ -0,0 +1,17 @@ +"""Debian operating system.""" + +from pathlib import Path + +from . import OS + + +class Debian(OS): + """Debian operating system.""" + + def __init__(self, path: Path) -> None: + """Initialize.""" + super().__init__(path) + + def get_name(self) -> str: + """Return name.""" + return "Debian" From 9c1136cfa0b978c9ed85311209dcdc6518f7bef6 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sat, 14 Sep 2024 15:41:56 +0200 Subject: [PATCH 02/18] staticmethod --- rwx/os/__init__.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/rwx/os/__init__.py b/rwx/os/__init__.py index 3bd3c15..d13857c 100644 --- a/rwx/os/__init__.py +++ b/rwx/os/__init__.py @@ -1,10 +1,15 @@ """Control Operating Systems.""" -from pathlib import Path +from __future__ import annotations + +from typing import TYPE_CHECKING from rwx.err import Error from rwx.os.debian import Debian +if TYPE_CHECKING: + from pathlib import Path + class OS: """Operating System.""" @@ -18,7 +23,7 @@ class OS: """Return mandatory name.""" raise Error - -def from_path(path: Path) -> OS: - """Initialize from an already existing path.""" - return Debian(path) + @staticmethod + def from_path(path: Path) -> OS: + """Initialize from an already existing path.""" + return Debian(path) From e75a624c466b77d05b781f760dd3d9536483892e Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sat, 14 Sep 2024 15:45:44 +0200 Subject: [PATCH 03/18] abc --- rwx/os/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rwx/os/__init__.py b/rwx/os/__init__.py index d13857c..1594cbb 100644 --- a/rwx/os/__init__.py +++ b/rwx/os/__init__.py @@ -2,16 +2,16 @@ from __future__ import annotations +from abc import ABC, abstractmethod from typing import TYPE_CHECKING -from rwx.err import Error from rwx.os.debian import Debian if TYPE_CHECKING: from pathlib import Path -class OS: +class OS(ABC): """Operating System.""" def __init__(self, path: Path) -> None: @@ -19,9 +19,9 @@ class OS: self.root = path self.name = self.get_name() + @abstractmethod def get_name(self) -> str: """Return mandatory name.""" - raise Error @staticmethod def from_path(path: Path) -> OS: From c5930b4107c212dc652f958728e343f366179691 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sat, 14 Sep 2024 16:24:10 +0200 Subject: [PATCH 04/18] os.os --- rwx/os/__init__.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/rwx/os/__init__.py b/rwx/os/__init__.py index 1594cbb..3dfa782 100644 --- a/rwx/os/__init__.py +++ b/rwx/os/__init__.py @@ -3,12 +3,10 @@ from __future__ import annotations from abc import ABC, abstractmethod -from typing import TYPE_CHECKING +from os import sep +from pathlib import Path -from rwx.os.debian import Debian - -if TYPE_CHECKING: - from pathlib import Path +from .debian import Debian class OS(ABC): @@ -27,3 +25,6 @@ class OS(ABC): def from_path(path: Path) -> OS: """Initialize from an already existing path.""" return Debian(path) + + +os = OS.from_path(Path(sep)) From f4498f691c9bd03d44898ff91f239f6f65209a7d Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sat, 14 Sep 2024 17:43:37 +0200 Subject: [PATCH 05/18] pm,ps --- rwx/os/pm/__init__.py | 17 +++++++++++++++++ rwx/os/pm/apt.py | 16 ++++++++++++++++ rwx/ps/__init__.py | 4 ++++ 3 files changed, 37 insertions(+) create mode 100644 rwx/os/pm/__init__.py create mode 100644 rwx/os/pm/apt.py diff --git a/rwx/os/pm/__init__.py b/rwx/os/pm/__init__.py new file mode 100644 index 0000000..0bcf1e6 --- /dev/null +++ b/rwx/os/pm/__init__.py @@ -0,0 +1,17 @@ +"""Package Manager.""" + +from abc import ABC, abstractmethod + +from rwx.ps import Command + + +class PM(ABC): + """Package Manager.""" + + def __init__(self) -> None: + """Set commands.""" + self.install = self.get_install_command() + + @abstractmethod + def get_install_command(self) -> Command: + """Command to install package(s).""" diff --git a/rwx/os/pm/apt.py b/rwx/os/pm/apt.py new file mode 100644 index 0000000..17caac3 --- /dev/null +++ b/rwx/os/pm/apt.py @@ -0,0 +1,16 @@ +"""Advanced Package Tool.""" + +from rwx.os.pm import PM +from rwx.ps import Command + + +class APT(PM): + """Advanced Package Tool.""" + + def __init__(self) -> None: + """Initialize.""" + super().__init__() + + def get_install_command(self) -> Command: + """Return install command.""" + return Command() diff --git a/rwx/ps/__init__.py b/rwx/ps/__init__.py index 0bbab9c..07ccce8 100644 --- a/rwx/ps/__init__.py +++ b/rwx/ps/__init__.py @@ -5,6 +5,10 @@ import subprocess from rwx import txt +class Command: + """Command to run.""" + + def get_tuples_args(*items: str | tuple[str, ...]) -> list[str]: """Turn arguments tuples into an arguments list.""" args: list[str] = [] From 148f757d5dbafe09a0bada3bad3daea8ae56cd6b Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sat, 14 Sep 2024 18:07:01 +0200 Subject: [PATCH 06/18] command/wip --- rwx/ps/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rwx/ps/__init__.py b/rwx/ps/__init__.py index 07ccce8..3ea9702 100644 --- a/rwx/ps/__init__.py +++ b/rwx/ps/__init__.py @@ -8,6 +8,11 @@ from rwx import txt class Command: """Command to run.""" + def __init__(self, *arguments: str | tuple[str, ...]) -> None: + """Set raw & flat arguments.""" + self.raw = arguments + self.flat: list[str] = [] + def get_tuples_args(*items: str | tuple[str, ...]) -> list[str]: """Turn arguments tuples into an arguments list.""" From 4d8c1d7aabb764bca4f9c2c9bf5df7626b97abdf Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sat, 14 Sep 2024 18:15:42 +0200 Subject: [PATCH 07/18] lint --- rwx/os/debian.py | 6 ------ rwx/os/pm/apt.py | 4 ---- rwx/prj/sphinx.py | 8 ++------ 3 files changed, 2 insertions(+), 16 deletions(-) diff --git a/rwx/os/debian.py b/rwx/os/debian.py index f8b5fdd..dbaaabb 100644 --- a/rwx/os/debian.py +++ b/rwx/os/debian.py @@ -1,17 +1,11 @@ """Debian operating system.""" -from pathlib import Path - from . import OS class Debian(OS): """Debian operating system.""" - def __init__(self, path: Path) -> None: - """Initialize.""" - super().__init__(path) - def get_name(self) -> str: """Return name.""" return "Debian" diff --git a/rwx/os/pm/apt.py b/rwx/os/pm/apt.py index 17caac3..ac669b6 100644 --- a/rwx/os/pm/apt.py +++ b/rwx/os/pm/apt.py @@ -7,10 +7,6 @@ from rwx.ps import Command class APT(PM): """Advanced Package Tool.""" - def __init__(self) -> None: - """Initialize.""" - super().__init__() - def get_install_command(self) -> Command: """Return install command.""" return Command() diff --git a/rwx/prj/sphinx.py b/rwx/prj/sphinx.py index be207ef..c1b2c17 100644 --- a/rwx/prj/sphinx.py +++ b/rwx/prj/sphinx.py @@ -14,10 +14,6 @@ from rwx.prj import Project class SphinxProject(Project): """Child class for a project based on Sphinx.""" - def __init__(self, file_path: str) -> None: - """Call the parent constructor.""" - super().__init__(file_path) - def build(self) -> None: """Build the project.""" output_root: Path = self.root / "out" @@ -31,9 +27,9 @@ class SphinxProject(Project): "-D", f"project={self.name}", "-D", - "master_doc={}".format("index"), + "master_doc=index", "-D", - "html_theme={}".format("sphinx_rtd_theme"), + "html_theme=sphinx_rtd_theme", "-c", str(self.root), # "-C", From 6f9ba7f8f704a24ded03b4c30071f9546b850ba1 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sat, 14 Sep 2024 18:16:40 +0200 Subject: [PATCH 08/18] imports --- rwx/prj/sphinx.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rwx/prj/sphinx.py b/rwx/prj/sphinx.py index c1b2c17..592e6dd 100644 --- a/rwx/prj/sphinx.py +++ b/rwx/prj/sphinx.py @@ -2,14 +2,14 @@ from typing import TYPE_CHECKING -if TYPE_CHECKING: - from pathlib import Path - from sphinx.cmd.build import build_main from rwx.fs import wipe from rwx.prj import Project +if TYPE_CHECKING: + from pathlib import Path + class SphinxProject(Project): """Child class for a project based on Sphinx.""" From 0ad5cc97018d13482820304d62494414a1eee995 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sat, 14 Sep 2024 23:40:39 +0200 Subject: [PATCH 09/18] cyclic --- rwx/os/__init__.py | 25 +++++-------------------- rwx/os/abstract.py | 17 +++++++++++++++++ rwx/os/debian.py | 2 +- 3 files changed, 23 insertions(+), 21 deletions(-) create mode 100644 rwx/os/abstract.py diff --git a/rwx/os/__init__.py b/rwx/os/__init__.py index 3dfa782..75a0bc9 100644 --- a/rwx/os/__init__.py +++ b/rwx/os/__init__.py @@ -1,30 +1,15 @@ """Control Operating Systems.""" -from __future__ import annotations - -from abc import ABC, abstractmethod from os import sep from pathlib import Path +from .abstract import OS from .debian import Debian -class OS(ABC): - """Operating System.""" - - def __init__(self, path: Path) -> None: - """Set root.""" - self.root = path - self.name = self.get_name() - - @abstractmethod - def get_name(self) -> str: - """Return mandatory name.""" - - @staticmethod - def from_path(path: Path) -> OS: - """Initialize from an already existing path.""" - return Debian(path) +def from_path(path: Path) -> OS: + """Initialize from an already existing path.""" + return Debian(path) -os = OS.from_path(Path(sep)) +up = from_path(Path(sep)) diff --git a/rwx/os/abstract.py b/rwx/os/abstract.py new file mode 100644 index 0000000..2d86f7e --- /dev/null +++ b/rwx/os/abstract.py @@ -0,0 +1,17 @@ +"""Abstract Operating System.""" + +from abc import ABC, abstractmethod +from pathlib import Path + + +class OS(ABC): + """Operating System.""" + + def __init__(self, path: Path) -> None: + """Set root.""" + self.root = path + self.name = self.get_name() + + @abstractmethod + def get_name(self) -> str: + """Return mandatory name.""" diff --git a/rwx/os/debian.py b/rwx/os/debian.py index dbaaabb..98c8928 100644 --- a/rwx/os/debian.py +++ b/rwx/os/debian.py @@ -1,6 +1,6 @@ """Debian operating system.""" -from . import OS +from .abstract import OS class Debian(OS): From f2991cff049828b0e28c2c24b6eda712f7357894 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sun, 15 Sep 2024 01:35:33 +0200 Subject: [PATCH 10/18] pm/str --- rwx/os/pm/__init__.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/rwx/os/pm/__init__.py b/rwx/os/pm/__init__.py index 0bcf1e6..e359a88 100644 --- a/rwx/os/pm/__init__.py +++ b/rwx/os/pm/__init__.py @@ -15,3 +15,9 @@ class PM(ABC): @abstractmethod def get_install_command(self) -> Command: """Command to install package(s).""" + + def __str__(self) -> str: + """Return commands.""" + return f"""\ +install = {self.install} +""" From 73c7ac00f426548d88c8af11e9a94d4788e817c8 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sun, 15 Sep 2024 01:37:45 +0200 Subject: [PATCH 11/18] os/str --- rwx/os/abstract.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/rwx/os/abstract.py b/rwx/os/abstract.py index 2d86f7e..e985dc5 100644 --- a/rwx/os/abstract.py +++ b/rwx/os/abstract.py @@ -15,3 +15,10 @@ class OS(ABC): @abstractmethod def get_name(self) -> str: """Return mandatory name.""" + + def __str__(self) -> str: + """Return root & name.""" + return f"""\ +root = {self.root} +name = {self.name} +""" From 5038e587af65449a7f674be2da7849a8c8d7ab6f Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sun, 15 Sep 2024 01:45:06 +0200 Subject: [PATCH 12/18] command/str --- rwx/ps/__init__.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/rwx/ps/__init__.py b/rwx/ps/__init__.py index 3ea9702..7f21c5d 100644 --- a/rwx/ps/__init__.py +++ b/rwx/ps/__init__.py @@ -13,6 +13,13 @@ class Command: self.raw = arguments self.flat: list[str] = [] + def __str__(self) -> str: + """Return raw & flat.""" + return f"""\ + raw = {self.raw} +flat = {self.flat} +""" + def get_tuples_args(*items: str | tuple[str, ...]) -> list[str]: """Turn arguments tuples into an arguments list.""" From 304c2bc617b49e8fc466e212f323cf5e2fbd42b3 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sun, 15 Sep 2024 01:46:25 +0200 Subject: [PATCH 13/18] project/str --- rwx/prj/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rwx/prj/__init__.py b/rwx/prj/__init__.py index 36dab99..04f1cd9 100644 --- a/rwx/prj/__init__.py +++ b/rwx/prj/__init__.py @@ -11,3 +11,11 @@ class Project: self.file: Path = Path(file_path).resolve() self.root: Path = self.file.parent self.name: str = self.root.name + + def __str__(self) -> str: + """Return file, root & name.""" + return f"""\ +file = {self.file} +root = {self.root} +name = {self.name} +""" From 63c179a0a48b237ae5a581ed823c93ce062f83fe Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sun, 15 Sep 2024 01:49:39 +0200 Subject: [PATCH 14/18] pm/clean --- rwx/os/pm/__init__.py | 6 ++++++ rwx/os/pm/apt.py | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/rwx/os/pm/__init__.py b/rwx/os/pm/__init__.py index e359a88..d248e47 100644 --- a/rwx/os/pm/__init__.py +++ b/rwx/os/pm/__init__.py @@ -10,8 +10,13 @@ class PM(ABC): def __init__(self) -> None: """Set commands.""" + self.clean = self.get_clean_command() self.install = self.get_install_command() + @abstractmethod + def get_clean_command(self) -> Command: + """Command to clean packages cache.""" + @abstractmethod def get_install_command(self) -> Command: """Command to install package(s).""" @@ -19,5 +24,6 @@ class PM(ABC): def __str__(self) -> str: """Return commands.""" return f"""\ + clean = {self.clean} install = {self.install} """ diff --git a/rwx/os/pm/apt.py b/rwx/os/pm/apt.py index ac669b6..03217b8 100644 --- a/rwx/os/pm/apt.py +++ b/rwx/os/pm/apt.py @@ -7,6 +7,10 @@ from rwx.ps import Command class APT(PM): """Advanced Package Tool.""" + def get_clean_command(self) -> Command: + """Return clean command.""" + return Command() + def get_install_command(self) -> Command: """Return install command.""" return Command() From f8567686fd196d36ef6dd6c2be6304bbef8b328c Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sun, 15 Sep 2024 01:59:00 +0200 Subject: [PATCH 15/18] project/repr --- rwx/prj/__init__.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/rwx/prj/__init__.py b/rwx/prj/__init__.py index 04f1cd9..f4a8acb 100644 --- a/rwx/prj/__init__.py +++ b/rwx/prj/__init__.py @@ -6,15 +6,21 @@ from pathlib import Path class Project: """Parent class for any type of project.""" - def __init__(self, file_path: str) -> None: + def __init__(self, file: Path) -> None: """Set file, root & name.""" - self.file: Path = Path(file_path).resolve() + self.raw = file + self.file = self.raw.resolve() self.root: Path = self.file.parent self.name: str = self.root.name + def __repr__(self) -> str: + """Represent project.""" + return f"Project(file={self.raw!r})" + def __str__(self) -> str: """Return file, root & name.""" return f"""\ + raw = {self.raw} file = {self.file} root = {self.root} name = {self.name} From 5a25c6df27b8be0530f286a27d29e7db55c7f359 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sun, 15 Sep 2024 02:02:36 +0200 Subject: [PATCH 16/18] command/repr --- rwx/ps/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rwx/ps/__init__.py b/rwx/ps/__init__.py index 7f21c5d..54d58cf 100644 --- a/rwx/ps/__init__.py +++ b/rwx/ps/__init__.py @@ -13,6 +13,10 @@ class Command: self.raw = arguments self.flat: list[str] = [] + def __repr__(self) -> str: + """Represent command.""" + return f"Command({self.raw!r})" + def __str__(self) -> str: """Return raw & flat.""" return f"""\ From 04eaae7ba3042b33c9debcac8d4fb678ada1e77d Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sun, 15 Sep 2024 15:03:13 +0200 Subject: [PATCH 17/18] pyproject/pydoclint --- pyproject.toml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 756a434..462a1d5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,6 +31,11 @@ requires-python = ">= 3.11" [tool.hatch.version] path = "rwx/__init__.py" +[tool.pydoclint] +allow-init-docstring = true +skip-checking-short-docstrings = false +style = "sphinx" + [tool.ruff] line-length = 80 From db47d5c80a70253b584a3cefcee35dc97bf194ea Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sun, 15 Sep 2024 15:07:47 +0200 Subject: [PATCH 18/18] doc/arg.split --- rwx/arg/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rwx/arg/__init__.py b/rwx/arg/__init__.py index 71ce0a7..a35dd4f 100644 --- a/rwx/arg/__init__.py +++ b/rwx/arg/__init__.py @@ -4,6 +4,10 @@ import sys def split() -> tuple[str, list[str]]: - """Split command & actual arguments.""" + """Split command & actual arguments. + + :return: both + :rtype: tuple[str, list[str]] + """ command, *arguments = sys.argv return command, arguments