Repository: readthedocs/readthedocs.org

Issue:
Change Python environment default to 3
Python 2 is going to stop being maintained in less than 3 years. We should switch our default Python version for projects to Python 3, as this should increase the number of python 3 projects being built on RTD by a large number. It's just a small settings change, but putting it here for discussion. 


Discussion:
The code to be changed is here: https://github.com/rtfd/readthedocs.org/blob/master/readthedocs/projects/models.py#L200

Resolving patch:
diff --git a/readthedocs/projects/migrations/0038_change-default-python-interpreter.py b/readthedocs/projects/migrations/0038_change-default-python-interpreter.py
new file mode 100644
--- /dev/null
+++ b/readthedocs/projects/migrations/0038_change-default-python-interpreter.py
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.18 on 2019-02-04 16:49
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('projects', '0037_add_htmlfile'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='project',
+            name='python_interpreter',
+            field=models.CharField(choices=[('python', 'CPython 2.x'), ('python3', 'CPython 3.x')], default='python3', help_text='The Python interpreter used to create the virtual environment.', max_length=20, verbose_name='Python Interpreter'),
+        ),
+    ]
diff --git a/readthedocs/projects/models.py b/readthedocs/projects/models.py
--- a/readthedocs/projects/models.py
+++ b/readthedocs/projects/models.py
@@ -303,7 +303,7 @@ class Project(models.Model):
         _('Python Interpreter'),
         max_length=20,
         choices=constants.PYTHON_CHOICES,
-        default='python',
+        default='python3',
         help_text=_(
             'The Python interpreter used to create the virtual '
             'environment.',


Test patch:
diff --git a/readthedocs/rtd_tests/tests/test_api.py b/readthedocs/rtd_tests/tests/test_api.py
--- a/readthedocs/rtd_tests/tests/test_api.py
+++ b/readthedocs/rtd_tests/tests/test_api.py
@@ -1468,7 +1468,7 @@ def test_get_version_by_id(self):
                 'language': 'en',
                 'name': 'Pip',
                 'programming_language': 'words',
-                'python_interpreter': 'python',
+                'python_interpreter': 'python3',
                 'repo': 'https://github.com/pypa/pip',
                 'repo_type': 'git',
                 'requirements_file': None,
diff --git a/readthedocs/rtd_tests/tests/test_config_integration.py b/readthedocs/rtd_tests/tests/test_config_integration.py
--- a/readthedocs/rtd_tests/tests/test_config_integration.py
+++ b/readthedocs/rtd_tests/tests/test_config_integration.py
@@ -97,7 +97,7 @@ def test_python_supported_versions_default_image_1_0(self, load_config):
                 ],
                 'use_system_packages': self.project.use_system_packages,
                 'requirements_file': self.project.requirements_file,
-                'python_version': 2,
+                'python_version': 3,
                 'sphinx_configuration': mock.ANY,
                 'build_image': 'readthedocs/build:1.0',
                 'doctype': self.project.documentation_type,
@@ -112,7 +112,7 @@ def test_python_supported_versions_default_image_1_0(self, load_config):
                 path=mock.ANY,
                 env_config=expected_env_config,
         )
-        self.assertEqual(config.python.version, 2)
+        self.assertEqual(config.python.version, 3)
 
     @mock.patch('readthedocs.doc_builder.config.load_config')
     def test_python_supported_versions_image_1_0(self, load_config):
@@ -151,8 +151,8 @@ def test_python_supported_versions_image_latest(self, load_config):
     def test_python_default_version(self, load_config):
         load_config.side_effect = create_load()
         config = load_yaml_config(self.version)
-        self.assertEqual(config.python.version, 2)
-        self.assertEqual(config.python_interpreter, 'python2.7')
+        self.assertEqual(config.python.version, 3)
+        self.assertEqual(config.python_interpreter, 'python3.7')
 
     @mock.patch('readthedocs.doc_builder.config.load_config')
     def test_python_set_python_version_on_project(self, load_config):