Compare commits

...

18 commits

Author SHA1 Message Date
db47d5c80a
doc/arg.split 2024-09-15 15:07:47 +02:00
04eaae7ba3
pyproject/pydoclint 2024-09-15 15:03:13 +02:00
5a25c6df27
command/repr 2024-09-15 02:02:36 +02:00
f8567686fd
project/repr 2024-09-15 01:59:00 +02:00
63c179a0a4
pm/clean 2024-09-15 01:49:39 +02:00
304c2bc617
project/str 2024-09-15 01:46:25 +02:00
5038e587af
command/str 2024-09-15 01:45:06 +02:00
73c7ac00f4
os/str 2024-09-15 01:37:45 +02:00
f2991cff04
pm/str 2024-09-15 01:35:33 +02:00
0ad5cc9701
cyclic 2024-09-14 23:40:39 +02:00
6f9ba7f8f7
imports 2024-09-14 18:16:40 +02:00
4d8c1d7aab
lint 2024-09-14 18:15:42 +02:00
148f757d5d
command/wip 2024-09-14 18:07:01 +02:00
f4498f691c
pm,ps 2024-09-14 17:43:37 +02:00
c5930b4107
os.os 2024-09-14 16:24:10 +02:00
e75a624c46
abc 2024-09-14 15:45:44 +02:00
9c1136cfa0
staticmethod 2024-09-14 15:41:56 +02:00
909e652f0d
os/debian 2024-09-14 15:23:06 +02:00
10 changed files with 140 additions and 17 deletions

View file

@ -31,6 +31,11 @@ requires-python = ">= 3.11"
[tool.hatch.version] [tool.hatch.version]
path = "rwx/__init__.py" path = "rwx/__init__.py"
[tool.pydoclint]
allow-init-docstring = true
skip-checking-short-docstrings = false
style = "sphinx"
[tool.ruff] [tool.ruff]
line-length = 80 line-length = 80

View file

@ -4,6 +4,10 @@ import sys
def split() -> tuple[str, list[str]]: 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 command, *arguments = sys.argv
return command, arguments return command, arguments

View file

@ -1,11 +1,15 @@
"""Control Operating Systems.""" """Control Operating Systems."""
from os import sep
from pathlib import Path from pathlib import Path
from .abstract import OS
from .debian import Debian
class OS:
"""Operating System."""
def __init__(self, path: str) -> None: def from_path(path: Path) -> OS:
"""Set root.""" """Initialize from an already existing path."""
self.root = Path(path) return Debian(path)
up = from_path(Path(sep))

24
rwx/os/abstract.py Normal file
View file

@ -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}
"""

11
rwx/os/debian.py Normal file
View file

@ -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"

29
rwx/os/pm/__init__.py Normal file
View file

@ -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}
"""

16
rwx/os/pm/apt.py Normal file
View file

@ -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()

View file

@ -6,8 +6,22 @@ from pathlib import Path
class Project: class Project:
"""Parent class for any type of 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.""" """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.root: Path = self.file.parent
self.name: str = self.root.name 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}
"""

View file

@ -2,22 +2,18 @@
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
if TYPE_CHECKING:
from pathlib import Path
from sphinx.cmd.build import build_main from sphinx.cmd.build import build_main
from rwx.fs import wipe from rwx.fs import wipe
from rwx.prj import Project from rwx.prj import Project
if TYPE_CHECKING:
from pathlib import Path
class SphinxProject(Project): class SphinxProject(Project):
"""Child class for a project based on Sphinx.""" """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: def build(self) -> None:
"""Build the project.""" """Build the project."""
output_root: Path = self.root / "out" output_root: Path = self.root / "out"
@ -31,9 +27,9 @@ class SphinxProject(Project):
"-D", "-D",
f"project={self.name}", f"project={self.name}",
"-D", "-D",
"master_doc={}".format("index"), "master_doc=index",
"-D", "-D",
"html_theme={}".format("sphinx_rtd_theme"), "html_theme=sphinx_rtd_theme",
"-c", "-c",
str(self.root), str(self.root),
# "-C", # "-C",

View file

@ -5,6 +5,26 @@ import subprocess
from rwx import txt 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]: def get_tuples_args(*items: str | tuple[str, ...]) -> list[str]:
"""Turn arguments tuples into an arguments list.""" """Turn arguments tuples into an arguments list."""
args: list[str] = [] args: list[str] = []