Skip to content

Commit

Permalink
tools: cron: Deep copy a config loaded as module
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
piotrnarajowski committed Aug 14, 2024
1 parent 73e8b0a commit a7b52f5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions autoptsclient_bot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python

#
# auto-pts - The Bluetooth PTS Automation Framework
#
Expand All @@ -21,6 +20,7 @@
import threading
import time
import schedule
import copy

from autopts.bot.common import get_absolute_module_path, load_module_from_path
from autopts.utils import log_running_threads, have_admin_rights, set_global_end
Expand Down Expand Up @@ -59,7 +59,7 @@ def import_bot_projects():
return None, config_path

module = load_module_from_path(config_path)
return getattr(module, "BotProjects", None), config_path
return copy.deepcopy(getattr(module, "BotProjects", None)), config_path


def import_bot_module(project):
Expand Down
4 changes: 2 additions & 2 deletions tools/cron/autopts_bisect.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
If last_bad_commit is empty, then takes HEAD commit.
"""

import copy
import importlib
import os
import re
Expand Down Expand Up @@ -110,7 +110,7 @@ def load_cfg(cfg):
raise Exception('{} does not exists!'.format(cfg_path))

mod = load_module_from_path(cfg_path)
return mod.BotProjects[0], cfg_path
return copy.deepcopy(mod.BotProjects[0]), cfg_path


def bisect(cfg, test_case, good_commit, bad_commit=''):
Expand Down
3 changes: 2 additions & 1 deletion tools/cron/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
$ eval `ssh-agent`
$ ssh-add path/to/id_rsa
"""
import copy
import logging
import os
import re
Expand Down Expand Up @@ -233,7 +234,7 @@ def load_config(cfg):
if not mod:
raise Exception(f'Could not load the config {cfg}')

return mod.BotProjects[0]
return copy.deepcopy(mod.BotProjects[0])


def find_workspace_in_tree(tree_path, workspace, init_depth=4):
Expand Down

0 comments on commit a7b52f5

Please sign in to comment.