Compare commits
19 commits
86d3615928
...
ae015fdfc4
Author | SHA1 | Date | |
---|---|---|---|
ae015fdfc4 | |||
69b06db6ad | |||
b112043e10 | |||
725bf8b981 | |||
d3d09445a0 | |||
e0da3ad50c | |||
844543f755 | |||
10941ad0d8 | |||
201ba91e00 | |||
c7cb8316e9 | |||
400fefeecc | |||
4bd86a8880 | |||
bfc4538dcf | |||
a9fa0d911d | |||
3e85c6e421 | |||
96d08df70d | |||
051c91a195 | |||
6142dd763d | |||
eda963ba49 |
9 changed files with 62 additions and 34 deletions
|
@ -31,6 +31,11 @@ requires-python = ">= 3.11"
|
||||||
[tool.hatch.version]
|
[tool.hatch.version]
|
||||||
path = "spcd/__init__.py"
|
path = "spcd/__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
|
||||||
|
|
||||||
|
|
|
@ -286,6 +286,7 @@ Handle project workflows in a unified way:
|
||||||
* automate versions fetching
|
* automate versions fetching
|
||||||
* gource, xvfb, xauth
|
* gource, xvfb, xauth
|
||||||
* handle openh264 repositories
|
* handle openh264 repositories
|
||||||
|
* link from workspace to actions root
|
||||||
* rpm fusion
|
* rpm fusion
|
||||||
* tex
|
* tex
|
||||||
* translate to french
|
* translate to french
|
||||||
|
|
|
@ -6,13 +6,13 @@ import sys
|
||||||
from os import environ, pathsep
|
from os import environ, pathsep
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import env
|
|
||||||
from rwx import fs
|
from rwx import fs
|
||||||
from rwx.log import stream as log
|
from rwx.log import stream as log
|
||||||
from rwx.ps import run
|
from rwx.ps import run
|
||||||
|
|
||||||
from spcd import cmd
|
from spcd import cmd
|
||||||
from spcd.ci import project, projects
|
from spcd.ci import project, projects
|
||||||
|
from spcd.shell import env
|
||||||
from spcd.util import browse, cat, split, step
|
from spcd.util import browse, cat, split, step
|
||||||
|
|
||||||
COMMANDS_PREFIX = "spcd-"
|
COMMANDS_PREFIX = "spcd-"
|
||||||
|
@ -26,10 +26,10 @@ def clone_project_branch() -> None:
|
||||||
split()
|
split()
|
||||||
log.info(project)
|
log.info(project)
|
||||||
split()
|
split()
|
||||||
log.info(f"""\
|
log.info("""\
|
||||||
{project.url}
|
%s
|
||||||
↓
|
↓
|
||||||
""")
|
""", project.url)
|
||||||
run(
|
run(
|
||||||
"git",
|
"git",
|
||||||
"clone",
|
"clone",
|
||||||
|
@ -37,7 +37,7 @@ def clone_project_branch() -> None:
|
||||||
project.branch,
|
project.branch,
|
||||||
"--",
|
"--",
|
||||||
project.url,
|
project.url,
|
||||||
project.root,
|
str(project.root),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -66,6 +66,8 @@ def install_python_packages() -> None:
|
||||||
"hatch",
|
"hatch",
|
||||||
"mypy",
|
"mypy",
|
||||||
"pelican",
|
"pelican",
|
||||||
|
"pydoclint",
|
||||||
|
"pylint",
|
||||||
"pytest",
|
"pytest",
|
||||||
"ruff",
|
"ruff",
|
||||||
"sphinx",
|
"sphinx",
|
||||||
|
@ -82,12 +84,12 @@ def list_environment_variables() -> None:
|
||||||
step("List environment variables")
|
step("List environment variables")
|
||||||
for variable, value in sorted(projects.environment.items()):
|
for variable, value in sorted(projects.environment.items()):
|
||||||
if variable not in ["SPCD", "SPCD_SSH_KEY"]:
|
if variable not in ["SPCD", "SPCD_SSH_KEY"]:
|
||||||
log.info(f"{variable} = {value}")
|
log.info("%s = %s", variable, value)
|
||||||
else:
|
else:
|
||||||
log.info(f"{variable}")
|
log.info("%s", variable)
|
||||||
|
|
||||||
|
|
||||||
def main(main: str) -> None:
|
def main(main_file: str) -> None:
|
||||||
"""Entry point to initialize environment or run a specific command."""
|
"""Entry point to initialize environment or run a specific command."""
|
||||||
paths = environ["PATH"].split(pathsep)
|
paths = environ["PATH"].split(pathsep)
|
||||||
if env.SPCD_PYTHON_VENV_BINARIES not in paths:
|
if env.SPCD_PYTHON_VENV_BINARIES not in paths:
|
||||||
|
@ -98,11 +100,11 @@ def main(main: str) -> None:
|
||||||
list_environment_variables()
|
list_environment_variables()
|
||||||
clone_project_branch()
|
clone_project_branch()
|
||||||
set_ssh()
|
set_ssh()
|
||||||
install_commands(main)
|
install_commands(main_file)
|
||||||
install_python_packages()
|
install_python_packages()
|
||||||
else:
|
else:
|
||||||
function = getattr(cmd, name.replace("-", "_"))
|
f = getattr(cmd, name.replace("-", "_"))
|
||||||
function(*arguments)
|
f(*arguments)
|
||||||
|
|
||||||
|
|
||||||
def set_ssh() -> None:
|
def set_ssh() -> None:
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
|
|
||||||
"""Entry point."""
|
"""Entry point."""
|
||||||
|
|
||||||
|
import importlib
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import env
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
env = importlib.import_module("env")
|
||||||
if env.SPCD_PYTHON_VENV_PACKAGES not in sys.path:
|
if env.SPCD_PYTHON_VENV_PACKAGES not in sys.path:
|
||||||
sys.path.insert(0, env.SPCD_PYTHON_VENV_PACKAGES)
|
sys.path.insert(0, env.SPCD_PYTHON_VENV_PACKAGES)
|
||||||
from spcd import main
|
from spcd import main
|
||||||
|
|
|
@ -3,10 +3,10 @@
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import env
|
|
||||||
from rwx import ps
|
from rwx import ps
|
||||||
|
|
||||||
from spcd.ci import project, projects
|
from spcd.ci import project, projects
|
||||||
|
from spcd.shell import env
|
||||||
from spcd.util import browse
|
from spcd.util import browse
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,12 +18,10 @@ def spcd_browse_workspace() -> None:
|
||||||
def spcd_build_project() -> None:
|
def spcd_build_project() -> None:
|
||||||
"""Perform the actual building process."""
|
"""Perform the actual building process."""
|
||||||
for extension in ["py", "sh"]:
|
for extension in ["py", "sh"]:
|
||||||
path = Path(project.root) / f"build.{extension}"
|
path = project.root / f"build.{extension}"
|
||||||
if path.exists():
|
if path.exists():
|
||||||
ps.run(path)
|
ps.run(str(path))
|
||||||
break
|
break
|
||||||
else:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def spcd_check_project() -> None:
|
def spcd_check_project() -> None:
|
||||||
|
|
|
@ -27,7 +27,7 @@ ROOT = [
|
||||||
class Project:
|
class Project:
|
||||||
"""Current project."""
|
"""Current project."""
|
||||||
|
|
||||||
def __init__(self: Project, projects: Projects) -> None:
|
def __init__(self, projects: Projects) -> None:
|
||||||
"""Set projects, branch, name, root & url."""
|
"""Set projects, branch, name, root & url."""
|
||||||
self.projects = projects
|
self.projects = projects
|
||||||
# branch
|
# branch
|
||||||
|
@ -41,11 +41,15 @@ class Project:
|
||||||
# root
|
# root
|
||||||
for variable in ROOT:
|
for variable in ROOT:
|
||||||
if value := projects.environment.get(variable, None):
|
if value := projects.environment.get(variable, None):
|
||||||
self.root = value
|
self.root = Path(value)
|
||||||
# url
|
# url
|
||||||
self.url = add_url_path(projects.url, self.name)
|
self.url = add_url_path(projects.url, self.name)
|
||||||
|
|
||||||
def __str__(self: Project) -> str:
|
def __repr__(self) -> str:
|
||||||
|
"""Represent project."""
|
||||||
|
return f"Project(projects={self.projects!r})"
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
"""List branch, name, root & url."""
|
"""List branch, name, root & url."""
|
||||||
return f"""\
|
return f"""\
|
||||||
branch = {self.branch}
|
branch = {self.branch}
|
||||||
|
|
|
@ -20,7 +20,7 @@ SERVER_URL = [
|
||||||
class Projects:
|
class Projects:
|
||||||
"""Other projects."""
|
"""Other projects."""
|
||||||
|
|
||||||
def __init__(self: Projects) -> None:
|
def __init__(self) -> None:
|
||||||
"""Set environment, group, name & url."""
|
"""Set environment, group, name & url."""
|
||||||
self.environment = os.environ
|
self.environment = os.environ
|
||||||
# group, name
|
# group, name
|
||||||
|
@ -34,7 +34,11 @@ class Projects:
|
||||||
if value := self.environment.get(variable, None):
|
if value := self.environment.get(variable, None):
|
||||||
self.url = add_url_path(value, self.group)
|
self.url = add_url_path(value, self.group)
|
||||||
|
|
||||||
def __str__(self: Projects) -> str:
|
def __repr__(self) -> str:
|
||||||
|
"""Represent projects."""
|
||||||
|
return "Projects()"
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
"""List group, name & url."""
|
"""List group, name & url."""
|
||||||
return f"""\
|
return f"""\
|
||||||
group = {self.group}
|
group = {self.group}
|
||||||
|
|
10
spcd/shell.py
Normal file
10
spcd/shell.py
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
"""Shell for environment module."""
|
||||||
|
|
||||||
|
import importlib
|
||||||
|
|
||||||
|
env = importlib.import_module("env")
|
||||||
|
|
||||||
|
try:
|
||||||
|
STEP = int(env.SPCD_STEP)
|
||||||
|
except AttributeError:
|
||||||
|
STEP = 1
|
26
spcd/util.py
26
spcd/util.py
|
@ -4,10 +4,12 @@ import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from urllib.parse import urlparse, urlunparse
|
from urllib.parse import urlparse, urlunparse
|
||||||
|
|
||||||
import env
|
|
||||||
from rwx import fs
|
from rwx import fs
|
||||||
from rwx.log import stream as log
|
from rwx.log import stream as log
|
||||||
|
|
||||||
|
from spcd import shell
|
||||||
|
from spcd.shell import env
|
||||||
|
|
||||||
|
|
||||||
def add_url_path(url: str, extra_path: str) -> str:
|
def add_url_path(url: str, extra_path: str) -> str:
|
||||||
"""Append an extra segment to an existing URL."""
|
"""Append an extra segment to an existing URL."""
|
||||||
|
@ -16,7 +18,7 @@ def add_url_path(url: str, extra_path: str) -> str:
|
||||||
return urlunparse(parts)
|
return urlunparse(parts)
|
||||||
|
|
||||||
|
|
||||||
def browse(root: str) -> None:
|
def browse(root: Path) -> None:
|
||||||
"""Frame the browsing of a root directory in the log output."""
|
"""Frame the browsing of a root directory in the log output."""
|
||||||
paths = []
|
paths = []
|
||||||
for directory, _, files in os.walk(root):
|
for directory, _, files in os.walk(root):
|
||||||
|
@ -24,27 +26,29 @@ def browse(root: str) -> None:
|
||||||
absolute_path = Path(directory) / file
|
absolute_path = Path(directory) / file
|
||||||
relative_path = os.path.relpath(absolute_path, start=root)
|
relative_path = os.path.relpath(absolute_path, start=root)
|
||||||
paths.append(relative_path)
|
paths.append(relative_path)
|
||||||
frame(root)
|
text = str(root)
|
||||||
|
frame(text)
|
||||||
for path in sorted(paths):
|
for path in sorted(paths):
|
||||||
log.info(path)
|
log.info(path)
|
||||||
shut(root)
|
shut(text)
|
||||||
|
|
||||||
|
|
||||||
def cat(file: str) -> None:
|
def cat(file: Path) -> None:
|
||||||
"""Frame the content of a file in the log output."""
|
"""Frame the content of a file in the log output."""
|
||||||
frame(file)
|
text = str(file)
|
||||||
|
frame(text)
|
||||||
log.info(fs.read_file_text(file).rstrip())
|
log.info(fs.read_file_text(file).rstrip())
|
||||||
shut(file)
|
shut(text)
|
||||||
|
|
||||||
|
|
||||||
def frame(text: str) -> None:
|
def frame(text: str) -> None:
|
||||||
"""Open a new frame in the log output."""
|
"""Open a new frame in the log output."""
|
||||||
log.info(f"{env.SPCD_OPEN}{text}")
|
log.info("%s%s", env.SPCD_OPEN, text)
|
||||||
|
|
||||||
|
|
||||||
def shut(text: str) -> None:
|
def shut(text: str) -> None:
|
||||||
"""Close current frame in the log output."""
|
"""Close current frame in the log output."""
|
||||||
log.info(f"{env.SPCD_SHUT}{text}")
|
log.info("%s%s", env.SPCD_SHUT, text)
|
||||||
|
|
||||||
|
|
||||||
def split() -> None:
|
def split() -> None:
|
||||||
|
@ -54,7 +58,7 @@ def split() -> None:
|
||||||
|
|
||||||
def step(text: str) -> None:
|
def step(text: str) -> None:
|
||||||
"""Increment the step number of the current build process."""
|
"""Increment the step number of the current build process."""
|
||||||
env.SPCD_STEP += 1
|
shell.STEP += 1
|
||||||
log.info(env.SPCD_DOWN)
|
log.info(env.SPCD_DOWN)
|
||||||
log.info(f"{env.SPCD_VERT} {env.SPCD_STEP} {text}")
|
log.info("%s %s %s", env.SPCD_VERT, shell.STEP, text)
|
||||||
log.info(env.SPCD___UP)
|
log.info(env.SPCD___UP)
|
||||||
|
|
Loading…
Reference in a new issue