Skip to content

Commit

Permalink
darker
Browse files Browse the repository at this point in the history
  • Loading branch information
ewdurbin committed Feb 7, 2023
1 parent fb84ad8 commit 21977cb
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 62 deletions.
42 changes: 21 additions & 21 deletions readthedocs/api/v2/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,27 +73,27 @@ def get_skip(self, obj):

class Meta(ProjectSerializer.Meta):
fields = ProjectSerializer.Meta.fields + (
'enable_epub_build',
'enable_pdf_build',
'conf_py_file',
'analytics_code',
'analytics_disabled',
'cdn_enabled',
'container_image',
'container_mem_limit',
'container_time_limit',
'install_project',
'use_system_packages',
'skip',
'requirements_file',
'python_interpreter',
'features',
'has_valid_clone',
'has_valid_webhook',
'show_advertising',
'environment_variables',
'max_concurrent_builds',
'rtd_conf_file',
"enable_epub_build",
"enable_pdf_build",
"conf_py_file",
"analytics_code",
"analytics_disabled",
"cdn_enabled",
"container_image",
"container_mem_limit",
"container_time_limit",
"install_project",
"use_system_packages",
"skip",
"requirements_file",
"python_interpreter",
"features",
"has_valid_clone",
"has_valid_webhook",
"show_advertising",
"environment_variables",
"max_concurrent_builds",
"rtd_conf_file",
)


