course-setup 3.0.6__tar.gz → 3.0.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: course-setup
3
- Version: 3.0.6
3
+ Version: 3.0.7
4
4
  Summary: CLI tools for setting up and retiring GitHub-backed course repositories
5
5
  Author: Reuven Lerner
6
6
  Author-email: Reuven Lerner <reuven@lerner.co.il>
@@ -177,6 +177,10 @@ retire-course ./Acme-2026-03 ./Beta-2026-03 ./Gamma-2026-02
177
177
 
178
178
  If any directory fails, the rest are still processed and errors are reported at the end.
179
179
 
180
+ > **Tip:** run `retire-course` from the *parent* of the course directory, not
181
+ > from inside it. If you're already inside, the command detects it and tells
182
+ > you to `cd ..` rather than failing with a confusing error.
183
+
180
184
  ### `archive-course` — Create a zip archive of a course
181
185
 
182
186
  ```bash
@@ -157,6 +157,10 @@ retire-course ./Acme-2026-03 ./Beta-2026-03 ./Gamma-2026-02
157
157
 
158
158
  If any directory fails, the rest are still processed and errors are reported at the end.
159
159
 
160
+ > **Tip:** run `retire-course` from the *parent* of the course directory, not
161
+ > from inside it. If you're already inside, the command detects it and tells
162
+ > you to `cd ..` rather than failing with a confusing error.
163
+
160
164
  ### `archive-course` — Create a zip archive of a course
161
165
 
162
166
  ```bash
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "course-setup"
3
- version = "3.0.6"
3
+ version = "3.0.7"
4
4
  description = "CLI tools for setting up and retiring GitHub-backed course repositories"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.13"
@@ -14,6 +14,36 @@ from setup_course_github import __author__, __email__, __version__, get_github
14
14
  from setup_course_github.config import load_config
15
15
 
16
16
 
17
+ class InsideCourseDirectoryError(RuntimeError):
18
+ """Raised when a command is run from inside the course directory it targets."""
19
+
20
+
21
+ def _check_not_inside_course(dirname: str) -> None:
22
+ """Raise InsideCourseDirectoryError if the user is inside *dirname*.
23
+
24
+ Two cases are detected:
25
+ 1. *dirname* resolves to the current working directory (e.g. ``.`` or
26
+ the absolute path of cwd).
27
+ 2. *dirname* does not exist relative to cwd, but its basename matches
28
+ cwd's basename — the user has cd'd into the directory and then
29
+ passed its bare name on the command line.
30
+ """
31
+ cwd = Path.cwd().resolve()
32
+ target = Path(dirname)
33
+
34
+ inside = False
35
+ if target.exists() and target.resolve() == cwd:
36
+ inside = True
37
+ elif not target.exists() and target.name == cwd.name:
38
+ inside = True
39
+
40
+ if inside:
41
+ raise InsideCourseDirectoryError(
42
+ f"You appear to be inside '{dirname}'. "
43
+ "Move up one directory (cd ..) and run the command again."
44
+ )
45
+
46
+
17
47
  def get_remote_url(dirname: str) -> str:
18
48
  """Return the git remote.origin.url for the repo in dirname."""
19
49
  result = subprocess.run(
@@ -126,6 +156,8 @@ def _build_retirement_summary(
126
156
 
127
157
  def retire_course(dirname: str, keep_public: bool = False) -> None:
128
158
  """Move the local directory to the archive, optionally making the repo private."""
159
+ _check_not_inside_course(dirname)
160
+
129
161
  config = load_config()
130
162
 
131
163
  remote_url = get_remote_url(dirname)
@@ -6,11 +6,17 @@ import sys
6
6
  from pathlib import Path
7
7
 
8
8
  from setup_course_github import __author__, __email__, __version__, get_github
9
- from setup_course_github.retire_course import get_remote_url, parse_repo_name
9
+ from setup_course_github.retire_course import (
10
+ _check_not_inside_course,
11
+ get_remote_url,
12
+ parse_repo_name,
13
+ )
10
14
 
11
15
 
12
16
  def unretire_course(dirname: str) -> None:
13
17
  """Make the repo public again and move the directory to cwd."""
18
+ _check_not_inside_course(dirname)
19
+
14
20
  remote_url = get_remote_url(dirname)
15
21
  repo_name = parse_repo_name(remote_url)
16
22