Skip to content
This repository was archived by the owner on Oct 21, 2022. It is now read-only.

Shallow clone the github head version for client libs#243

Merged
liyanhui1228 merged 1 commit intoGoogleCloudPlatform:masterfrom
liyanhui1228:shallow_clone
Feb 12, 2019
Merged

Shallow clone the github head version for client libs#243
liyanhui1228 merged 1 commit intoGoogleCloudPlatform:masterfrom
liyanhui1228:shallow_clone

Conversation

@liyanhui1228
Copy link
Copy Markdown
Member

An alternative for #241

@liyanhui1228 liyanhui1228 merged commit 036c673 into GoogleCloudPlatform:master Feb 12, 2019
@liyanhui1228 liyanhui1228 deleted the shallow_clone branch February 12, 2019 22:48
PYPI_URL = 'https://pypi.org/pypi/'
CONTAINER_WITH_PKG = "checker"
TIME_OUT = 300 # seconds
GITHUB_CLIENTLIBS_PREFIX = 'git+git://github.com/googleapis/' \
Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Member Author

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.

output)
# If there is cloud client libraries, install it from source.
# Else install it from PyPI.
for pkg in self._packages:
Copy link
Copy Markdown
Contributor

@brianquinlan brianquinlan Feb 14, 2019

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

# Shallow clone the repository
shallow_clone_command = ['git', 'clone', '--depth', '1',
CLIENTLIBS_GITHUB_URL]
self._run_command(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants