-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Do a small builder refactor. #1924
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
Changes from 9 commits
ade1885
9f14fd9
7785bdf
c0e08dd
bccc217
7d2d54b
cd03138
9b6cef6
fbfe56f
0865b36
af81a01
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,12 +108,11 @@ def run(self, pk, version_pk=None, build_pk=None, record=True, docker=False, | |
self.build_force = force | ||
|
||
env_cls = LocalEnvironment | ||
if docker or settings.DOCKER_ENABLE: | ||
env_cls = DockerEnvironment | ||
self.build_env = env_cls(project=self.project, version=self.version, | ||
self.setup_env = env_cls(project=self.project, version=self.version, | ||
build=self.build, record=record) | ||
|
||
with self.build_env: | ||
# Environment used for code checkout & initial configuration reading | ||
with self.setup_env: | ||
if self.project.skip: | ||
raise BuildEnvironmentError( | ||
_('Builds for this project are temporarily disabled')) | ||
|
@@ -126,12 +125,20 @@ def run(self, pk, version_pk=None, build_pk=None, record=True, docker=False, | |
status_code=423 | ||
) | ||
|
||
self.config = load_yaml_config(version=self.version) | ||
|
||
bash_env = self.get_bash_env() | ||
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. Same note regarding |
||
if docker or settings.DOCKER_ENABLE: | ||
env_cls = DockerEnvironment | ||
self.build_env = env_cls(project=self.project, version=self.version, | ||
build=self.build, record=record, environment=bash_env) | ||
|
||
# Environment used for building code, usually with Docker | ||
with self.build_env: | ||
|
||
if self.project.documentation_type == 'auto': | ||
self.update_documentation_type() | ||
|
||
# Read YAML config after code checkout has been run | ||
self.config = load_yaml_config(version=self.version) | ||
|
||
python_env_cls = Virtualenv | ||
if self.config.use_conda: | ||
self._log('Using conda') | ||
|
@@ -195,20 +202,6 @@ def get_build(build_pk): | |
if key not in ['project', 'version', 'resource_uri', | ||
'absolute_uri']) | ||
|
||
def update_documentation_type(self): | ||
""" | ||
Force Sphinx for 'auto' documentation type | ||
|
||
This used to determine the type and automatically set the documentation | ||
type to Sphinx for rST and Mkdocs for markdown. It now just forces | ||
Sphinx, due to markdown support. | ||
""" | ||
ret = 'sphinx' | ||
project_data = api_v2.project(self.project.pk).get() | ||
project_data['documentation_type'] = ret | ||
api_v2.project(self.project.pk).put(project_data) | ||
self.project.documentation_type = ret | ||
|
||
def setup_vcs(self): | ||
""" | ||
Update the checkout of the repo to make sure it's the latest. | ||
|
@@ -217,7 +210,7 @@ def setup_vcs(self): | |
|
||
:param build_env: Build environment | ||
""" | ||
self.build_env.update_build(state=BUILD_STATE_CLONING) | ||
self.setup_env.update_build(state=BUILD_STATE_CLONING) | ||
|
||
self._log(msg='Updating docs from VCS') | ||
try: | ||
|
@@ -229,6 +222,43 @@ def setup_vcs(self): | |
raise BuildEnvironmentError('Failed to import project', | ||
status_code=404) | ||
|
||
def get_bash_env(self): | ||
""" | ||
Get bash environment variables used for all builder commands. | ||
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.
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. We need some way to name them different than the 2 other types of environments we use. Any suggestions? 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.
|
||
""" | ||
env = { | ||
'READTHEDOCS': True, | ||
'READTHEDOCS_VERSION': self.version.slug, | ||
'READTHEDOCS_PROJECT': self.project.slug | ||
} | ||
|
||
if self.config.use_conda: | ||
env.update({ | ||
'CONDA_ENVS_PATH': os.path.join(self.project.doc_path, 'conda'), | ||
'CONDA_DEFAULT_ENV': self.version.slug, | ||
'PATH': os.path.join(self.project.doc_path, 'conda', self.version.slug, 'bin') | ||
}) | ||
else: | ||
env.update({ | ||
'PATH': os.path.join(self.project.doc_path, 'envs', self.version.slug, 'bin') | ||
}) | ||
|
||
return env | ||
|
||
def update_documentation_type(self): | ||
""" | ||
Force Sphinx for 'auto' documentation type | ||
|
||
This used to determine the type and automatically set the documentation | ||
type to Sphinx for rST and Mkdocs for markdown. It now just forces | ||
Sphinx, due to markdown support. | ||
""" | ||
ret = 'sphinx' | ||
project_data = api_v2.project(self.project.pk).get() | ||
project_data['documentation_type'] = ret | ||
api_v2.project(self.project.pk).put(project_data) | ||
self.project.documentation_type = ret | ||
|
||
def setup_environment(self): | ||
""" | ||
Build the virtualenv and install the project into it. | ||
|
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.
Probably can lose this comma, but it's not a big deal.