Skip to content

Commit fa3ce4c

Browse files
committed
Merge remote-tracking branch 'origin/master' into humitos/lock/appropiate-log
2 parents e0c8405 + adde923 commit fa3ce4c

File tree

93 files changed

+1138
-646
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+1138
-646
lines changed

.coveragerc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ exclude_lines =
1717
pragma: no cover
1818
raise NotImplementedError
1919
if __name__ == .__main__.:
20+
if getattr(settings, 'DEBUG'):

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ matrix:
1616
script: tox
1717
- python: 3.6
1818
env: TOXENV=eslint
19+
- python: 3.6
20+
env: TOXENV=migrations
1921
cache:
2022
directories:
2123
- ~/.cache/pip

CHANGELOG.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
Version 2.8.0
2+
-------------
3+
4+
:Date: October 30, 2018
5+
6+
Major change is an upgrade to Django 1.11.
7+
8+
* `@humitos <http://github.com/humitos>`__: Cleanup old code (remove old_div) (`#4817 <https://github.com/rtfd/readthedocs.org/pull/4817>`__)
9+
* `@humitos <http://github.com/humitos>`__: Remove unnecessary migration (`#4806 <https://github.com/rtfd/readthedocs.org/pull/4806>`__)
10+
* `@humitos <http://github.com/humitos>`__: Feature flag to make `readthedocs` theme default on MkDocs docs (`#4802 <https://github.com/rtfd/readthedocs.org/pull/4802>`__)
11+
* `@stsewd <http://github.com/stsewd>`__: Add codecov badge (`#4799 <https://github.com/rtfd/readthedocs.org/pull/4799>`__)
12+
* `@humitos <http://github.com/humitos>`__: Pin missing dependency for the MkDocs guide compatibility (`#4798 <https://github.com/rtfd/readthedocs.org/pull/4798>`__)
13+
* `@ericholscher <http://github.com/ericholscher>`__: Release 2.7.2 (`#4796 <https://github.com/rtfd/readthedocs.org/pull/4796>`__)
14+
* `@humitos <http://github.com/humitos>`__: Do not log as error a webhook with an invalid branch name (`#4779 <https://github.com/rtfd/readthedocs.org/pull/4779>`__)
15+
* `@ericholscher <http://github.com/ericholscher>`__: Run travis on release branches (`#4763 <https://github.com/rtfd/readthedocs.org/pull/4763>`__)
16+
* `@ericholscher <http://github.com/ericholscher>`__: Remove Eric & Anthony from ADMINS & MANAGERS settings (`#4762 <https://github.com/rtfd/readthedocs.org/pull/4762>`__)
17+
* `@stsewd <http://github.com/stsewd>`__: Don't use RequestsContext (`#4759 <https://github.com/rtfd/readthedocs.org/pull/4759>`__)
18+
* `@davidfischer <http://github.com/davidfischer>`__: Django 1.11 upgrade (`#4750 <https://github.com/rtfd/readthedocs.org/pull/4750>`__)
19+
* `@stsewd <http://github.com/stsewd>`__: Dropdown to select Advanced Settings (`#4710 <https://github.com/rtfd/readthedocs.org/pull/4710>`__)
20+
* `@stsewd <http://github.com/stsewd>`__: Remove hardcoded constant from config module (`#4704 <https://github.com/rtfd/readthedocs.org/pull/4704>`__)
21+
* `@stsewd <http://github.com/stsewd>`__: Update tastypie (`#4325 <https://github.com/rtfd/readthedocs.org/pull/4325>`__)
22+
* `@stsewd <http://github.com/stsewd>`__: Update to Django 1.10 (`#4319 <https://github.com/rtfd/readthedocs.org/pull/4319>`__)
23+
124
Version 2.7.2
225
-------------
326

