mirror of
https://github.com/bndr/pipreqs.git
synced 2025-06-07 12:05:33 +00:00
added support for >= instead of ==
using flag --gt (gt = greater than)
This commit is contained in:
parent
5707a39df6
commit
64845c574e
@ -12,6 +12,7 @@ Arguments:
|
|||||||
directory).
|
directory).
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
|
--gt Replace format from name==version to name>=version
|
||||||
--use-local Use ONLY local package info instead of querying PyPI.
|
--use-local Use ONLY local package info instead of querying PyPI.
|
||||||
--pypi-server <url> Use custom PyPi server.
|
--pypi-server <url> Use custom PyPi server.
|
||||||
--proxy <url> Use Proxy, parameter will be passed to requests
|
--proxy <url> Use Proxy, parameter will be passed to requests
|
||||||
@ -160,21 +161,21 @@ def filter_line(l):
|
|||||||
return len(l) > 0 and l[0] != "#"
|
return len(l) > 0 and l[0] != "#"
|
||||||
|
|
||||||
|
|
||||||
def generate_requirements_file(path, imports):
|
def generate_requirements_file(path, imports, equal_fmt):
|
||||||
with _open(path, "w") as out_file:
|
with _open(path, "w") as out_file:
|
||||||
logging.debug('Writing {num} requirements: {imports} to {file}'.format(
|
logging.debug('Writing {num} requirements: {imports} to {file}'.format(
|
||||||
num=len(imports),
|
num=len(imports),
|
||||||
file=path,
|
file=path,
|
||||||
imports=", ".join([x['name'] for x in imports])
|
imports=", ".join([x['name'] for x in imports])
|
||||||
))
|
))
|
||||||
fmt = '{name}=={version}'
|
fmt = '{name}%s{version}' % equal_fmt
|
||||||
out_file.write('\n'.join(
|
out_file.write('\n'.join(
|
||||||
fmt.format(**item) if item['version'] else '{name}'.format(**item)
|
fmt.format(**item) if item['version'] else '{name}'.format(**item)
|
||||||
for item in imports) + '\n')
|
for item in imports) + '\n')
|
||||||
|
|
||||||
|
|
||||||
def output_requirements(imports):
|
def output_requirements(imports, equal_fmt):
|
||||||
generate_requirements_file('-', imports)
|
generate_requirements_file('-', imports, equal_fmt)
|
||||||
|
|
||||||
|
|
||||||
def get_imports_info(
|
def get_imports_info(
|
||||||
@ -394,12 +395,13 @@ def init(args):
|
|||||||
extra_ignore_dirs = args.get('--ignore')
|
extra_ignore_dirs = args.get('--ignore')
|
||||||
follow_links = not args.get('--no-follow-links')
|
follow_links = not args.get('--no-follow-links')
|
||||||
input_path = args['<path>']
|
input_path = args['<path>']
|
||||||
|
is_gt = args.get("--gt")
|
||||||
|
equal_fmt = ">=" if is_gt else "=="
|
||||||
if input_path is None:
|
if input_path is None:
|
||||||
input_path = os.path.abspath(os.curdir)
|
input_path = os.path.abspath(os.curdir)
|
||||||
|
|
||||||
if extra_ignore_dirs:
|
if extra_ignore_dirs:
|
||||||
extra_ignore_dirs = extra_ignore_dirs.split(',')
|
extra_ignore_dirs = extra_ignore_dirs.split(',')
|
||||||
|
|
||||||
candidates = get_all_imports(input_path,
|
candidates = get_all_imports(input_path,
|
||||||
encoding=encoding,
|
encoding=encoding,
|
||||||
extra_ignore_dirs=extra_ignore_dirs,
|
extra_ignore_dirs=extra_ignore_dirs,
|
||||||
@ -448,10 +450,10 @@ def init(args):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if args["--print"]:
|
if args["--print"]:
|
||||||
output_requirements(imports)
|
output_requirements(imports, equal_fmt)
|
||||||
logging.info("Successfully output requirements")
|
logging.info("Successfully output requirements")
|
||||||
else:
|
else:
|
||||||
generate_requirements_file(path, imports)
|
generate_requirements_file(path, imports, equal_fmt)
|
||||||
logging.info("Successfully saved requirements file in " + path)
|
logging.info("Successfully saved requirements file in " + path)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user