1
1
"""Project models."""
2
+
2
3
import fnmatch
3
4
import hashlib
4
5
import hmac
34
35
from readthedocs .core .resolver import Resolver
35
36
from readthedocs .core .utils import extract_valid_attributes_for_model , slugify
36
37
from readthedocs .core .utils .url import unsafe_join_url_path
38
+ from readthedocs .doc_builder .exceptions import MkDocsYAMLParseError
37
39
from readthedocs .domains .querysets import DomainQueryset
38
40
from readthedocs .domains .validators import check_domains_limit
39
41
from readthedocs .notifications .models import Notification as NewNotification
@@ -80,7 +82,6 @@ def default_privacy_level():
80
82
81
83
82
84
class ProjectRelationship (models .Model ):
83
-
84
85
"""
85
86
Project to project relationship.
86
87
@@ -135,7 +136,6 @@ def subproject_prefix(self):
135
136
136
137
137
138
class AddonsConfig (TimeStampedModel ):
138
-
139
139
"""
140
140
Addons project configuration.
141
141
@@ -266,7 +266,6 @@ class AddonsConfig(TimeStampedModel):
266
266
267
267
268
268
class AddonSearchFilter (TimeStampedModel ):
269
-
270
269
"""
271
270
Addon search user defined filter.
272
271
@@ -279,7 +278,6 @@ class AddonSearchFilter(TimeStampedModel):
279
278
280
279
281
280
class Project (models .Model ):
282
-
283
281
"""Project model."""
284
282
285
283
# Auto fields
@@ -962,7 +960,6 @@ def conf_file(self, version=LATEST):
962
960
# contains the `doc` word in its path and return this one
963
961
if filename .find ("doc" , 70 ) != - 1 :
964
962
return filename
965
-
966
963
# If the project has more than one conf.py file but none of them have
967
964
# the `doc` word in the path, we raise an error informing this to the user
968
965
if len (files ) > 1 :
@@ -972,11 +969,27 @@ def conf_file(self, version=LATEST):
972
969
973
970
raise ProjectConfigurationError (ProjectConfigurationError .NOT_FOUND )
974
971
972
+ def yml_file (self , version = LATEST ):
973
+ """Find a Mkdocs ``mkdocs.yml`` file in the project checkout."""
974
+ files = self .find ("mkdocs.yml" , version )
975
+ if not files :
976
+ files = self .full_find ("mkdocs.yml" , version )
977
+ if len (files ) == 1 :
978
+ return files [0 ]
979
+ # TODO: handle for multiple mkdocs.yml files
980
+
981
+ raise MkDocsYAMLParseError (MkDocsYAMLParseError .NOT_FOUND )
982
+
975
983
def conf_dir (self , version = LATEST ):
976
984
conf_file = self .conf_file (version )
977
985
if conf_file :
978
986
return os .path .dirname (conf_file )
979
987
988
+ def mkdocs_dir (self , version = LATEST ):
989
+ yml_file = self .yml_file (version )
990
+ if yml_file :
991
+ return os .path .dirname (yml_file )
992
+
980
993
@property
981
994
def has_good_build (self ):
982
995
# Check if there is `_good_build` annotation in the Queryset.
@@ -1432,7 +1445,6 @@ def organization(self):
1432
1445
1433
1446
1434
1447
class APIProject (Project ):
1435
-
1436
1448
"""
1437
1449
Project proxy model for API data deserialization.
1438
1450
@@ -1506,7 +1518,6 @@ def environment_variables(self, *, public_only=True):
1506
1518
1507
1519
1508
1520
class ImportedFile (models .Model ):
1509
-
1510
1521
"""
1511
1522
Imported files model.
1512
1523
@@ -1558,7 +1569,6 @@ def get_absolute_url(self):
1558
1569
1559
1570
1560
1571
class HTMLFile (ImportedFile ):
1561
-
1562
1572
"""
1563
1573
Imported HTML file Proxy model.
1564
1574
@@ -1580,7 +1590,6 @@ def processed_json(self):
1580
1590
1581
1591
1582
1592
class Notification (TimeStampedModel ):
1583
-
1584
1593
"""WebHook / Email notification attached to a Project."""
1585
1594
1586
1595
# TODO: Overridden from TimeStampedModel just to allow null values,
@@ -1745,7 +1754,6 @@ def sign_payload(self, payload):
1745
1754
1746
1755
1747
1756
class Domain (TimeStampedModel ):
1748
-
1749
1757
"""A custom domain name for a project."""
1750
1758
1751
1759
# TODO: Overridden from TimeStampedModel just to allow null values,
@@ -1869,7 +1877,6 @@ def save(self, *args, **kwargs):
1869
1877
1870
1878
1871
1879
class HTTPHeader (TimeStampedModel , models .Model ):
1872
-
1873
1880
"""
1874
1881
Define a HTTP header for a user Domain.
1875
1882
@@ -1912,7 +1919,6 @@ def __str__(self):
1912
1919
1913
1920
1914
1921
class Feature (models .Model ):
1915
-
1916
1922
"""
1917
1923
Project feature flags.
1918
1924
0 commit comments