You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

72 lines
2.3 KiB

  1. from __future__ import absolute_import
  2. import sys
  3. import pip
  4. from pip.basecommand import Command
  5. from pip.operations.freeze import freeze
  6. from pip.wheel import WheelCache
  7. class FreezeCommand(Command):
  8. """
  9. Output installed packages in requirements format.
  10. packages are listed in a case-insensitive sorted order.
  11. """
  12. name = 'freeze'
  13. usage = """
  14. %prog [options]"""
  15. summary = 'Output installed packages in requirements format.'
  16. log_streams = ("ext://sys.stderr", "ext://sys.stderr")
  17. def __init__(self, *args, **kw):
  18. super(FreezeCommand, self).__init__(*args, **kw)
  19. self.cmd_opts.add_option(
  20. '-r', '--requirement',
  21. dest='requirement',
  22. action='store',
  23. default=None,
  24. metavar='file',
  25. help="Use the order in the given requirements file and its "
  26. "comments when generating output.")
  27. self.cmd_opts.add_option(
  28. '-f', '--find-links',
  29. dest='find_links',
  30. action='append',
  31. default=[],
  32. metavar='URL',
  33. help='URL for finding packages, which will be added to the '
  34. 'output.')
  35. self.cmd_opts.add_option(
  36. '-l', '--local',
  37. dest='local',
  38. action='store_true',
  39. default=False,
  40. help='If in a virtualenv that has global access, do not output '
  41. 'globally-installed packages.')
  42. self.cmd_opts.add_option(
  43. '--user',
  44. dest='user',
  45. action='store_true',
  46. default=False,
  47. help='Only output packages installed in user-site.')
  48. self.parser.insert_option_group(0, self.cmd_opts)
  49. def run(self, options, args):
  50. format_control = pip.index.FormatControl(set(), set())
  51. wheel_cache = WheelCache(options.cache_dir, format_control)
  52. freeze_kwargs = dict(
  53. requirement=options.requirement,
  54. find_links=options.find_links,
  55. local_only=options.local,
  56. user_only=options.user,
  57. skip_regex=options.skip_requirements_regex,
  58. isolated=options.isolated_mode,
  59. wheel_cache=wheel_cache)
  60. for line in freeze(**freeze_kwargs):
  61. sys.stdout.write(line + '\n')