mirror of
https://github.com/bndr/pipreqs.git
synced 2025-06-07 03:55:22 +00:00
[pipreqs/pipreqs.py] Use codec
to get an open
with encoding
argument ; fix __version__
read (import cannot work) ; don't crash on UnicodeDecodeError
This commit is contained in:
parent
a593d27e3d
commit
ff846fde1b
@ -43,12 +43,24 @@ import re
|
|||||||
import logging
|
import logging
|
||||||
import ast
|
import ast
|
||||||
import traceback
|
import traceback
|
||||||
|
from codecs import open
|
||||||
|
|
||||||
from docopt import docopt
|
from docopt import docopt
|
||||||
import requests
|
import requests
|
||||||
from yarg import json2package
|
from yarg import json2package
|
||||||
from yarg.exceptions import HTTPError
|
from yarg.exceptions import HTTPError
|
||||||
|
|
||||||
from pipreqs import __version__
|
if sys.version[0] == "2":
|
||||||
|
from itertools import imap as map, ifilter as filter
|
||||||
|
|
||||||
|
with open(os.path.join(os.path.dirname(__file__), "__init__.py"), "rt") as f:
|
||||||
|
__version__ = next(map(
|
||||||
|
lambda buf: next(map(lambda e: e.value.s, ast.parse(buf).body)),
|
||||||
|
filter(
|
||||||
|
lambda line: line.startswith("__version__"),
|
||||||
|
f,
|
||||||
|
),
|
||||||
|
))
|
||||||
|
|
||||||
REGEXP = [
|
REGEXP = [
|
||||||
re.compile(r'^import (.+)$'),
|
re.compile(r'^import (.+)$'),
|
||||||
@ -190,6 +202,10 @@ def get_imports_info(
|
|||||||
logging.debug(
|
logging.debug(
|
||||||
'Package %s does not exist or network problems', item)
|
'Package %s does not exist or network problems', item)
|
||||||
continue
|
continue
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
logging.debug(
|
||||||
|
'Package %s could not be read from server', item)
|
||||||
|
continue
|
||||||
result.append({'name': item, 'version': data.latest_release_id})
|
result.append({'name': item, 'version': data.latest_release_id})
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user