14
14
from docker .errors import APIError as DockerAPIError
15
15
from docker .errors import DockerException
16
16
from docker .errors import NotFound as DockerNotFoundError
17
- from requests .exceptions import ConnectionError , ReadTimeout # noqa
17
+ from requests .exceptions import ConnectionError , ReadTimeout
18
18
from requests_toolbelt .multipart .encoder import MultipartEncoder
19
19
20
20
from readthedocs .api .v2 .client import api as api_v2
@@ -73,7 +73,7 @@ def __init__(
73
73
bin_path = None ,
74
74
record_as_success = False ,
75
75
demux = False ,
76
- ** kwargs , # pylint: disable=unused-argument
76
+ ** kwargs ,
77
77
):
78
78
self .command = command
79
79
self .shell = shell
@@ -252,8 +252,8 @@ def save(self):
252
252
{key : str (value ) for key , value in data .items ()}
253
253
)
254
254
resource = api_v2 .command
255
- resp = resource ._store [" session" ].post ( # pylint: disable=protected-access
256
- resource ._store [" base_url" ] + "/" , # pylint: disable=protected-access
255
+ resp = resource ._store [' session' ].post (
256
+ resource ._store [' base_url' ] + '/' ,
257
257
data = encoder ,
258
258
headers = {
259
259
'Content-Type' : encoder .content_type ,
@@ -301,40 +301,11 @@ def run(self):
301
301
302
302
self .start_time = datetime .utcnow ()
303
303
client = self .build_env .get_client ()
304
-
305
- # Create a copy of the environment to update PATH variable
306
- environment = self ._environment .copy ()
307
- # Default PATH variable
308
- # This default comes from our Docker image:
309
- #
310
- # $ docker run --user docs -it --rm readthedocs/build:ubuntu-22.04 /bin/bash
311
- # docs@bfe702e31cdd:~$ echo $PATH
312
- # /home/docs/.asdf/shims:/home/docs/.asdf/bin
313
- # :/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
314
- # docs@bfe702e31cdd:~$
315
- asdf_paths = (
316
- f"/home/{ settings .RTD_DOCKER_USER } /.asdf/shims"
317
- f":/home/{ settings .RTD_DOCKER_USER } /.asdf/bin"
318
- )
319
- if settings .RTD_DOCKER_COMPOSE :
320
- asdf_paths += ":/root/.asdf/shims:/root/.asdf/bin"
321
-
322
- default_paths = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
323
- environment ["PATH" ] = f"{ asdf_paths } :{ default_paths } "
324
-
325
- # Prepend the BIN_PATH if it's defined
326
- if self .bin_path :
327
- original_path = environment .get ("PATH" )
328
- escaped_bin_path = self ._escape_command (self .bin_path )
329
- environment ["PATH" ] = escaped_bin_path
330
- if original_path :
331
- environment ["PATH" ] = f"{ escaped_bin_path } :{ original_path } "
332
-
333
304
try :
334
305
exec_cmd = client .exec_create (
335
306
container = self .build_env .container_id ,
336
307
cmd = self .get_wrapped_command (),
337
- environment = environment ,
308
+ environment = self . _environment ,
338
309
user = self .user ,
339
310
workdir = self .cwd ,
340
311
stdout = True ,
@@ -386,18 +357,31 @@ def get_wrapped_command(self):
386
357
"""
387
358
Wrap command in a shell and optionally escape special bash characters.
388
359
360
+ In order to set the current working path inside a docker container, we
361
+ need to wrap the command in a shell call manually.
362
+
389
363
Some characters will be interpreted as shell characters without
390
364
escaping, such as: ``pip install requests<0.8``. When passing
391
365
``escape_command=True`` in the init method this escapes a good majority
392
366
of those characters.
393
367
"""
368
+ prefix = ''
369
+ if self .bin_path :
370
+ bin_path = self ._escape_command (self .bin_path )
371
+ prefix += f'PATH={ bin_path } :$PATH '
372
+
394
373
command = (
395
374
' ' .join (
396
375
self ._escape_command (part ) if self .escape_command else part
397
376
for part in self .command
398
377
)
399
378
)
400
- return f"/bin/bash -c '{ command } '"
379
+ return (
380
+ "/bin/sh -c '{prefix}{cmd}'" .format (
381
+ prefix = prefix ,
382
+ cmd = command ,
383
+ )
384
+ )
401
385
402
386
def _escape_command (self , cmd ):
403
387
r"""Escape the command by prefixing suspicious chars with `\`."""
@@ -540,14 +524,14 @@ class BuildEnvironment(BaseEnvironment):
540
524
"""
541
525
542
526
def __init__ (
543
- self ,
544
- project = None ,
545
- version = None ,
546
- build = None ,
547
- config = None ,
548
- environment = None ,
549
- record = True ,
550
- ** kwargs , # pylint: disable=unused-argument
527
+ self ,
528
+ project = None ,
529
+ version = None ,
530
+ build = None ,
531
+ config = None ,
532
+ environment = None ,
533
+ record = True ,
534
+ ** kwargs ,
551
535
):
552
536
super ().__init__ (project , environment )
553
537
self .version = version
@@ -573,7 +557,7 @@ def run(self, *cmd, **kwargs):
573
557
})
574
558
return super ().run (* cmd , ** kwargs )
575
559
576
- def run_command_class (self , * cmd , ** kwargs ): # pylint: disable=signature-differs
560
+ def run_command_class (self , * cmd , ** kwargs ): # pylint: disable=arguments-differ
577
561
kwargs .update ({
578
562
'build_env' : self ,
579
563
})
0 commit comments