repo
stringclasses
454 values
file_path
stringlengths
5
201
extension
stringclasses
1 value
content
stringlengths
8
509k
num_lines
int64
3
16.9k
size_bytes
int64
8
511k
readthedocs.org
readthedocs/builds/managers.py
.py
"""Build and Version class model Managers.""" import hashlib import json import structlog from django.core.exceptions import ObjectDoesNotExist from django.db import models from readthedocs.builds.constants import BRANCH from readthedocs.builds.constants import EXTERNAL from readthedocs.builds.constants import LATES...
149
4,678
readthedocs.org
readthedocs/builds/forms.py
.py
"""Django forms for the builds app.""" from crispy_forms.helper import FormHelper from crispy_forms.layout import HTML from crispy_forms.layout import Fieldset from crispy_forms.layout import Layout from django import forms from django.conf import settings from django.template.loader import render_to_string from djang...
122
4,488
readthedocs.org
readthedocs/builds/tasks.py
.py
import json import requests import structlog from django.conf import settings from django.contrib.contenttypes.models import ContentType from django.core.cache import cache from django.urls import reverse from django.utils import timezone from django.utils.translation import gettext_lazy as _ from oauthlib.oauth2.rfc6...
794
29,179
readthedocs.org
readthedocs/builds/tests/test_views.py
.py
from unittest import mock from django.conf import settings from django.contrib.auth.models import User from django.test import TestCase, override_settings from django.urls import reverse from django_dynamic_fixture import get from readthedocs.builds.constants import ( BUILD_STATE_CANCELLED, BUILD_STATE_INSTAL...
142
5,434
readthedocs.org
readthedocs/builds/tests/test_tasks.py
.py
from datetime import datetime, timedelta from textwrap import dedent from unittest import mock from django.conf import settings from django.contrib.auth.models import User from django.test import TestCase, override_settings from django.utils import timezone from django_dynamic_fixture import get from readthedocs.buil...
691
27,758
readthedocs.org
readthedocs/builds/tests/test_build_queryset.py
.py
from django.test import override_settings import django_dynamic_fixture as fixture import pytest from readthedocs.builds.models import Build from readthedocs.organizations.models import Organization from readthedocs.projects.models import Project from readthedocs.subscriptions.constants import TYPE_CONCURRENT_BUILDS f...
170
5,900
readthedocs.org
readthedocs/builds/tests/test_trigger_build.py
.py
from unittest import mock import django_dynamic_fixture as fixture import pytest from readthedocs.builds.constants import ( BUILD_STATE_BUILDING, BUILD_STATE_CANCELLED, BUILD_STATE_CLONING, BUILD_STATE_FINISHED, BUILD_STATE_INSTALLING, BUILD_STATE_TRIGGERED, BUILD_STATE_UPLOADING, ) from r...
115
3,789
readthedocs.org
readthedocs/builds/tests/test_buildconfig.py
.py
"""Tests for BuildConfig model and Build.readthedocs_yaml_config field.""" import django_dynamic_fixture as fixture import pytest from readthedocs.builds.models import Build from readthedocs.builds.models import BuildConfig from readthedocs.builds.models import Version from readthedocs.projects.models import Project ...
104
4,149
readthedocs.org
readthedocs/doc_builder/exceptions.py
.py
""" Exceptions raised when building documentation. Exceptions defined here have different categories based on - responsibility (user or application) - special cases (they need to be handled in a special way, e.g. concurrency limit reached) - grouped by topic (e.g. MkDocs errors) All these exception should only de...
93
3,644
readthedocs.org
readthedocs/doc_builder/constants.py
.py
"""Doc build constants.""" import re import structlog from django.conf import settings log = structlog.get_logger(__name__) PDF_RE = re.compile("Output written on (.*?)") # Docker DOCKER_SOCKET = settings.DOCKER_SOCKET DOCKER_VERSION = settings.DOCKER_VERSION DOCKER_IMAGE = settings.DOCKER_IMAGE DOCKER_TIMEOUT_EX...
29
513
readthedocs.org
readthedocs/doc_builder/environments.py
.py
"""Documentation Builder Environments.""" import os import re import subprocess import sys import uuid from datetime import datetime import structlog from django.conf import settings from django.urls import reverse from django.utils.translation import gettext_lazy as _ from docker import APIClient from docker.errors ...
942
37,333
readthedocs.org
readthedocs/doc_builder/config.py
.py
"""An API to load config from a readthedocs.yml file.""" from readthedocs.config import load as load_config def load_yaml_config(version, readthedocs_yaml_path=None): """ Load a build configuration file (`.readthedocs.yaml`). This uses the configuration logic from `readthedocs-build`, which will keep ...
30
1,099
readthedocs.org
readthedocs/doc_builder/loader.py
.py
"""Lookup tables for builders and backends.""" from importlib import import_module from django.conf import settings # Managers mkdocs = import_module(settings.MKDOCS_BACKEND) sphinx = import_module(settings.SPHINX_BACKEND) BUILDER_BY_NAME = { # Possible HTML Builders "sphinx": sphinx.HtmlBuilder, "sphi...
28
690
readthedocs.org
readthedocs/doc_builder/python_environments.py
.py
"""An abstraction over virtualenv and Conda environments.""" import copy import os import structlog import yaml from readthedocs.config import PIP from readthedocs.config import SETUPTOOLS from readthedocs.config import ParseError from readthedocs.config import parse as parse_yaml from readthedocs.config.models impo...
464
16,006
readthedocs.org
readthedocs/doc_builder/base.py
.py
"""Base classes for Builders.""" import os from functools import wraps import structlog log = structlog.get_logger(__name__) def restoring_chdir(fn): # XXX:dc: This would be better off in a neutral module @wraps(fn) def decorator(*args, **kw): path = os.getcwd() try: return...
65
1,857
readthedocs.org
readthedocs/doc_builder/director.py
.py
""" The ``director`` module can be seen as the entrypoint of the build process. It "directs" all of the high-level build jobs: * checking out the repo * setting up the environment * fetching instructions etc. """ import datetime import os import tarfile import structlog import yaml from django.conf import settings ...
931
36,691
readthedocs.org
readthedocs/doc_builder/backends/sphinx.py
.py
""" Sphinx_ backend for building docs. .. _Sphinx: http://www.sphinx-doc.org/ """ import itertools import os from glob import glob from pathlib import Path import structlog from readthedocs.doc_builder.python_environments import UvEnv from readthedocs.projects.constants import OLD_LANGUAGES_CODE_MAPPING from readth...
468
16,615
readthedocs.org
readthedocs/doc_builder/backends/mkdocs.py
.py
""" MkDocs_ backend for building docs. .. _MkDocs: http://www.mkdocs.org/ """ import os import structlog import yaml from django.conf import settings from readthedocs.doc_builder.base import BaseBuilder from readthedocs.doc_builder.python_environments import UvEnv from readthedocs.projects.exceptions import UserFil...
163
4,493
readthedocs.org
readthedocs/doc_builder/tests/test_director.py
.py
import os from unittest import mock from django.test import TestCase, override_settings from django_dynamic_fixture import get from readthedocs.builds.models import Build, Version from readthedocs.config.tests.test_config import get_build_config from readthedocs.doc_builder.director import BuildDirector from readthed...
148
6,019
readthedocs.org
readthedocs/doc_builder/tests/test_environments.py
.py
from django.test import TestCase from readthedocs.doc_builder.environments import DockerBuildCommand class TestDockerBuildEnvironment(TestCase): def test_command_escape(self): commands = [ ( ["ls", ".", "; touch /tmp/test"], "nice -n 10 /bin/sh -c 'ls . \\;\\ t...
33
1,144
readthedocs.org
readthedocs/analytics/proxied_api.py
.py
"""Analytics views that are served from the same domain as the docs.""" from functools import lru_cache from urllib.parse import urlparse import structlog from django.http import JsonResponse from django.shortcuts import get_object_or_404 from rest_framework import status as status_codes from rest_framework.response ...
152
5,359
readthedocs.org
readthedocs/analytics/admin.py
.py
"""Analytics Admin classes.""" from django.contrib import admin from .models import PageView @admin.register(PageView) class PageViewAdmin(admin.ModelAdmin): raw_id_fields = ("project", "version") list_display = ("project", "version", "path", "view_count", "date") search_fields = ("project__slug", "vers...
15
441
readthedocs.org
readthedocs/analytics/utils.py
.py
"""Utilities related to analytics.""" import hashlib import ipaddress import structlog from django.conf import settings from django.utils.crypto import get_random_string from django.utils.encoding import force_bytes from django.utils.encoding import force_str from user_agents import parse log = structlog.get_logger...
90
2,856
readthedocs.org
readthedocs/analytics/tests.py
.py
from unittest import mock import pytest from django.test import RequestFactory, TestCase, override_settings from django.urls import reverse from django.utils import timezone from django_dynamic_fixture import get from readthedocs.builds.constants import EXTERNAL from readthedocs.builds.models import Version from read...
276
10,856
readthedocs.org
readthedocs/analytics/models.py
.py
"""Analytics modeling to help understand the projects on Read the Docs.""" import datetime from collections import namedtuple from urllib.parse import urlparse from django.db import models from django.db.models import Sum from django.utils import timezone from django.utils.translation import gettext_lazy as _ from r...
212
7,334
readthedocs.org
readthedocs/analytics/apps.py
.py
"""Django app config for the analytics app.""" from django.apps import AppConfig class AnalyticsAppConfig(AppConfig): """Analytics app init code.""" default_auto_field = "django.db.models.BigAutoField" name = "readthedocs.analytics" verbose_name = "Analytics"
12
280
readthedocs.org
readthedocs/analytics/tasks.py
.py
"""Tasks for Read the Docs' analytics.""" from django.conf import settings from django.utils import timezone from readthedocs.analytics.models import PageView from readthedocs.worker import app @app.task(queue="web") def delete_old_page_counts(): """ Delete page counts older than ``RTD_ANALYTICS_DEFAULT_RET...
26
858
readthedocs.org
readthedocs/analytics/tests/test_models.py
.py
import pytest from django.contrib.auth.models import User from django.db import IntegrityError from django.test import TestCase from django_dynamic_fixture import get from readthedocs.analytics.models import PageView from readthedocs.projects.models import Project class TestModels(TestCase): def setUp(self): ...
67
1,861
readthedocs.org
readthedocs/payments/utils.py
.py
""" Payment utility functions. These are mostly one-off functions. Define the bulk of Stripe operations on :py:class:`readthedocs.payments.forms.StripeResourceMixin`. """ import stripe import structlog from django.conf import settings from djstripe.models import Account log = structlog.get_logger(__name__) def ge...
59
1,764
readthedocs.org
readthedocs/payments/mixins.py
.py
"""Payment view mixin classes.""" from djstripe.enums import APIKeyType from djstripe.models import APIKey class StripeMixin: """Adds Stripe publishable key to the context data.""" def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context["stripe_publishable"...
16
437
readthedocs.org
readthedocs/payments/tests/utils.py
.py
from djstripe.models import APIKey from djstripe.enums import APIKeyType from djstripe.models import Account class PaymentMixin: def setUp(self): super().setUp() Account.objects.create( id="acct_1032D82eZvKYlo2C", charges_enabled=True, country="US", ...
21
648
readthedocs.org
readthedocs/payments/tests/test_utils.py
.py
import requests_mock from django.test import TestCase from readthedocs.payments.tests.utils import PaymentMixin from readthedocs.payments.utils import cancel_subscription class TestUtils(PaymentMixin, TestCase): @requests_mock.Mocker(kw="mock_request") def test_cancel_subscription(self, mock_request): ...
23
723
readthedocs.org
readthedocs/gold/admin.py
.py
"""Django admin configuration for the Gold membership app.""" from django.contrib import admin from .models import GoldUser @admin.register(GoldUser) class GoldAdmin(admin.ModelAdmin): model = GoldUser raw_id_fields = ("user", "projects") list_display = ("user", "level", "modified_date", "subscribed") ...
15
433
readthedocs.org
readthedocs/gold/models.py
.py
"""Django models for recurring donations aka Gold membership.""" import math from django.contrib.auth.models import User from django.db import models from django.utils.translation import gettext_lazy as _ from readthedocs.projects.models import Project #: The membership options that are currently available LEVEL_C...
62
1,691
readthedocs.org
readthedocs/gold/apps.py
.py
"""Django app configuration for the Gold membership app.""" from django.apps import AppConfig class GoldAppConfig(AppConfig): name = "readthedocs.gold" verbose_name = "Gold" def ready(self): import readthedocs.gold.signals # noqa
12
255
readthedocs.org
readthedocs/gold/__init__.py
.py
""" A Django app for Gold membership. Gold membership is Read the Docs' program for recurring, monthly donations. """
6
119
readthedocs.org
readthedocs/gold/views.py
.py
"""Gold subscription views.""" import json import structlog from django.conf import settings from django.contrib import messages from django.http import HttpResponseRedirect from django.http import JsonResponse from django.shortcuts import get_object_or_404 from django.urls import reverse_lazy from django.utils.trans...
197
6,743
readthedocs.org
readthedocs/gold/signals.py
.py
"""Gold model signals.""" from django.db.models.signals import pre_delete from django.dispatch import receiver from readthedocs.payments import utils from .models import GoldUser @receiver(pre_delete, sender=GoldUser) def delete_customer(sender, instance, **__): """On Gold subscription deletion, remove the cus...
18
567
readthedocs.org
readthedocs/gold/urls.py
.py
"""Gold subscription URLs.""" from django.urls import path from readthedocs.gold import views urlpatterns = [ path( "", views.GoldSubscription.as_view(), name="gold_detail", ), path( "subscription/checkout/create/", views.GoldCreateCheckoutSession.as_view(), ...
31
729
readthedocs.org
readthedocs/gold/forms.py
.py
"""Gold subscription forms.""" from django import forms from django.utils.translation import gettext_lazy as _ from readthedocs.projects.models import Project from .models import LEVEL_CHOICES from .models import GoldUser class GoldSubscriptionForm(forms.ModelForm): """Gold subscription form.""" class Met...
63
1,848
readthedocs.org
readthedocs/gold/tests/test_views.py
.py
import re from django.contrib.auth.models import User from django.test import TestCase from django.urls import reverse from django_dynamic_fixture import get from readthedocs.payments.tests.utils import PaymentMixin class TestViews(PaymentMixin, TestCase): def setUp(self): super().setUp() self.us...
32
1,110
readthedocs.org
readthedocs/gold/tests/test_signals.py
.py
import requests_mock from unittest import mock import django_dynamic_fixture as fixture from django.contrib.auth.models import User from django.test import TestCase from ..models import GoldUser from readthedocs.payments.tests.utils import PaymentMixin class GoldSignalTests(PaymentMixin, TestCase): def setUp(se...
35
1,318
readthedocs.org
readthedocs/sso/admin.py
.py
"""Admin interface for SSO models.""" import structlog from django.contrib import admin from django.contrib import messages from readthedocs.core.permissions import AdminPermission from readthedocs.oauth.tasks import sync_remote_repositories from .models import SSODomain from .models import SSOIntegration log = st...
54
1,636
readthedocs.org
readthedocs/sso/models.py
.py
"""Single Sign On models.""" import uuid from django.db import models from readthedocs.projects.validators import validate_domain_name class SSOIntegration(models.Model): """Single Sign-On integration for an Organization.""" PROVIDER_ALLAUTH = "allauth" PROVIDER_EMAIL = "email" PROVIDER_SAML = "sa...
77
1,755
readthedocs.org
readthedocs/sso/apps.py
.py
"""Single Sign On (SSO) app.""" from django.apps import AppConfig class SsoConfig(AppConfig): name = "readthedocs.sso"
8
126
readthedocs.org
readthedocs/audit/admin.py
.py
"""Audit admin.""" from django.contrib import admin from readthedocs.audit.models import AuditLog @admin.register(AuditLog) class AuditLogAdmin(admin.ModelAdmin): raw_id_fields = ("user", "project", "organization") search_fields = ( "log_user_username", "ip", "browser", "log_...
28
592
readthedocs.org
readthedocs/audit/models.py
.py
"""Audit models.""" from django.contrib.auth.models import User from django.db import models from django.utils.translation import gettext_lazy as _ from django_extensions.db.models import TimeStampedModel from readthedocs.acl.utils import get_auth_backend from readthedocs.analytics.utils import get_client_ip class ...
264
7,734
readthedocs.org
readthedocs/audit/apps.py
.py
"""Audit module.""" import structlog from django.apps import AppConfig log = structlog.get_logger(__name__) class AuditConfig(AppConfig): name = "readthedocs.audit" def ready(self): import readthedocs.audit.signals # noqa
15
245
readthedocs.org
readthedocs/audit/filters.py
.py
"""Filters used in our views.""" from django_filters import CharFilter from django_filters import ChoiceFilter from django_filters import DateFromToRangeFilter from django_filters import FilterSet from readthedocs.audit.models import AuditLog class UserSecurityLogFilter(FilterSet): """Filter for user security l...
61
2,351
readthedocs.org
readthedocs/audit/serializers.py
.py
""" Serializers used to save the corresponding data from a model in a log entry. .. note:: These aren't used in an API, but to extract data from objects to save it in log entries (AuditLog.data). """ from django.contrib.auth.models import User from rest_framework import serializers from readthedocs.invitation...
76
1,988
readthedocs.org
readthedocs/audit/signals.py
.py
"""Audit signals.""" from django.contrib.auth.models import User from django.contrib.auth.signals import user_logged_in from django.contrib.auth.signals import user_logged_out from django.contrib.auth.signals import user_login_failed from django.db.models import Q from django.dispatch import receiver from readthedocs...
50
1,411
readthedocs.org
readthedocs/audit/tasks.py
.py
"""Celery tasks related to audit logs.""" import structlog from django.conf import settings from django.utils import timezone from readthedocs.audit.models import AuditLog from readthedocs.worker import app log = structlog.get_logger(__name__) @app.task(queue="web") def delete_old_personal_audit_logs(days=None): ...
32
948
readthedocs.org
readthedocs/audit/tests/test_tasks.py
.py
from unittest import mock from django.contrib.auth.models import User from django.test import TestCase, override_settings from django.utils import timezone from django_dynamic_fixture import get from readthedocs.audit.models import AuditLog from readthedocs.audit.tasks import delete_old_personal_audit_logs from readt...
117
3,531
readthedocs.org
readthedocs/audit/tests/test_models.py
.py
from django.contrib.auth.models import User from django.test import TestCase, override_settings from django_dynamic_fixture import get from readthedocs.audit.models import AuditLog from readthedocs.organizations.models import Organization, OrganizationOwner from readthedocs.projects.models import Project @override_s...
98
3,519
readthedocs.org
readthedocs/audit/tests/test_signals.py
.py
from django.contrib.auth.models import User from django.test import TestCase from django_dynamic_fixture import get from readthedocs.audit.models import AuditLog class TestSignals(TestCase): def setUp(self): self.user = get( User, username="test", ) self.user.set_p...
41
1,531
readthedocs.org
readthedocs/projects/notifications.py
.py
"""Notifications related to projects.""" import textwrap from django.utils.translation import gettext_noop as _ from readthedocs.notifications.constants import ERROR from readthedocs.notifications.constants import INFO from readthedocs.notifications.constants import WARNING from readthedocs.notifications.messages im...
244
9,001
readthedocs.org
readthedocs/projects/admin.py
.py
"""Django administration interface for `projects.models`.""" from django.conf import settings from django.contrib import admin from django.contrib import messages from django.contrib.admin.actions import delete_selected from django.db.models import Exists from django.db.models import IntegerField from django.db.models...
543
17,654
readthedocs.org
readthedocs/projects/utils.py
.py
"""Utility functions used by projects.""" import csv import structlog from django.http import StreamingHttpResponse from django.utils.http import content_disposition_header log = structlog.get_logger(__name__) class Echo: """ A class that implements just the write method of the file-like interface. T...
38
1,045
readthedocs.org
readthedocs/projects/exceptions.py
.py
"""Project exceptions.""" from readthedocs.doc_builder.exceptions import BuildAppError from readthedocs.doc_builder.exceptions import BuildUserError class ProjectConfigurationError(BuildUserError): """Error raised trying to configure a project for build.""" NOT_FOUND = "project:sphinx:conf-py-not-found" ...
34
1,247
readthedocs.org
readthedocs/projects/models.py
.py
"""Project models.""" import fnmatch import hashlib import hmac import os import re from shlex import quote from urllib.parse import urlparse import regex import structlog from django.conf import settings from django.contrib.auth.models import User from django.contrib.contenttypes.fields import GenericRelation from d...
2,731
94,172
readthedocs.org
readthedocs/projects/querysets.py
.py
"""Project model QuerySet classes.""" from django.conf import settings from django.db import models from django.db.models import Count from django.db.models import Exists from django.db.models import OuterRef from django.db.models import Prefetch from django.db.models import Q from readthedocs.core.permissions import...
289
9,967
readthedocs.org
readthedocs/projects/apps.py
.py
"""Project app config.""" import socket from django.apps import AppConfig from django.conf import settings from django.core.checks.registry import registry class ProjectsConfig(AppConfig): name = "readthedocs.projects" def ready(self): # Load and register notification messages for this application ...
30
1,276
readthedocs.org
readthedocs/projects/filters.py
.py
"""Filters used in project dashboard.""" import structlog from django.db.models import Count from django.db.models import F from django.db.models import Max from django.utils.translation import gettext_lazy as _ from django_filters import ChoiceFilter from django_filters import OrderingFilter from readthedocs.core.fi...
279
9,864
readthedocs.org
readthedocs/projects/tag_utils.py
.py
"""Customizations to Django Taggit.""" import requests from allauth.socialaccount.models import SocialApp from django.db.models import Count from django.utils.text import slugify from taggit.models import Tag from taggit.utils import _parse_tags from .constants import GITHUB_REGEXS def rtd_parse_tags(tag_string): ...
86
2,417
readthedocs.org
readthedocs/projects/constants.py
.py
""" Project constants. Default values and other various configuration for projects, including available theme names and repository types. """ import os import re from django.utils.translation import gettext_lazy as _ SPHINX = "sphinx" MKDOCS = "mkdocs" SPHINX_HTMLDIR = "sphinx_htmldir" SPHINX_SINGLEHTML = "sphinx_...
457
13,125
readthedocs.org
readthedocs/projects/signals.py
.py
"""Project signals.""" from dataclasses import asdict import django.dispatch import structlog from django.db.models.signals import post_save from django.dispatch import receiver from readthedocs.integrations.models import GitHubAppIntegrationProviderData from readthedocs.integrations.models import Integration from r...
48
1,489
readthedocs.org
readthedocs/projects/managers.py
.py
from django.db import models class HTMLFileManager(models.Manager): def get_queryset(self): return super().get_queryset().filter(name__endswith=".html") class AutomationRuleMatchManager(models.Manager): def register_match(self, rule, version, max_registers=15): created = self.create( ...
22
649
readthedocs.org
readthedocs/projects/forms.py
.py
"""Project forms.""" import json import re from random import choice from re import fullmatch from urllib.parse import urlparse import dns.name import dns.resolver from allauth.socialaccount.models import SocialAccount from crispy_forms.helper import FormHelper from crispy_forms.layout import Field from crispy_forms....
1,556
58,118
readthedocs.org
readthedocs/projects/ordering.py
.py
"""Utilities to manage the position of items in a project.""" from django.db.models import F class ProjectItemPositionManager: def __init__(self, position_field_name): self.position_field_name = position_field_name def change_position_before_save(self, item): """ Re-order the positio...
141
6,363
readthedocs.org
readthedocs/projects/version_handling.py
.py
"""Project version handling.""" import operator import unicodedata from bumpver.v2version import parse_version_info from bumpver.version import PatternError from packaging.version import InvalidVersion from packaging.version import Version from readthedocs.builds.constants import LATEST from readthedocs.builds.const...
271
8,737
readthedocs.org
readthedocs/projects/validators.py
.py
"""Validators for projects app.""" import re from urllib.parse import urlparse from django.conf import settings from django.core.exceptions import ValidationError from django.core.validators import RegexValidator from django.db.models import Sum from django.db.models.functions import Length from django.utils.deconstr...
258
8,523
readthedocs.org
readthedocs/projects/urls/public.py
.py
"""Project URLS for public users.""" from django.urls import path from django.urls import re_path from django.views.generic.base import RedirectView from readthedocs.builds import views as build_views from readthedocs.constants import pattern_opts from readthedocs.projects.views import public from readthedocs.project...
85
2,808
readthedocs.org
readthedocs/projects/urls/private.py
.py
"""Project URLs for authenticated users.""" from django.contrib.auth.decorators import login_required from django.urls import path from django.urls import re_path from django.views.generic.base import RedirectView from readthedocs.core.views import PageNotFoundView from readthedocs.projects.backends.views import Impo...
410
14,082
readthedocs.org
readthedocs/projects/management/commands/import_project_from_live.py
.py
"""Import project command.""" import json import os import requests from django.contrib.auth.models import User from django.core.management import call_command from django.core.management.base import BaseCommand from django.core.management.base import CommandError from ...models import Project class Command(BaseCo...
97
3,457
readthedocs.org
readthedocs/projects/tasks/utils.py
.py
import datetime import os import re import socket import boto3 import structlog from botocore.exceptions import ClientError from celery.worker.request import Request from django.conf import settings from django.core.exceptions import ValidationError from django.db.models import Q from django.utils import timezone fro...
329
11,272
readthedocs.org
readthedocs/projects/tasks/storage.py
.py
from enum import StrEnum from enum import auto import structlog from django.core.files.storage import storages from readthedocs.doc_builder.exceptions import BuildAppError log = structlog.get_logger(__name__) class StorageType(StrEnum): build_media = auto() build_tools = auto() def get_storage(*, build_...
101
3,158
readthedocs.org
readthedocs/projects/tasks/builds.py
.py
""" Tasks related to projects. This includes fetching repository code, cleaning ``conf.py`` files, and rebuilding documentation. """ import datetime import os import shutil import signal import socket import subprocess from dataclasses import dataclass from dataclasses import field from pathlib import Path import st...
1,050
43,268
readthedocs.org
readthedocs/projects/tasks/search.py
.py
from fnmatch import fnmatch import structlog from django.conf import settings from readthedocs.builds.constants import BUILD_STATE_FINISHED from readthedocs.builds.constants import INTERNAL from readthedocs.builds.constants import LATEST from readthedocs.builds.models import Build from readthedocs.builds.models impor...
411
14,705
readthedocs.org
readthedocs/projects/tasks/mixins.py
.py
from collections import Counter import structlog from readthedocs.builds import tasks as build_tasks from readthedocs.builds.constants import LATEST_VERBOSE_NAME from readthedocs.builds.constants import STABLE_VERBOSE_NAME from readthedocs.builds.models import APIVersion from ..exceptions import RepositoryError from...
105
3,423
readthedocs.org
readthedocs/projects/backends/views.py
.py
""" Project views loaded by configuration settings. Use these views instead of calling the views directly, in order to allow for settings override of the view class. """ from readthedocs.core.utils.extend import SettingsOverrideObject from readthedocs.projects.views import private # Project Import Wizard class Impo...
16
450
readthedocs.org
readthedocs/projects/tests/test_views.py
.py
import csv from unittest import mock from allauth.account.models import EmailAddress from django.contrib.auth.models import User from django.contrib.messages import get_messages from django.test import TestCase, override_settings from django.urls import reverse from django_dynamic_fixture import get from readthedocs....
671
25,629
readthedocs.org
readthedocs/projects/tests/mockers.py
.py
import os import shutil from unittest import mock from django.conf import settings from readthedocs.api.v2.serializers import VersionAdminSerializer from readthedocs.builds.constants import BUILD_STATE_TRIGGERED from readthedocs.projects.constants import MKDOCS from readthedocs.projects.tasks.builds import UpdateDocs...
261
9,868
readthedocs.org
readthedocs/projects/tests/test_build_tasks.py
.py
import os import pathlib import textwrap import uuid from pathlib import Path from unittest import mock import django_dynamic_fixture as fixture from django_dynamic_fixture import get import pytest from django.conf import settings from django.test.utils import override_settings from readthedocs.allauth.providers.gith...
3,177
111,456
readthedocs.org
readthedocs/projects/tests/test_models.py
.py
import pytest from django.core.exceptions import ValidationError from django.test import TestCase from django_dynamic_fixture import get from readthedocs.analytics.models import PageView from readthedocs.builds.models import Build, Version from readthedocs.oauth.models import RemoteRepository from readthedocs.projects...
286
11,221
readthedocs.org
readthedocs/projects/tests/test_validators.py
.py
import pytest from django.core.exceptions import ValidationError from readthedocs.projects import validators def test_repository_path_validator(): # Invalid stuff with pytest.raises(ValidationError): validators.validate_build_config_file("/absolute_path") with pytest.raises(ValidationError): ...
43
1,608
readthedocs.org
readthedocs/projects/tests/test_domain_views.py
.py
from unittest import mock import dns.resolver from django.contrib.auth.models import User from django.contrib.messages import get_messages from django.test import TestCase, override_settings from django.urls import reverse from django_dynamic_fixture import get from readthedocs.organizations.models import Organizatio...
238
9,319
readthedocs.org
readthedocs/projects/tests/test_signals.py
.py
from django.contrib.auth.models import User from django.test import TestCase from django_dynamic_fixture import get from readthedocs.integrations.models import Integration from readthedocs.oauth.constants import GITHUB, GITHUB_APP from readthedocs.oauth.models import GitHubAppInstallation, RemoteRepository from readthe...
48
1,848
readthedocs.org
readthedocs/projects/tests/test_version_handling.py
.py
import django_dynamic_fixture as fixture import pytest from readthedocs.builds.constants import BRANCH, TAG from readthedocs.builds.models import Build, Version from readthedocs.projects.models import Project from readthedocs.projects.version_handling import ( determine_stable_version, sort_versions_calver, ...
249
6,554
readthedocs.org
readthedocs/projects/tests/test_docker_environment.py
.py
import django_dynamic_fixture as fixture import pytest from readthedocs.api.v2.client import setup_api from readthedocs.builds.models import Build from readthedocs.doc_builder.environments import DockerBuildEnvironment from readthedocs.projects.models import Project @pytest.mark.django_db class TestDockerBuildEnviro...
40
1,193
readthedocs.org
readthedocs/projects/tests/test_indexers.py
.py
from django.test import TestCase from django_dynamic_fixture import get from readthedocs.builds.constants import BUILD_STATE_FINISHED, EXTERNAL from readthedocs.builds.models import Build, Version from readthedocs.projects.models import Project from readthedocs.projects.tasks.search import SearchIndexer, _get_indexers...
73
2,858
readthedocs.org
readthedocs/projects/views/public.py
.py
"""Public project views.""" import hashlib import mimetypes import os import structlog from django.conf import settings from django.contrib import messages from django.db.models import prefetch_related_objects from django.http import Http404 from django.http import HttpResponse from django.http import HttpResponseRed...
457
15,461
readthedocs.org
readthedocs/projects/views/private.py
.py
"""Project views for authenticated users.""" from functools import lru_cache import structlog from django.conf import settings from django.contrib import messages from django.contrib.messages.views import SuccessMessageMixin from django.db.models import Count from django.db.models import Q from django.http import Htt...
1,351
47,145
readthedocs.org
readthedocs/projects/views/mixins.py
.py
"""Mixin classes for project views.""" from urllib.parse import urlparse import structlog from celery import chain from django.shortcuts import get_object_or_404 from readthedocs.core.resolver import Resolver from readthedocs.core.utils import prepare_build from readthedocs.projects.models import Project log = str...
141
4,549
readthedocs.org
readthedocs/projects/views/base.py
.py
"""Mix-in classes for project views.""" from functools import lru_cache import structlog from django.conf import settings from django.contrib.messages.views import SuccessMessageMixin from django.shortcuts import get_object_or_404 from django.shortcuts import render from readthedocs.projects.models import Project ...
126
4,083
readthedocs.org
readthedocs/projects/templatetags/projects_tags.py
.py
"""Project template tags and filters.""" from django import template from readthedocs.builds.constants import INTERNAL from readthedocs.core.permissions import AdminPermission from readthedocs.projects.version_handling import comparable_version register = template.Library() @register.filter def sort_version_aware...
35
972
readthedocs.org
readthedocs/embed/utils.py
.py
"""Embed utils.""" from urllib.parse import urlparse from pyquery import PyQuery as PQ # noqa def recurse_while_none(element): """Recursively find the leaf node with the ``href`` attribute.""" if element.text is None and element.getchildren(): return recurse_while_none(element.getchildren()[0]) ...
76
2,629
readthedocs.org
readthedocs/embed/apps.py
.py
"""Embed app config.""" from django.apps import AppConfig class EmbedConfig(AppConfig): name = "readthedocs.embed" verbose_name = "Embedded API"
9
156
readthedocs.org
readthedocs/embed/views.py
.py
"""Views for the embed app.""" import structlog from rest_framework import status from rest_framework.permissions import AllowAny from rest_framework.renderers import JSONRenderer from rest_framework.response import Response from rest_framework.views import APIView from readthedocs.api.mixins import EmbedAPIMixin l...
30
900
readthedocs.org
readthedocs/embed/urls.py
.py
from django.urls import path from .views import EmbedAPI urlpatterns = [ path("", EmbedAPI.as_view(), name="embed_api"), ]
9
130
readthedocs.org
readthedocs/embed/tests/test_api.py
.py
import pytest from django.urls import reverse from django_dynamic_fixture import get from rest_framework import status from readthedocs.builds.constants import LATEST from readthedocs.projects.constants import PUBLIC from readthedocs.projects.models import Project from readthedocs.subscriptions.constants import TYPE_E...
56
1,661