From 8b5eacc65c3d386646aeb73f787d390415b72c43 Mon Sep 17 00:00:00 2001 From: kristiewirth Date: Mon, 28 Sep 2020 14:13:09 -0600 Subject: [PATCH] Add poetry func --- pipreqs/pipreqs.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/pipreqs/pipreqs.py b/pipreqs/pipreqs.py index 40ef745..bc99a60 100755 --- a/pipreqs/pipreqs.py +++ b/pipreqs/pipreqs.py @@ -179,8 +179,21 @@ def output_requirements(imports): generate_requirements_file('-', imports) -def get_imports_info( - imports, pypi_server="https://pypi.python.org/pypi/", proxy=None): +def add_requirements_poetry(imports): + packages = [item["name"] for item in imports] + # Run all commands even if one fails + poetry_command = "".join([f"poetry add {pkg}; " for pkg in packages]) + # Remove extra lingering ; from end of command + poetry_command_cleaned = poetry_command[:-2] + logging.info("Running '%s'", poetry_command_cleaned) + if os.path.exists("pyproject.toml"): + os.system(poetry_command_cleaned) + else: + # Install poetry and create pyproject.toml file if needed + os.system("pip install poetry -q") + os.system("poetry init -n -q") + os.system(poetry_command_cleaned) + result = [] for item in imports: