def main(): args = parse_args() if args.freeze: pipfile = Project().lockfile_content else: # pylint: disable=protected-access pipfile = Project()._lockfile # pylint: enable=protected-access # Create pip-compatible dependency list def_req = [ formatPipenvEntryForRequirements(n, i) for n, i in pipfile.get("default", {}).items() ] dev_req = [ formatPipenvEntryForRequirements(n, i) for n, i in pipfile.get("develop", {}).items() ] intro = [ "################################################################################", "# This requirements file has been automatically generated from `Pipfile` with", '# `pipenv-to-requirements`', '#', '#', '# This has been done to maintain backward compatibility with tools and services', '# that do not support `Pipfile` yet.', '#', "# Do NOT edit it directly, use `pipenv install [-d]` to modify `Pipfile` and", "# `Pipfile.lock` and then regenerate `requirements*.txt`.", "################################################################################", "" ] if def_req: if args.output: requirement_txt = args.output elif args.dev_output: # if -d without -o, do not generate packages, for compatibility sake requirement_txt = None else: requirement_txt = "requirements.txt" if requirement_txt: with open(requirement_txt, "w") as f: f.write("\n".join(intro + sorted(def_req)) + "\n") print("generated: {0}".format(requirement_txt)) if dev_req: if args.dev_output: requirement_txt = args.dev_output elif args.output: # if -o without -d, do not generate dev packages, for compatibility sake requirement_txt = None else: requirement_txt = "requirements-dev.txt" if requirement_txt: with open(requirement_txt, "w") as f: f.write("\n".join(intro + sorted(dev_req)) + "\n") print("generated: {0}".format(requirement_txt))
def main(): if "-h" in sys.argv or "--help" in sys.argv: print("Usage: ") print(" pipenv-to-requirements [-f|--freeze]") print() print("Options:") print(" -f --freeze Generate requirements*.txt with frozen versions") sys.exit(0) if "-f" in sys.argv or "--freeze" in sys.argv: pipfile = Project().lockfile_content else: # pylint: disable=protected-access pipfile = Project()._lockfile # pylint: enable=protected-access def_req = parse_pip_file(pipfile, "default") dev_req = parse_pip_file(pipfile, "develop") # Create pip-compatible dependency list def_req = [ formatPipenvEntryForRequirements(n, i) for n, i in pipfile.get("default", {}).items() ] dev_req = [ formatPipenvEntryForRequirements(n, i) for n, i in pipfile.get("develop", {}).items() ] intro = [ "################################################################################", "# This requirements files has been automatically generated from `Pipfile` with", '# `pipenv-to-requirements`', '#', '#', '# This has been done to maintain backward compatibility with tools and services', '# that do not support `Pipfile` yet.', '#', "# Do NOT edit it directly, use `pipenv install [-d]` to modify `Pipfile` and", "# `Pipfile.lock` and then regenerate `requirements*.txt`.", "################################################################################", "" ] if def_req: with open("requirements.txt", "w") as f: f.write("\n".join(intro + sorted(def_req)) + "\n") print("generated: requirements.txt") if dev_req: with open("requirements-dev.txt", "w") as f: f.write("\n".join(intro + sorted(dev_req)) + "\n") print("generated: requirements-dev.txt")
def main(): parser = argparse.ArgumentParser( description='Generate requirements*.txt matching Pipfile*') parser.add_argument( '-o', '--output', help='Generate only the main requirements.txt to a different file') parser.add_argument('-f', '--freeze', action="store_true", help='Generate requirements*.txt with frozen versions') args = parser.parse_args() if args.freeze: pipfile = Project().lockfile_content else: # pylint: disable=protected-access pipfile = Project()._lockfile # pylint: enable=protected-access def_req = parse_pip_file(pipfile, "default") dev_req = parse_pip_file(pipfile, "develop") # Create pip-compatible dependency list def_req = [ formatPipenvEntryForRequirements(n, i) for n, i in pipfile.get("default", {}).items() ] dev_req = [ formatPipenvEntryForRequirements(n, i) for n, i in pipfile.get("develop", {}).items() ] intro = [ "################################################################################", "# This requirements file has been automatically generated from `Pipfile` with", '# `pipenv-to-requirements`', '#', '#', '# This has been done to maintain backward compatibility with tools and services', '# that do not support `Pipfile` yet.', '#', "# Do NOT edit it directly, use `pipenv install [-d]` to modify `Pipfile` and", "# `Pipfile.lock` and then regenerate `requirements*.txt`.", "################################################################################", "" ] if def_req: if args.output: requirement_txt = args.output else: requirement_txt = "requirements.txt" with open(requirement_txt, "w") as f: f.write("\n".join(intro + sorted(def_req)) + "\n") print("generated: {0}".format(requirement_txt)) if args.output: return if dev_req: with open("requirements-dev.txt", "w") as f: f.write("\n".join(intro + sorted(dev_req)) + "\n") print("generated: requirements-dev.txt")