Skip to content

Commit 7f83fcd

Browse files
committed
Allow to use 3.10 as string in YAML config file
1 parent d9c9ed6 commit 7f83fcd

File tree

4 files changed

+38
-48
lines changed

4 files changed

+38
-48
lines changed

readthedocs/config/config.py

+4-23
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def validate(self):
255255
@property
256256
def python_interpreter(self):
257257
ver = self.python_full_version
258-
if not ver or isinstance(ver, (int, float)):
258+
if not ver or isinstance(ver, (int, float)) or ver == '3.10':
259259
return 'python{}'.format(ver)
260260

261261
# Allow to specify ``pypy3.5`` as Python interpreter
@@ -264,11 +264,11 @@ def python_interpreter(self):
264264
@property
265265
def python_full_version(self):
266266
ver = self.python.version
267-
if ver in [2, 3]:
267+
if ver in [2, 3, '2', '3']:
268268
# use default Python version if user only set '2', or '3'
269269
return self.get_default_python_version_for_image(
270270
self.build.image,
271-
ver,
271+
int(ver),
272272
)
273273
return ver
274274

@@ -513,19 +513,8 @@ def validate_python(self):
513513

514514
if 'version' in raw_python:
515515
with self.catch_validation_error('python.version'):
516-
# Try to convert strings to an int first, to catch '2', then
517-
# a float, to catch '2.7'
518-
version = raw_python['version']
519-
if isinstance(version, str):
520-
try:
521-
version = int(version)
522-
except ValueError:
523-
try:
524-
version = float(version)
525-
except ValueError:
526-
pass
527516
python['version'] = validate_choice(
528-
version,
517+
raw_python['version'],
529518
self.get_valid_python_versions(),
530519
)
531520

@@ -840,14 +829,6 @@ def validate_python(self):
840829
python = {}
841830
with self.catch_validation_error('python.version'):
842831
version = self.pop_config('python.version', 3)
843-
if isinstance(version, str):
844-
try:
845-
version = int(version)
846-
except ValueError:
847-
try:
848-
version = float(version)
849-
except ValueError:
850-
pass
851832
python['version'] = validate_choice(
852833
version,
853834
self.get_valid_python_versions(),

readthedocs/config/tests/test_config.py

+13-18
Original file line numberDiff line numberDiff line change
@@ -381,23 +381,6 @@ def test_it_validates_wrong_type(self):
381381
assert excinfo.value.key == 'python.version'
382382
assert excinfo.value.code == INVALID_CHOICE
383383

384-
def test_it_validates_wrong_type_right_value(self):
385-
build = get_build_config(
386-
{'python': {'version': '3.6'}},
387-
)
388-
build.validate()
389-
assert build.python.version == 3.6
390-
assert build.python_interpreter == 'python3.6'
391-
assert build.python_full_version == 3.6
392-
393-
build = get_build_config(
394-
{'python': {'version': '3'}},
395-
)
396-
build.validate()
397-
assert build.python.version == 3
398-
assert build.python_interpreter == 'python3.7'
399-
assert build.python_full_version == 3.7
400-
401384
def test_it_validates_env_supported_versions(self):
402385
build = get_build_config(
403386
{'python': {'version': 3.6}},
@@ -1030,7 +1013,19 @@ def test_python_version_accepts_string(self):
10301013
},
10311014
})
10321015
build.validate()
1033-
assert build.python.version == 3.6
1016+
assert build.python.version == '3.6'
1017+
1018+
def test_python_version_310(self):
1019+
build = self.get_build_config({
1020+
'build': {
1021+
'image': 'testing',
1022+
},
1023+
'python': {
1024+
'version': '3.10',
1025+
},
1026+
})
1027+
build.validate()
1028+
assert build.python.version == '3.10'
10341029

10351030
@pytest.mark.parametrize(
10361031
'image,versions',

readthedocs/rtd_tests/tests/test_config_integration.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def test_python_supported_versions_image_2_0(self, load_config):
124124
config = load_yaml_config(self.version)
125125
self.assertEqual(
126126
config.get_valid_python_versions(),
127-
[2, 2.7, 3, 3.5],
127+
[2, 2.7, 3, 3.5, '2', '2.7', '3', '3.5'],
128128
)
129129

130130
@mock.patch('readthedocs.doc_builder.config.load_config')
@@ -135,7 +135,7 @@ def test_python_supported_versions_image_latest(self, load_config):
135135
config = load_yaml_config(self.version)
136136
self.assertEqual(
137137
config.get_valid_python_versions(),
138-
[2, 2.7, 3, 3.5, 3.6, 3.7, 3.8, 'pypy3.5'],
138+
[2, 2.7, 3, 3.5, 3.6, 3.7, 3.8, 'pypy3.5', '2', '2.7', '3', '3.5', '3.6', '3.7', '3.8'],
139139
)
140140

141141
@mock.patch('readthedocs.doc_builder.config.load_config')
@@ -166,6 +166,16 @@ def test_python_set_python_version_in_config(self, load_config):
166166
self.assertEqual(config.python.version, 3.5)
167167
self.assertEqual(config.python_interpreter, 'python3.5')
168168

169+
@mock.patch('readthedocs.doc_builder.config.load_config')
170+
def test_python_set_python_310_version_in_config(self, load_config):
171+
load_config.side_effect = create_load({
172+
'build': {'image': 'testing'},
173+
'python': {'version': '3.10'},
174+
})
175+
config = load_yaml_config(self.version)
176+
self.assertEqual(config.python.version, '3.10')
177+
self.assertEqual(config.python_interpreter, 'python3.10')
178+
169179
@mock.patch('readthedocs.doc_builder.config.load_config')
170180
def test_python_invalid_version_in_config(self, load_config):
171181
load_config.side_effect = create_load({

readthedocs/settings/base.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -490,18 +490,22 @@ def TEMPLATES(self):
490490
},
491491
'readthedocs/build:7.0': {
492492
'python': {
493-
# TODO: migrate these float numbers to be strings and avoid
494-
# issues with ``3.10`` and ``3.1`` see
495-
# https://github.com/readthedocs/readthedocs.org/pull/8328#discussion_r666366384
496-
# for more details
497-
'supported_versions': [2, 2.7, 3, 3.5, 3.6, 3.7, 3.8, 3.9, 3.10, 'pypy3.5'],
493+
'supported_versions': [2, 2.7, 3, 3.5, 3.6, 3.7, 3.8, 3.9, '3.10', 'pypy3.5'],
498494
'default_version': {
499495
2: 2.7,
500496
3: 3.7,
501497
},
502498
},
503499
},
504500
}
501+
502+
# Convert all `python.supported_versions` to string for backward compatiblity
503+
# see https://github.com/readthedocs/readthedocs.org/pull/8328#discussion_r666366384
504+
for k in DOCKER_IMAGE_SETTINGS:
505+
for version in DOCKER_IMAGE_SETTINGS[k]['python']['supported_versions']:
506+
if isinstance(version, (int, float)):
507+
DOCKER_IMAGE_SETTINGS[k]['python']['supported_versions'].append(str(version))
508+
505509
# Alias tagged via ``docker tag`` on the build servers
506510
DOCKER_IMAGE_SETTINGS.update({
507511
'readthedocs/build:stable': DOCKER_IMAGE_SETTINGS.get('readthedocs/build:5.0'),

0 commit comments

Comments
 (0)