Skip to content

Commit 666e360

Browse files
committed
Read prefs yaml in personalize.py
1 parent 482477b commit 666e360

File tree

3 files changed

+33
-16
lines changed

3 files changed

+33
-16
lines changed

pyflask-preferences.yaml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
1-
# is_personalized decides if the codebase has been personalized
1+
docker_maintainer_details: User <[email protected]>
22
is_personalized: false
3-
# service_name is base name for the service
4-
service_name: pyflask-microservice
5-
# python_env_name is the environment name used by the environment manager
6-
python_env_name: pyflask-base-env
7-
# env_manager: name of the environment manager used in the project
8-
# supported environment managers: venv | conda
9-
python_env_manager: venv
10-
# python_base_version: python base version for the project
11-
# supported python versions: 3.7 | 3.8
123
python_base_version_major: 3
134
python_base_version_minor: 8
14-
# docker_maintainer_details: add info of maintainer to docker image
15-
docker_maintainer_details: User <[email protected]>
5+
python_env_manager: venv
6+
python_env_name: pyflask-base-env
7+
service_name: pyflask-microservice

scripts/dev/personalize.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,31 @@
1+
import fnmatch
12
import os
3+
import sys
4+
5+
import yaml
26

37
if __name__ == "__main__":
8+
exclude_dirs_args = sys.argv[1].split(",")
9+
exclude_dirs = ["src", "test", "assets"] + exclude_dirs_args
10+
exclude_files = ["personalize.py"]
11+
12+
matches = []
13+
for root, dirs, file_names in os.walk("."):
14+
dirs[:] = [d for d in dirs if d not in exclude_dirs and not d.startswith(".")]
15+
file_names[:] = [f for f in file_names if f not in exclude_files]
16+
for filename in fnmatch.filter(file_names, "*"):
17+
matches.append(os.path.join(root, filename))
418

5-
directory = os.listdir("scripts/dev")
19+
with open(r"./pyflask-preferences.yaml") as file:
20+
# The FullLoader parameter handles the conversion from YAML
21+
# scalar values to Python the dictionary format
22+
pyflask_pref_dict = yaml.load(file, Loader=yaml.FullLoader)
23+
print(pyflask_pref_dict)
24+
with open(r"./pyflask-preferences.yaml", "w") as file:
25+
documents = yaml.dump(pyflask_pref_dict, file)
626

7-
for f_name in directory:
8-
print(f_name)
27+
for f in matches:
28+
with open(f) as open_f:
29+
for num, line in enumerate(open_f, 1):
30+
if "pyflask_config" in line:
31+
print(line)

scripts/dev/service_init.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ function main() {
4949
# shellcheck disable=SC2154
5050
if [ "$pyflask_pref_is_personalized" == "false" ]; then
5151
echo "$style_bold_blue""Starting project personalization . . .""$style_reset"
52-
python3 scripts/dev/personalize.py
52+
rm -rf .github
53+
pip3 install pyyaml
54+
python3 scripts/dev/personalize.py "$pyflask_pref_python_env_name"
5355
printf "\n"
5456
fi
5557

0 commit comments

Comments
 (0)