@@ -1007,6 +1007,11 @@ def create_requirements_json(cls, json_path=Path.cwd()):
1007
1007
json_path : str, optional
1008
1008
The path to a Python project, by default the current working directory.
1009
1009
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
+
1010
1015
Yields
1011
1016
------
1012
1017
requirements.json : file
@@ -1029,32 +1034,27 @@ def create_requirements_json(cls, json_path=Path.cwd()):
1029
1034
item [0 ] for item in package_and_version if not item [1 ]
1030
1035
]
1031
1036
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
+ }
1043
1053
)
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
1058
1058
1059
1059
@classmethod
1060
1060
def get_local_package_version (cls , package_list ):
0 commit comments