Skip to content

Commit

Permalink
Adopt automatic changes from pre-commit in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri committed Mar 10, 2022
1 parent 483182c commit 2eab243
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 91 deletions.
2 changes: 1 addition & 1 deletion readthedocs/api/v2/templates/restapi/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<dt>{% trans "Languages" %}</dt>

{# Output the main project language since it isn't included in translations list #}

<dd {% if main_project.language == current_language %} class="rtd-current-item" {% endif %}>
<a href="{{ main_project.get_docs_url }}{{ path }}">{{ main_project.language }}</a>
</dd>
Expand Down
26 changes: 13 additions & 13 deletions readthedocs/api/v2/views/footer_views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Endpoint to generate footer HTML."""

import structlog
import re
from functools import lru_cache

import structlog
from django.conf import settings
from django.shortcuts import get_object_or_404
from django.template import loader as template_loader
Expand Down Expand Up @@ -162,18 +162,18 @@ def _get_context(self):
path = page_slug + '.html'

context = {
'project': project,
'version': version,
'path': path,
'downloads': version.get_downloads(pretty=True),
'current_version': version,
'versions': self._get_active_versions_sorted(),
'main_project': main_project,
'translations': main_project.translations.all(),
'current_language': project.language,
'new_theme': new_theme,
'settings': settings,
'github_edit_url': version.get_github_url(
"project": project,
"version": version,
"path": path,
"downloads": version.get_downloads(pretty=True),
"current_version": version,
"versions": self._get_active_versions_sorted(),
"main_project": main_project,
"translations": main_project.translations.all(),
"current_language": project.language,
"new_theme": new_theme,
"settings": settings,
"github_edit_url": version.get_github_url(
docroot,
page_slug,
source_suffix,
Expand Down
11 changes: 4 additions & 7 deletions readthedocs/builds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
from django.utils import timezone
from django.utils.translation import gettext
from django.utils.translation import gettext_lazy as _
from django_extensions.db.fields import (
CreationDateTimeField,
ModificationDateTimeField,
)
from django_extensions.db.fields import CreationDateTimeField, ModificationDateTimeField
from django_extensions.db.models import TimeStampedModel
from polymorphic.models import PolymorphicModel

Expand Down Expand Up @@ -225,9 +222,9 @@ def explicit_name(self):
if not self.is_external:
return self.verbose_name

template = '#{name} ({abbrev})'
template = "#{name} ({abbrev})"
external_origin = external_version_name(self)
abbrev = ''.join(word[0].upper() for word in external_origin.split())
abbrev = "".join(word[0].upper() for word in external_origin.split())
return template.format(name=self.verbose_name, abbrev=abbrev)

@property
Expand Down Expand Up @@ -1334,7 +1331,7 @@ def match(self, version, match_arg):
pattern=match_arg,
version_slug=version.slug,
)
except Exception as e:
except Exception:
log.exception('Error parsing regex.', exc_info=True)
return False, None

Expand Down
3 changes: 1 addition & 2 deletions readthedocs/builds/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Utilities for the builds app."""
from time import monotonic

from contextlib import contextmanager
from time import monotonic

from django.core.cache import cache

Expand Down
51 changes: 11 additions & 40 deletions readthedocs/projects/tasks/mixins.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
import datetime
import json
import os
import signal
import socket
import tarfile
import tempfile
from collections import Counter, defaultdict

from celery.exceptions import SoftTimeLimitExceeded
from django.conf import settings
from django.db.models import Q
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
from slumber.exceptions import HttpClientError
from sphinx.ext import intersphinx
from collections import Counter

import structlog
from django.utils.translation import gettext_lazy as _

from readthedocs.api.v2.client import api as api_v2
from readthedocs.builds import tasks as build_tasks
Expand All @@ -30,30 +17,14 @@
LATEST_VERBOSE_NAME,
STABLE_VERBOSE_NAME,
)
from readthedocs.builds.models import APIVersion, Build, Version
from readthedocs.builds.signals import build_complete
from readthedocs.config import ConfigError
from readthedocs.doc_builder.config import load_yaml_config
from readthedocs.builds.models import APIVersion
from readthedocs.doc_builder.environments import (
DockerBuildEnvironment,
LocalBuildEnvironment,
)
from readthedocs.doc_builder.loader import get_builder_class
from readthedocs.doc_builder.python_environments import Conda, Virtualenv
from readthedocs.search.utils import index_new_files, remove_indexed_files
from readthedocs.sphinx_domains.models import SphinxDomain
from readthedocs.storage import build_environment_storage, build_media_storage
from readthedocs.worker import app

from ..models import APIProject, Feature, WebHookEvent
from ..models import HTMLFile, ImportedFile, Project
from ..signals import (
after_build,
before_build,
before_vcs,
files_changed,
)

