#!/usr/bin/env python import os, sys from pathlib import Path cwd = os.getcwd() pip_path = Path("{}/Pipfile".format(cwd)) req_path = Path("{}/requirements.txt".format(cwd)) dev_req_path = Path("{}/requirements-dev.txt".format(cwd)) pip_lines = [] if pip_path.is_file(): f = open("Pipfile", "r") pip_lines = f.readlines() f.close() else: print("No Pipfile found. Exiting") sys.exit(0) if req_path.is_file(): req_file = open("{}/requirements.converted.txt".format(cwd), "w") else: req_file = open("{}/requirements.txt".format(cwd), "w") if dev_req_path.is_file(): dev_req_file = open("{}/requirements-dev.converted.txt".format(cwd), "w") else: dev_req_file = open("{}/requirements-dev.txt".format(cwd), "w") is_package = False is_dev_package = False for l in pip_lines: entry = l.strip() print("entry: {}".format(entry)) if is_package: if entry == "": is_package = False is_dev_package = False continue dep, v = l.split("=") if v.strip() == '"*"': dep = "{}\n".format(dep.strip()) else: dep = "{}=={}\n".format(dep.strip(), v.strip().strip('"')) if is_dev_package: dev_req_file.write(dep) else: req_file.write(dep) else: if entry == "": continue if entry[0] == "[": entry = entry.strip("[]") is_package = False if entry == "packages" or entry == "dev-packages": is_package = True if entry[0:3] == "dev": is_dev_package = True req_file.close() dev_req_file.close()