Skip to content

Commit 1a9de28

Browse files
committed
docs: one-liner installation instructions
1 parent 7fbe9f2 commit 1a9de28

File tree

2 files changed

+83
-32
lines changed

2 files changed

+83
-32
lines changed

bootstrap.py

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,17 @@
2020
import tarfile
2121
import json
2222
import re
23+
from functools import lru_cache
2324

24-
def get_default_mrdocs_src_dir():
25+
@lru_cache(maxsize=1)
26+
def running_from_mrdocs_source_dir():
2527
"""
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.
28+
Checks if the current working directory is the same as the script directory.
29+
:return:
4330
"""
4431
script_dir = os.path.dirname(os.path.abspath(__file__))
4532
cwd = os.getcwd()
46-
if cwd == script_dir:
47-
return cwd
48-
else:
49-
return os.path.join(cwd, "mrdocs")
50-
33+
return cwd == script_dir
5134

5235
@dataclass
5336
class InstallOptions:
@@ -67,16 +50,16 @@ class InstallOptions:
6750
cmake_path: str = ''
6851

6952
# MrDocs
70-
mrdocs_src_dir: str = field(default_factory=get_default_mrdocs_src_dir)
53+
mrdocs_src_dir: str = field(default_factory=lambda: os.getcwd() if running_from_mrdocs_source_dir() else os.path.join(os.getcwd(), "mrdocs"))
7154
mrdocs_build_type: str = "Release"
7255
mrdocs_repo: str = "https://github.com/cppalliance/mrdocs"
7356
mrdocs_branch: str = "develop"
7457
mrdocs_use_user_presets: bool = True
7558
mrdocs_preset_name: str = "<mrdocs-build-type:lower>-<os:lower>"
7659
mrdocs_build_dir: str = "<mrdocs-src-dir>/build/<mrdocs-build-type:lower>-<os:lower>"
7760
mrdocs_build_tests: bool = True
78-
mrdocs_install_dir: str = "<mrdocs-src-dir>/install/<mrdocs-build-type:lower>-<os:lower>"
79-
mrdocs_system_install: bool = False
61+
mrdocs_system_install: bool = field(default_factory=lambda: not running_from_mrdocs_source_dir())
62+
mrdocs_install_dir: str = field(default_factory=lambda: "<mrdocs-src-dir>/install/<mrdocs-build-type:lower>-<os:lower>" if running_from_mrdocs_source_dir() else "")
8063
mrdocs_run_tests: bool = True
8164

8265
# Third-party dependencies
@@ -771,8 +754,9 @@ def install_mrdocs(self):
771754
self.prompt_option("mrdocs_install_dir")
772755

773756
extra_args = []
774-
if self.options.mrdocs_system_install and self.options.mrdocs_install_dir:
757+
if not self.options.mrdocs_system_install and self.options.mrdocs_install_dir:
775758
extra_args.extend(["-D", f"CMAKE_INSTALL_PREFIX={self.options.mrdocs_install_dir}"])
759+
776760
if self.options.mrdocs_use_user_presets:
777761
extra_args.append(f"--preset={self.options.mrdocs_preset_name}")
778762
else:
@@ -802,7 +786,12 @@ def install_mrdocs(self):
802786
"--no-tests=error", "--output-on-failure", "--parallel", str(os.cpu_count() or 1)]
803787
self.run_cmd(test_args)
804788

805-
print(f"\nMrDocs has been successfully installed in {self.options.mrdocs_install_dir}.\n")
789+
YELLOW = "\033[93m"
790+
RESET = "\033[0m"
791+
if self.supports_ansi():
792+
print(f"{YELLOW}MrDocs has been successfully installed in {self.options.mrdocs_install_dir}.{RESET}")
793+
else:
794+
print(f"\nMrDocs has been successfully installed in {self.options.mrdocs_install_dir}.\n")
806795

807796
def install_all(self):
808797
self.check_tools()

docs/modules/ROOT/pages/install.adoc

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,48 @@ mrdocs-releases::[]
1111
[#mrdocs-source-script]
1212
== Python Bootstrap Script
1313
14-
The Python bootstrap script available in the repository provides an alternative way to install MrDocs and its dependencies
15-
from source. Just run the script from the root of the MrDocs repository:
14+
The Python bootstrap script available in the repository provides an alternative way to install MrDocs and its
15+
dependencies from source. Just run the script from the root of the MrDocs repository:
1616
1717
[source,bash]
1818
----
1919
git clone https://www.github.com/cppalliance/mrdocs.git
2020
cd mrdocs
21-
python3 bootstrap.py
21+
python bootstrap.py
2222
----
2323
24+
Or if you just want to install MrDocs without cloning the repository, you can run the script directly from the web:
25+
26+
[tabs]
27+
====
28+
Windows::
29+
+
30+
--
31+
[source,powershell]
32+
----
33+
python -c "$(Invoke-WebRequest -Uri 'https://raw.githubusercontent.com/cppalliance/mrdocs/refs/heads/develop/bootstrap.py' -UseBasicParsing | Select-Object -ExpandProperty Content)"
34+
----
35+
--
36+
37+
Linux::
38+
+
39+
--
40+
[source,bash]
41+
----
42+
python3 -c "$(curl -fsSL https://raw.githubusercontent.com/cppalliance/mrdocs/refs/heads/develop/bootstrap.py)"
43+
----
44+
--
45+
46+
macOS::
47+
+
48+
--
49+
[source,bash]
50+
----
51+
python -c "$(curl -fsSL https://raw.githubusercontent.com/cppalliance/mrdocs/refs/heads/develop/bootstrap.py)"
52+
----
53+
--
54+
====
55+
2456
This method automates the download, configuration, and build steps for MrDocs and all required third-party libraries.
2557
It is especially useful for developers and for users who prefer a streamlined, interactive setup or need to install
2658
MrDocs in custom environments.
@@ -30,7 +62,37 @@ Every option can be defined in the command line directly instead of being prompt
3062
All options can be listed with the `--help` option.
3163
3264
The `--non-interactive` option allows you to run the script without any prompts, using
33-
values specified in the command line and default values for other options.
65+
values specified in the command line and default values for other options. In the default case, the script will download the source code to the current directory and install MrDocs system-wide.
66+
67+
[tabs]
68+
====
69+
Windows PowerShell::
70+
+
71+
--
72+
[source,powershell]
73+
----
74+
python -c "$(Invoke-WebRequest -Uri 'https://raw.githubusercontent.com/cppalliance/mrdocs/refs/heads/develop/bootstrap.py' -UseBasicParsing)" --non-interactive
75+
----
76+
--
77+
78+
Linux::
79+
+
80+
--
81+
[source,bash]
82+
----
83+
python3 -c "$(curl -fsSL https://raw.githubusercontent.com/cppalliance/mrdocs/refs/heads/develop/bootstrap.py)" --non-interactive
84+
----
85+
--
86+
87+
macOS::
88+
+
89+
--
90+
[source,bash]
91+
----
92+
python -c "$(curl -fsSL https://raw.githubusercontent.com/cppalliance/mrdocs/refs/heads/develop/bootstrap.py)" --non-interactive
93+
----
94+
--
95+
====
3496
3597
The script handles tool checks, repository cloning, patching, and CMake configuration, reducing
3698
manual intervention and potential errors.

0 commit comments

Comments
 (0)