Skip to content

Commit c6f8214

Browse files
piotrnarajowskimkasenberg
authored andcommitted
tools: cron: Deep copy a config loaded as module
A .py file loaded as a module is cached until it is explicitly removed from sys.modules. So subsequent attempts to load the file only return a reference to the existing module-dictionary. So we need to deep-copy a config.py to prevent overwriting its original values and reuse it e.g. in subsequent PR jobs.
1 parent f5d2d92 commit c6f8214

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

autoptsclient_bot.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python
2-
32
#
43
# auto-pts - The Bluetooth PTS Automation Framework
54
#
@@ -21,6 +20,7 @@
2120
import threading
2221
import time
2322
import schedule
23+
import copy
2424

2525
from autopts.bot.common import get_absolute_module_path, load_module_from_path
2626
from autopts.utils import log_running_threads, have_admin_rights, set_global_end
@@ -59,7 +59,7 @@ def import_bot_projects():
5959
return None, config_path
6060

6161
module = load_module_from_path(config_path)
62-
return getattr(module, "BotProjects", None), config_path
62+
return copy.deepcopy(getattr(module, "BotProjects", None)), config_path
6363

6464

6565
def import_bot_module(project):

tools/cron/autopts_bisect.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
2525
If last_bad_commit is empty, then takes HEAD commit.
2626
"""
27-
27+
import copy
2828
import importlib
2929
import os
3030
import re
@@ -110,7 +110,7 @@ def load_cfg(cfg):
110110
raise Exception('{} does not exists!'.format(cfg_path))
111111

112112
mod = load_module_from_path(cfg_path)
113-
return mod.BotProjects[0], cfg_path
113+
return copy.deepcopy(mod.BotProjects[0]), cfg_path
114114

115115

116116
def bisect(cfg, test_case, good_commit, bad_commit=''):

tools/cron/common.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
$ eval `ssh-agent`
2525
$ ssh-add path/to/id_rsa
2626
"""
27+
import copy
2728
import logging
2829
import os
2930
import re
@@ -233,7 +234,7 @@ def load_config(cfg):
233234
if not mod:
234235
raise Exception(f'Could not load the config {cfg}')
235236

236-
return mod.BotProjects[0]
237+
return copy.deepcopy(mod.BotProjects[0])
237238

238239

239240
def find_workspace_in_tree(tree_path, workspace, init_depth=4):

0 commit comments

Comments
 (0)