@@ -30,22 +30,28 @@ def get_commands():
3030 return commands
3131
3232
33- def check_if_package ():
33+ def find_and_chdir_package ():
3434 """
35- Function to check if current directory is a package
35+ Checks if current directory or parent directory is a package directory.
36+ If it is, it changes the current working directory to it and returns True.
37+ If it isn't, it returns False.
3638 """
37-
38- cwd = os .getcwd ()
39- if os .path .exists (os .path .join (cwd , 'config.yml' )):
39+ if os .path .exists (os .path .join (os .getcwd (), 'config.yml' )):
40+ return True
41+ elif os .path .exists (os .path .join (os .getcwd (), '..' , 'config.yml' )):
42+ os .chdir ('..' )
4043 return True
41- return False
44+ else :
45+ return False
4246
4347
4448def exit_if_not_package ():
4549 """
46- Function that exits if current directory is not a package
50+ Checks if current directory or parent directory is a package directory.
51+ If it is, current working directory is changed to it.
52+ If it isn't, it exits with an error.
4753 """
48- if not check_if_package ():
54+ if not find_and_chdir_package ():
4955 exit_with_error ('You are not in a package directory (couldn\' t find config.yml in current directory).' )
5056
5157
@@ -292,7 +298,7 @@ def make_version_changes():
292298 # In version 1.5.9 we changed the format of sinol_expected_scores.
293299 # Now all groups have specified points and status.
294300
295- if check_if_package ():
301+ if find_and_chdir_package ():
296302 with open ("config.yml" , "r" ) as config_file :
297303 config = yaml .load (config_file , Loader = yaml .FullLoader )
298304
0 commit comments