def main(path, extra_ignore_dirs): # Get all potential imports. candidates = pipreqs.get_all_imports(path, extra_ignore_dirs=extra_ignore_dirs, ignore_errors=True) if len(candidates) == 0: print(json.dumps([])) return # Get imports that can be found locally. # Note: although the pipreqs package gets the mapping first it seems that # `get_import_local` requires the names without the mapping. Must be a bug. local = pipreqs.get_import_local(candidates) # Now get the mapping (e.g. bs4 -> beatifulsoup4) # Start with our own custom mapping candidates = [ mapping[name.lower()] if name.lower() in mapping else name for name in candidates ] # pipreqs mapping candidates = pipreqs.get_pkg_names(candidates) # Compute the diff difference = [ x for x in candidates if x.lower() not in [z['name'].lower() for z in local] ] # To get the version we need to call pypi but that's too risky to do # on every call so, for now, we go with the latest version. # See https://goo.gl/3nJLMq print(json.dumps([{'version': '*', 'name': name} for name in difference]))
def test_get_use_local_only(self): """ 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 """ # should find only docopt and requests imports_with_info = pipreqs.get_import_local(self.modules) for item in imports_with_info: self.assertTrue(item['name'].lower() in self.local)
def get_formatted_imports(self): candidates = pi.get_pkg_names(self.get_imports()) pypi_server = "https://pypi.python.org/pypi/" proxy = None local = pi.get_import_local(candidates) # Get packages that were not found locally difference = [x for x in candidates if x.lower() not in [z['name'].lower() for z in local]] imports = local + pi.get_imports_info(difference, proxy=proxy, pypi_server=pypi_server) return imports
def collect_reqs_specific(config, prompt=False, cwd='.'): if prompt: _prompt_and_clean(cwd) candidates = pipreqs.get_all_imports( str(cwd), extra_ignore_dirs=config.pipreqs_ignore) candidates = pipreqs.get_pkg_names(candidates) local = pipreqs.get_import_local(candidates) difference = [ x for x in candidates if x.lower() not in [z['name'].lower() for z in local] ] imports = local + pipreqs.get_imports_info(difference) reqs = [ f"{item['name']}=={item['version']}" for item in imports if 'INFO' not in item ] return reqs
from setuptools import setup, find_packages from pipreqs.pipreqs import get_all_imports, get_pkg_names, get_import_local reqs = get_import_local(get_pkg_names(get_all_imports('./', encoding='utf-8')), encoding='utf-8') reqs = list(map(lambda req: '{}>={}'.format(req['name'], req['version']), reqs)) with open('requirements.txt', mode='w', encoding='utf-8') as f: f.write('\n'.join(reqs)) setup( name='py_bootstrap', version='0.0.15', description=('python端启动器'), long_description_content_type="text/markdown", long_description=open('README.md', encoding='utf-8').read(), author='zouwendi', author_email='*****@*****.**', maintainer='zouwendi', maintainer_email='*****@*****.**', license='GPL3 License', packages=find_packages(), platforms=["all"], url='https://github.com/MyCupOfTeaOo/py_bootstrap', install_requires=reqs, classifiers=[ 'Development Status :: 4 - Beta', 'Operating System :: OS Independent', 'Intended Audience :: Developers', 'Programming Language :: Python', 'Programming Language :: Python :: Implementation', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.4',
def test_get_use_local_only(self): # should find only docopt and requests imports_with_info = pipreqs.get_import_local(self.modules) self.assertEqual(len(imports_with_info), 2)
def get_import_list(path): candidates = pipreqs.get_all_imports(path) candidates = pipreqs.get_pkg_names(candidates) imports = pipreqs.get_import_local(candidates) return imports
def test_get_use_local_only(self): # should find only docopt and requests imports_with_info = pipreqs.get_import_local(self.modules) for item in imports_with_info: self.assertTrue(item['name'].lower() in self.local)