Added full_command argument to to_pip_install_commands.

This is useful if we just want to get the list of pip dependencies and
create our own pip command.
This commit is contained in:
Fabio Manganiello 2023-08-23 02:19:54 +02:00
parent 2bff4c9cf1
commit 1ef0d804db
Signed by: blacklight
GPG key ID: D90FBA7F76362774

View file

@ -331,10 +331,14 @@ class Dependencies:
] ]
) )
def to_pip_install_commands(self) -> Generator[str, None, None]: def to_pip_install_commands(self, full_command=True) -> Generator[str, None, None]:
""" """
Generates the pip commands required to install the given dependencies on Generates the pip commands required to install the given dependencies on
the system. the system.
:param full_command: Whether to return the full pip command to execute
(as a single string) or the list of packages that will be installed
through another script.
""" """
wants_break_system_packages = not ( wants_break_system_packages = not (
# Docker installations shouldn't require --break-system-packages in # Docker installations shouldn't require --break-system-packages in
@ -348,11 +352,20 @@ class Dependencies:
) )
if self.pip: if self.pip:
deps = sorted(self.pip)
if full_command:
yield ( yield (
'pip install -U --no-input --no-cache-dir ' 'pip install -U --no-input --no-cache-dir '
+ ('--break-system-packages ' if wants_break_system_packages else '') + (
+ ' '.join(sorted(self.pip)) '--break-system-packages '
if wants_break_system_packages
else ''
) )
+ ' '.join(deps)
)
else:
for dep in deps:
yield dep
def to_install_commands(self) -> Generator[str, None, None]: def to_install_commands(self) -> Generator[str, None, None]:
""" """
@ -530,7 +543,6 @@ class Manifests:
Get all the manifest objects associated to the extensions declared in a Get all the manifest objects associated to the extensions declared in a
given configuration file. given configuration file.
""" """
import platypush
from platypush.config import Config from platypush.config import Config
conf_args = [] conf_args = []
@ -538,7 +550,7 @@ class Manifests:
conf_args.append(conf_file) conf_args.append(conf_file)
Config.init(*conf_args) Config.init(*conf_args)
app_dir = os.path.dirname(inspect.getfile(platypush)) app_dir = get_src_root()
for name in Config.get_backends().keys(): for name in Config.get_backends().keys():
yield Manifest.from_file( yield Manifest.from_file(