Skip to content

Commit bd36494

Browse files
authored
Add temporary method for skipping submodule checkout (#3821)
* Add temporary method for skipping submodule checkout This adds a project feature that allows for a project to specify that they would like to skip submodule installation. Currently we are forcing all submodules to be checked out, so this fails on private submodules. Refs readthedocs/readthedocs-build#30 * Also protect git clone * Lint fixes
1 parent 2a79250 commit bd36494

File tree

4 files changed

+52
-7
lines changed

4 files changed

+52
-7
lines changed

readthedocs/projects/models.py

+2
Original file line numberDiff line numberDiff line change
@@ -1067,12 +1067,14 @@ def add_features(sender, **kwargs):
10671067
USE_SETUPTOOLS_LATEST = 'use_setuptools_latest'
10681068
ALLOW_DEPRECATED_WEBHOOKS = 'allow_deprecated_webhooks'
10691069
PIP_ALWAYS_UPGRADE = 'pip_always_upgrade'
1070+
SKIP_SUBMODULES = 'skip_submodules'
10701071

10711072
FEATURES = (
10721073
(USE_SPHINX_LATEST, _('Use latest version of Sphinx')),
10731074
(USE_SETUPTOOLS_LATEST, _('Use latest version of setuptools')),
10741075
(ALLOW_DEPRECATED_WEBHOOKS, _('Allow deprecated webhook views')),
10751076
(PIP_ALWAYS_UPGRADE, _('Always run pip install --upgrade')),
1077+
(SKIP_SUBMODULES, _('Skip git submodule checkout')),
10761078
)
10771079

10781080
projects = models.ManyToManyField(

readthedocs/rtd_tests/tests/test_backend.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
from os.path import exists
33

44
from django.contrib.auth.models import User
5+
import django_dynamic_fixture as fixture
56

6-
from readthedocs.projects.models import Project
7+
from readthedocs.projects.models import Project, Feature
78
from readthedocs.rtd_tests.base import RTDTestCase
89

910
from readthedocs.rtd_tests.utils import make_test_git, make_test_hg
@@ -82,11 +83,23 @@ def test_check_for_submodules(self):
8283
repo = self.project.vcs_repo()
8384

8485
repo.checkout()
85-
self.assertFalse(repo.submodules_exists())
86+
self.assertFalse(repo.are_submodules_available())
8687

8788
# The submodule branch contains one submodule
8889
repo.checkout('submodule')
89-
self.assertTrue(repo.submodules_exists())
90+
self.assertTrue(repo.are_submodules_available())
91+
92+
def test_skip_submodule_checkout(self):
93+
repo = self.project.vcs_repo()
94+
repo.checkout('submodule')
95+
self.assertTrue(repo.are_submodules_available())
96+
feature = fixture.get(
97+
Feature,
98+
projects=[self.project],
99+
feature_id=Feature.SKIP_SUBMODULES,
100+
)
101+
self.assertTrue(self.project.has_feature(Feature.SKIP_SUBMODULES))
102+
self.assertFalse(repo.are_submodules_available())
90103

91104

92105
class TestHgBackend(RTDTestCase):

readthedocs/vcs_support/backends/git.py

+33-4
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,20 @@ def repo_exists(self):
5454
code, _, _ = self.run('git', 'status', record=False)
5555
return code == 0
5656

57-
def submodules_exists(self):
57+
def are_submodules_available(self):
58+
"""
59+
Test whether git submodule checkout step should be performed.
60+
61+
.. note::
62+
63+
Temporarily, we support skipping these steps as submodule step can
64+
fail if using private submodules. This will eventually be
65+
configureable with our YAML config.
66+
"""
67+
# TODO remove with https://github.com/rtfd/readthedocs-build/issues/30
68+
from readthedocs.projects.models import Feature
69+
if self.project.has_feature(Feature.SKIP_SUBMODULES):
70+
return False
5871
code, out, _ = self.run('git', 'submodule', 'status', record=False)
5972
return code == 0 and bool(out)
6073

@@ -74,7 +87,22 @@ def checkout_revision(self, revision=None):
7487
return [code, out, err]
7588

7689
def clone(self):
77-
code, _, _ = self.run('git', 'clone', '--recursive', self.repo_url, '.')
90+
"""
91+
Clone the repository.
92+
93+
.. note::
94+
95+
Temporarily, we support skipping submodule recursive clone via a
96+
feature flag. This will eventually be configureable with our YAML
97+
config.
98+
"""
99+
# TODO remove with https://github.com/rtfd/readthedocs-build/issues/30
100+
from readthedocs.projects.models import Feature
101+
cmd = ['git', 'clone']
102+
if not self.project.has_feature(Feature.SKIP_SUBMODULES):
103+
cmd.append('--recursive')
104+
cmd.extend([self.repo_url, '.'])
105+
code, _, _ = self.run(*cmd)
78106
if code != 0:
79107
raise RepositoryError
80108

@@ -199,8 +227,9 @@ def checkout(self, identifier=None):
199227
# Clean any remains of previous checkouts
200228
self.run('git', 'clean', '-d', '-f', '-f')
201229

202-
# Update submodules
203-
if self.submodules_exists():
230+
# Update submodules, temporarily allow for skipping submodule checkout
231+
# step for projects need more submodule configuration.
232+
if self.are_submodules_available():
204233
self.run('git', 'submodule', 'sync')
205234
self.run(
206235
'git',

readthedocs/vcs_support/base.py

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class BaseVCS(object):
5252
# pylint: disable=unused-argument
5353
def __init__(self, project, version_slug, environment=None, **kwargs):
5454
self.default_branch = project.default_branch
55+
self.project = project
5556
self.name = project.name
5657
self.repo_url = project.clean_repo
5758
self.working_dir = project.checkout_path(version_slug)

0 commit comments

Comments
 (0)