Skip to content

Commit ffc873d

Browse files
committed
[CI] Move requests and openstack imports to where they are used.
Moving the imports of openstack and requests to the place where they are used allows for running the script locally without openstack or S3 access. Only if one attempts downloads or uploads, the imports become necessary.
1 parent 433523e commit ffc873d

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

.github/workflows/root-ci-config/build_root.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import time
2525

2626
import build_utils
27-
import openstack
2827
from build_utils import (
2928
calc_options_hash,
3029
die,
@@ -38,12 +37,6 @@
3837
S3CONTAINER = 'ROOT-build-artifacts' # Used for uploads
3938
S3URL = 'https://s3.cern.ch/swift/v1/' + S3CONTAINER # Used for downloads
4039

41-
try:
42-
CONNECTION = openstack.connect(cloud='envvars')
43-
except Exception as exc:
44-
print("Failed to open the S3 connection:", exc, file=sys.stderr)
45-
CONNECTION = None
46-
4740
WINDOWS = (os.name == 'nt')
4841
WORKDIR = (os.environ['HOME'] + '/ROOT-CI') if not WINDOWS else 'C:/ROOT-CI'
4942
COMPRESSIONLEVEL = 6 if not WINDOWS else 1
@@ -346,6 +339,14 @@ def archive_and_upload(archive_name, prefix):
346339
targz.add("src")
347340
targz.add("build")
348341

342+
try:
343+
import openstack
344+
CONNECTION = openstack.connect(cloud='envvars')
345+
except Exception as exc:
346+
print("Failed to open the S3 connection:", exc, file=sys.stderr)
347+
CONNECTION = None
348+
349+
349350
upload_file(
350351
connection=CONNECTION,
351352
container=S3CONTAINER,

.github/workflows/root-ci-config/build_utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
from shutil import which
1515
from typing import Callable, Dict
1616

17-
from openstack.connection import Connection
18-
from requests import get
19-
2017

2118
def is_macos():
2219
return 'Darwin' == platform.system()
@@ -238,7 +235,7 @@ def calc_options_hash(options: str) -> str:
238235
options_and_defines += sp_result.stdout
239236
return sha1(options_and_defines.encode('utf-8')).hexdigest()
240237

241-
def upload_file(connection: Connection, container: str, dest_object: str, src_file: str) -> None:
238+
def upload_file(connection, container: str, dest_object: str, src_file: str) -> None:
242239
print(f"Attempting to upload {src_file} to {dest_object}")
243240

244241
if not os.path.exists(src_file):
@@ -282,6 +279,8 @@ def create_object_local():
282279

283280

284281
def download_file(url: str, dest: str) -> None:
282+
from requests import get
283+
285284
print(f"\nAttempting to download {url} to {dest}")
286285

287286
parent_dir = os.path.dirname(dest)
@@ -297,6 +296,7 @@ def download_latest(url: str, prefix: str, destination: str) -> str:
297296
"""Downloads latest build artifact starting with <prefix>,
298297
and returns the file path to the downloaded file and shell_log."""
299298

299+
from requests import get
300300
# https://docs.openstack.org/api-ref/object-store/#show-container-details-and-list-objects
301301
with get(f"{url}/?prefix={prefix}&format=json", timeout=20) as req:
302302
if req.status_code == HTTPStatus.NO_CONTENT or req.content == b'[]':

0 commit comments

Comments
 (0)