Skip to content

Commit 90414db

Browse files
committed
merge global and frontmatter env values #49
1 parent 23b9064 commit 90414db

File tree

5 files changed

+23
-2
lines changed

5 files changed

+23
-2
lines changed

docs/syntax.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ All given relative paths are relative to the `shellinspector.yaml` file itself.
6969
Shellinspector can be configured in various ways outlined below. These config
7070
values are set using an optional YAML section at the start of the file. This
7171
takes precedence over the values provided in the config file. The `settings`
72-
dict gets merged, all other values are overwritten completely.
72+
and the `environment` dicts gets merged, all other values are overwritten
73+
completely.
7374

7475
```yaml
7576
---

src/shellinspector/parser.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,22 @@ def parse(
388388

389389
setattr(specfile.settings, key.name, value)
390390

391+
global_env = config.get("environment", {})
392+
frontmatter_env = frontmatter_settings.get("environment", {})
393+
394+
for key in global_env.keys():
395+
value = None
396+
397+
with suppress(LookupError):
398+
value = global_env[key]
399+
root_path = config_path.parent
400+
401+
with suppress(LookupError):
402+
value = frontmatter_env[key]
403+
root_path = specfile.path.parent
404+
405+
specfile.environment[key] = value
406+
391407
for sk, sv in specfile.environment.items():
392408
if not isinstance(sv, str):
393409
continue

tests/e2e/311_env_external_1.ispec

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ environment:
77
alessa
88
[@local]$ echo $OUTSIDE_PAGER2
99
bless
10+
# from shellinspector.yaml
11+
[@local]$ echo $OUTSIDE_PAGER3
12+
cless

tests/e2e/shellinspector.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
environment:
33
OUTSIDE_PAGER1: a${PAGER}a
44
OUTSIDE_PAGER2: b$PAGER
5+
OUTSIDE_PAGER3: c$PAGER

tests/test_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ def test_global_config_combine():
574574
),
575575
)
576576

577-
assert specfile.environment == {"FROM_ISPEC": 1}
577+
assert specfile.environment == {"FROM_ISPEC": 1, "FROM_CONFIG": 1}
578578
assert specfile.examples == [{"FROM_ISPEC": 1}]
579579

580580

0 commit comments

Comments
 (0)