Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ help:

.venv-build/bin/activate: requirements.build.txt
@echo "Setting up development virtual env in .venv"
set -e; \
python -m venv .venv-build; \
. .venv-build/bin/activate; \
python -m pip install -r requirements.build.txt

.venv-runtime/bin/activate: requirements.txt
@echo "Setting up development virtual env in .venv"
set -e; \
python -m venv .venv-runtime; \
. .venv-runtime/bin/activate; \
python -m pip install -r requirements.txt
Expand All @@ -49,27 +51,33 @@ clean:
git clean --force -dX

build: .venv-build/bin/activate
set -e; \
. .venv-build/bin/activate; \
python -m build

standalone: .venv-build/bin/activate
set -e; \
. .venv-build/bin/activate; \
python -m PyInstaller --distpath . toltecmk.spec

test: .venv-runtime/bin/activate
set -e; \
. .venv-runtime/bin/activate; \
python -m unittest; \
tests/foobar/test.sh

format: .venv-build/bin/activate
set -e; \
. .venv-build/bin/activate; \
black --line-length 80 --check --diff toltec tests

format-fix: .venv-build/bin/activate
set -e; \
. .venv-build/bin/activate; \
black --line-length 80 toltec tests

lint: .venv-build/bin/activate
set -e; \
. .venv-build/bin/activate; \
echo "==> Typechecking files"; \
mypy --disallow-untyped-defs toltec; \
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/rmkit/package
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ prepare() {

build() {
pip3 install okp
make
make -j$(nporc)
}

bufshot() {
Expand Down
2 changes: 1 addition & 1 deletion tests/foobar/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ python -m toltec \
--arch-name rmall \
$(dirname $0)

tree $tmpdir/dist
tree -pug $tmpdir/dist
exists $tmpdir/dist/rmall/foo_0.0.0-1_rmall.ipk
missing $tmpdir/dist/rm1/foo_0.0.0-1_rm1.ipk
missing $tmpdir/dist/rm2/foo_0.0.0-1_rm2.ipk
Expand Down
1 change: 1 addition & 0 deletions tests/test_toltec.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# SPDX-License-Identifier: MIT

from os import path
import os
import unittest
from tempfile import TemporaryDirectory
import subprocess
Expand Down
3 changes: 1 addition & 2 deletions toltec/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import os
import sys
from importlib.util import find_spec, spec_from_file_location, module_from_spec
from typing import Dict, List, Optional
from toltec import parse_recipe
from toltec.builder import Builder
from toltec.recipe import Package
Expand Down Expand Up @@ -97,7 +96,7 @@ def main() -> int: # pylint:disable=too-many-branches
f"Hook module '{ident}' couldn’t be loaded"
)

build_matrix: Optional[Dict[str, Optional[List[Package]]]] = None
build_matrix: dict[str, list[Package] | None] | None = None

if args.arch_name or args.package_name:
build_matrix = {}
Expand Down
29 changes: 15 additions & 14 deletions toltec/bash.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
import subprocess
import logging
from collections import deque
from typing import Deque, Dict, Generator, List, Optional, Tuple, Union
from collections.abc import Generator
from docker.client import DockerClient

AssociativeArray = Dict[str, str]
IndexedArray = List[Optional[str]]
AssociativeArray = dict[str, str]
IndexedArray = list[str | None]
LogGenerator = Generator[str, None, None]
Any = Union[str, AssociativeArray, IndexedArray]
Variables = Dict[str, Optional[Any]]
Functions = Dict[str, str]
Any = str | AssociativeArray | IndexedArray
Variables = dict[str, Any | None]
Functions = dict[str, str]


class ScriptError(Exception):
Expand All @@ -36,6 +36,7 @@ class ScriptError(Exception):
"BASH_COMMAND",
"BASH_LINENO",
"BASH_LOADABLES_PATH",
"BASH_MONOSECONDS",
"BASH_SOURCE",
"BASH_SUBSHELL",
"BASH_VERSINFO",
Expand Down Expand Up @@ -90,7 +91,7 @@ def _get_bash_stdout(src: str) -> str:
:param src: bash script to run
:returns: the stdout of the script
"""
env: Dict[str, str] = {
env: dict[str, str] = {
"PATH": os.environ["PATH"],
}

Expand All @@ -112,7 +113,7 @@ def _get_bash_stdout(src: str) -> str:
return subshell.stdout.decode()


def get_declarations(src: str) -> Tuple[Variables, Functions]:
def get_declarations(src: str) -> tuple[Variables, Functions]:
"""
Extract all variables and functions defined by a Bash script.

Expand Down Expand Up @@ -225,7 +226,7 @@ def _generate_string(string: str) -> str:
def _parse_indexed(lexer: shlex.shlex) -> IndexedArray:
"""Parse an indexed Bash array."""
assert lexer.get_token() == "("
result: List[Optional[str]] = []
result: list[str | None] = []

while True:
token = lexer.get_token()
Expand Down Expand Up @@ -304,7 +305,7 @@ def _generate_assoc(array: AssociativeArray) -> str:
)


def _parse_var(lexer: shlex.shlex) -> Tuple[str, Optional[Any]]:
def _parse_var(lexer: shlex.shlex) -> tuple[str, Any | None]:
"""Parse a variable declaration."""
flags_token = lexer.get_token()
assert flags_token is not None
Expand All @@ -315,7 +316,7 @@ def _parse_var(lexer: shlex.shlex) -> Tuple[str, Optional[Any]]:
var_flags = set()

var_name = lexer.get_token()
var_value: Optional[Any] = None
var_value: Any | None = None
lookahead = lexer.get_token()
assert var_name is not None
assert lookahead is not None
Expand All @@ -339,7 +340,7 @@ def _parse_var(lexer: shlex.shlex) -> Tuple[str, Optional[Any]]:
return var_name, var_value


def _parse_func(lexer: shlex.shlex) -> Tuple[int, int]:
def _parse_func(lexer: shlex.shlex) -> tuple[int, int]:
"""Find the starting and end bounds of a function declaration."""
assert lexer.get_token() == "{"
brace_depth = 1
Expand Down Expand Up @@ -402,7 +403,7 @@ def run_script(variables: Variables, script: str) -> LogGenerator:
def run_script_in_container(
docker: DockerClient,
image: str,
mounts: List,
mounts: list,
variables: Variables,
script: str,
) -> LogGenerator:
Expand Down Expand Up @@ -469,7 +470,7 @@ def pipe_logs(
:param max_lines_on_fail: number of context lines to print
in non-debug mode
"""
log_buffer: Deque[str] = deque()
log_buffer: deque[str] = deque()

try:
for line in logs:
Expand Down
Loading