Compare commits

...

16 commits

Author SHA1 Message Date
94e85a8f36
ruff/format
Some checks failed
/ job (push) Failing after 50s
2024-08-19 18:18:16 +02:00
e9e3779018
docstring/class 2024-08-19 18:17:50 +02:00
7dd1dc6dcf
docstring/init 2024-08-19 18:15:24 +02:00
f54c9d598b
docstring/str 2024-08-19 18:03:55 +02:00
dddad18357
docstring/spcd/init/main 2024-08-19 17:56:35 +02:00
ba59b1618f
docstring/spcd/init 2024-08-19 17:50:34 +02:00
b41478a747
docstring/cmd 2024-08-19 17:44:07 +02:00
57a171ae0d
docstring/cmd 2024-08-19 17:38:23 +02:00
6619f791ea
docstring/ci 2024-08-19 17:37:19 +02:00
247f15586e
docstring/util 2024-08-19 17:20:41 +02:00
29c701b3d5
docstring/util/url 2024-08-19 17:18:41 +02:00
42166a2c4e
docstring/util/browse,cat 2024-08-19 17:16:34 +02:00
87b39b4486
docstring/util/frame,shut 2024-08-19 17:13:04 +02:00
2576b0eba1
add hatch 2024-08-19 17:02:06 +02:00
bf7da671dc
docstring/util/split 2024-08-19 16:34:47 +02:00
e55a7f3ba1
docstring/util/step 2024-08-19 16:33:07 +02:00
6 changed files with 34 additions and 2 deletions

View file

@ -19,6 +19,7 @@ COMMANDS_PREFIX = "spcd-"
def clone_project_branch() -> None:
"""Clone project on triggering branch into the current workspace."""
if not projects.environment.get("GITLAB_CI"):
step("Clone project branch")
log.info(projects)
@ -41,6 +42,7 @@ def clone_project_branch() -> None:
def install_commands(path: str) -> None:
"""Make commands callable in the operating system."""
step("Install commands")
user = Path("/usr/local/bin")
for command in [
@ -54,11 +56,13 @@ def install_commands(path: str) -> None:
def install_python_packages() -> None:
"""Upgrade pip then install extra Python packages."""
step("Install Python packages")
log.info("pip")
run("pip", "install", "--upgrade", "pip")
split()
packages = [
"hatch",
"mypy",
"pelican",
"pytest",
@ -73,6 +77,7 @@ def install_python_packages() -> None:
def list_environment_variables() -> None:
"""List accessible variables and their public contents."""
step("List environment variables")
for variable, value in sorted(projects.environment.items()):
if variable not in ["SPCD", "SPCD_SSH_KEY"]:
@ -82,6 +87,7 @@ def list_environment_variables() -> None:
def main(main: str) -> None:
"""Entry point to initialize environment or run a specific command."""
paths = environ["PATH"].split(pathsep)
if env.SPCD_PYTHON_VENV_BINARIES not in paths:
environ["PATH"] = pathsep.join([env.SPCD_PYTHON_VENV_BINARIES, *paths])
@ -99,6 +105,7 @@ def main(main: str) -> None:
def set_ssh() -> None:
"""Set things up to enable access to targets through SSH."""
step("Set SSH")
# get variables
ssh_hosts = projects.environment.get("SPCD_SSH_HOSTS")

View file

@ -1,3 +1,5 @@
"""Continuous Integration."""
from spcd.project import Project
from spcd.projects import Projects

View file

@ -1,3 +1,5 @@
"""Commands available for workflows."""
import os
from pathlib import Path
@ -9,10 +11,12 @@ from spcd.util import browse
def spcd_browse_workspace() -> None:
"""Browse the current workspace for the project."""
browse(project.root)
def spcd_build_project() -> None:
"""Perform the actual building process."""
for extension in ["py", "sh"]:
path = Path(project.root) / f"build.{extension}"
if path.exists():
@ -23,12 +27,14 @@ def spcd_build_project() -> None:
def spcd_check_project() -> None:
"""Check the project for anything wrong."""
ps.run("ruff", "check")
def spcd_synchronize(
target: str | None = None, source: str | None = None
) -> None:
"""Synchronize output towards a target."""
if not target:
user = "cd"
host = env.SPCD_PROJECT_PATH

View file

@ -1,4 +1,4 @@
"""CI project."""
"""Continuous Integration project."""
from __future__ import annotations
@ -25,7 +25,10 @@ ROOT = [
class Project:
"""Current project."""
def __init__(self: Project, projects: Projects) -> None:
"""Set projects, branch, name, root & url."""
self.projects = projects
# branch
for variable in BRANCH:
@ -43,6 +46,7 @@ class Project:
self.url = add_url_path(projects.url, self.name)
def __str__(self: Project) -> str:
"""List branch, name, root & url."""
return f"""\
branch = {self.branch}
name = {self.name}

View file

@ -1,4 +1,4 @@
"""CI projects."""
"""Continuous Integration projects."""
from __future__ import annotations
@ -18,7 +18,10 @@ SERVER_URL = [
class Projects:
"""Other projects."""
def __init__(self: Projects) -> None:
"""Set environment, group, name & url."""
self.environment = os.environ
# group, name
for variable in GROUP_AND_NAME:
@ -32,6 +35,7 @@ class Projects:
self.url = add_url_path(value, self.group)
def __str__(self: Projects) -> str:
"""List group, name & url."""
return f"""\
group = {self.group}
name = {self.name}

View file

@ -1,3 +1,5 @@
"""Basic utilities."""
import os
from pathlib import Path
from urllib.parse import urlparse, urlunparse
@ -8,12 +10,14 @@ from rwx.log import stream as log
def add_url_path(url: str, extra_path: str) -> str:
"""Append an extra segment to an existing URL."""
parts = urlparse(url)
parts = parts._replace(path=str(Path(parts.path) / extra_path))
return urlunparse(parts)
def browse(root: str) -> None:
"""Frame the browsing of a root directory in the log output."""
paths = []
for directory, _, files in os.walk(root):
for file in files:
@ -27,24 +31,29 @@ def browse(root: str) -> None:
def cat(file: str) -> None:
"""Frame the content of a file in the log output."""
frame(file)
log.info(fs.read_file_text(file).rstrip())
shut(file)
def frame(text: str) -> None:
"""Open a new frame in the log output."""
log.info(f"{env.SPCD_OPEN}{text}")
def shut(text: str) -> None:
"""Close current frame in the log output."""
log.info(f"{env.SPCD_SHUT}{text}")
def split() -> None:
"""Separate previous log outputs from the ones following."""
log.info(env.SPCD_SPLT)
def step(text: str) -> None:
"""Increment the step number of the current build process."""
env.SPCD_STEP += 1
log.info(env.SPCD_DOWN)
log.info(f"{env.SPCD_VERT} {env.SPCD_STEP} {text}")