Skip to content

Build: Get installed packages #8123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions readthedocs/doc_builder/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ class BuildCommand(BuildCommandResultMixin):
or ``user``. Defaults to ``RTD_DOCKER_USER``.
:param build_env: build environment to use to execute commands
:param bin_path: binary path to add to PATH resolution
:param bool stdout: Include stdout in the output.
:param bool stderr: Include stderr in the output.
:param description: a more grokable description of the command being run
:param kwargs: allow to subclass this class and extend it
"""
Expand All @@ -97,6 +99,8 @@ def __init__(
user=None,
build_env=None,
bin_path=None,
stdout=True,
stderr=True,
description=None,
record_as_success=False,
**kwargs,
Expand All @@ -115,6 +119,9 @@ def __init__(
self.start_time = None
self.end_time = None

self.stdout = stdout
self.stderr = stderr

self.bin_path = bin_path
self.description = description or ''
self.record_as_success = record_as_success
Expand Down Expand Up @@ -157,8 +164,8 @@ def run(self):
# as we want docker to expand inside the container
cwd=os.path.expandvars(self.cwd),
stdin=None,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
stdout=subprocess.PIPE if self.stdout else None,
stderr=subprocess.STDOUT if self.stderr else None,
env=environment,
)
cmd_stdout, cmd_stderr = proc.communicate()
Expand Down Expand Up @@ -302,8 +309,8 @@ def run(self):
cmd=self.get_wrapped_command(),
environment=self.environment,
user=self.user,
stdout=True,
stderr=True,
stdout=self.stdout,
stderr=self.stderr,
)

cmd_output = client.exec_start(exec_id=exec_cmd['Id'], stream=False)
Expand Down
62 changes: 62 additions & 0 deletions readthedocs/doc_builder/python_environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,30 @@ def install_requirements_file(self, install):
bin_path=self.venv_bin(),
)

def get_installed_packages(self):
args = [
self.venv_bin(filename='python'),
'-m',
'pip',
'list',
# Inlude pre-release versions.
'--pre',
# Don't include global packages if --system-site-packages was used.
'--local',
# List only top packages, not their dependencies.
'--not-required',
'--format',
'json',
]
# TODO: return the output.
self.build_env.run(
*args,
# Don't add warnings to the output.
stderr=False,
cwd=self.checkout_path,
bin_path=self.venv_bin(),
)

def list_packages_installed(self):
"""List packages installed in pip."""
args = [
Expand Down Expand Up @@ -709,6 +733,44 @@ def install_requirements_file(self, install):
# defined by the user, there is nothing to update at this point
pass

def get_installed_packages(self):
args = [
self.conda_bin_name(),
'list',
'--json',
'--name',
self.version.slug,
]
self.build_env.run(
*args,
# Don't add warnings to the output.
stderr=False,
cwd=self.checkout_path,
bin_path=self.venv_bin(),
)
args = [
self.venv_bin(filename='python'),
'-m',
'pip',
'list',
# Inlude pre-release versions.
'--pre',
# Don't include global packages if --system-site-packages was used.
'--local',
# List only top packages, not their dependencies.
'--not-required',
'--format',
'json',
]
# TODO: return the output.
self.build_env.run(
*args,
# Don't add warnings to the output.
stderr=False,
cwd=self.checkout_path,
bin_path=self.venv_bin(),
)

def list_packages_installed(self):
"""List packages installed in conda."""
args = [
Expand Down