Expand Down
6 changes: 4 additions & 2 deletions readthedocs/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1377,12 +1377,14 @@ def load(path, env_config, config_file=None):
the version of the configuration a build object would be load and validated,
``BuildConfigV1`` is the default.
"""
if config_file is None or config_file == '':
if config_file is None or config_file == "":
filename = find_one(path, CONFIG_FILENAME_REGEX)
else:
filename = os.path.join(path, config_file)
if not os.path.exists(filename):
raise ConfigError(f".readthedocs.yml not found at {config_file}", CONFIG_FILE_REQUIRED)
raise ConfigError(
f".readthedocs.yml not found at {config_file}", CONFIG_FILE_REQUIRED
)

if not filename:
raise ConfigFileNotFound(path)
Expand Down
28 changes: 14 additions & 14 deletions readthedocs/projects/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,16 @@ class ProjectAdvancedForm(ProjectTriggerBuildMixin, ProjectForm):
class Meta:
model = Project
per_project_settings = (
'default_version',
'default_branch',
'privacy_level',
'analytics_code',
'analytics_disabled',
'show_version_warning',
'single_version',
'external_builds_enabled',
'external_builds_privacy_level',
'rtd_conf_file',
"default_version",
"default_branch",
"privacy_level",
"analytics_code",
"analytics_disabled",
"show_version_warning",
"single_version",
"external_builds_enabled",
"external_builds_privacy_level",
"rtd_conf_file",
)
# These that can be set per-version using a config file.
per_version_settings = (
Expand Down Expand Up @@ -359,12 +359,12 @@ def clean_conf_py_file(self):
return filename

def clean_rtd_conf_file(self):
filename = self.cleaned_data.get('rtd_conf_file', '').strip()
if filename and '.readthedocs.yml' not in filename:
filename = self.cleaned_data.get("rtd_conf_file", "").strip()
if filename and ".readthedocs.yml" not in filename:
raise forms.ValidationError(
_(
'Your configuration file is invalid, make sure it contains '
'.readthedocs.yml in it.',
"Your configuration file is invalid, make sure it contains "
".readthedocs.yml in it.",
),
) # yapf: disable
return filename
Expand Down
26 changes: 19 additions & 7 deletions readthedocs/projects/migrations/0096_auto_20230207_1642.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,30 @@
class Migration(migrations.Migration):

dependencies = [
('projects', '0095_default_branch_helptext'),
("projects", "0095_default_branch_helptext"),
]

operations = [
migrations.AddField(
model_name='historicalproject',
name='rtd_conf_file',
field=models.CharField(blank=True, default='', help_text='Path from project root to <code>.readthedocs.yml</code> file (ex. <code>docs/.readthedocs.yml</code>). Leave blank if you want us to find it for you.', max_length=255, verbose_name='.readthedocs.yml configuration file'),
model_name="historicalproject",
name="rtd_conf_file",
field=models.CharField(
blank=True,
default="",
help_text="Path from project root to <code>.readthedocs.yml</code> file (ex. <code>docs/.readthedocs.yml</code>). Leave blank if you want us to find it for you.",
max_length=255,
verbose_name=".readthedocs.yml configuration file",
),
),
migrations.AddField(
model_name='project',
name='rtd_conf_file',
field=models.CharField(blank=True, default='', help_text='Path from project root to <code>.readthedocs.yml</code> file (ex. <code>docs/.readthedocs.yml</code>). Leave blank if you want us to find it for you.', max_length=255, verbose_name='.readthedocs.yml configuration file'),
model_name="project",
name="rtd_conf_file",
field=models.CharField(
blank=True,
default="",
help_text="Path from project root to <code>.readthedocs.yml</code> file (ex. <code>docs/.readthedocs.yml</code>). Leave blank if you want us to find it for you.",
max_length=255,
verbose_name=".readthedocs.yml configuration file",
),
),
]
16 changes: 8 additions & 8 deletions readthedocs/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,20 +352,20 @@ class Project(models.Model):
default='',
blank=True,
help_text=_(
'Path from project root to <code>conf.py</code> file '
'(ex. <code>docs/conf.py</code>). '
'Leave blank if you want us to find it for you.',
"Path from project root to <code>conf.py</code> file "
"(ex. <code>docs/conf.py</code>). "
"Leave blank if you want us to find it for you.",
),
)
rtd_conf_file = models.CharField(
_('.readthedocs.yml configuration file'),
_(".readthedocs.yml configuration file"),
max_length=255,
default='',
default="",
blank=True,
help_text=_(
'Path from project root to <code>.readthedocs.yml</code> file '
'(ex. <code>docs/.readthedocs.yml</code>). '
'Leave blank if you want us to find it for you.',
"Path from project root to <code>.readthedocs.yml</code> file "
"(ex. <code>docs/.readthedocs.yml</code>). "
"Leave blank if you want us to find it for you.",
),
)

Expand Down
16 changes: 9 additions & 7 deletions readthedocs/rtd_tests/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,22 +686,24 @@ class APITests(TestCase):
def test_user_doesnt_get_full_api_return(self):
user_normal = get(User, is_staff=False)
user_admin = get(User, is_staff=True)
project = get(Project, main_language_project=None, conf_py_file='foo', rtd_conf_file='bar')
project = get(
Project, main_language_project=None, conf_py_file="foo", rtd_conf_file="bar"
)
client = APIClient()

client.force_authenticate(user=user_normal)
resp = client.get('/api/v2/project/%s/' % (project.pk))
self.assertEqual(resp.status_code, 200)
self.assertNotIn('conf_py_file', resp.data)
self.assertNotIn('rtd_conf_file', resp.data)
self.assertNotIn("conf_py_file", resp.data)
self.assertNotIn("rtd_conf_file", resp.data)

client.force_authenticate(user=user_admin)
resp = client.get('/api/v2/project/%s/' % (project.pk))
self.assertEqual(resp.status_code, 200)
self.assertIn('conf_py_file', resp.data)
self.assertEqual(resp.data['conf_py_file'], 'foo')
self.assertIn('rtd_conf_file', resp.data)
self.assertEqual(resp.data['rtd_conf_file'], 'bar')
self.assertIn("conf_py_file", resp.data)
self.assertEqual(resp.data["conf_py_file"], "foo")
self.assertIn("rtd_conf_file", resp.data)
self.assertEqual(resp.data["rtd_conf_file"], "bar")

def test_project_features(self):
user = get(User, is_staff=True)
Expand Down
6 changes: 3 additions & 3 deletions readthedocs/rtd_tests/tests/test_config_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ def test_python_supported_versions_default_image_1_0(self, load_config):
expected_env_config.update(img_settings)

load_config.assert_called_once_with(
path=mock.ANY,
env_config=expected_env_config,
config_file='',
path=mock.ANY,
env_config=expected_env_config,
config_file="",
)
self.assertEqual(config.python.version, '3')

Expand Down

0 comments on commit 21977cb

Please sign in to comment.