From eb7d4b2178e095fd55c8604dd6e123555b1b1ca9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jelmer=20Vernoo=C4=B3?= Date: Sun, 6 Jan 2019 23:49:16 +0000 Subject: [PATCH] Bazaar: Export directly from the remote branch. This significantly improves performance, since it allows the remote server to directly stream a tarball that just contains the requested revision rather than the full repository contents. --- .travis.yml | 4 ++++ news/5443.feature | 1 + src/pip/_internal/vcs/bazaar.py | 13 +++++-------- tests/functional/test_vcs_bazaar.py | 25 +++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 news/5443.feature create mode 100644 tests/functional/test_vcs_bazaar.py diff --git a/.travis.yml b/.travis.yml index 430dd76db..bb64a6123 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,10 @@ language: python cache: pip dist: xenial python: 3.6 +addons: + apt: + packages: + - bzr stages: - primary diff --git a/news/5443.feature b/news/5443.feature new file mode 100644 index 000000000..4e1215bef --- /dev/null +++ b/news/5443.feature @@ -0,0 +1 @@ +Avoid creating an unnecessary local clone of a Bazaar branch when exporting. diff --git a/src/pip/_internal/vcs/bazaar.py b/src/pip/_internal/vcs/bazaar.py index 4c6ac79d1..93456d5cd 100644 --- a/src/pip/_internal/vcs/bazaar.py +++ b/src/pip/_internal/vcs/bazaar.py @@ -9,7 +9,6 @@ from pip._internal.download import path_to_url from pip._internal.utils.misc import ( display_path, make_vcs_requirement_url, rmtree, ) -from pip._internal.utils.temp_dir import TempDirectory from pip._internal.vcs import VersionControl, vcs logger = logging.getLogger(__name__) @@ -42,13 +41,11 @@ class Bazaar(VersionControl): if os.path.exists(location): rmtree(location) - with TempDirectory(kind="export") as temp_dir: - self.unpack(temp_dir.path) - - self.run_command( - ['export', location], - cwd=temp_dir.path, show_stdout=False, - ) + url, rev_options = self.get_url_rev_options(self.url) + self.run_command( + ['export', location, url] + rev_options.to_args(), + show_stdout=False, + ) def fetch_new(self, dest, url, rev_options): rev_display = rev_options.to_display() diff --git a/tests/functional/test_vcs_bazaar.py b/tests/functional/test_vcs_bazaar.py new file mode 100644 index 000000000..8852cdc63 --- /dev/null +++ b/tests/functional/test_vcs_bazaar.py @@ -0,0 +1,25 @@ +""" +Contains functional tests of the Bazaar class. +""" + +import os + +from pip._internal.vcs.bazaar import Bazaar +from tests.lib import _test_path_to_file_url, _vcs_add, create_file, need_bzr + + +@need_bzr +def test_export(script, tmpdir): + """Test that a Bazaar branch can be exported.""" + branch_path = tmpdir / 'test-branch' + branch_path.mkdir() + + create_file(branch_path / 'test_file', 'something') + + _vcs_add(script, str(branch_path), vcs='bazaar') + + bzr = Bazaar('bzr+' + _test_path_to_file_url(branch_path)) + export_dir = str(tmpdir / 'export') + bzr.export(export_dir) + + assert os.listdir(export_dir) == ['test_file']