Skip to content

Commit 4f7e9ff

Browse files
authored
Merge pull request readthedocs#4896 from stsewd/remove-usage-of-project-doctype
Remove usage of project.documentation_type in tasks
2 parents d351c21 + 20c671f commit 4f7e9ff

File tree

2 files changed

+168
-48
lines changed

2 files changed

+168
-48
lines changed

readthedocs/projects/tasks.py

Lines changed: 53 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,7 @@ def update_app_instances(
729729
args=[
730730
self.project.pk,
731731
self.version.pk,
732+
self.config.doctype,
732733
],
733734
kwargs=dict(
734735
hostname=socket.gethostname(),
@@ -812,7 +813,9 @@ def build_docs_html(self):
812813
broadcast(
813814
type='app',
814815
task=move_files,
815-
args=[self.version.pk, socket.gethostname()],
816+
args=[
817+
self.version.pk, socket.gethostname(), self.config.doctype
818+
],
816819
kwargs=dict(html=True),
817820
)
818821
except socket.error:
@@ -885,6 +888,7 @@ def is_type_sphinx(self):
885888
def sync_files(
886889
project_pk,
887890
version_pk,
891+
doctype,
888892
hostname=None,
889893
html=False,
890894
localmedia=False,
@@ -919,6 +923,7 @@ def sync_files(
919923
move_files(
920924
version_pk,
921925
hostname,
926+
doctype,
922927
html=html,
923928
localmedia=localmedia,
924929
search=search,
@@ -937,6 +942,7 @@ def sync_files(
937942
def move_files(
938943
version_pk,
939944
hostname,
945+
doctype,
940946
html=False,
941947
localmedia=False,
942948
search=False,
@@ -971,59 +977,58 @@ def move_files(
971977
if html:
972978
from_path = version.project.artifact_path(
973979
version=version.slug,
974-
type_=version.project.documentation_type,
980+
type_=doctype,
975981
)
976982
target = version.project.rtd_build_path(version.slug)
977983
Syncer.copy(from_path, target, host=hostname)
978984

979-
if 'sphinx' in version.project.documentation_type:
980-
if search:
981-
from_path = version.project.artifact_path(
982-
version=version.slug,
983-
type_='sphinx_search',
984-
)
985-
to_path = version.project.get_production_media_path(
986-
type_='json',
987-
version_slug=version.slug,
988-
include_file=False,
989-
)
990-
Syncer.copy(from_path, to_path, host=hostname)
985+
if search:
986+
from_path = version.project.artifact_path(
987+
version=version.slug,
988+
type_='sphinx_search',
989+
)
990+
to_path = version.project.get_production_media_path(
991+
type_='json',
992+
version_slug=version.slug,
993+
include_file=False,
994+
)
995+
Syncer.copy(from_path, to_path, host=hostname)
991996

992-
if localmedia:
993-
from_path = version.project.artifact_path(
994-
version=version.slug,
995-
type_='sphinx_localmedia',
996-
)
997-
to_path = version.project.get_production_media_path(
998-
type_='htmlzip',
999-
version_slug=version.slug,
1000-
include_file=False,
1001-
)
1002-
Syncer.copy(from_path, to_path, host=hostname)
997+
if localmedia:
998+
from_path = version.project.artifact_path(
999+
version=version.slug,
1000+
type_='sphinx_localmedia',
1001+
)
1002+
to_path = version.project.get_production_media_path(
1003+
type_='htmlzip',
1004+
version_slug=version.slug,
1005+
include_file=False,
1006+
)
1007+
Syncer.copy(from_path, to_path, host=hostname)
10031008

1004-
# Always move PDF's because the return code lies.
1005-
if pdf:
1006-
from_path = version.project.artifact_path(
1007-
version=version.slug,
1008-
type_='sphinx_pdf',
1009-
)
1010-
to_path = version.project.get_production_media_path(
1011-
type_='pdf',
1012-
version_slug=version.slug,
1013-
include_file=False,
1014-
)
1015-
Syncer.copy(from_path, to_path, host=hostname)
1016-
if epub:
1017-
from_path = version.project.artifact_path(
1018-
version=version.slug,
1019-
type_='sphinx_epub',
1020-
)
1021-
to_path = version.project.get_production_media_path(
1022-
type_='epub',
1023-
version_slug=version.slug,
1024-
include_file=False,
1025-
)
1026-
Syncer.copy(from_path, to_path, host=hostname)
1009+
# Always move PDF's because the return code lies.
1010+
if pdf:
1011+
from_path = version.project.artifact_path(
1012+
version=version.slug,
1013+
type_='sphinx_pdf',
1014+
)
1015+
to_path = version.project.get_production_media_path(
1016+
type_='pdf',
1017+
version_slug=version.slug,
1018+
include_file=False,
1019+
)
1020+
Syncer.copy(from_path, to_path, host=hostname)
1021+
if epub:
1022+
from_path = version.project.artifact_path(
1023+
version=version.slug,
1024+
type_='sphinx_epub',
1025+
)
1026+
to_path = version.project.get_production_media_path(
1027+
type_='epub',
1028+
version_slug=version.slug,
1029+
include_file=False,
1030+
)
1031+
Syncer.copy(from_path, to_path, host=hostname)
10271032

10281033

10291034
@app.task(queue='web')
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
from __future__ import division, print_function, unicode_literals
2+
3+
from django.test import TestCase
4+
from django_dynamic_fixture import get
5+
from mock import patch
6+
7+
from readthedocs.builds.models import Version
8+
from readthedocs.projects.models import Project
9+
from readthedocs.projects.tasks import sync_files
10+
11+
12+
class SyncFilesTests(TestCase):
13+
14+
def setUp(self):
15+
self.project = get(Project)
16+
self.version = get(Version, project=self.project)
17+
18+
@patch('readthedocs.builds.syncers.Syncer.copy')
19+
@patch('readthedocs.projects.tasks.shutil.rmtree')
20+
def test_sync_files_clean_old_artifacts(self, rmtree, copy):
21+
sync_files(self.project.pk, self.version.pk, 'sphinx', html=True)
22+
pdf, epub = rmtree.call_args_list
23+
24+
# pdf and epub are cleaned
25+
args, _ = pdf
26+
self.assertIn('pdf', args[0])
27+
args, _ = epub
28+
self.assertIn('epub', args[0])
29+
30+
# Artifacts are copied to the rtd-builds directory
31+
copy.assert_called_once()
32+
args, _ = copy.call_args
33+
self.assertIn('artifacts', args[0])
34+
self.assertIn('sphinx', args[0])
35+
self.assertIn('rtd-builds', args[1])
36+
37+
@patch('readthedocs.builds.syncers.Syncer.copy')
38+
@patch('readthedocs.projects.tasks.shutil.rmtree')
39+
def test_sync_files_pdf(self, rmtree, copy):
40+
sync_files(
41+
self.project.pk, self.version.pk, 'sphinx', pdf=True
42+
)
43+
44+
# epub is cleaned
45+
rmtree.assert_called_once()
46+
args, _ = rmtree.call_args
47+
self.assertIn('epub', args[0])
48+
49+
# Artifacts are copied to the media directory
50+
copy.assert_called_once()
51+
args, _ = copy.call_args
52+
self.assertIn('artifacts', args[0])
53+
self.assertIn('sphinx_pdf', args[0])
54+
self.assertIn('media/pdf', args[1])
55+
56+
@patch('readthedocs.builds.syncers.Syncer.copy')
57+
@patch('readthedocs.projects.tasks.shutil.rmtree')
58+
def test_sync_files_epub(self, rmtree, copy):
59+
sync_files(
60+
self.project.pk, self.version.pk, 'sphinx', epub=True
61+
)
62+
63+
# pdf is cleaned
64+
rmtree.assert_called_once()
65+
args, _ = rmtree.call_args
66+
self.assertIn('pdf', args[0])
67+
68+
# Artifacts are copied to the media directory
69+
copy.assert_called_once()
70+
args, _ = copy.call_args
71+
self.assertIn('artifacts', args[0])
72+
self.assertIn('sphinx_epub', args[0])
73+
self.assertIn('media/epub', args[1])
74+
75+
@patch('readthedocs.builds.syncers.Syncer.copy')
76+
@patch('readthedocs.projects.tasks.shutil.rmtree')
77+
def test_sync_files_localmedia(self, rmtree, copy):
78+
sync_files(
79+
self.project.pk, self.version.pk, 'sphinx', localmedia=True
80+
)
81+
pdf, epub = rmtree.call_args_list
82+
83+
# pdf and epub are cleaned
84+
args, _ = pdf
85+
self.assertIn('pdf', args[0])
86+
args, _ = epub
87+
self.assertIn('epub', args[0])
88+
89+
# Artifacts are copied to the media directory
90+
copy.assert_called_once()
91+
args, _ = copy.call_args
92+
self.assertIn('artifacts', args[0])
93+
self.assertIn('sphinx_localmedia', args[0])
94+
self.assertIn('media/htmlzip', args[1])
95+
96+
@patch('readthedocs.builds.syncers.Syncer.copy')
97+
@patch('readthedocs.projects.tasks.shutil.rmtree')
98+
def test_sync_files_search(self, rmtree, copy):
99+
sync_files(
100+
self.project.pk, self.version.pk, 'sphinx', search=True
101+
)
102+
pdf, epub = rmtree.call_args_list
103+
104+
# pdf and epub are cleaned
105+
args, _ = pdf
106+
self.assertIn('pdf', args[0])
107+
args, _ = epub
108+
self.assertIn('epub', args[0])
109+
110+
# Artifacts are copied to the media directory
111+
copy.assert_called_once()
112+
args, _ = copy.call_args
113+
self.assertIn('artifacts', args[0])
114+
self.assertIn('sphinx_search', args[0])
115+
self.assertIn('media/json', args[1])

0 commit comments

Comments
 (0)