from ..exceptions import RepositoryError
from ..models import Feature

log = structlog.get_logger(__name__)

Expand Down Expand Up @@ -209,11 +180,11 @@ def get_vcs_env_vars(self):
def get_rtd_env_vars(self):
"""Get bash environment variables specific to Read the Docs."""
env = {
'READTHEDOCS': 'True',
'READTHEDOCS_VERSION': self.data.version.slug,
'READTHEDOCS_VERSION_TYPE': self.data.version.type,
'READTHEDOCS_VERSION_NAME': self.data.version.verbose_name,
'READTHEDOCS_PROJECT': self.data.project.slug,
'READTHEDOCS_LANGUAGE': self.data.project.language,
"READTHEDOCS": "True",
"READTHEDOCS_VERSION": self.data.version.slug,
"READTHEDOCS_VERSION_TYPE": self.data.version.type,
"READTHEDOCS_VERSION_NAME": self.data.version.verbose_name,
"READTHEDOCS_PROJECT": self.data.project.slug,
"READTHEDOCS_LANGUAGE": self.data.project.language,
}
return env
27 changes: 10 additions & 17 deletions readthedocs/projects/tests/test_build_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,8 @@
from readthedocs.config.config import BuildConfigV2
from readthedocs.doc_builder.exceptions import BuildAppError
from readthedocs.projects.exceptions import RepositoryError
from readthedocs.projects.models import (
EnvironmentVariable,
Project,
WebHookEvent,
)
from readthedocs.projects.tasks.builds import (
sync_repository_task,
update_docs_task,
)
from readthedocs.projects.models import EnvironmentVariable, Project, WebHookEvent
from readthedocs.projects.tasks.builds import sync_repository_task, update_docs_task

from .mockers import BuildEnvironmentMocker

Expand Down Expand Up @@ -199,14 +192,14 @@ def test_get_env_vars_default(self, load_yaml_config):
)

env = {
'NO_COLOR': '1',
'READTHEDOCS': 'True',
'READTHEDOCS_VERSION': self.version.slug,
'READTHEDOCS_VERSION_TYPE': self.version.type,
'READTHEDOCS_VERSION_NAME': self.version.verbose_name,
'READTHEDOCS_PROJECT': self.project.slug,
'READTHEDOCS_LANGUAGE': self.project.language,
'BIN_PATH': os.path.join(
"NO_COLOR": "1",
"READTHEDOCS": "True",
"READTHEDOCS_VERSION": self.version.slug,
"READTHEDOCS_VERSION_TYPE": self.version.type,
"READTHEDOCS_VERSION_NAME": self.version.verbose_name,
"READTHEDOCS_PROJECT": self.project.slug,
"READTHEDOCS_LANGUAGE": self.project.language,
"BIN_PATH": os.path.join(
self.project.doc_path,
'envs',
self.version.slug,
Expand Down
22 changes: 11 additions & 11 deletions readthedocs/rtd_tests/tests/test_footer.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,27 +73,27 @@ def test_footer_dont_show_version_warning(self):
self.assertEqual(r.context['main_project'], self.pip)

def test_footer_show_explicit_name_for_external_version(self):
project = Project.objects.get(slug='pip')
project = Project.objects.get(slug="pip")
version = project.versions.get(slug=LATEST)
version.type = EXTERNAL
version.verbose_name = '4'
version.verbose_name = "4"
version.save()
self.url = (
reverse('footer_html') +
f'?project={project.slug}&version={version.slug}&page=index&docroot=/'
reverse("footer_html")
+ f"?project={project.slug}&version={version.slug}&page=index&docroot=/"
)

git_provider_name = 'readthedocs.projects.models.Project.git_provider_name'
git_provider_name = "readthedocs.projects.models.Project.git_provider_name"
with mock.patch(git_provider_name, GITHUB_BRAND):
r = self.render()
self.assertIn('#4 (PR)', r.data['html'])
self.assertNotIn('#4 (MR)', r.data['html'])
self.assertNotIn('#4 (EV)', r.data['html'])
self.assertIn("#4 (PR)", r.data["html"])
self.assertNotIn("#4 (MR)", r.data["html"])
self.assertNotIn("#4 (EV)", r.data["html"])
with mock.patch(git_provider_name, GITLAB_BRAND):
r = self.render()
self.assertIn('#4 (MR)', r.data['html'])
self.assertNotIn('#4 (PR)', r.data['html'])
self.assertNotIn('#4 (EV)', r.data['html'])
self.assertIn("#4 (MR)", r.data["html"])
self.assertNotIn("#4 (PR)", r.data["html"])
self.assertNotIn("#4 (EV)", r.data["html"])

def test_footer_dont_show_version_warning_for_external_versions(self):
self.latest.type = EXTERNAL
Expand Down

0 comments on commit 2eab243

Please sign in to comment.