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 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 diff --git a/rwx/os/__init__.py b/rwx/os/__init__.py index 70ca05c..75a0bc9 100644 --- a/rwx/os/__init__.py +++ b/rwx/os/__init__.py @@ -1,11 +1,15 @@ """Control Operating Systems.""" +from os import sep from pathlib import Path +from .abstract import OS +from .debian import Debian -class OS: - """Operating System.""" - def __init__(self, path: str) -> None: - """Set root.""" - self.root = Path(path) +def from_path(path: Path) -> OS: + """Initialize from an already existing path.""" + return Debian(path) + + +up = from_path(Path(sep)) diff --git a/rwx/os/abstract.py b/rwx/os/abstract.py new file mode 100644 index 0000000..e985dc5 --- /dev/null +++ b/rwx/os/abstract.py @@ -0,0 +1,24 @@ +"""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.""" + + def __str__(self) -> str: + """Return root & name.""" + return f"""\ +root = {self.root} +name = {self.name} +""" diff --git a/rwx/os/debian.py b/rwx/os/debian.py new file mode 100644 index 0000000..98c8928 --- /dev/null +++ b/rwx/os/debian.py @@ -0,0 +1,11 @@ +"""Debian operating system.""" + +from .abstract import OS + + +class Debian(OS): + """Debian operating system.""" + + def get_name(self) -> str: + """Return name.""" + return "Debian" diff --git a/rwx/os/pm/__init__.py b/rwx/os/pm/__init__.py new file mode 100644 index 0000000..d248e47 --- /dev/null +++ b/rwx/os/pm/__init__.py @@ -0,0 +1,29 @@ +"""Package Manager.""" + +from abc import ABC, abstractmethod + +from rwx.ps import Command + + +class PM(ABC): + """Package Manager.""" + + 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).""" + + 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 new file mode 100644 index 0000000..03217b8 --- /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 get_clean_command(self) -> Command: + """Return clean command.""" + return Command() + + def get_install_command(self) -> Command: + """Return install command.""" + return Command() diff --git a/rwx/prj/__init__.py b/rwx/prj/__init__.py index 36dab99..f4a8acb 100644 --- a/rwx/prj/__init__.py +++ b/rwx/prj/__init__.py @@ -6,8 +6,22 @@ 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} +""" diff --git a/rwx/prj/sphinx.py b/rwx/prj/sphinx.py index be207ef..592e6dd 100644 --- a/rwx/prj/sphinx.py +++ b/rwx/prj/sphinx.py @@ -2,22 +2,18 @@ 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.""" - 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", diff --git a/rwx/ps/__init__.py b/rwx/ps/__init__.py index 0bbab9c..54d58cf 100644 --- a/rwx/ps/__init__.py +++ b/rwx/ps/__init__.py @@ -5,6 +5,26 @@ import subprocess 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 __repr__(self) -> str: + """Represent command.""" + return f"Command({self.raw!r})" + + 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.""" args: list[str] = []