1111# The path in Docker's filesystem where the user's home directory is mounted
1212_DOCKER_HOME = "/home/user/mounted_home"
1313
14+
1415def get_build_dir (build_dir = None , repo_root = None , version = None ):
1516 """Return a string giving the path to the build directory.
1617
@@ -43,8 +44,10 @@ def get_build_dir(build_dir=None, repo_root=None, version=None):
4344 if not version_explicit :
4445 branch_found , version = sys_utils .git_current_branch ()
4546 if not branch_found :
46- raise RuntimeError ("Problem determining version based on git branch; "
47- "set --version on the command line." )
47+ raise RuntimeError (
48+ "Problem determining version based on git branch; "
49+ "set --version on the command line."
50+ )
4851
4952 build_dir_no_version = os .path .join (repo_root , "versions" )
5053 if not os .path .isdir (build_dir_no_version ):
@@ -60,6 +63,7 @@ def get_build_dir(build_dir=None, repo_root=None, version=None):
6063
6164 return build_dir , version
6265
66+
6367def get_build_command (
6468 build_dir ,
6569 run_from_dir ,
@@ -84,24 +88,26 @@ def get_build_command(
8488 with the given name
8589 """
8690 if docker_name is None :
87- return _get_make_command (build_dir = build_dir ,
88- build_target = build_target ,
89- num_make_jobs = num_make_jobs ,
90- warnings_as_warnings = warnings_as_warnings ,
91- )
91+ return _get_make_command (
92+ build_dir = build_dir ,
93+ build_target = build_target ,
94+ num_make_jobs = num_make_jobs ,
95+ warnings_as_warnings = warnings_as_warnings ,
96+ )
9297
9398 # But if we're using Docker, we have more work to do to create the command....
9499
95100 # Mount the user's home directory in the Docker image; this assumes that both
96101 # run_from_dir and build_dir reside somewhere under the user's home directory (we
97102 # check this assumption below).
98- docker_mountpoint = os .path .expanduser ('~' )
103+ docker_mountpoint = os .path .expanduser ("~" )
99104
105+ errmsg_if_not_under_mountpoint = "build_docs must be run from somewhere in your home directory"
100106 docker_workdir = _docker_path_from_local_path (
101107 local_path = run_from_dir ,
102108 docker_mountpoint = docker_mountpoint ,
103- errmsg_if_not_under_mountpoint =
104- "build_docs must be run from somewhere within your home directory" )
109+ errmsg_if_not_under_mountpoint = errmsg_if_not_under_mountpoint ,
110+ )
105111
106112 if os .path .isabs (build_dir ):
107113 build_dir_abs = build_dir
@@ -110,31 +116,40 @@ def get_build_command(
110116 docker_build_dir = _docker_path_from_local_path (
111117 local_path = build_dir_abs ,
112118 docker_mountpoint = docker_mountpoint ,
113- errmsg_if_not_under_mountpoint =
114- "build directory must reside under your home directory" )
119+ errmsg_if_not_under_mountpoint = "build directory must reside under your home directory" ,
120+ )
115121
116122 # Get current user's UID and GID
117123 uid = os .getuid ()
118124 gid = os .getgid ()
119125
120- make_command = _get_make_command (build_dir = docker_build_dir ,
121- build_target = build_target ,
122- num_make_jobs = num_make_jobs ,
123- warnings_as_warnings = warnings_as_warnings ,
124- )
125-
126- docker_command = ["docker" , "run" ,
127- "--name" , docker_name ,
128- "--user" , f"{ uid } :{ gid } " ,
129- "--mount" ,
130- f"type=bind,source={ docker_mountpoint } ,target={ _DOCKER_HOME } " ,
131- "--workdir" , docker_workdir ,
132- "-t" , # "-t" is needed for colorful output
133- "--rm" ,
134- "-e" , f"current_version={ version } " ,
135- docker_image ] + make_command
126+ make_command = _get_make_command (
127+ build_dir = docker_build_dir ,
128+ build_target = build_target ,
129+ num_make_jobs = num_make_jobs ,
130+ warnings_as_warnings = warnings_as_warnings ,
131+ )
132+
133+ docker_command = [
134+ "docker" ,
135+ "run" ,
136+ "--name" ,
137+ docker_name ,
138+ "--user" ,
139+ f"{ uid } :{ gid } " ,
140+ "--mount" ,
141+ f"type=bind,source={ docker_mountpoint } ,target={ _DOCKER_HOME } " ,
142+ "--workdir" ,
143+ docker_workdir ,
144+ "-t" , # "-t" is needed for colorful output
145+ "--rm" ,
146+ "-e" ,
147+ f"current_version={ version } " ,
148+ docker_image ,
149+ ] + make_command
136150 return docker_command
137151
152+
138153def _get_make_command (build_dir , build_target , num_make_jobs , warnings_as_warnings ):
139154 """Return the make command to run (as a list)
140155
@@ -149,6 +164,7 @@ def _get_make_command(build_dir, build_target, num_make_jobs, warnings_as_warnin
149164 sphinxopts += "-W --keep-going"
150165 return ["make" , sphinxopts , builddir_arg , "-j" , str (num_make_jobs ), build_target ]
151166
167+
152168def _docker_path_from_local_path (local_path , docker_mountpoint , errmsg_if_not_under_mountpoint ):
153169 """Given a path on the local file system, return the equivalent path in Docker space
154170
0 commit comments