contrib/add-project.py

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
"""
2+
Script to add a Git project as cloned from a Github repository
3+
to ReadTheDocs. Invoke from the checkout.
4+
"""
5+
6+
__requires__ = ['requests-toolbelt', 'autocommand', 'keyring']
7+
8+
9+
import os
10+
import getpass
11+
import re
12+
import urllib.parse
13+
import subprocess
14+
import pathlib
15+
16+
import autocommand
17+
import keyring
18+
from requests_toolbelt import sessions
19+
20+
21+
rtd = sessions.BaseUrlSession(
22+
os.environ.get('RTD_URL', 'https://readthedocs.org/api/v2/'))
23+
github = sessions.BaseUrlSession('https://api.github.com/')
24+
github.headers.update(Accept='application/vnd.github.v3+json')
25+
26+
27+
class User:
28+
"""
29+
A User (with a password) in RTD.
30+
31+
Resolves username using ``getpass.getuser()``. Override with
32+
RTD_USERNAME environment variable.
33+
34+
Resolves password using keyring. Install keyring and run
35+
``keyring set https://readthedocs.org/ $USER`` to set the pw.
36+
Override with RTD_PASSWORD environment variable.
37+
"""
38+
def __init__(self):
39+
self.name = os.environ.get('RTD_USERNAME') or getpass.getuser()
40+
system = rtd.create_url('/')
41+
self.password = (
42+
os.environ.get('RTD_PASSWORD')
43+
or keyring.get_password(system, self.name)
44+
)
45+
46+
@property
47+
def id(self):
48+
resp = rtd.get('../v1/user/', params=dict(username=self.name))
49+
resp.raise_for_status()
50+
ob, = resp.json()['objects']
51+
return ob['id']
52+
53+
@property
54+
def tuple(self):
55+
return self.name, self.password
56+
57+
58+
class Sluggable(str):
59+
"""
60+
A name for use in RTD with a 'slug' version.
61+
"""
62+
@property
63+
def slug(self):
64+
return self.replace('.', '')
65+
66+
67+
class Repo:
68+
"""
69+
A Git repo
70+
"""
71+
72+
def __init__(self, root):
73+
self.root = root
74+
cmd = ['git', '-C', root, 'remote', 'get-url', 'origin']
75+
proc = subprocess.run(
76+
cmd, check=True, text=True, stdout=subprocess.PIPE)
77+
self.url = proc.stdout.strip()
78+
79+
@property
80+
def name(self):
81+
return Sluggable(pathlib.Path(self.url).stem)
82+
83+
84+
def create_project(repo):
85+
"""
86+
Create the project from a Repo
87+
"""
88+
user = User()
89+
payload = dict(
90+
repo=repo.url,
91+
slug=repo.name.slug,
92+
name=repo.name,
93+
users=[user.id],
94+
)
95+
resp = rtd.post('project/', json=payload, auth=user.tuple)
96+
resp.raise_for_status()
97+
98+
99+
def configure_github(name, url):
100+
"""
101+
Given a project name and webhook URL, configure the webhook
102+
in GitHub.
103+
104+
Resolves username from ``getpass.getuser()``. Override with
105+
``GITHUB_USERNAME``.
106+
107+
Resolves access token from keyring for username and system
108+
'github.com'. Override with ``GITHUB_TOKEN`` environment
109+
variable.
110+
"""
111+
user = os.environ.get('GITHUB_USERNAME') or getpass.getuser()
112+
token = (
113+
keyring.get_password('github.com', user)
114+
or os.environ['GITHUB_TOKEN']
115+
)
116+
headers = dict(Authorization=f'token {token}')
117+
path = f'/repos/{user}/{name}/hooks'
118+
params = dict(
119+
name='web',
120+
config=dict(
121+
url=url,
122+
content_type='json',
123+
),
124+
)
125+
github.post(path, json=params, headers=headers)
126+
127+
128+
def configure_webhook(name):
129+
"""
130+
Identify the webhook URL for a RTD project named name.
131+
"""
132+
login_path = '/accounts/login/'
133+
resp = rtd.get(login_path)
134+
token = rtd.cookies.get('csrftoken') or rtd.cookies['csrf']
135+
user = User()
136+
params = dict(
137+
login=user.name,
138+
password=user.password,
139+
csrfmiddlewaretoken=token,
140+
next='/',
141+
)
142+
headers = dict(Referer=rtd.create_url(login_path))
143+
resp = rtd.post(login_path, data=params, headers=headers)
144+
token = rtd.cookies.get('csrftoken') or rtd.cookies['csrf']
145+
params = dict(
146+
integration_type='github_webhook',
147+
csrfmiddlewaretoken=token,
148+
next='/',
149+
)
150+
create_path = f'/dashboard/{name.slug}/integrations/create/'
151+
headers = dict(
152+
Referer=rtd.create_url(create_path),
153+
)
154+
resp = rtd.post(
155+
create_path,
156+
data=params,
157+
headers=headers,
158+
)
159+
resp.raise_for_status()
160+
ref = re.search(f'<a href="(.*?)">.*?webhook.*?</a>', resp.text).group(1)
161+
return urllib.parse.urljoin(resp.url, ref)
162+
163+
164+
@autocommand.autocommand(__name__)
165+
def main(repo: Repo = Repo('.')):
166+
create_project(repo)
167+
url = configure_webhook(repo.name)
168+
configure_github(repo.name, url)

