mirror of
https://github.com/bndr/pipreqs.git
synced 2025-06-06 03:25:21 +00:00
Merge pull request #41 from dmand/fix-duplicate-dependencies
Make pipreqs not write diplicate lines to requirements.txt file
This commit is contained in:
commit
bd3f208c59
@ -182,7 +182,8 @@ def get_pkg_names(pkgs):
|
||||
if item[0] == pkg:
|
||||
toappend = item[1]
|
||||
break
|
||||
result.append(toappend)
|
||||
if toappend not in result:
|
||||
result.append(toappend)
|
||||
return result
|
||||
|
||||
|
||||
|
6
tests/_data_duplicated_deps/db.py
Normal file
6
tests/_data_duplicated_deps/db.py
Normal file
@ -0,0 +1,6 @@
|
||||
import pymongo
|
||||
from bson.objectid import ObjectId
|
||||
|
||||
# 'bson' package is mapped to 'pymongo'.
|
||||
# But running pipreqs should not result in two duplicated
|
||||
# lines 'pymongo==x.x.x'.
|
@ -26,6 +26,7 @@ class TestPipreqs(unittest.TestCase):
|
||||
self.project = os.path.join(os.path.dirname(__file__), "_data")
|
||||
self.project_invalid = os.path.join(os.path.dirname(__file__), "_invalid_data")
|
||||
self.project_with_ignore_directory = os.path.join(os.path.dirname(__file__), "_data_ignore")
|
||||
self.project_with_duplicated_deps = os.path.join(os.path.dirname(__file__), "_data_duplicated_deps")
|
||||
self.requirements_path = os.path.join(self.project, "requirements.txt")
|
||||
self.alt_requirement_path = os.path.join(
|
||||
self.project, "requirements2.txt")
|
||||
@ -43,6 +44,12 @@ class TestPipreqs(unittest.TestCase):
|
||||
self.assertFalse("django" in imports)
|
||||
self.assertFalse("models" in imports)
|
||||
|
||||
def test_deduplicate_dependencies(self):
|
||||
imports = pipreqs.get_all_imports(self.project_with_duplicated_deps)
|
||||
pkgs = pipreqs.get_pkg_names(imports)
|
||||
self.assertEqual(len(pkgs), 1)
|
||||
self.assertTrue("pymongo" in pkgs)
|
||||
|
||||
def test_invalid_python(self):
|
||||
"""
|
||||
Test that invalid python files cannot be imported.
|
||||
|
Loading…
x
Reference in New Issue
Block a user