11"""Project models."""
2+
23import fnmatch
34import hashlib
45import hmac
3435from readthedocs .core .resolver import Resolver
3536from readthedocs .core .utils import extract_valid_attributes_for_model , slugify
3637from readthedocs .core .utils .url import unsafe_join_url_path
38+ from readthedocs .doc_builder .exceptions import MkDocsYAMLParseError
3739from readthedocs .domains .querysets import DomainQueryset
3840from readthedocs .domains .validators import check_domains_limit
3941from readthedocs .notifications .models import Notification as NewNotification
@@ -80,7 +82,6 @@ def default_privacy_level():
8082
8183
8284class ProjectRelationship (models .Model ):
83-
8485 """
8586 Project to project relationship.
8687
@@ -135,7 +136,6 @@ def subproject_prefix(self):
135136
136137
137138class AddonsConfig (TimeStampedModel ):
138-
139139 """
140140 Addons project configuration.
141141
@@ -266,7 +266,6 @@ class AddonsConfig(TimeStampedModel):
266266
267267
268268class AddonSearchFilter (TimeStampedModel ):
269-
270269 """
271270 Addon search user defined filter.
272271
@@ -279,7 +278,6 @@ class AddonSearchFilter(TimeStampedModel):
279278
280279
281280class Project (models .Model ):
282-
283281 """Project model."""
284282
285283 # Auto fields
@@ -962,7 +960,6 @@ def conf_file(self, version=LATEST):
962960 # contains the `doc` word in its path and return this one
963961 if filename .find ("doc" , 70 ) != - 1 :
964962 return filename
965-
966963 # If the project has more than one conf.py file but none of them have
967964 # the `doc` word in the path, we raise an error informing this to the user
968965 if len (files ) > 1 :
@@ -972,11 +969,27 @@ def conf_file(self, version=LATEST):
972969
973970 raise ProjectConfigurationError (ProjectConfigurationError .NOT_FOUND )
974971
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+
975983 def conf_dir (self , version = LATEST ):
976984 conf_file = self .conf_file (version )
977985 if conf_file :
978986 return os .path .dirname (conf_file )
979987
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+
980993 @property
981994 def has_good_build (self ):
982995 # Check if there is `_good_build` annotation in the Queryset.
@@ -1432,7 +1445,6 @@ def organization(self):
14321445
14331446
14341447class APIProject (Project ):
1435-
14361448 """
14371449 Project proxy model for API data deserialization.
14381450
@@ -1506,7 +1518,6 @@ def environment_variables(self, *, public_only=True):
15061518
15071519
15081520class ImportedFile (models .Model ):
1509-
15101521 """
15111522 Imported files model.
15121523
@@ -1558,7 +1569,6 @@ def get_absolute_url(self):
15581569
15591570
15601571class HTMLFile (ImportedFile ):
1561-
15621572 """
15631573 Imported HTML file Proxy model.
15641574
@@ -1580,7 +1590,6 @@ def processed_json(self):
15801590
15811591
15821592class Notification (TimeStampedModel ):
1583-
15841593 """WebHook / Email notification attached to a Project."""
15851594
15861595 # TODO: Overridden from TimeStampedModel just to allow null values,
@@ -1745,7 +1754,6 @@ def sign_payload(self, payload):
17451754
17461755
17471756class Domain (TimeStampedModel ):
1748-
17491757 """A custom domain name for a project."""
17501758
17511759 # TODO: Overridden from TimeStampedModel just to allow null values,
@@ -1869,7 +1877,6 @@ def save(self, *args, **kwargs):
18691877
18701878
18711879class HTTPHeader (TimeStampedModel , models .Model ):
1872-
18731880 """
18741881 Define a HTTP header for a user Domain.
18751882
@@ -1912,7 +1919,6 @@ def __str__(self):
19121919
19131920
19141921class Feature (models .Model ):
1915-
19161922 """
19171923 Project feature flags.
19181924
0 commit comments