Skip to content

Commit 049d999

Browse files
authored
Fix #579 fconf.parse_all support *.yaml & arbitrary glob (#580)
1 parent b3bc42a commit 049d999

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

pykern/fconf.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ def __init__(self, files, base_vars=None):
218218

219219
def _add_file(self, path):
220220
e = path.ext[1:].lower()
221+
if e == "yaml":
222+
e = "yml"
221223
f = _File(
222224
content=getattr(self, f"_ext_{e}")(path),
223225
ext=e,
@@ -299,7 +301,7 @@ def _functions(self, obj, co_filename=None):
299301
return m
300302

301303

302-
def parse_all(path, base_vars=None):
304+
def parse_all(path, base_vars=None, glob="*"):
303305
"""Parse all the Python and YAML files in `directory`
304306
305307
Files are read in sorted order with all Python files first and
@@ -308,14 +310,16 @@ def parse_all(path, base_vars=None):
308310
Args:
309311
path (py.path): directory that ``*.py`` and ``*.yml`` files
310312
base_vars (PKDict): initial variable state. May be hierarchical. [None]
313+
glob (str): basename to search in in directory
311314
Returns:
312315
PKDict: evaluated and merged files plus base_vars
313316
"""
314-
return Parser(
315-
pykern.pkio.sorted_glob(path.join("*.py"))
316-
+ pykern.pkio.sorted_glob(path.join("*.yml")),
317-
base_vars=None,
318-
).result
317+
318+
def _glob(ext):
319+
return pykern.pkio.sorted_glob(path.join(f"{glob}.{ext}"))
320+
321+
# yml & yaml need to be sorted together
322+
return Parser(_glob("py") + sorted(_glob("yml"), _glob("yaml"))).result
319323

320324

321325
class _Builtins:

tests/fconf_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# -*- coding: utf-8 -*-
21
"""test fconf
32
43
:copyright: Copyright (c) 2022 RadiaSoft LLC. All Rights Reserved.
54
:license: http://www.apache.org/licenses/LICENSE-2.0.html
65
"""
6+
77
import pytest
88

99

0 commit comments

Comments
 (0)