From 2fa690a5b6d648ff3d4448705a8508119813db26 Mon Sep 17 00:00:00 2001 From: Mateusz Masiarz Date: Sat, 23 Sep 2023 15:11:30 +0200 Subject: [PATCH 1/4] Allow running `sinol-make` in subdirectory of package (cherry picked from commit 8151dba09d6074a22902061c5f1b416ed438987c) --- src/sinol_make/util.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/sinol_make/util.py b/src/sinol_make/util.py index 68c2f4f9..6940520d 100644 --- a/src/sinol_make/util.py +++ b/src/sinol_make/util.py @@ -33,11 +33,13 @@ def check_if_package(): """ Function to check if current directory is a package """ - - cwd = os.getcwd() - if os.path.exists(os.path.join(cwd, 'config.yml')): + if os.path.exists(os.path.join(os.getcwd(), 'config.yml')): + return True + elif os.path.exists(os.path.join(os.getcwd(), '..', 'config.yml')): + os.chdir('..') return True - return False + else: + return False def exit_if_not_package(): From 63bd382be97adc803ed1b7cbdb52b23dff106efd Mon Sep 17 00:00:00 2001 From: Mateusz Masiarz Date: Sat, 23 Sep 2023 15:12:04 +0200 Subject: [PATCH 2/4] Add test (cherry picked from commit 902abc464805d3d0b7c50cc9218be64ca0a48132) --- tests/commands/run/test_integration.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/commands/run/test_integration.py b/tests/commands/run/test_integration.py index c9837a8c..f7a599e1 100644 --- a/tests/commands/run/test_integration.py +++ b/tests/commands/run/test_integration.py @@ -553,3 +553,17 @@ def test_flag_tests_not_existing_tests(create_package, time_tool, capsys): assert e.value.code == 1 out = capsys.readouterr().out assert "There are no tests to run." in out + + +@pytest.mark.parametrize("create_package", [get_simple_package_path()], indirect=True) +def test_cwd_in_prog(create_package): + """ + Test if `sinol-make` works when cwd is in prog. + """ + package_path = create_package + os.chdir("prog") + create_ins_outs(package_path) + parser = configure_parsers() + args = parser.parse_args(["run"]) + command = Command() + command.run(args) From 1047bcb08590b6b39ce2720d9bd7e3ea782ac0c2 Mon Sep 17 00:00:00 2001 From: Mateusz Masiarz Date: Sat, 23 Sep 2023 23:28:14 +0200 Subject: [PATCH 3/4] Refactor --- src/sinol_make/util.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/sinol_make/util.py b/src/sinol_make/util.py index 6940520d..33348e40 100644 --- a/src/sinol_make/util.py +++ b/src/sinol_make/util.py @@ -29,9 +29,11 @@ def get_commands(): return commands -def check_if_package(): +def find_and_chdir_package(): """ - Function to check if current directory is a package + Checks if current directory or parent directory is a package directory. + If it is, it changes the current working directory to it and returns True. + If it isn't, it returns False. """ if os.path.exists(os.path.join(os.getcwd(), 'config.yml')): return True @@ -44,9 +46,11 @@ def check_if_package(): def exit_if_not_package(): """ - Function that exits if current directory is not a package + Checks if current directory or parent directory is a package directory. + If it is, current working directory is changed to it. + If it isn't, it exits with an error. """ - if not check_if_package(): + if not find_and_chdir_package(): exit_with_error('You are not in a package directory (couldn\'t find config.yml in current directory).') From b70861fe2624fb67104b2e006886b7ca6c9707a1 Mon Sep 17 00:00:00 2001 From: Mateusz Masiarz Date: Sun, 24 Sep 2023 12:40:55 +0200 Subject: [PATCH 4/4] Fix tests --- src/sinol_make/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sinol_make/util.py b/src/sinol_make/util.py index 7cb97cd0..dfd81005 100644 --- a/src/sinol_make/util.py +++ b/src/sinol_make/util.py @@ -298,7 +298,7 @@ def make_version_changes(): # In version 1.5.9 we changed the format of sinol_expected_scores. # Now all groups have specified points and status. - if check_if_package(): + if find_and_chdir_package(): with open("config.yml", "r") as config_file: config = yaml.load(config_file, Loader=yaml.FullLoader)