File tree Expand file tree Collapse file tree 2 files changed +17
-12
lines changed Expand file tree Collapse file tree 2 files changed +17
-12
lines changed Original file line number Diff line number Diff line change @@ -316,24 +316,25 @@ def format_path(
316
316
When escape=True, the non-passed elements of the path are regex-escaped, so the
317
317
resulting string can be used as a pattern to match path components.
318
318
"""
319
-
320
319
kwargs = dict (
321
320
nbgrader_step = nbgrader_step ,
322
321
student_id = student_id ,
323
322
assignment_id = assignment_id
324
323
)
325
-
326
- if escape :
327
- base = Path (re .escape (self .root ))
328
- else :
329
- base = Path (self .root )
330
-
331
- path = base / self .directory_structure .format (** kwargs )
332
-
324
+ base = Path (self .root )
325
+ structure = Path (self .directory_structure .format (** kwargs ))
333
326
if escape :
334
- return path .anchor + re .escape (os .path .sep ).join (path .parts [1 :])
327
+ if structure .is_absolute ():
328
+ anchor = structure .anchor
329
+ parts = list (structure .parts )
330
+ else :
331
+ anchor = base .anchor
332
+ parts = [re .escape (part ) for part in base ._tail ] + list (structure .parts )
333
+ return re .escape (anchor ) + re .escape (os .path .sep ).join (parts )
335
334
else :
336
- return str (path )
335
+ if structure .is_absolute ():
336
+ return str (structure )
337
+ return str (base / structure )
337
338
338
339
def find_assignments (self ,
339
340
nbgrader_step : str = "*" ,
Original file line number Diff line number Diff line change @@ -20,7 +20,11 @@ def test_coursedir_configurable(conf, course_dir):
20
20
assert coursedir .root == course_dir
21
21
22
22
23
- @pytest .mark .parametrize ("root" , [None , os .path .sep + "[special]~root" ])
23
+ @pytest .mark .parametrize ("root" , [
24
+ None , # Keep the course_dir fixture
25
+ os .path .sep + "[special]~root" ,
26
+ "C:\\ Users\\ Student" ,
27
+ ])
24
28
def test_coursedir_format_path (conf , root ):
25
29
if root is not None :
26
30
conf .CourseDirectory .root = root
You can’t perform that action at this time.
0 commit comments