28 lines
983 B
Python
28 lines
983 B
Python
import json
|
|
|
|
def generate_requirements_from_json(json_file, output_file="requirements.txt"):
|
|
try:
|
|
# Load JSON data from the file
|
|
with open(json_file, "r") as f:
|
|
data = json.load(f)
|
|
|
|
# Extract the package names and versions
|
|
requirements = []
|
|
for entry in data:
|
|
package = entry.get("package", {})
|
|
package_name = package.get("package_name")
|
|
installed_version = package.get("installed_version")
|
|
if package_name and installed_version:
|
|
requirements.append(f"{package_name}=={installed_version}")
|
|
|
|
# Write to requirements.txt
|
|
with open(output_file, "w") as f:
|
|
f.write("\n".join(requirements))
|
|
|
|
print(f"Requirements file generated: {output_file}")
|
|
except Exception as e:
|
|
print(f"An error occurred: {e}")
|
|
|
|
# Replace 'input.json' with your actual JSON file name
|
|
generate_requirements_from_json("requirements_pipedtree.json")
|