Skip to content

Commit 586c38c

Browse files
VindeeRdbeltrankyl
authored andcommitted
Changing behavior when copy another experiment to copy the git session info too (#2830)
(cherry picked from commit 9621313)
1 parent d6afc2a commit 586c38c

File tree

4 files changed

+49
-12
lines changed

4 files changed

+49
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ release.
9595
Changes and improvements to fixtures and pytest organisation and setup #2745
9696
- Removed broken migrate command #2617
9797
- Allow users to delete multiple experiments #1216 #2793
98+
- Copying git session of an experiment #2828
9899

99100
### 4.1.15: Bug fixes, enhancements, and new features
100101

autosubmit/config/configcommon.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
from bscearth.utils.date import parse_date
3535
from configobj import ConfigObj
36-
from pyparsing import nestedExpr
36+
from pyparsing import nested_expr
3737
from ruamel.yaml import YAML
3838

3939
from autosubmit.config.basicconfig import BasicConfig
@@ -2298,7 +2298,7 @@ def get_date_list(self):
22982298
string = f'[{date_value}]'
22992299
else:
23002300
string = date_value
2301-
split_string = nestedExpr('[', ']').parseString(string).asList()
2301+
split_string = nested_expr('[', ']').parse_string(string).asList()
23022302
string_date = None
23032303
for split in split_string[0]:
23042304
if type(split) is list:
@@ -2373,7 +2373,7 @@ def get_member_list(self, run_only=False):
23732373
return member_list
23742374
elif not string.startswith("["):
23752375
string = f'[{string}]'
2376-
split_string = nestedExpr('[', ']').parseString(string).asList()
2376+
split_string = nested_expr('[', ']').parse_string(string).asList()
23772377
string_member = None
23782378
for split in split_string[0]:
23792379
if type(split) is list:

autosubmit/utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ def as_conf_default_values(autosubmit_version: str, exp_id: str, hpc: str = "",
6060
yaml_data['LOCAL']['PROJECT_PATH'] = ""
6161

6262
if 'GIT' in yaml_data:
63-
yaml_data['GIT']['PROJECT_ORIGIN'] = f'{git_repo}'
64-
yaml_data['GIT']['PROJECT_BRANCH'] = f'{git_branch}'
63+
if git_repo != "":
64+
yaml_data['GIT']['PROJECT_ORIGIN'] = f'{git_repo}'
65+
if git_branch != "":
66+
yaml_data['GIT']['PROJECT_BRANCH'] = f'{git_branch}'
6567

6668
if minimal_configuration:
6769
if 'DEFAULT' in yaml_data:

test/integration/test_expid.py

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ def test_copying_experiment_with_hpc_in_command(autosubmit_exp: Callable, autosu
8888
assert yaml_data['MAIL']['TO'] == ""
8989
assert yaml_data['JOBS']['LOCAL_SEND_INITIAL']['CHUNKS_FROM']['1']['CHUNKS_TO'] == '1'
9090
assert yaml_data['LOCAL']['PROJECT_PATH'] == ""
91-
assert yaml_data['GIT']['PROJECT_ORIGIN'] == ""
92-
assert yaml_data['GIT']['PROJECT_BRANCH'] == ""
91+
assert yaml_data['GIT']['PROJECT_ORIGIN'] == "origin_test"
92+
assert yaml_data['GIT']['PROJECT_BRANCH'] == "branch_test"
9393

9494

9595
def test_copying_experiment_without_hpc_in_command(autosubmit_exp: Callable, autosubmit: Autosubmit, tmp_path):
@@ -190,8 +190,20 @@ def test_copying_experiment_with_hpc_in_file(autosubmit_exp: Callable, autosubmi
190190
yaml_data = yaml.load(open(tmp_path / f"{exp_id}/conf/metadata/experiment_data.yml"))
191191
assert yaml_data['DEFAULT']['HPCARCH'] == "MN5"
192192

193-
194-
def test_as_conf_default_values(autosubmit_exp: Callable, autosubmit: Autosubmit, tmp_path):
193+
@pytest.mark.parametrize(
194+
'git_command,git_session',
195+
[
196+
(['', ''], ['', '']),
197+
(['test_1', 'test_2'], ['', '']),
198+
(['', 'test_2'], ['', '']),
199+
(['test_1', ''], ['', '']),
200+
(['', ''], ['test_3', 'test_4']),
201+
(['test_1', 'test_2'], ['test_3', 'test_4']),
202+
(['', 'test_2'], ['test_3', 'test_4']),
203+
(['test_1', ''], ['test_3', 'test_4']),
204+
],
205+
)
206+
def test_as_conf_default_values(git_command, git_session, autosubmit_exp: Callable, autosubmit: Autosubmit, tmp_path):
195207
"""Test that the ``check_jobs_file_exists`` function ignores a non-existent section."""
196208
exp = autosubmit_exp(experiment_data={
197209
'JOBS': {
@@ -203,8 +215,12 @@ def test_as_conf_default_values(autosubmit_exp: Callable, autosubmit: Autosubmit
203215
}
204216
}
205217
},
218+
'GIT': {
219+
'PROJECT_ORIGIN': f'{git_session[0]}',
220+
'PROJECT_BRANCH': f'{git_session[1]}'
221+
},
206222
})
207-
as_conf_default_values(autosubmit.autosubmit_version, exp.expid, 'MN5', True, 'test_1', 'test_2', 'test_3')
223+
as_conf_default_values(autosubmit.autosubmit_version, exp.expid, 'MN5', True, git_command[0], git_command[1], 'test_3')
208224

209225
yaml = YAML(typ='rt')
210226
assert autosubmit.create(exp.expid, noplot=True, hide=True) == 0
@@ -213,8 +229,26 @@ def test_as_conf_default_values(autosubmit_exp: Callable, autosubmit: Autosubmit
213229
assert yaml_data['DEFAULT']['EXPID'] == exp.expid
214230
assert yaml_data['DEFAULT']['CUSTOM_CONFIG'] == f'"{tmp_path}/{exp.expid}/proj/test_3"'
215231
assert yaml_data['LOCAL']['PROJECT_PATH'] == ""
216-
assert yaml_data['GIT']['PROJECT_ORIGIN'] == "test_1"
217-
assert yaml_data['GIT']['PROJECT_BRANCH'] == "test_2"
232+
233+
if git_command[0] != '':
234+
assert yaml_data['GIT']['PROJECT_ORIGIN'] == git_command[0]
235+
else:
236+
assert yaml_data['GIT']['PROJECT_ORIGIN'] == git_session[0]
237+
238+
if git_command[1] != '':
239+
assert yaml_data['GIT']['PROJECT_BRANCH'] == git_command[1]
240+
else:
241+
assert yaml_data['GIT']['PROJECT_BRANCH'] == git_session[1]
242+
243+
if git_session[0] != '' and git_command[0] == '':
244+
assert yaml_data['GIT']['PROJECT_ORIGIN'] == git_session[0]
245+
else:
246+
assert yaml_data['GIT']['PROJECT_ORIGIN'] == git_command[0]
247+
248+
if git_session[1] != '' and git_command[1] == '':
249+
assert yaml_data['GIT']['PROJECT_BRANCH'] == git_session[1]
250+
else:
251+
assert yaml_data['GIT']['PROJECT_BRANCH'] == git_command[1]
218252

219253

220254
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)