From a4bd5b552a7688075c3753ba546eb585394b619e Mon Sep 17 00:00:00 2001 From: Hari Sekhon Date: Tue, 18 Feb 2020 13:59:50 +0000 Subject: [PATCH 01/14] fixed MySQL + krbV mappings to be reversed --- pipreqs/mapping | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pipreqs/mapping b/pipreqs/mapping index 6359f8e..06fa00c 100644 --- a/pipreqs/mapping +++ b/pipreqs/mapping @@ -699,7 +699,7 @@ html:pies2overrides htmloutput:nosehtmloutput http:pies2overrides hvad:django_hvad -krbV:krbv +krbv:krbV i99fix:199Fix igraph:python_igraph imdb:IMDbPY @@ -793,7 +793,7 @@ msgpack:msgpack_python mutations:aino_mutations mws:amazon_mws mysql:mysql_connector_repackaged -MySQL-python:MySQLdb +MySQLdb:MySQL-python native_tags:django_native_tags ndg:ndg_httpsclient nereid:trytond_nereid From 2022f25ae96edc7e6a8cd71aaef2c6702fbaedf3 Mon Sep 17 00:00:00 2001 From: AlexPHorta Date: Thu, 27 Feb 2020 00:59:02 -0300 Subject: [PATCH 02/14] Working on issue #88 --- pipreqs/pipreqs.py | 5 +++++ tests/_data/test.py | 4 ++++ tests/test_pipreqs.py | 30 +++++++++++++++++++++++++++--- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/pipreqs/pipreqs.py b/pipreqs/pipreqs.py index 4b817c3..e280841 100755 --- a/pipreqs/pipreqs.py +++ b/pipreqs/pipreqs.py @@ -368,6 +368,11 @@ def diff(file_, imports): def clean(file_, imports): """Remove modules that aren't imported in project from file.""" modules_not_imported = compare_modules(file_, imports) + + if len(modules_not_imported) == 0: + logging.info("Nothing to clean in " + file_) + return + re_remove = re.compile("|".join(modules_not_imported)) to_write = [] diff --git a/tests/_data/test.py b/tests/_data/test.py index cfd039c..fdb6ec3 100644 --- a/tests/_data/test.py +++ b/tests/_data/test.py @@ -31,6 +31,10 @@ from pyflakes.test.test_imports import Test as TestImports # Nose from nose.importer import Importer, add_path, remove_path # loader.py +# see issue #88 +import analytics +import flask_seasurf + import atexit from __future__ import print_function from docopt import docopt diff --git a/tests/test_pipreqs.py b/tests/test_pipreqs.py index dcd75c5..acdac0b 100755 --- a/tests/test_pipreqs.py +++ b/tests/test_pipreqs.py @@ -19,7 +19,7 @@ class TestPipreqs(unittest.TestCase): def setUp(self): self.modules = ['flask', 'requests', 'sqlalchemy', - 'docopt', 'boto', 'ipython', 'pyflakes', 'nose', + 'docopt', 'boto', 'ipython', 'pyflakes', 'nose', 'analytics_python', 'flask_seasurf', 'peewee', 'ujson', 'nonexistendmodule', 'bs4', 'after_method_is_valid_even_if_not_pep8' ] self.modules2 = ['beautifulsoup4'] self.local = ["docopt", "requests", "nose", 'pyflakes'] @@ -33,7 +33,7 @@ class TestPipreqs(unittest.TestCase): def test_get_all_imports(self): imports = pipreqs.get_all_imports(self.project) - self.assertEqual(len(imports), 13) + self.assertEqual(len(imports), 15) # old value, 13 for item in imports: self.assertTrue( item.lower() in self.modules, "Import is missing: " + item) @@ -63,7 +63,7 @@ class TestPipreqs(unittest.TestCase): imports = pipreqs.get_all_imports(self.project) with_info = pipreqs.get_imports_info(imports) # Should contain 10 items without the "nonexistendmodule" and "after_method_is_valid_even_if_not_pep8" - self.assertEqual(len(with_info), 11) + self.assertEqual(len(with_info), 13) # old value, 11 for item in with_info: self.assertTrue( item['name'].lower() in self.modules, @@ -200,6 +200,30 @@ class TestPipreqs(unittest.TestCase): for item in ['beautifulsoup4==4.8.1', 'boto==2.49.0']: self.assertFalse(item.lower() in data) + def test_clean(self): + """ + Test --clean parameter + """ + pipreqs.init({'': self.project, '--savepath': None, '--print': False, + '--use-local': None, '--force': True, '--proxy': None, + '--pypi-server': None, '--diff': None, '--clean': None}) + assert os.path.exists(self.requirements_path) == 1 + # with open(self.requirements_path, "r") as f: + # print('A') + # for l in f: print(l) + pipreqs.init({'': self.project, '--savepath': None, '--print': False, + '--use-local': None, '--force': None, '--proxy': None, + '--pypi-server': None, '--diff': None, + '--clean': self.requirements_path, '--no-pin': True}) + # with open(self.requirements_path, "r") as f: + # print('B') + # for l in f: print(l) + with open(self.requirements_path, "r") as f: + data = f.read().lower() + print(data) + for item in self.modules[:-3]: # ['analytics_python', 'flask_seasurf']: + self.assertTrue(item.lower() in data) + def tearDown(self): """ Remove requiremnts.txt files that were written From 386e677d80e900f740528c8dae32e2a5918c7b18 Mon Sep 17 00:00:00 2001 From: AlexPHorta Date: Thu, 27 Feb 2020 07:54:44 -0300 Subject: [PATCH 03/14] More --clean tests. --- tests/_data_clean/test.py | 65 +++++++++++++++++++++++++++++++++++++++ tests/test_pipreqs.py | 29 ++++++++++++----- 2 files changed, 87 insertions(+), 7 deletions(-) create mode 100644 tests/_data_clean/test.py diff --git a/tests/_data_clean/test.py b/tests/_data_clean/test.py new file mode 100644 index 0000000..8cffb51 --- /dev/null +++ b/tests/_data_clean/test.py @@ -0,0 +1,65 @@ +"""unused import""" +# pylint: disable=undefined-all-variable, import-error, no-absolute-import, too-few-public-methods, missing-docstring +import xml.etree # [unused-import] +import xml.sax # [unused-import] +import os.path as test # [unused-import] +from sys import argv as test2 # [unused-import] +from sys import flags # [unused-import] +# +1:[unused-import,unused-import] +from collections import deque, OrderedDict, Counter +# All imports above should be ignored +import requests # [unused-import] + +# setuptools +import zipimport # command/easy_install.py + +# twisted +from importlib import invalidate_caches # python/test/test_deprecate.py + +# astroid +import zipimport # manager.py +# IPython +from importlib.machinery import all_suffixes # core/completerlib.py +import importlib # html/notebookapp.py + +from IPython.utils.importstring import import_item # Many files + +# pyflakes +# test/test_doctests.py +from pyflakes.test.test_imports import Test as TestImports + +# Nose +from nose.importer import Importer, add_path, remove_path # loader.py + +# see issue #88 +import analytics +import flask_seasurf + +import atexit +from __future__ import print_function +from docopt import docopt +import curses, logging, sqlite3 +import logging +import os +import sqlite3 +import time +import sys +import signal +import bs4 +import nonexistendmodule +import boto as b, peewee as p +# import django +import flask.ext.somext # # # +# from sqlalchemy import model +try: + import ujson as json +except ImportError: + import json + +import models + + +def main(): + pass + +import after_method_is_valid_even_if_not_pep8 diff --git a/tests/test_pipreqs.py b/tests/test_pipreqs.py index acdac0b..849d5a7 100755 --- a/tests/test_pipreqs.py +++ b/tests/test_pipreqs.py @@ -19,11 +19,12 @@ class TestPipreqs(unittest.TestCase): def setUp(self): self.modules = ['flask', 'requests', 'sqlalchemy', - 'docopt', 'boto', 'ipython', 'pyflakes', 'nose', 'analytics_python', 'flask_seasurf', + 'docopt', 'boto', 'ipython', 'pyflakes', 'nose', 'analytics', 'flask_seasurf', 'peewee', 'ujson', 'nonexistendmodule', 'bs4', 'after_method_is_valid_even_if_not_pep8' ] self.modules2 = ['beautifulsoup4'] self.local = ["docopt", "requests", "nose", 'pyflakes'] self.project = os.path.join(os.path.dirname(__file__), "_data") + self.project_clean = os.path.join(os.path.dirname(__file__), "_data_clean") 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") @@ -33,6 +34,7 @@ class TestPipreqs(unittest.TestCase): def test_get_all_imports(self): imports = pipreqs.get_all_imports(self.project) + print(imports) self.assertEqual(len(imports), 15) # old value, 13 for item in imports: self.assertTrue( @@ -208,16 +210,29 @@ class TestPipreqs(unittest.TestCase): '--use-local': None, '--force': True, '--proxy': None, '--pypi-server': None, '--diff': None, '--clean': None}) assert os.path.exists(self.requirements_path) == 1 - # with open(self.requirements_path, "r") as f: - # print('A') - # for l in f: print(l) pipreqs.init({'': self.project, '--savepath': None, '--print': False, '--use-local': None, '--force': None, '--proxy': None, '--pypi-server': None, '--diff': None, '--clean': self.requirements_path, '--no-pin': True}) - # with open(self.requirements_path, "r") as f: - # print('B') - # for l in f: print(l) + with open(self.requirements_path, "r") as f: + data = f.read().lower() + print(data) + for item in self.modules[:-3]: # ['analytics_python', 'flask_seasurf']: + self.assertTrue(item.lower() in data) + + def test_clean_with_extras(self): + """ + Test --clean parameter when there are imports to clean + """ + pipreqs.init({'': self.project, '--savepath': None, '--print': False, + '--use-local': None, '--force': True, '--proxy': None, + '--pypi-server': None, '--diff': None, '--clean': None}) + assert os.path.exists(self.requirements_path) == 1 + # Continua... + pipreqs.init({'': self.project, '--savepath': None, '--print': False, + '--use-local': None, '--force': None, '--proxy': None, + '--pypi-server': None, '--diff': None, + '--clean': self.requirements_path, '--no-pin': True}) with open(self.requirements_path, "r") as f: data = f.read().lower() print(data) From 21d3907e960140f9ac45030af63e8c1721cb1cd8 Mon Sep 17 00:00:00 2001 From: AlexPHorta Date: Thu, 27 Feb 2020 21:24:31 -0300 Subject: [PATCH 04/14] Fixed #88 --- tests/test_pipreqs.py | 200 ++++++++++++++++++++++++++---------------- 1 file changed, 123 insertions(+), 77 deletions(-) diff --git a/tests/test_pipreqs.py b/tests/test_pipreqs.py index 849d5a7..550b29b 100755 --- a/tests/test_pipreqs.py +++ b/tests/test_pipreqs.py @@ -18,24 +18,40 @@ from pipreqs import pipreqs class TestPipreqs(unittest.TestCase): def setUp(self): - self.modules = ['flask', 'requests', 'sqlalchemy', - 'docopt', 'boto', 'ipython', 'pyflakes', 'nose', 'analytics', 'flask_seasurf', - 'peewee', 'ujson', 'nonexistendmodule', 'bs4', 'after_method_is_valid_even_if_not_pep8' ] + self.modules = [ + 'flask', 'requests', 'sqlalchemy', 'docopt', 'boto', 'ipython', + 'pyflakes', 'nose', 'analytics', 'flask_seasurf', 'peewee', + 'ujson', 'nonexistendmodule', 'bs4', + 'after_method_is_valid_even_if_not_pep8' + ] self.modules2 = ['beautifulsoup4'] self.local = ["docopt", "requests", "nose", 'pyflakes'] self.project = os.path.join(os.path.dirname(__file__), "_data") - self.project_clean = os.path.join(os.path.dirname(__file__), "_data_clean") - 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.project_clean = os.path.join( + os.path.dirname(__file__), + "_data_clean" + ) + 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") + self.project, + "requirements2.txt" + ) def test_get_all_imports(self): imports = pipreqs.get_all_imports(self.project) - print(imports) - self.assertEqual(len(imports), 15) # old value, 13 + self.assertEqual(len(imports), 15) for item in imports: self.assertTrue( item.lower() in self.modules, "Import is missing: " + item) @@ -56,7 +72,8 @@ class TestPipreqs(unittest.TestCase): """ Test that invalid python files cannot be imported. """ - self.assertRaises(SyntaxError, pipreqs.get_all_imports, self.project_invalid) + self.assertRaises( + SyntaxError, pipreqs.get_all_imports, self.project_invalid) def test_get_imports_info(self): """ @@ -64,8 +81,9 @@ class TestPipreqs(unittest.TestCase): """ imports = pipreqs.get_all_imports(self.project) with_info = pipreqs.get_imports_info(imports) - # Should contain 10 items without the "nonexistendmodule" and "after_method_is_valid_even_if_not_pep8" - self.assertEqual(len(with_info), 13) # old value, 11 + # Should contain 10 items without the "nonexistendmodule" and + # "after_method_is_valid_even_if_not_pep8" + self.assertEqual(len(with_info), 13) for item in with_info: self.assertTrue( item['name'].lower() in self.modules, @@ -79,10 +97,12 @@ class TestPipreqs(unittest.TestCase): def test_get_use_local_only(self): """ - Test without checking PyPI, check to see if names of local imports matches what we expect + Test without checking PyPI, check to see if names of local + imports matches what we expect - Note even though pyflakes isn't in requirements.txt, - It's added to locals since it is a development dependency for testing + It's added to locals since it is a development dependency + for testing """ # should find only docopt and requests imports_with_info = pipreqs.get_import_local(self.modules) @@ -91,11 +111,13 @@ class TestPipreqs(unittest.TestCase): def test_init(self): """ - Test that all modules we will test upon, are in requirements file + Test that all modules we will test upon are in requirements file """ - pipreqs.init({'': self.project, '--savepath': None, '--print': False, - '--use-local': None, '--force': True, '--proxy':None, '--pypi-server':None, - '--diff': None, '--clean': None}) + pipreqs.init( + {'': self.project, '--savepath': None, '--print': False, + '--use-local': None, '--force': True, '--proxy': None, + '--pypi-server': None, '--diff': None, '--clean': None} + ) assert os.path.exists(self.requirements_path) == 1 with open(self.requirements_path, "r") as f: data = f.read().lower() @@ -104,11 +126,14 @@ class TestPipreqs(unittest.TestCase): def test_init_local_only(self): """ - Test that items listed in requirements.text are the same as locals expected + Test that items listed in requirements.text are the same + as locals expected """ - pipreqs.init({'': self.project, '--savepath': None, '--print': False, - '--use-local': True, '--force': True, '--proxy':None, '--pypi-server':None, - '--diff': None, '--clean': None}) + pipreqs.init( + {'': self.project, '--savepath': None, '--print': False, + '--use-local': True, '--force': True, '--proxy': None, + '--pypi-server': None, '--diff': None, '--clean': None} + ) assert os.path.exists(self.requirements_path) == 1 with open(self.requirements_path, "r") as f: data = f.readlines() @@ -118,11 +143,14 @@ class TestPipreqs(unittest.TestCase): def test_init_savepath(self): """ - Test that we can save requiremnts.tt correctly to a different path + Test that we can save requirements.txt correctly + to a different path """ - pipreqs.init({'': self.project, '--savepath': - self.alt_requirement_path, '--use-local': None, '--proxy':None, '--pypi-server':None, '--print': False, - "--diff": None, "--clean": None}) + pipreqs.init( + {'': self.project, '--savepath': self.alt_requirement_path, + '--use-local': None, '--proxy': None, '--pypi-server': None, + '--print': False, "--diff": None, "--clean": None} + ) assert os.path.exists(self.alt_requirement_path) == 1 with open(self.alt_requirement_path, "r") as f: data = f.read().lower() @@ -133,13 +161,16 @@ class TestPipreqs(unittest.TestCase): def test_init_overwrite(self): """ - Test that if requiremnts.txt exists, it will not automatically be overwritten + Test that if requiremnts.txt exists, it will not be + automatically overwritten """ with open(self.requirements_path, "w") as f: f.write("should_not_be_overwritten") - pipreqs.init({'': self.project, '--savepath': None, - '--use-local': None, '--force': None, '--proxy':None, '--pypi-server':None, '--print': False, - "--diff": None, "--clean": None}) + pipreqs.init( + {'': self.project, '--savepath': None, '--use-local': None, + '--force': None, '--proxy': None, '--pypi-server': None, + '--print': False, '--diff': None, '--clean': None} + ) assert os.path.exists(self.requirements_path) == 1 with open(self.requirements_path, "r") as f: data = f.read().lower() @@ -147,38 +178,48 @@ class TestPipreqs(unittest.TestCase): def test_get_import_name_without_alias(self): """ - Test that function get_name_without_alias() will work on a string. - - Note: This isn't truly needed when pipreqs is walking the AST to find imports + Test that function get_name_without_alias() + will work on a string. + - Note: This isn't truly needed when pipreqs is walking + the AST to find imports """ import_name_with_alias = "requests as R" expected_import_name_without_alias = "requests" import_name_without_aliases = pipreqs.get_name_without_alias( import_name_with_alias) self.assertEqual( - import_name_without_aliases, expected_import_name_without_alias) + import_name_without_aliases, + expected_import_name_without_alias + ) def test_custom_pypi_server(self): """ Test that trying to get a custom pypi sever fails correctly """ - self.assertRaises(requests.exceptions.MissingSchema, pipreqs.init, {'': self.project, '--savepath': None, '--print': False, - '--use-local': None, '--force': True, '--proxy': None, '--pypi-server': 'nonexistent'}) + self.assertRaises( + requests.exceptions.MissingSchema, pipreqs.init, + {'': self.project, '--savepath': None, '--print': False, + '--use-local': None, '--force': True, '--proxy': None, + '--pypi-server': 'nonexistent'} + ) def test_ignored_directory(self): """ Test --ignore parameter """ pipreqs.init( - {'': self.project_with_ignore_directory, '--savepath': None, '--print': False, - '--use-local': None, '--force': True, - '--proxy':None, - '--pypi-server':None, - '--ignore':'.ignored_dir,.ignore_second', - '--diff': None, - '--clean': None - } - ) - with open(os.path.join(self.project_with_ignore_directory, "requirements.txt"), "r") as f: + {'': self.project_with_ignore_directory, '--savepath': None, + '--print': False, '--use-local': None, '--force': True, + '--proxy': None, '--pypi-server': None, + '--ignore': '.ignored_dir,.ignore_second', '--diff': None, + '--clean': None} + ) + with open( + os.path.join( + self.project_with_ignore_directory, + "requirements.txt" + ), "r" + ) as f: data = f.read().lower() for item in ['click', 'getpass']: self.assertFalse(item.lower() in data) @@ -188,16 +229,15 @@ class TestPipreqs(unittest.TestCase): Test --no-pin parameter """ pipreqs.init( - {'': self.project_with_ignore_directory, '--savepath': None, '--print': False, - '--use-local': None, '--force': True, - '--proxy': None, - '--pypi-server': None, - '--diff': None, - '--clean': None, - '--no-pin': True - } - ) - with open(os.path.join(self.project_with_ignore_directory, "requirements.txt"), "r") as f: + {'': self.project_with_ignore_directory, '--savepath': None, + '--print': False, '--use-local': None, '--force': True, + '--proxy': None, '--pypi-server': None, '--diff': None, + '--clean': None, '--no-pin': True} + ) + with open(os.path.join( + self.project_with_ignore_directory, + "requirements.txt"), "r" + ) as f: data = f.read().lower() for item in ['beautifulsoup4==4.8.1', 'boto==2.49.0']: self.assertFalse(item.lower() in data) @@ -206,38 +246,44 @@ class TestPipreqs(unittest.TestCase): """ Test --clean parameter """ - pipreqs.init({'': self.project, '--savepath': None, '--print': False, - '--use-local': None, '--force': True, '--proxy': None, - '--pypi-server': None, '--diff': None, '--clean': None}) + pipreqs.init( + {'': self.project, '--savepath': None, '--print': False, + '--use-local': None, '--force': True, '--proxy': None, + '--pypi-server': None, '--diff': None, '--clean': None} + ) assert os.path.exists(self.requirements_path) == 1 - pipreqs.init({'': self.project, '--savepath': None, '--print': False, - '--use-local': None, '--force': None, '--proxy': None, - '--pypi-server': None, '--diff': None, - '--clean': self.requirements_path, '--no-pin': True}) + pipreqs.init( + {'': self.project, '--savepath': None, '--print': False, + '--use-local': None, '--force': None, '--proxy': None, + '--pypi-server': None, '--diff': None, + '--clean': self.requirements_path, '--no-pin': True} + ) with open(self.requirements_path, "r") as f: data = f.read().lower() - print(data) - for item in self.modules[:-3]: # ['analytics_python', 'flask_seasurf']: + for item in self.modules[:-3]: self.assertTrue(item.lower() in data) - def test_clean_with_extras(self): + def test_clean_with_imports_to_clean(self): """ Test --clean parameter when there are imports to clean """ - pipreqs.init({'': self.project, '--savepath': None, '--print': False, - '--use-local': None, '--force': True, '--proxy': None, - '--pypi-server': None, '--diff': None, '--clean': None}) + cleaned_module = 'sqlalchemy' + pipreqs.init( + {'': self.project, '--savepath': None, '--print': False, + '--use-local': None, '--force': True, '--proxy': None, + '--pypi-server': None, '--diff': None, '--clean': None} + ) assert os.path.exists(self.requirements_path) == 1 - # Continua... - pipreqs.init({'': self.project, '--savepath': None, '--print': False, - '--use-local': None, '--force': None, '--proxy': None, - '--pypi-server': None, '--diff': None, - '--clean': self.requirements_path, '--no-pin': True}) + modules_clean = [m for m in self.modules if m != cleaned_module] + pipreqs.init( + {'': self.project_clean, '--savepath': None, + '--print': False, '--use-local': None, '--force': None, + '--proxy': None, '--pypi-server': None, '--diff': None, + '--clean': self.requirements_path, '--no-pin': True} + ) with open(self.requirements_path, "r") as f: data = f.read().lower() - print(data) - for item in self.modules[:-3]: # ['analytics_python', 'flask_seasurf']: - self.assertTrue(item.lower() in data) + self.assertTrue(cleaned_module not in data) def tearDown(self): """ From 7b2b5e9e5880cde1922c0b9c7ac238247f3850f4 Mon Sep 17 00:00:00 2001 From: Pat Myron Date: Tue, 21 Apr 2020 11:17:49 -0700 Subject: [PATCH 05/14] mapping aws-sam-translator https://pypi.org/project/aws-sam-translator/ https://github.com/awslabs/serverless-application-model --- pipreqs/mapping | 1 + 1 file changed, 1 insertion(+) diff --git a/pipreqs/mapping b/pipreqs/mapping index 6f5a469..26b83cb 100644 --- a/pipreqs/mapping +++ b/pipreqs/mapping @@ -999,6 +999,7 @@ ruamel:ruamel.base s2repoze:pysaml2 saga:saga_python saml2:pysaml2 +samtranslator:aws-sam-translator sass:libsass sassc:libsass sasstests:libsass From fc720f18bb5e1689d05ae4f83f4bfef5d173e704 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Singh Date: Thu, 10 Oct 2019 18:34:59 +0530 Subject: [PATCH 06/14] Fixed#133 Sorted `imports` based on `lowercase` package's `name`, similar to `pip freeze`. --- pipreqs/pipreqs.py | 2 ++ tests/test_pipreqs.py | 3 +++ 2 files changed, 5 insertions(+) diff --git a/pipreqs/pipreqs.py b/pipreqs/pipreqs.py index 57147e2..42a4e45 100755 --- a/pipreqs/pipreqs.py +++ b/pipreqs/pipreqs.py @@ -430,6 +430,8 @@ def init(args): imports = local + get_imports_info(difference, proxy=proxy, pypi_server=pypi_server) + # sort imports based on lowercase name of package, similar to `pip freeze`. + imports = sorted(imports, key=lambda x: x['name'].lower()) path = (args["--savepath"] if args["--savepath"] else os.path.join(input_path, "requirements.txt")) diff --git a/tests/test_pipreqs.py b/tests/test_pipreqs.py index dcd75c5..68f7249 100755 --- a/tests/test_pipreqs.py +++ b/tests/test_pipreqs.py @@ -99,6 +99,9 @@ class TestPipreqs(unittest.TestCase): data = f.read().lower() for item in self.modules[:-3]: self.assertTrue(item.lower() in data) + # It should be sorted based on names. + data = data.strip().split('\n') + self.assertEqual(data, sorted(data)) def test_init_local_only(self): """ From bd88dd85cdfc647dcfa6ba1fb234ed80a03b5ded Mon Sep 17 00:00:00 2001 From: Ben Bodenmiller Date: Thu, 9 Jul 2020 16:11:56 -0700 Subject: [PATCH 07/14] Tweak formatting --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 139fa7d..2a33b60 100644 --- a/README.rst +++ b/README.rst @@ -70,5 +70,5 @@ Why not pip freeze? ------------------- - ``pip freeze`` only saves the packages that are installed with ``pip install`` in your environment. -- ``pip freeze`` saves all packages in the environment including those that you don't use in your current project. (if you don't have virtualenv) -- and sometimes you just need to create requirements.txt for a new project without installing modules. +- ``pip freeze`` saves all packages in the environment including those that you don't use in your current project (if you don't have ``virtualenv``). +- and sometimes you just need to create ``requirements.txt`` for a new project without installing modules. From 30d8fab76c41b79652b1b7632c7041fe60339c94 Mon Sep 17 00:00:00 2001 From: John Kruper <36000@users.noreply.github.com> Date: Tue, 10 Nov 2020 10:27:02 -0800 Subject: [PATCH 08/14] Add pyAFQ Mapping --- pipreqs/mapping | 1 + 1 file changed, 1 insertion(+) diff --git a/pipreqs/mapping b/pipreqs/mapping index 6f5a469..77c2ed0 100644 --- a/pipreqs/mapping +++ b/pipreqs/mapping @@ -1,3 +1,4 @@ +AFQ:pyAFQ AG_fft_tools:agpy ANSI:pexpect Adafruit:Adafruit_Libraries From 469baefc1e7219c02f1dfe343e5a3bfbc66603c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Kalemba?= <5924586+pkalemba@users.noreply.github.com> Date: Thu, 10 Dec 2020 10:04:17 +0100 Subject: [PATCH 09/14] Add discord mapping Map discord to discord.py --- pipreqs/mapping | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pipreqs/mapping b/pipreqs/mapping index 6f5a469..e4be845 100644 --- a/pipreqs/mapping +++ b/pipreqs/mapping @@ -22,6 +22,7 @@ Kittens:astro_kittens Levenshtein:python_Levenshtein Lifetime:Zope2 MethodObject:ExtensionClass +MySQL-python:MySQLdb OFS:Zope2 OpenGL:PyOpenGL OpenSSL:pyOpenSSL @@ -592,6 +593,7 @@ devtools:tg.devtools dgis:2gis dhtmlparser:pyDHTMLParser digitalocean:python_digitalocean +discord:discord.py distribute_setup:ez_setup distutils2:Distutils2 django:Django @@ -701,7 +703,6 @@ html:pies2overrides htmloutput:nosehtmloutput http:pies2overrides hvad:django_hvad -krbV:krbv i99fix:199Fix igraph:python_igraph imdb:IMDbPY @@ -727,6 +728,7 @@ keyczar:python_keyczar keyedcache:django_keyedcache keystoneclient:python_keystoneclient kickstarter:kickstart +krbV:krbv kss:kss.core kuyruk:Kuyruk langconv:AdvancedLangConv @@ -798,7 +800,6 @@ msgpack:msgpack_python mutations:aino_mutations mws:amazon_mws mysql:mysql_connector_repackaged -MySQL-python:MySQLdb native_tags:django_native_tags ndg:ndg_httpsclient nereid:trytond_nereid From bcd0be47d0f90e9cf47ed8d19392e56817fc220f Mon Sep 17 00:00:00 2001 From: SwiftWinds <12981958+SwiftWinds@users.noreply.github.com> Date: Sat, 13 Mar 2021 14:46:02 -0800 Subject: [PATCH 10/14] Add PyFunctional mapping Maps `functional` to `pyfunctional`. Fixes #232. --- pipreqs/mapping | 1 + 1 file changed, 1 insertion(+) diff --git a/pipreqs/mapping b/pipreqs/mapping index 6f5a469..7eb67dc 100644 --- a/pipreqs/mapping +++ b/pipreqs/mapping @@ -13,6 +13,7 @@ Crypto:pycryptodome Cryptodome:pycryptodomex FSM:pexpect FiftyOneDegrees:51degrees_mobile_detector_v3_wrapper +functional:pyfunctional GeoBaseMain:GeoBasesDev GeoBases:GeoBasesDev Globals:Zope2 From 7b69881e76934167a3a012796376895ccebe796f Mon Sep 17 00:00:00 2001 From: alan-barzilay Date: Wed, 24 Mar 2021 16:21:56 -0300 Subject: [PATCH 11/14] Upgrade pip before running tests on travis This should ensure that all tests use the same version of pip and this should hopefully fix the pypy build that is using pip 19 --- .travis.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 324b044..bfe9a9d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,8 +17,12 @@ matrix: - python: 3.6 env: TOX_ENV=flake8 +# This should ensure that all tests use the same pip version +before_install: + - python -m pip install --upgrade pip + # Use tox to run tests on Travis-CI to keep one unified method of running tests in any environment -install: +install: - pip install coverage coveralls tox # Command to run tests, e.g. python setup.py test From b1725c7409f98cc7a97b3440bb64160cc266a200 Mon Sep 17 00:00:00 2001 From: alan-barzilay Date: Wed, 24 Mar 2021 18:33:15 -0300 Subject: [PATCH 12/14] Upgrading pypy to pypy3 Maybe forcing pypy to use python 3 will solve the issue (although it works fine with python 2.7 at the moment) --- .travis.yml | 4 ++-- tox.ini | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index bfe9a9d..5772134 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,8 +12,8 @@ matrix: env: TOX_ENV=py34 - python: 2.7 env: TOX_ENV=py27 - - python: pypy - env: TOX_ENV=pypy + - python: pypy3 + env: TOX_ENV=pypy3 - python: 3.6 env: TOX_ENV=flake8 diff --git a/tox.ini b/tox.ini index 28a1dfa..554b3c1 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27, py34, py35, py36, pypy, flake8 +envlist = py27, py34, py35, py36, pypy3, flake8 [testenv] setenv = From b7e061f73a534dddc6d6de974c52dd58dedbcea2 Mon Sep 17 00:00:00 2001 From: alan-barzilay Date: Wed, 24 Mar 2021 18:40:30 -0300 Subject: [PATCH 13/14] Remove unecessary pip upgrade step --- .travis.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5772134..7988659 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,10 +17,6 @@ matrix: - python: 3.6 env: TOX_ENV=flake8 -# This should ensure that all tests use the same pip version -before_install: - - python -m pip install --upgrade pip - # Use tox to run tests on Travis-CI to keep one unified method of running tests in any environment install: - pip install coverage coveralls tox From c7c91fcabe66a4550ef5513d8a411ae544b16bc9 Mon Sep 17 00:00:00 2001 From: ryan-rozario Date: Fri, 26 Mar 2021 23:56:20 +0400 Subject: [PATCH 14/14] Mapping for github3 --- pipreqs/mapping | 1 + 1 file changed, 1 insertion(+) diff --git a/pipreqs/mapping b/pipreqs/mapping index cf90aa5..73173b4 100644 --- a/pipreqs/mapping +++ b/pipreqs/mapping @@ -679,6 +679,7 @@ geventwebsocket:gevent_websocket gflags:python_gflags git:GitPython github:PyGithub +github3:github3.py gitpy:git_py globusonline:globusonline_transfer_api_client google:protobuf