Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow running sinol-make from package's subdirectory #129

Merged
merged 5 commits into from
Sep 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions src/sinol_make/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,28 @@ 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.
"""

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():
"""
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).')


Expand Down Expand Up @@ -292,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)

Expand Down
14 changes: 14 additions & 0 deletions tests/commands/run/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,3 +632,17 @@ def test(file_to_change, lang, comment_character):
test("liblib.cpp", "cpp", "//")
test("liblib.h", "cpp", "//")
test("liblib.py", "py", "#")


@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)
Loading