Skip to content

Commit

Permalink
Allow missing SCONS_FLAGS keys when registering builds
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelLefkowitz committed Nov 23, 2024
1 parent af421fe commit 86e5e17
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
{
"packageManager": "[email protected]",
"scripts": {
"postinstall": "husky"
"postinstall": "husky",
"prepack": "pinst --disable",
"postpack": "pinst --enable"
},
"devDependencies": {
"cspell": "^8.0.0",
"husky": "^9.0.0",
"pinst": "^3.0.0",
"prettier": "^3.0.0"
}
}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ src = "miniscons"
lint = [
"npx cspell . --dot --gitignore",
"pylint src --disable=C0114,C0115,C0116,C0411,C3001",
"mypy -m src --ignore-missing-import",
"mypy src --ignore-missing-import",
"trufflehog3",
]

Expand Down
5 changes: 4 additions & 1 deletion src/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ def path(self, file: str) -> str:
return f"{root.replace('.', '-')}-[{self.name}]"

def merge(self, env: Environment) -> dict[str, list[str]]:
merged = {k: unique(env[k] + self.packages.get(k, [])) for k in SCONS_FLAGS}
merged = {
k: unique(env.get(k, []) + self.packages.get(k, [])) for k in SCONS_FLAGS
}

merged["CXXFLAGS"] += self.flags
return merged

Expand Down
16 changes: 13 additions & 3 deletions src/containers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
from functools import reduce
from typing import TypeVar

T = TypeVar("T")
U = TypeVar("U")

def unique(lst: list[str]) -> list[str]:
empty = [] # type: list[str]

def unique(lst: list[T]) -> list[T]:
empty = [] # type: list[T]
return list(reduce(lambda acc, x: acc if x in acc else [*acc, x], lst, empty))


def flatten(ignore: list[str | list[str]]) -> list[str]:
def flatten(ignore: list[T | list[T]]) -> list[T]:
return list(sum(map(lambda x: x if isinstance(x, list) else [x], ignore), []))


def merge_maps(
x: dict[T, list[U]], y: dict[T, list[U]], keys: list[T]
) -> dict[T, list[U]]:
return {k: unique(x.get(k, []) + y.get(k, [])) for k in keys}
7 changes: 6 additions & 1 deletion test/test_containers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from src.containers import flatten, unique
from src.containers import flatten, merge_maps, unique


def test_unique():
Expand All @@ -7,3 +7,8 @@ def test_unique():

def test_flatten():
assert flatten(["a", ["b", "c"]]) == ["a", "b", "c"]


def test_merge_maps():
assert merge_maps({}, {}, ["a"]) == {"a": []}
assert merge_maps({"a": [1]}, {"a": [2, 3]}, ["a"]) == {"a": [1, 2, 3]}

0 comments on commit 86e5e17

Please sign in to comment.