From efe02b583a38dd9806d5ddbb9be0fb27deb67001 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20M=2E=20Thi=C3=A9ry?= Date: Wed, 4 Sep 2024 17:13:24 +0200 Subject: [PATCH] Quickstart and Deploy: simplified structure in the "embed" case In the embed case, the directory structure generated by quickstart and expected by deploy is: /Instructors/ /Instructors/ComputerLab/ This commit simplifies it by indentifying and Instructors: / /ComputerLab/ This structure has been successfuly in use by many instructors. Instructors can still have an overarching directory holding the above should they wish to, but they don't have to. --- travo/console_scripts.py | 13 +++++++++---- travo/course.py | 28 ++++++++++++++++------------ travo/tests/test_console_scripts.py | 20 ++++++++++++-------- 3 files changed, 37 insertions(+), 24 deletions(-) diff --git a/travo/console_scripts.py b/travo/console_scripts.py index 6d0cb485..e78a5203 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 9077528a..d8a730eb 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 c13a8e8d..51a92c05 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")) -- GitLab