2121import json
2222import re
2323
24+ def get_default_mrdocs_src_dir ():
25+ """
26+ Returns the default source directory for MrDocs based on the current working directory.
27+
28+ If the current working directory is the same as the script directory, it
29+ means we're working on development. The script is being called from a location
30+ that's already a MrDocs repository. So the user wants the current directory
31+ to be used as the source directory, not to create a new source directory
32+ every time the script is run.
33+
34+ If the current working directory is different from the script directory,
35+ it means we're running the script from a different location, likely a
36+ pre-existing MrDocs repository. In this case, we assume the user wants to
37+ create a new source directory for MrDocs in the current working directory
38+ under the name "mrdocs" or anywhere else in order to avoid conflicts
39+ and we assume the user is running this whole procedure to bootstrap,
40+ build, and install MrDocs from scratch.
41+
42+ :return: str: The default source directory for MrDocs.
43+ """
44+ script_dir = os .path .dirname (os .path .abspath (__file__ ))
45+ cwd = os .getcwd ()
46+ if cwd == script_dir :
47+ return cwd
48+ else :
49+ return os .path .join (cwd , "mrdocs" )
50+
51+
2452@dataclass
2553class InstallOptions :
2654 """
@@ -39,7 +67,7 @@ class InstallOptions:
3967 cmake_path : str = ''
4068
4169 # MrDocs
42- mrdocs_src_dir : str = field (default_factory = lambda : os . getcwd () )
70+ mrdocs_src_dir : str = field (default_factory = get_default_mrdocs_src_dir )
4371 mrdocs_build_type : str = "Release"
4472 mrdocs_repo : str = "https://github.com/cppalliance/mrdocs"
4573 mrdocs_branch : str = "develop"
0 commit comments