mirror of
https://github.com/bndr/pipreqs.git
synced 2025-06-06 03:25:21 +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 ast
|
||||
import traceback
|
||||
from codecs import open
|
||||
|
||||
from docopt import docopt
|
||||
import requests
|
||||
from yarg import json2package
|
||||
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 = [
|
||||
re.compile(r'^import (.+)$'),
|
||||
@ -190,6 +202,10 @@ def get_imports_info(
|
||||
logging.debug(
|
||||
'Package %s does not exist or network problems', item)
|
||||
continue
|
||||
except UnicodeDecodeError:
|
||||
logging.debug(
|
||||
'Package %s could not be read from server', item)
|
||||
continue
|
||||
result.append({'name': item, 'version': data.latest_release_id})
|
||||
return result
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user