Skip to content

Commit 5cf3350

Browse files
committed
Don't mutate Environment.environment
1 parent c098df8 commit 5cf3350

File tree

5 files changed

+16
-25
lines changed

5 files changed

+16
-25
lines changed

readthedocs/doc_builder/environments.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ def __init__(
105105
self.shell = shell
106106
self.cwd = cwd or settings.RTD_DOCKER_WORKDIR
107107
self.user = user or settings.RTD_DOCKER_USER
108-
self.environment = environment.copy() if environment else {}
109-
if 'PATH' in self.environment:
108+
self._environment = environment.copy() if environment else {}
109+
if 'PATH' in self._environment:
110110
raise BuildEnvironmentError('\'PATH\' can\'t be set. Use bin_path')
111111

112112
self.build_env = build_env
@@ -132,7 +132,7 @@ def run(self):
132132
log.info("Running: '%s' [%s]", self.get_command(), self.cwd)
133133

134134
self.start_time = datetime.utcnow()
135-
environment = self.environment.copy()
135+
environment = self._environment.copy()
136136
if 'DJANGO_SETTINGS_MODULE' in environment:
137137
del environment['DJANGO_SETTINGS_MODULE']
138138
if 'PYTHONPATH' in environment:
@@ -302,7 +302,7 @@ def run(self):
302302
exec_cmd = client.exec_create(
303303
container=self.build_env.container_id,
304304
cmd=self.get_wrapped_command(),
305-
environment=self.environment,
305+
environment=self._environment,
306306
user=self.user,
307307
workdir=self.cwd,
308308
stdout=True,
@@ -384,7 +384,7 @@ class BaseEnvironment:
384384
def __init__(self, project, environment=None):
385385
# TODO: maybe we can remove this Project dependency also
386386
self.project = project
387-
self.environment = environment or {}
387+
self._environment = environment or {}
388388
self.commands = []
389389

390390
def record_command(self, command):
@@ -423,7 +423,7 @@ def run_command_class(
423423
kwargs.update({'record_as_success': record_as_success})
424424

425425
# Remove PATH from env, and set it to bin_path if it isn't passed in
426-
environment = self.environment.copy()
426+
environment = self._environment.copy()
427427
env_path = environment.pop('BIN_PATH', None)
428428
if 'bin_path' not in kwargs and env_path:
429429
kwargs['bin_path'] = env_path

readthedocs/projects/tasks.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,13 @@ def validate_duplicate_reserved_versions(self, tags_data, branches_data):
311311
RepositoryError.DUPLICATED_RESERVED_VERSIONS,
312312
)
313313

314+
def get_vcs_env_vars(self):
315+
"""Get environment variables to be included in the VCS setup step."""
316+
env = self.get_rtd_env_vars()
317+
# Don't prompt for username, this requires Git 2.3+
318+
env['GIT_TERMINAL_PROMPT'] = '0'
319+
return env
320+
314321
def get_rtd_env_vars(self):
315322
"""Get bash environment variables specific to Read the Docs."""
316323
env = {
@@ -370,7 +377,7 @@ def run(self, version_pk): # pylint: disable=arguments-differ
370377
version=self.version,
371378
record=False,
372379
update_on_success=False,
373-
environment=self.get_rtd_env_vars(),
380+
environment=self.get_vcs_env_vars(),
374381
)
375382
log.info(
376383
'Running sync_repository_task: project=%s version=%s',
@@ -657,7 +664,7 @@ def run_setup(self, record=True):
657664
build=self.build,
658665
record=record,
659666
update_on_success=False,
660-
environment=self.get_rtd_env_vars(),
667+
environment=self.get_vcs_env_vars(),
661668
)
662669
self.build_start_time = environment.start_time
663670

readthedocs/rtd_tests/tests/test_doc_building.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ def test_command_env(self):
10241024
env = {'FOOBAR': 'foobar', 'BIN_PATH': 'foobar'}
10251025
cmd = BuildCommand('echo', environment=env)
10261026
for key in list(env.keys()):
1027-
self.assertEqual(cmd.environment[key], env[key])
1027+
self.assertEqual(cmd._environment[key], env[key])
10281028

10291029
def test_result(self):
10301030
"""Test result of output using unix true/false commands."""

readthedocs/vcs_support/backends/git.py

-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Git-related utilities."""
22

33
import logging
4-
import os
54
import re
65

76
import git
@@ -359,11 +358,3 @@ def ref_exists(self, ref):
359358
except (BadName, ValueError):
360359
return False
361360
return False
362-
363-
@property
364-
def env(self):
365-
env = super().env
366-
env['GIT_DIR'] = os.path.join(self.working_dir, '.git')
367-
# Don't prompt for username, this requires Git 2.3+
368-
env['GIT_TERMINAL_PROMPT'] = '0'
369-
return env

readthedocs/vcs_support/base.py

-7
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ def __init__(
7272
from readthedocs.doc_builder.environments import LocalBuildEnvironment
7373
self.environment = environment or LocalBuildEnvironment(record=False)
7474

75-
# Update the env variables with the proper VCS env variables
76-
self.environment.environment.update(self.env)
77-
7875
def check_working_dir(self):
7976
if not os.path.exists(self.working_dir):
8077
os.makedirs(self.working_dir)
@@ -84,10 +81,6 @@ def make_clean_working_dir(self):
8481
shutil.rmtree(self.working_dir, ignore_errors=True)
8582
self.check_working_dir()
8683

87-
@property
88-
def env(self):
89-
return {}
90-
9184
def update(self):
9285
"""
9386
Update a local copy of the repository in self.working_dir.

0 commit comments

Comments
 (0)