mirror of
https://github.com/bndr/pipreqs.git
synced 2025-06-07 03:55:22 +00:00
feat(cli): add --encoding parameter for open()
This commit is contained in:
parent
e0137f2245
commit
195565b50c
@ -6,12 +6,13 @@ Usage:
|
|||||||
pipreqs [options] <path>
|
pipreqs [options] <path>
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
--use-local Use ONLY local package info instead of querying PyPI
|
--use-local Use ONLY local package info instead of querying PyPI
|
||||||
--pypi-server Use custom PyPi server
|
--pypi-server Use custom PyPi server
|
||||||
--proxy Use Proxy, parameter will be passed to requests library
|
--proxy Use Proxy, parameter will be passed to requests library
|
||||||
--debug Print debug information
|
--debug Print debug information
|
||||||
--savepath <file> Save the list of requirements in the given file
|
--encoding <charset> Use encoding parameter for file open
|
||||||
--force Overwrite existing requirements.txt
|
--savepath <file> Save the list of requirements in the given file
|
||||||
|
--force Overwrite existing requirements.txt
|
||||||
"""
|
"""
|
||||||
from __future__ import print_function, absolute_import
|
from __future__ import print_function, absolute_import
|
||||||
import os
|
import os
|
||||||
@ -32,7 +33,7 @@ REGEXP = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def get_all_imports(path):
|
def get_all_imports(path, encoding=None):
|
||||||
imports = []
|
imports = []
|
||||||
candidates = []
|
candidates = []
|
||||||
ignore_dirs = [".hg", ".svn", ".git", "__pycache__", "env"]
|
ignore_dirs = [".hg", ".svn", ".git", "__pycache__", "env"]
|
||||||
@ -45,7 +46,7 @@ def get_all_imports(path):
|
|||||||
|
|
||||||
candidates += [os.path.splitext(fn)[0] for fn in files]
|
candidates += [os.path.splitext(fn)[0] for fn in files]
|
||||||
for file_name in files:
|
for file_name in files:
|
||||||
with open(os.path.join(root, file_name), "r") as f:
|
with open(os.path.join(root, file_name), "r", encoding=encoding) as f:
|
||||||
lines = filter(
|
lines = filter(
|
||||||
filter_line, map(lambda l: l.partition("#")[0].strip(), f))
|
filter_line, map(lambda l: l.partition("#")[0].strip(), f))
|
||||||
for line in lines:
|
for line in lines:
|
||||||
@ -162,7 +163,8 @@ def join(f):
|
|||||||
|
|
||||||
|
|
||||||
def init(args):
|
def init(args):
|
||||||
candidates = get_all_imports(args['<path>'])
|
encoding = args.get('encoding')
|
||||||
|
candidates = get_all_imports(args['<path>'], encoding=encoding)
|
||||||
candidates = get_pkg_names(candidates)
|
candidates = get_pkg_names(candidates)
|
||||||
logging.debug("Found imports: " + ", ".join(candidates))
|
logging.debug("Found imports: " + ", ".join(candidates))
|
||||||
pypi_server = "https://pypi.python.org/pypi/"
|
pypi_server = "https://pypi.python.org/pypi/"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user