Compare commits
8 commits
3393f09907
...
78dd431ca5
Author | SHA1 | Date | |
---|---|---|---|
78dd431ca5 | |||
b3e66ec1c3 | |||
065d647e51 | |||
5e3c8e93ff | |||
cfa9ca9e3c | |||
de80d7ecff | |||
ef45fc9d81 | |||
0a9404fb2f |
3 changed files with 22 additions and 19 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
import os
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
from rwx import ps
|
||||
|
||||
|
@ -48,20 +49,23 @@ def get_path_uuid(path: str) -> str:
|
|||
|
||||
def make_directory(path: str) -> None:
|
||||
"""Make a directory (and its parents) from a path."""
|
||||
os.makedirs(path, exist_ok=True)
|
||||
Path(path).mkdir(exist_ok=True, parents=True)
|
||||
|
||||
|
||||
def read_file(file_path: str):
|
||||
with open(file_path, "br") as file_object:
|
||||
def read_file_bytes(file_path: str) -> bytes:
|
||||
"""Read whole file bytes."""
|
||||
with Path(file_path).open("br") as file_object:
|
||||
return file_object.read()
|
||||
|
||||
|
||||
def read_file_lines(file_path: str, charset: str = CHARSET):
|
||||
return read_file_text(file_path).split(os.linesep)
|
||||
def read_file_lines(file_path: str, charset: str = CHARSET) -> list[str]:
|
||||
"""Read whole file lines."""
|
||||
return read_file_text(file_path, charset).split(os.linesep)
|
||||
|
||||
|
||||
def read_file_text(file_path: str, charset: str = CHARSET):
|
||||
return read_file(file_path).decode(charset)
|
||||
def read_file_text(file_path: str, charset: str = CHARSET) -> str:
|
||||
"""Read whole file text."""
|
||||
return read_file_bytes(file_path).decode(charset)
|
||||
|
||||
|
||||
def wipe(path: str) -> None:
|
||||
|
@ -69,12 +73,12 @@ def wipe(path: str) -> None:
|
|||
try:
|
||||
shutil.rmtree(path)
|
||||
except NotADirectoryError:
|
||||
os.remove(path)
|
||||
Path(path).unlink(missing_ok=True)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
|
||||
def write(file_path: str, text: str, charset: str = CHARSET) -> None:
|
||||
"""Write text into a file."""
|
||||
with open(file_path, "bw") as file_object:
|
||||
file_object.write(text.encode(charset))
|
||||
with Path(file_path).open(encoding=charset, mode="w") as file_object:
|
||||
file_object.write(text)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"""Handle projects."""
|
||||
|
||||
from os import path
|
||||
from os.path import realpath
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
class Project:
|
||||
|
@ -8,6 +9,6 @@ class Project:
|
|||
|
||||
def __init__(self, file_path: str) -> None:
|
||||
"""Set file, root & name."""
|
||||
self.file: str = path.realpath(file_path)
|
||||
self.root: str = path.dirname(self.file)
|
||||
self.name: str = path.basename(self.root)
|
||||
self.file: str = realpath(file_path)
|
||||
self.root: str = Path(self.file).parent
|
||||
self.name: str = self.root.name
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
"""Project consisting only of a Sphinx documentation."""
|
||||
|
||||
from os import path
|
||||
|
||||
from sphinx.cmd.build import build_main
|
||||
|
||||
from rwx.fs import wipe
|
||||
|
@ -17,7 +15,7 @@ class SphinxProject(Project):
|
|||
|
||||
def build(self) -> None:
|
||||
"""Build the project."""
|
||||
output_root: str = path.join(self.root, "out")
|
||||
output_root: str = self.root / "out"
|
||||
wipe(output_root)
|
||||
arguments: list[str] = [
|
||||
"-E",
|
||||
|
@ -34,7 +32,7 @@ class SphinxProject(Project):
|
|||
"-c",
|
||||
self.root,
|
||||
# "-C",
|
||||
path.join(self.root, self.name),
|
||||
path.join(output_root, "web"),
|
||||
self.root / self.name,
|
||||
output_root / "web",
|
||||
]
|
||||
build_main(arguments)
|
||||
|
|
Loading…
Reference in a new issue