def test_get_imports_info(self): imports = pipreqs.get_all_imports(self.project) with_info = pipreqs.get_imports_info(imports) # Should contain only 4 Elements without the "nonexistendmodule" self.assertEqual(len(with_info),4, "Length of imports array with info is wrong") for item in with_info: self.assertTrue(item['name'] in self.modules, "Import item appears to be missing")
def _set_imports(self): """Set required imports for the python script at self.script_path.""" # Get the names of packages imported in the script import_names = pipreqs.get_all_imports( os.path.dirname(self.script_path)) # Of those names, store the ones that are available via pip self._pip_imports = pipreqs.get_imports_info(import_names) if not self._pin_pip_versions: self._pip_imports = [{ "name": item["name"], "version": None } for item in self._pip_imports] # If some imports were left out, store their names pip_names = set([i["name"] for i in self.pip_imports]) self._missing_imports = list(set(import_names) - pip_names) if len(import_names) != (len(self.pip_imports) + len(self.github_installs)): # And warn the user mod_logger.warning( "Warning, some imports not found by pipreqs. You will " "need to edit the Dockerfile by hand, e.g by installing " "from github. You need to install the following packages " "{missing!s}".format(missing=self.missing_imports))
def __init__(self, tor=False, info={}, driver=False, log = {}, errorlog={}): self.path = os.path.dirname(os.path.realpath(__file__)) #le chemin du dossier où est exécuté le fichier self.info = info self.tor = tor self.log = log self.errorlog = errorlog self.programm = { 'software': "Python", 'software_version': platform.python_version(), 'modules': pipreqs.get_imports_info(pipreqs.get_all_imports(self.path, encoding='utf-8')) } self.system = { 'os_name': platform.system(), 'computer_name': platform.node(), 'os_release': platform.release(), 'os_version': platform.version(), 'processor': platform.processor() } self.ip = '' if driver: try: driver.get('http://httpbin.org/ip') content = driver.find_element_by_xpath("//body").text self.ip = json.loads(content)['origin'] except: print('Documentation - erreur à retrouver l\'adresse IP publique.') else: if self.tor: proxies = {'http': 'socks5h://127.0.0.1:9050', 'https': 'socks5h://127.0.0.1:9050'} else: proxies = {} try: self.ip = requests.get('http://httpbin.org/ip', proxies=proxies).json()['origin'] #utilisation du service ipinfo.io except: print('Documentation - erreur à retrouver l\'adresse IP publique.')
def test_get_imports_info(self): imports = pipreqs.get_all_imports(self.project) with_info = pipreqs.get_imports_info(imports) # Should contain only 5 Elements without the "nonexistendmodule" self.assertEqual(len(with_info), 10) for item in with_info: self.assertTrue(item['name'].lower( ) in self.modules, "Import item appears to be missing " + item['name'])
def test_get_imports_info(self): imports = pipreqs.get_all_imports(self.project) with_info = pipreqs.get_imports_info(imports) # Should contain only 4 Elements without the "nonexistendmodule" self.assertEqual(len(with_info), 4, "Length of imports array with info is wrong") for item in with_info: self.assertTrue(item['name'] in self.modules, "Import item appears to be missing")
def test_get_imports_info(self): """ Test to see that the right number of packages were found on PyPI """ 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) for item in with_info: self.assertTrue( item['name'].lower() in self.modules, "Import item appears to be missing " + item['name'])
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 get_dependencies(cls, path: Optional[str] = None) -> List[InstalledPackage]: all_imports = pipreqs.get_all_imports(path or '.') pkg_names = pipreqs.get_pkg_names(all_imports) public_pkg_names = [ p['name'] for p in pipreqs.get_imports_info(pkg_names) ] installed_packages = [ InstalledPackage.from_name(name, private=name not in public_pkg_names) for name in pkg_names ] return [ installed_package for installed_package in installed_packages if installed_package ]
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
def _set_imports(self): """Set required imports for the python script at self.script_path""" # Get the names of packages imported in the script import_names = pipreqs.get_all_imports( os.path.dirname(self.script_path)) # Of those names, store that ones that are available via pip self._pip_imports = pipreqs.get_imports_info(import_names) # If some imports were left out, store their names pip_names = set([i['name'] for i in self.pip_imports]) self._missing_imports = list(set(import_names) - pip_names) if len(import_names) != (len(self.pip_imports) + len(self.github_installs)): # And warn the user mod_logger.warning( 'Warning, some imports not found by pipreqs. You will ' 'need to edit the Dockerfile by hand, e.g by installing ' 'from github. You need to install the following packages ' '{missing!s}'.format(missing=self.missing_imports))