mirror of
https://github.com/bndr/pipreqs.git
synced 2025-06-06 19:45:22 +00:00
fix pep8 linting issues
This commit is contained in:
parent
bb61883079
commit
5537bcd217
@ -176,7 +176,11 @@ def get_imports_info(
|
|||||||
|
|
||||||
for item in imports:
|
for item in imports:
|
||||||
try:
|
try:
|
||||||
logging.warning('Import named "%s" not found locally. Trying to resolve it at the PyPI server.', item)
|
logging.warning(
|
||||||
|
'Import named "%s" not found locally.'
|
||||||
|
'Trying to resolve it at the PyPI server.',
|
||||||
|
item
|
||||||
|
)
|
||||||
response = requests.get(
|
response = requests.get(
|
||||||
"{0}{1}/json".format(pypi_server, item), proxies=proxy)
|
"{0}{1}/json".format(pypi_server, item), proxies=proxy)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
@ -191,7 +195,10 @@ def get_imports_info(
|
|||||||
logging.warning(
|
logging.warning(
|
||||||
'Package "%s" does not exist or network problems', item)
|
'Package "%s" does not exist or network problems', item)
|
||||||
continue
|
continue
|
||||||
logging.warning('Import named "%s" was resolved to "%s:%s" package (%s).\nPlease, verify manually the final list of requirements.txt to avoid possible dependency confusions.',
|
logging.warning(
|
||||||
|
'Import named "%s" was resolved to "%s:%s" package (%s).'
|
||||||
|
'Please, verify manually the final list of requirements.txt'
|
||||||
|
'to avoid possible dependency confusions.',
|
||||||
item,
|
item,
|
||||||
data.name,
|
data.name,
|
||||||
data.latest_release_id,
|
data.latest_release_id,
|
||||||
@ -217,13 +224,16 @@ def get_locally_installed_packages(encoding=None):
|
|||||||
# TODO: What errors do we intend to suppress here?
|
# TODO: What errors do we intend to suppress here?
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# filter off explicitly ignored top-level modules, such as test, egg, etc.
|
# filter off explicitly ignored top-level modules
|
||||||
|
# such as test, egg, etc.
|
||||||
filtered_top_level_modules = list()
|
filtered_top_level_modules = list()
|
||||||
|
|
||||||
for module in top_level_modules:
|
for module in top_level_modules:
|
||||||
if ((module not in ignore) and
|
if (
|
||||||
(package[0] not in ignore)):
|
(module not in ignore) and
|
||||||
# append valid exported top level modules to the final list
|
(package[0] not in ignore)
|
||||||
|
):
|
||||||
|
# append exported top level modules to the list
|
||||||
filtered_top_level_modules.append(module)
|
filtered_top_level_modules.append(module)
|
||||||
|
|
||||||
version = None
|
version = None
|
||||||
@ -231,7 +241,8 @@ def get_locally_installed_packages(encoding=None):
|
|||||||
version = package[1].replace(
|
version = package[1].replace(
|
||||||
".dist", "").replace(".egg", "")
|
".dist", "").replace(".egg", "")
|
||||||
|
|
||||||
# append package: top_level_modules pairs instead of top_level_module: package pairs
|
# append package: top_level_modules pairs
|
||||||
|
# instead of top_level_module: package pairs
|
||||||
packages.append({
|
packages.append({
|
||||||
'name': package[0],
|
'name': package[0],
|
||||||
'version': version,
|
'version': version,
|
||||||
@ -246,16 +257,17 @@ def get_import_local(imports, encoding=None):
|
|||||||
for item in imports:
|
for item in imports:
|
||||||
# search through local packages
|
# search through local packages
|
||||||
for package in local:
|
for package in local:
|
||||||
# if candidate import name matches export name inside the package exports
|
# if candidate import name matches export name
|
||||||
# or candidate import name equals to the package name
|
# or candidate import name equals to the package name
|
||||||
# append it to the result
|
# append it to the result
|
||||||
if item in package['exports'] or item == package['name']:
|
if item in package['exports'] or item == package['name']:
|
||||||
result.append(package)
|
result.append(package)
|
||||||
|
|
||||||
# removing duplicates of package/version
|
# removing duplicates of package/version
|
||||||
# had to use second method instead of the first, listed here, because we have a list in the 'exports' field
|
# had to use second method instead of the previous one,
|
||||||
|
# because we have a list in the 'exports' field
|
||||||
# https://stackoverflow.com/questions/9427163/remove-duplicate-dict-in-list-in-python
|
# https://stackoverflow.com/questions/9427163/remove-duplicate-dict-in-list-in-python
|
||||||
result_unique = [i for n, i in enumerate(result) if i not in result[n + 1:]]
|
result_unique = [i for n, i in enumerate(result) if i not in result[n+1:]]
|
||||||
|
|
||||||
return result_unique
|
return result_unique
|
||||||
|
|
||||||
@ -462,17 +474,18 @@ def init(args):
|
|||||||
logging.debug("Getting packages information from Local/PyPI")
|
logging.debug("Getting packages information from Local/PyPI")
|
||||||
local = get_import_local(candidates, encoding=encoding)
|
local = get_import_local(candidates, encoding=encoding)
|
||||||
|
|
||||||
# check if candidate name is found in the list of exported modules, installed locally
|
# check if candidate name is found in
|
||||||
|
# the list of exported modules, installed locally
|
||||||
# and the package name is not in the list of local module names
|
# and the package name is not in the list of local module names
|
||||||
# it add to difference
|
# it add to difference
|
||||||
difference = [x for x in candidates
|
difference = [x for x in candidates if
|
||||||
if
|
|
||||||
# aggregate all export lists into one
|
# aggregate all export lists into one
|
||||||
# flatten the list
|
# flatten the list
|
||||||
|
# check if candidate is in exports
|
||||||
x.lower() not in [y for x in local for y in x['exports']]
|
x.lower() not in [y for x in local for y in x['exports']]
|
||||||
and
|
and
|
||||||
x.lower() not in [x['name'] for x in local]
|
# check if candidate is package names
|
||||||
]
|
x.lower() not in [x['name'] for x in local]]
|
||||||
|
|
||||||
imports = local + get_imports_info(difference,
|
imports = local + get_imports_info(difference,
|
||||||
proxy=proxy,
|
proxy=proxy,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user