Skip to content

Commit 931be82

Browse files
committed
Moved and renamed a function and clarified documentation related to build step splitting
Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com>
1 parent 796c41e commit 931be82

4 files changed

Lines changed: 18 additions & 16 deletions

File tree

JSON.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ These are copies of the module directories, where it's more "safe" to do things
222222
## All available build steps
223223

224224
The build steps below manipulate the temporary files in the steps directories and write results to the output policy set, in `out/masterfiles`.
225-
Unless otherwise noted, all steps are run inside the module's folder (`out/steps/...`) with sources / file paths relative to that folder, and targets / destinations mentioned below are relative to the output policy set (`out/masterfiles`, which in the end will be deployed as `/var/cfengine/masterfiles`).
225+
Unless otherwise noted, all steps are run inside the module's folder (`out/steps/...`) with sources / file paths relative to that folder, and targets / destinations mentioned below are relative to the output policy set (`out/masterfiles`, which in the end will be deployed as `/var/cfengine/masterfiles`). In `cfbs.json`'s `"steps"`, the build step name must be separated from the rest of the build step by a regular space.
226226

227227
* `copy <source> <destination>`
228228
* Copy a single file or a directory recursively.

cfbs/build.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import logging as log
3+
from typing import List, Tuple
34
from cfbs.utils import (
45
canonify,
56
cp,
@@ -12,7 +13,6 @@
1213
read_json,
1314
rm,
1415
sh,
15-
split_command,
1616
strip_left,
1717
touch,
1818
user_error,
@@ -73,8 +73,14 @@ def _generate_augment(module_name, input_data):
7373
return augment
7474

7575

76+
def split_build_step(command) -> Tuple[str, List[str]]:
77+
terms = command.split(" ")
78+
operation, args = terms[0], terms[1:]
79+
return operation, args
80+
81+
7682
def _perform_build_step(module, step, max_length):
77-
operation, args = split_command(step)
83+
operation, args = split_build_step(step)
7884
source = module["_directory"]
7985
counter = module["_counter"]
8086
destination = "out/masterfiles"
@@ -245,7 +251,7 @@ def perform_build_steps(config) -> int:
245251
# mini-validation
246252
for module in config.get("build", []):
247253
for step in module["steps"]:
248-
operation, args = split_command(step)
254+
operation, args = split_build_step(step)
249255

250256
if step.split() != [operation] + args:
251257
user_error(

cfbs/utils.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import copy
66
import subprocess
77
import hashlib
8-
from typing import List, Tuple
98
import urllib
109
import urllib.request # needed on some platforms
1110
from collections import OrderedDict
@@ -86,12 +85,6 @@ def pad_right(s, n):
8685
return s.ljust(n)
8786

8887

89-
def split_command(command) -> Tuple[str, List[str]]:
90-
terms = command.split(" ")
91-
operation, args = terms[0], terms[1:]
92-
return operation, args
93-
94-
9588
def is_valid_arg_count(args, expected):
9689
actual = len(args)
9790

@@ -173,7 +166,7 @@ def read_json(path) -> OrderedDict:
173166
except NotADirectoryError:
174167
return None
175168
except json.decoder.JSONDecodeError as ex:
176-
print("Error reading json file {} : {}".format(path, ex))
169+
print("Error reading json file '{}': {}".format(path, ex))
177170
sys.exit(1)
178171

179172

cfbs/validate.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import argparse
2-
import json
32
import sys
43
import re
54
from collections import OrderedDict
65

7-
from cfbs.utils import is_valid_arg_count, is_a_commit_hash, split_command, user_error
6+
from cfbs.utils import (
7+
is_valid_arg_count,
8+
is_a_commit_hash,
9+
user_error,
10+
)
811
from cfbs.pretty import TOP_LEVEL_KEYS, MODULE_KEYS
912
from cfbs.cfbs_config import CFBSConfig
10-
from cfbs.build import AVAILABLE_BUILD_STEPS
13+
from cfbs.build import AVAILABLE_BUILD_STEPS, split_build_step
1114

1215

1316
class CFBSValidationError(Exception):
@@ -266,7 +269,7 @@ def validate_steps(name, module):
266269
raise CFBSValidationError(
267270
name, '"steps" must be a list of non-empty / non-whitespace strings'
268271
)
269-
operation, args = split_command(step)
272+
operation, args = split_build_step(step)
270273
if not operation in AVAILABLE_BUILD_STEPS:
271274
x = ", ".join(AVAILABLE_BUILD_STEPS)
272275
raise CFBSValidationError(

0 commit comments

Comments
 (0)