mirror of
https://github.com/bndr/pipreqs.git
synced 2025-06-06 03:25:21 +00:00
Version 0.2.8
Add --force option Clean up
This commit is contained in:
parent
91db3afac7
commit
fe71b90075
1
.gitignore
vendored
1
.gitignore
vendored
@ -41,3 +41,4 @@ output/*/index.html
|
||||
|
||||
# Sphinx
|
||||
docs/_build
|
||||
.idea/
|
||||
|
@ -3,6 +3,11 @@
|
||||
History
|
||||
-------
|
||||
|
||||
0.2.8 (2015-05-11)
|
||||
---------------------
|
||||
|
||||
* Add --force option as a protection for overwrites
|
||||
|
||||
0.2.6 (2015-05-11)
|
||||
---------------------
|
||||
|
||||
|
@ -40,7 +40,7 @@ Usage
|
||||
--use-local Use ONLY local package information instead of querying PyPI
|
||||
--debug Print debug information
|
||||
--savepath <file> Save the list of requirements in the given file
|
||||
|
||||
--force Overwrite existing requirements.txt
|
||||
Example
|
||||
-------
|
||||
|
||||
|
@ -9,11 +9,11 @@ Options:
|
||||
--use-local Use ONLY local package information instead of querying PyPI
|
||||
--debug Print debug information
|
||||
--savepath <file> Save the list of requirements in the given file
|
||||
--force Overwrite existing requirements.txt
|
||||
"""
|
||||
from __future__ import print_function
|
||||
import os
|
||||
import sys
|
||||
from distutils.sysconfig import get_python_lib
|
||||
import re
|
||||
import logging
|
||||
|
||||
@ -28,8 +28,6 @@ REGEXP = [
|
||||
]
|
||||
|
||||
|
||||
|
||||
|
||||
def get_all_imports(path):
|
||||
imports = []
|
||||
candidates = []
|
||||
@ -101,9 +99,9 @@ def get_locally_installed_packages():
|
||||
package_import = f.read().strip().split("\n")
|
||||
except:
|
||||
continue
|
||||
for item in package_import:
|
||||
if item not in ignore and package[0] not in ignore:
|
||||
packages[item] = {
|
||||
for i_item in package_import:
|
||||
if i_item not in ignore and package[0] not in ignore:
|
||||
packages[i_item] = {
|
||||
'version': package[1].replace(".dist", ""),
|
||||
'name': package[0]
|
||||
}
|
||||
@ -147,7 +145,7 @@ def join(f):
|
||||
|
||||
def init(args):
|
||||
candidates = get_all_imports(args['<path>'])
|
||||
candidates = get_pkg_names(get_all_imports(args['<path>']))
|
||||
candidates = get_pkg_names(candidates)
|
||||
logging.debug("Found imports: " + ", ".join(candidates))
|
||||
|
||||
if args['--use-local']:
|
||||
@ -162,10 +160,13 @@ def init(args):
|
||||
for z in local]]
|
||||
imports = local + get_imports_info(difference)
|
||||
|
||||
path = args[
|
||||
"--savepath"] if args["--savepath"] else os.path.join(args['<path>'], "requirements.txt")
|
||||
path = args["--savepath"] if args["--savepath"] else os.path.join(args['<path>'], "requirements.txt")
|
||||
|
||||
if not args["--savepath"] and not args["--force"] and os.path.exists(path):
|
||||
logging.info("Requirements.txt already exists, use --force to overwrite it")
|
||||
return
|
||||
generate_requirements_file(path, imports)
|
||||
print("Successfully saved requirements file in " + path)
|
||||
logging.info("Successfully saved requirements file in " + path)
|
||||
|
||||
|
||||
def main(): # pragma: no cover
|
||||
|
2
setup.py
2
setup.py
@ -20,7 +20,7 @@ requirements = [
|
||||
|
||||
setup(
|
||||
name='pipreqs',
|
||||
version='0.2.7',
|
||||
version='0.2.8',
|
||||
description="Pip requirements.txt generator based on imports in project",
|
||||
long_description=readme + '\n\n' + history,
|
||||
author="Vadim Kravcenko",
|
||||
|
@ -51,13 +51,12 @@ class TestPipreqs(unittest.TestCase):
|
||||
def test_get_use_local_only(self):
|
||||
# should find only docopt and requests
|
||||
imports_with_info = pipreqs.get_import_local(self.modules)
|
||||
print(imports_with_info)
|
||||
for item in imports_with_info:
|
||||
self.assertTrue(item['name'].lower() in self.local)
|
||||
|
||||
def test_init(self):
|
||||
pipreqs.init(
|
||||
{'<path>': self.project, '--savepath': None, '--use-local': None})
|
||||
{'<path>': self.project, '--savepath': None, '--use-local': None, '--force': True})
|
||||
assert os.path.exists(self.requirements_path) == 1
|
||||
with open(self.requirements_path, "r") as f:
|
||||
data = f.read().lower()
|
||||
@ -66,7 +65,7 @@ class TestPipreqs(unittest.TestCase):
|
||||
|
||||
def test_init_local_only(self):
|
||||
pipreqs.init(
|
||||
{'<path>': self.project, '--savepath': None, '--use-local': True})
|
||||
{'<path>': self.project, '--savepath': None, '--use-local': True, '--force': True})
|
||||
assert os.path.exists(self.requirements_path) == 1
|
||||
with open(self.requirements_path, "r") as f:
|
||||
data = f.readlines()
|
||||
@ -85,6 +84,15 @@ class TestPipreqs(unittest.TestCase):
|
||||
for item in self.modules2:
|
||||
self.assertTrue(item.lower() in data)
|
||||
|
||||
def test_init_overwrite(self):
|
||||
with open(self.requirements_path, "w") as f:
|
||||
f.write("should_not_be_overwritten")
|
||||
pipreqs.init({'<path>': self.project, '--savepath': None, '--use-local': None, '--force': None})
|
||||
assert os.path.exists(self.requirements_path) == 1
|
||||
with open(self.requirements_path, "r") as f:
|
||||
data = f.read().lower()
|
||||
self.assertEqual(data, "should_not_be_overwritten")
|
||||
|
||||
def test_get_import_name_without_alias(self):
|
||||
import_name_with_alias = "requests as R"
|
||||
expected_import_name_without_alias = "requests"
|
||||
|
Loading…
x
Reference in New Issue
Block a user