diff --git a/travo/console_scripts.py b/travo/console_scripts.py index 6d0cb485296b1a5314539ddec2fe08ba0eb855aa..e78a52038b620add5aee2016ebc599023ecd5db4 100755 --- a/travo/console_scripts.py +++ b/travo/console_scripts.py @@ -256,18 +256,23 @@ class Travo: template : str remote repository hosting the template demo for the course embed : bool - Initialize ComputerLab as subdirectory of Instructors, default is `True` + Whether the instructors directory coincides with the + course directory (and therefore embeds `ComputerLab`) or + is a subdirectory `Instructors` of the course directory. Examples: travo quickstart MyCourse template="simple-jupyter-course" """ forge = GitLab("https://gitlab.com") - instructors_dir = os.path.join(course_dir, "Instructors") + + # Define the local directory structure if embed: - computerlab_dir = os.path.join(instructors_dir, "ComputerLab") + instructors_dir = course_dir else: - computerlab_dir = os.path.join(course_dir, "ComputerLab") + instructors_dir = os.path.join(course_dir, "Instructors") + computerlab_dir = os.path.join(course_dir, "ComputerLab") + course = os.path.join(computerlab_dir, "course.py") forge.git( [ diff --git a/travo/course.py b/travo/course.py index 9077528a52e3ea1aba08a3cd4a60299904bf831b..d8a730ebe3fad325343b0c4fc5910862167e8681 100755 --- a/travo/course.py +++ b/travo/course.py @@ -1192,9 +1192,11 @@ class Course: course_dir : str Local directory holding the course share_with_instructors : bool - Publish the source teaching material on the forge as private repos for other instructors. Default: true. + Publish the source teaching material on the forge as a private repository for other instructors. Default: true. embed : bool - Search for the ComputerLab as subdirectory of Instructors directory + Whether the instructors directory coincides with the + course directory (and therefore embeds `ComputerLab`) or + is the subdirectory `Instructors` of the course directory. This is an idempotent operation: if some of the course structure already exists on the forge, it is updated by adding @@ -1206,12 +1208,13 @@ class Course: The local directory, typically, initialized with `travo quickstart` is expected to have the following structure: - - `/(Instructors)/ComputerLab`: a git repository containing the + - `/ComputerLab`: a git repository containing the course script `course.py`, typically together with documentation and assets on how to use the course as a - student. Can be inside or outside of Instructors, see option `embed`. - - (with the share option) `/Instructors`: a git - repository holding the course material. + student. + - (with the share option) `` (if embed) or + `/Instructors`: a git repository holding the + course material. The course structure on the forge is deployed according to the following conventions: @@ -1222,7 +1225,7 @@ class Course: - With the `share` option, a private project `/Instructors` to host the source course material. It is initialized with the content of the local - git repository `/Instructors`, and is set as origin + git repository `/(Instructors)`, and is set as origin for this repository. If the course has subcourses, then this is instead done for each subcourse, replacing `Instructors` by the subcourse name. @@ -1234,11 +1237,12 @@ class Course: subgroups `` as needed. """ - # Define ComputerLab local directory + # Define the local directory structure if embed: - computerlab_dir = os.path.join(course_dir, "Instructors", "ComputerLab") + instructors_dir = course_dir else: - computerlab_dir = os.path.join(course_dir, "ComputerLab") + instructors_dir = os.path.join(course_dir, "Instructors") + computerlab_dir = os.path.join(course_dir, "ComputerLab") # Check if course.py has been modified : to be decommented once decided # course_diff = subprocess.run( @@ -1307,9 +1311,9 @@ class Course: "origin", repository.http_url_with_base_to_repo(), ], - cwd=os.path.join(course_dir, "Instructors"), + cwd=instructors_dir, ) - self.forge.git(["push"], cwd=os.path.join(course_dir, "Instructors")) + self.forge.git(["push"], cwd=instructors_dir) # Create project ComputerLab repository = self.forge.ensure_project( diff --git a/travo/tests/test_console_scripts.py b/travo/tests/test_console_scripts.py index c13a8e8d6809d51593e978ca56c84570d5444b9a..51a92c0579e32c2cd0b5747fed7783c2b9af7d0c 100644 --- a/travo/tests/test_console_scripts.py +++ b/travo/tests/test_console_scripts.py @@ -3,14 +3,18 @@ import os from travo.console_scripts import Travo -@pytest.mark.parametrize("embed_option", [False, True]) -def test_quickstart(embed_option, tmp_path): +@pytest.mark.parametrize("embed", [False, True]) +def test_quickstart(embed: bool, tmp_path: str) -> None: # Initialise the course directory course_dir = os.path.join(tmp_path, "MyCourse") - Travo.quickstart(course_dir=course_dir, embed=embed_option) - if embed_option: - clab_dir = os.path.join(course_dir, "Instructors") + Travo.quickstart(course_dir=course_dir, embed=embed) + + # Define the local directory structure + if embed: + instructors_dir = course_dir else: - clab_dir = course_dir - assert os.path.isdir(course_dir + "/Instructors") - assert os.path.isdir(clab_dir + "/ComputerLab") + instructors_dir = os.path.join(course_dir, "Instructors") + computerlab_dir = os.path.join(course_dir, "ComputerLab") + + assert os.path.isdir(os.path.join(computerlab_dir, ".git")) + assert os.path.isdir(os.path.join(instructors_dir, ".git"))