mirror of https://github.com/pypa/pip
Merge 1bfb36a5fe
into a15dd75d98
This commit is contained in:
commit
3df249b121
|
@ -81,6 +81,21 @@ class FreezeCommand(Command):
|
|||
action="store_true",
|
||||
help="Exclude editable package from output.",
|
||||
)
|
||||
self.cmd_opts.add_option(
|
||||
"--exclude-dependencies",
|
||||
dest="exclude_dependencies",
|
||||
action="store_true",
|
||||
help="Exclude dependency packages from output.",
|
||||
)
|
||||
self.cmd_opts.add_option(
|
||||
"--user-requested",
|
||||
dest="user_requested",
|
||||
action="store_true",
|
||||
help=(
|
||||
"List packages that were explicitly requested by user, either directly "
|
||||
"via a command line argument or indirectly via a requirements file."
|
||||
),
|
||||
)
|
||||
self.cmd_opts.add_option(cmdoptions.list_exclude())
|
||||
|
||||
self.parser.insert_option_group(0, self.cmd_opts)
|
||||
|
@ -103,6 +118,8 @@ class FreezeCommand(Command):
|
|||
isolated=options.isolated_mode,
|
||||
skip=skip,
|
||||
exclude_editable=options.exclude_editable,
|
||||
exclude_dependencies=options.exclude_dependencies,
|
||||
user_requested=options.user_requested,
|
||||
):
|
||||
sys.stdout.write(line + "\n")
|
||||
return SUCCESS
|
||||
|
|
|
@ -129,6 +129,21 @@ class ListCommand(IndexGroupCommand):
|
|||
help="Include editable package from output.",
|
||||
default=True,
|
||||
)
|
||||
self.cmd_opts.add_option(
|
||||
"--exclude-dependencies",
|
||||
dest="exclude_dependencies",
|
||||
action="store_true",
|
||||
help="Exclude dependency packages from output.",
|
||||
)
|
||||
self.cmd_opts.add_option(
|
||||
"--user-requested",
|
||||
dest="user_requested",
|
||||
action="store_true",
|
||||
help=(
|
||||
"List packages that were explicitly requested by user, either directly "
|
||||
"via a command line argument or indirectly via a requirements file."
|
||||
),
|
||||
)
|
||||
self.cmd_opts.add_option(cmdoptions.list_exclude())
|
||||
index_opts = cmdoptions.make_option_group(cmdoptions.index_group, self.parser)
|
||||
|
||||
|
@ -176,6 +191,8 @@ class ListCommand(IndexGroupCommand):
|
|||
user_only=options.user,
|
||||
editables_only=options.editable,
|
||||
include_editables=options.include_editable,
|
||||
exclude_dependencies=options.exclude_dependencies,
|
||||
user_requested=options.user_requested,
|
||||
skip=skip,
|
||||
)
|
||||
]
|
||||
|
|
|
@ -649,6 +649,8 @@ class BaseEnvironment:
|
|||
include_editables: bool = True,
|
||||
editables_only: bool = False,
|
||||
user_only: bool = False,
|
||||
exclude_dependencies: bool = False,
|
||||
user_requested: bool = False,
|
||||
) -> Iterator[BaseDistribution]:
|
||||
"""Return a list of installed distributions.
|
||||
|
||||
|
@ -665,8 +667,25 @@ class BaseEnvironment:
|
|||
:param editables_only: If True, only report editables.
|
||||
:param user_only: If True, only report installations in the user
|
||||
site directory.
|
||||
:param exclude_dependencies: If True, dont't report distributions
|
||||
that are dependencies of other installed distributions.
|
||||
:param user_requested: If True, report only distributions that were
|
||||
explicitly requested by user, either directly via a command line argument
|
||||
or indirectly via a requirements file.
|
||||
"""
|
||||
it = self.iter_all_distributions()
|
||||
if exclude_dependencies:
|
||||
dists = list(self.iter_all_distributions())
|
||||
it = iter(dists)
|
||||
dep_keys = {
|
||||
canonicalize_name(dep.name)
|
||||
for dist in dists
|
||||
for dep in (dist.iter_dependencies() or ())
|
||||
}
|
||||
it = (d for d in it if d.canonical_name not in dep_keys)
|
||||
else:
|
||||
it = self.iter_all_distributions()
|
||||
if user_requested:
|
||||
it = (d for d in it if d.requested)
|
||||
if local_only:
|
||||
it = (d for d in it if d.local)
|
||||
if not include_editables:
|
||||
|
|
|
@ -30,6 +30,8 @@ def freeze(
|
|||
paths: Optional[List[str]] = None,
|
||||
isolated: bool = False,
|
||||
exclude_editable: bool = False,
|
||||
exclude_dependencies: bool = False,
|
||||
user_requested: bool = False,
|
||||
skip: Container[str] = (),
|
||||
) -> Generator[str, None, None]:
|
||||
installations: Dict[str, FrozenRequirement] = {}
|
||||
|
@ -38,6 +40,8 @@ def freeze(
|
|||
local_only=local_only,
|
||||
skip=(),
|
||||
user_only=user_only,
|
||||
exclude_dependencies=exclude_dependencies,
|
||||
user_requested=user_requested,
|
||||
)
|
||||
for dist in dists:
|
||||
req = FrozenRequirement.from_dist(dist)
|
||||
|
|
Loading…
Reference in New Issue