From ea680f204fb0e48789710c22c8f597a9bf01bc16 Mon Sep 17 00:00:00 2001 From: Richard Ipsum Date: Fri, 17 Oct 2014 12:02:57 +0100 Subject: Add --list-dependencies option --- pip/commands/install.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pip/commands/install.py b/pip/commands/install.py index cbf22a086..4589130cb 100644 --- a/pip/commands/install.py +++ b/pip/commands/install.py @@ -160,6 +160,13 @@ class InstallCommand(Command): cmd_opts.add_option(cmdoptions.no_clean.make()) + cmd_opts.add_option( + '--list-dependencies', + dest="list_dependencies", + metavar="file", + default=None, + help="Don't install anything, write all dependencies into ") + index_opts = cmdoptions.make_option_group(cmdoptions.index_group, self.parser) self.parser.insert_option_group(0, index_opts) @@ -183,6 +190,14 @@ class InstallCommand(Command): session=session, ) + def write_dependencies_to_file(self, path, requirements): + def strspecs(specs): + return ''.join(['%s%s,' % (op, ver) for (op, ver) in specs]).rstrip(',') + + with open(path, 'w') as f: + for req in requirements.values(): + f.write('%s%s\n' % (req.name, strspecs(req.req.specs))) + def run(self, options, args): if ( @@ -252,6 +267,7 @@ class InstallCommand(Command): session=session, pycompile=options.compile, ) + for name in args: requirement_set.add_requirement( InstallRequirement.from_line(name, None)) @@ -274,11 +290,17 @@ class InstallCommand(Command): return try: + # Obtain requirement set if not options.no_download: requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle) else: requirement_set.locate_files() + if options.list_dependencies: + self.write_dependencies_to_file(options.list_dependencies, + requirement_set.requirements) + return + if not options.no_install and not self.bundle: requirement_set.install(install_options, global_options, root=options.root_path) installed = ' '.join([req.name for req in -- cgit v1.2.1