Skip to content

Commit 89a4369

Browse files
committed
Adjust json creation to be a single dump of list of dicts; include return statement for list. #143
1 parent eba9e4f commit 89a4369

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

src/sasctl/pzmm/write_json_files.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,11 @@ def create_requirements_json(cls, json_path=Path.cwd()):
10071007
json_path : str, optional
10081008
The path to a Python project, by default the current working directory.
10091009
1010+
Returns
1011+
-------
1012+
list of dicts
1013+
List of dictionary representations of the json file contents, split into each package and/or warning.
1014+
10101015
Yields
10111016
------
10121017
requirements.json : file
@@ -1029,32 +1034,27 @@ def create_requirements_json(cls, json_path=Path.cwd()):
10291034
item[0] for item in package_and_version if not item[1]
10301035
]
10311036

1032-
with open(Path(json_path) / "requirements.json", "w") as file:
1033-
if missing_package_versions:
1034-
json_step = json.dumps(
1035-
[
1036-
{
1037-
"Warning": "The existence and/or versions for the following packages could not be "
1038-
"determined:",
1039-
"Packages": ", ".join(missing_package_versions),
1040-
}
1041-
],
1042-
indent=4,
1037+
# Create a list of dicts related to each package or warning
1038+
json_dicts = []
1039+
if missing_package_versions:
1040+
json_dicts.append(
1041+
{
1042+
"Warning": "The existence and/or versions for the following packages could not be determined:",
1043+
"Packages": ", ".join(missing_package_versions),
1044+
}
1045+
)
1046+
for package, version in package_and_version:
1047+
if version:
1048+
json_dicts.append(
1049+
{
1050+
"step": f"install {package}",
1051+
"command": f"pip install {package}=={version}",
1052+
}
10431053
)
1044-
file.write(json_step)
1045-
1046-
for package, version in package_and_version:
1047-
if version:
1048-
json_step = json.dumps(
1049-
[
1050-
{
1051-
"step": "install " + package,
1052-
"command": "pip install " + package + "==" + version,
1053-
}
1054-
],
1055-
indent=4,
1056-
)
1057-
file.write(json_step)
1054+
with open(Path(json_path) / "requirements.json", "w") as file:
1055+
file.write(json.dumps(json_dicts, indent=4))
1056+
1057+
return json_dicts
10581058

10591059
@classmethod
10601060
def get_local_package_version(cls, package_list):

0 commit comments

Comments
 (0)