mirror of
https://github.com/jupyter/notebook.git
synced 2025-01-30 12:11:32 +08:00
Fix bundler tool failures on Windows
* Normalize to system path separator format * Fix hardcoded separators * Fix hardcoded test paths
This commit is contained in:
parent
513b4c0a57
commit
925709b5b4
@ -84,12 +84,12 @@ b/
|
||||
|
||||
def test_glob_dir(self):
|
||||
'''Should expand to single file in the resources/ subfolder.'''
|
||||
self.assertIn('resources/empty.ipynb',
|
||||
self.assertIn(os.path.join('resources', 'empty.ipynb'),
|
||||
tools.expand_references(HERE, ['resources/empty.ipynb']))
|
||||
|
||||
def test_glob_subdir(self):
|
||||
'''Should expand to all files in the resources/ subfolder.'''
|
||||
self.assertIn('resources/empty.ipynb',
|
||||
self.assertIn(os.path.join('resources', 'empty.ipynb'),
|
||||
tools.expand_references(HERE, ['resources/']))
|
||||
|
||||
def test_glob_splat(self):
|
||||
@ -101,24 +101,24 @@ b/
|
||||
def test_glob_splatsplat_in_middle(self):
|
||||
'''Should expand to test_file.txt deep under this test/ directory.'''
|
||||
globs = tools.expand_references(HERE, ['resources/**/test_file.txt'])
|
||||
self.assertIn('resources/subdir/test_file.txt', globs, globs)
|
||||
self.assertIn(os.path.join('resources', 'subdir', 'test_file.txt'), globs, globs)
|
||||
|
||||
def test_glob_splatsplat_trailing(self):
|
||||
'''Should expand to all descendants of this test/ directory.'''
|
||||
globs = tools.expand_references(HERE, ['resources/**'])
|
||||
self.assertIn('resources/empty.ipynb', globs, globs)
|
||||
self.assertIn('resources/subdir/test_file.txt', globs, globs)
|
||||
self.assertIn(os.path.join('resources', 'empty.ipynb'), globs, globs)
|
||||
self.assertIn(os.path.join('resources', 'subdir', 'test_file.txt'), globs, globs)
|
||||
|
||||
def test_glob_splatsplat_leading(self):
|
||||
'''Should expand to test_file.txt under any path.'''
|
||||
globs = tools.expand_references(HERE, ['**/test_file.txt'])
|
||||
self.assertIn('resources/subdir/test_file.txt', globs, globs)
|
||||
self.assertIn('resources/another_subdir/test_file.txt', globs, globs)
|
||||
self.assertIn(os.path.join('resources', 'subdir', 'test_file.txt'), globs, globs)
|
||||
self.assertIn(os.path.join('resources', 'another_subdir', 'test_file.txt'), globs, globs)
|
||||
|
||||
def test_copy_filelist(self):
|
||||
'''Should copy select files from source to destination'''
|
||||
globs = tools.expand_references(HERE, ['**/test_file.txt'])
|
||||
tools.copy_filelist(HERE, self.tmp, globs)
|
||||
self.assertTrue(os.path.isfile(os.path.join(self.tmp, 'resources/subdir/test_file.txt')))
|
||||
self.assertTrue(os.path.isfile(os.path.join(self.tmp, 'resources/another_subdir/test_file.txt')))
|
||||
self.assertFalse(os.path.isfile(os.path.join(self.tmp, 'resources/empty.ipynb')))
|
||||
self.assertTrue(os.path.isfile(os.path.join(self.tmp, 'resources', 'subdir', 'test_file.txt')))
|
||||
self.assertTrue(os.path.isfile(os.path.join(self.tmp, 'resources', 'another_subdir', 'test_file.txt')))
|
||||
self.assertFalse(os.path.isfile(os.path.join(self.tmp, 'resources', 'empty.ipynb')))
|
||||
|
@ -124,18 +124,30 @@ def expand_references(root_path, references):
|
||||
root_path: str
|
||||
Assumed root directory for the patterns
|
||||
references: list
|
||||
Reference patterns from get_reference_patterns
|
||||
Reference patterns from get_reference_patterns expressed with
|
||||
forward-slash directory separators
|
||||
|
||||
Returns
|
||||
-------
|
||||
list
|
||||
Filename strings relative to the root path
|
||||
"""
|
||||
# Use normpath to convert to platform specific slashes, but be sure
|
||||
# to retain a trailing slash which normpath pulls off
|
||||
normalized_references = []
|
||||
for ref in references:
|
||||
normalized_ref = os.path.normpath(ref)
|
||||
# un-normalized separator
|
||||
if ref.endswith('/'):
|
||||
normalized_ref += os.sep
|
||||
normalized_references.append(normalized_ref)
|
||||
references = normalized_references
|
||||
|
||||
globbed = []
|
||||
negations = []
|
||||
must_walk = []
|
||||
for pattern in references:
|
||||
if pattern and pattern.find('/') < 0:
|
||||
if pattern and pattern.find(os.sep) < 0:
|
||||
# simple shell glob
|
||||
cwd = os.getcwd()
|
||||
os.chdir(root_path)
|
||||
@ -156,7 +168,7 @@ def expand_references(root_path, references):
|
||||
for root, _, filenames in os.walk(root_path):
|
||||
for filename in filenames:
|
||||
joined = os.path.join(root[len(root_path) + 1:], filename)
|
||||
if testpattern.endswith('/'):
|
||||
if testpattern.endswith(os.sep):
|
||||
if joined.startswith(testpattern):
|
||||
if pattern_is_negation:
|
||||
negations.append(joined)
|
||||
|
Loading…
Reference in New Issue
Block a user