docs/.rstcheck.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[rstcheck]
2-
ignore_directives=automodule,http:get
2+
ignore_directives=automodule,http:get,tabs,tab
33
ignore_roles=djangosetting,setting
44
ignore_messages=(Duplicate implicit target name: ".*")|(Hyperlink target ".*" is not referenced)

docs/api/v2.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ Build list
253253
:>json array results: Array of ``Build`` objects.
254254

255255
:query string project__slug: Narrow to builds for a specific ``Project``
256+
:query string commit: Narrow to builds for a specific ``commit``
256257

257258
Build detail
258259
++++++++++++

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
'sphinxcontrib.httpdomain',
2828
'djangodocs',
2929
'doc_extensions',
30+
'sphinx_tabs.tabs',
3031
]
3132
templates_path = ['_templates']
3233

docs/design.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,10 @@ There's not a hard browser range, but your design changes should work reasonably
5151
browsers, IE8+ -- that's not to say it needs to be pixel-perfect in older browsers! Just avoid
5252
making changes that render older browsers utterly unusable (or provide a sane fallback).
5353

54+
Brand Guidelines
55+
----------------
56+
57+
Find our branding guidelines in our guidelines documentation: https://read-the-docs-guidelines.readthedocs-hosted.com.
58+
5459
.. _Read the Docs GitHub project: https://github.com/rtfd/readthedocs.org/pulls
60+

docs/faq.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ I get import errors on libraries that depend on C modules
7070
.. note::
7171
Another use case for this is when you have a module with a C extension.
7272

73-
This happens because our build system doesn't have the dependencies for building your project. This happens with things like libevent and mysql, and other python things that depend on C libraries. We can't support installing random C binaries on our system, so there is another way to fix these imports.
73+
This happens because our build system doesn't have the dependencies for building your project. This happens with things like ``libevent``, ``mysql``, and other python packages that depend on C libraries. We can't support installing random C binaries on our system, so there is another way to fix these imports.
7474

75-
You can mock out the imports for these modules in your ``conf.py`` with the following snippet::
75+
With Sphinx you can use the built-in `autodoc_mock_imports`_ for mocking. Alternatively you can use the mock library by putting the following snippet in your ``conf.py``::
7676

7777
import sys
7878
from unittest.mock import MagicMock
@@ -85,7 +85,7 @@ You can mock out the imports for these modules in your ``conf.py`` with the foll
8585
MOCK_MODULES = ['pygtk', 'gtk', 'gobject', 'argparse', 'numpy', 'pandas']
8686
sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES)
8787

88-
Of course, replacing `MOCK_MODULES` with the modules that you want to mock out.
88+
You need to replace ``MOCK_MODULES`` with the modules that you want to mock out.
8989

9090
.. Tip:: The library ``unittest.mock`` was introduced on python 3.3. On earlier versions install the ``mock`` library
9191
from PyPI with (ie ``pip install mock``) and replace the above import::
@@ -94,6 +94,8 @@ Of course, replacing `MOCK_MODULES` with the modules that you want to mock out.
9494

9595
If such libraries are installed via ``setup.py``, you also will need to remove all the C-dependent libraries from your ``install_requires`` in the RTD environment.
9696

97+
.. _autodoc_mock_imports: http://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#confval-autodoc_mock_imports
98+
9799
`Client Error 401` when building documentation
98100
----------------------------------------------
99101

0 commit comments

Comments
 (0)