This repository was archived by the owner on Oct 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Shallow clone the github head version for client libs #243
Merged
liyanhui1228
merged 1 commit into
GoogleCloudPlatform:master
from
liyanhui1228:shallow_clone
Feb 12, 2019
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,9 @@ | |
| PYPI_URL = 'https://pypi.org/pypi/' | ||
| CONTAINER_WITH_PKG = "checker" | ||
| TIME_OUT = 300 # seconds | ||
| GITHUB_CLIENTLIBS_PREFIX = 'git+git://github.com/googleapis/' \ | ||
| 'google-cloud-python.git#subdirectory=' | ||
| CLIENTLIBS_GITHUB_URL = 'https://github.com/googleapis/google-cloud-python.git' | ||
|
|
||
| # Pattern for pip installation errors not related to the package being | ||
| # installed. See: | ||
|
|
@@ -353,24 +356,44 @@ def _build_command(self, subcommands: List[str]): | |
|
|
||
| def _install(self, container: docker.models.containers.Container): | ||
| """Run pip install in the container.""" | ||
| command = self._build_command(['install', '-U'] + self._packages) | ||
| returncode, output = self._run_command( | ||
| container, | ||
| command, | ||
| stdout=False, | ||
| stderr=True, | ||
| raise_on_failure=False) | ||
| if returncode: | ||
| # Checking for environment error | ||
| environment_error = PIP_ENVIRONMENT_ERROR_PATTERN.search(output) | ||
| if environment_error: | ||
| raise PipError(error_msg=environment_error.group('error'), | ||
| command=command, | ||
| returncode=returncode) | ||
|
|
||
| return PipCheckResult(self._packages, | ||
| PipCheckResultType.INSTALL_ERROR, | ||
| output) | ||
| # If there is cloud client libraries, install it from source. | ||
| # Else install it from PyPI. | ||
| for pkg in self._packages: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd structure this a bit differently to make it more readable. def _clone_repo(self, container, repo):
"""<docstring>"""
_, directory = self._run_command(
container,
"echo $(mktemp -d)"
stderr=False,
stdout=True,
raise_on_failure=True)
shallow_clone_command = ['git', 'clone', '--depth', '1', repo, directory]
self._run_command(
container,
shallow_clone_command,
stdout=False,
stderr=True,
raise_on_failure=True)
return directory
def _install(self, container: docker.models.containers.Container):
if any(GITHUB_CLIENTLIBS_PREFIX in pkg for pkg in self._packages):
# The https://github.com/googleapis/google-cloud-python repository is large,
# has a large amount of history and contains many independent packages.
# Installing packages from that repository is quite slow e.g.
# $ time pip install git+git://...
# <result>
# As an optimization, if any provided package is installed from this repository,
# it is first cloned (using --depth=1 to avoid unnecessary history) and then
# installed from local disk e.g.
# $ time git clone --depth=1 ... && pip install ...
# <result>
client_repo_directory = self._clone_repo(CLIENTLIBS_GITHUB_URL)
install_names = []
for pkg in self._packages:
if GITHUB_CLIENTLIBS_PREFIX in pkg:
install_subdirectory = pkg.split(GITHUB_CLIENTLIBS_PREFIX)[1]
install_names.append(os.path.join(client_repo_directory, install_subdirectory))
else:
install_names.append(pkg)
command = self._build_command(['install', '-U'] + install_names)
# Rest is the same.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| if GITHUB_CLIENTLIBS_PREFIX in pkg: | ||
| # Shallow clone the repository | ||
| shallow_clone_command = ['git', 'clone', '--depth', '1', | ||
| CLIENTLIBS_GITHUB_URL] | ||
| self._run_command( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like that we can run this multiple times and every time after the first will fail. I also don't like that we don't check for failures. |
||
| container, | ||
| shallow_clone_command, | ||
| stdout=False, | ||
| stderr=True, | ||
| raise_on_failure=False) | ||
| gh_clientlib = pkg.split(GITHUB_CLIENTLIBS_PREFIX)[1] | ||
| command = self._build_command( | ||
| ['install', '-e', | ||
| 'google-cloud-python/{}'.format(gh_clientlib)]) | ||
| else: | ||
| command = self._build_command(['install', '-U'] + [pkg]) | ||
|
|
||
| returncode, output = self._run_command( | ||
| container, | ||
| command, | ||
| stdout=False, | ||
| stderr=True, | ||
| raise_on_failure=False) | ||
|
|
||
| if returncode: | ||
| # Checking for environment error | ||
| environment_error = PIP_ENVIRONMENT_ERROR_PATTERN.search( | ||
| output) | ||
| if environment_error: | ||
| raise PipError(error_msg=environment_error.group('error'), | ||
| command=command, | ||
| returncode=returncode) | ||
| return PipCheckResult(self._packages, | ||
| PipCheckResultType.INSTALL_ERROR, | ||
| output) | ||
| return PipCheckResult(self._packages, PipCheckResultType.SUCCESS) | ||
|
|
||
| def _check(self, container: docker.models.containers.Container): | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really called client libs? I thought that was https://github.com/googleapis/google-api-python-client
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's https://github.com/googleapis/google-cloud-python actually, I just call it clientlibs for short. That one is the discovery based APIs.