|
From: <mi...@us...> - 2022-11-28 23:56:00
|
Revision: 9283
http://sourceforge.net/p/docutils/code/9283
Author: milde
Date: 2022-11-28 23:55:57 +0000 (Mon, 28 Nov 2022)
Log Message:
-----------
Use pathlib.Path in utils.find_file_in_dirs().
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/docutils/utils/__init__.py
trunk/docutils/test/test_utils.py
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2022-11-28 23:55:46 UTC (rev 9282)
+++ trunk/docutils/HISTORY.txt 2022-11-28 23:55:57 UTC (rev 9283)
@@ -47,7 +47,9 @@
* docutils/utils/__init__.py
- New utility function `xml_declaration()`.
- - `utils.DependencyList.add()` accepts `pathlib.Path` instances.
+ - `DependencyList.add()` accepts `pathlib.Path` instances.
+ - `find_file_in_dirs()` now returns a POSIX path also on Windows;
+ `get_stylesheet_list()` no longer converts "\" to "/".
* docutils/utils/math/latex2mathml.py
Modified: trunk/docutils/docutils/utils/__init__.py
===================================================================
--- trunk/docutils/docutils/utils/__init__.py 2022-11-28 23:55:46 UTC (rev 9282)
+++ trunk/docutils/docutils/utils/__init__.py 2022-11-28 23:55:57 UTC (rev 9283)
@@ -11,7 +11,7 @@
import sys
import os
import os.path
-from pathlib import PurePath
+from pathlib import PurePath, Path
import re
import itertools
import warnings
@@ -534,9 +534,9 @@
# Return 'stylesheet' or 'stylesheet_path' arguments as list.
#
# The original settings arguments are kept unchanged: you can test
-# with e.g. ``if settings.stylesheet_path:``
+# with e.g. ``if settings.stylesheet_path: ...``.
#
-# Differences to ``get_stylesheet_reference``:
+# Differences to the depracated `get_stylesheet_reference()`:
# * return value is a list
# * no re-writing of the path (and therefore no optional argument)
# (if required, use ``utils.relative_path(source, target)``
@@ -555,8 +555,6 @@
# expand relative paths if found in stylesheet-dirs:
stylesheets = [find_file_in_dirs(path, settings.stylesheet_dirs)
for path in stylesheets]
- if os.sep != '/': # for URLs, we need POSIX paths
- stylesheets = [path.replace(os.sep, '/') for path in stylesheets]
return stylesheets
@@ -566,17 +564,14 @@
Return the first expansion that matches an existing file.
"""
- if os.path.isabs(path):
- return path
+ path = Path(path)
+ if path.is_absolute():
+ return path.as_posix()
for d in dirs:
- if d == '.':
- f = path
- else:
- d = os.path.expanduser(d)
- f = os.path.join(d, path)
- if os.path.exists(f):
- return f
- return path
+ f = Path(d).expanduser() / path
+ if f.exists():
+ return f.as_posix()
+ return path.as_posix()
def get_trim_footnote_ref_space(settings):
Modified: trunk/docutils/test/test_utils.py
===================================================================
--- trunk/docutils/test/test_utils.py 2022-11-28 23:55:46 UTC (rev 9282)
+++ trunk/docutils/test/test_utils.py 2022-11-28 23:55:57 UTC (rev 9283)
@@ -351,13 +351,10 @@
dirs = (os.path.join(TEST_ROOT, 'nonex'),
TEST_ROOT,
os.path.join(TEST_ROOT, '..'))
- found = os.path.relpath(
- os.path.join(utils.find_file_in_dirs('HISTORY.txt', dirs)),
- TEST_ROOT).replace('\\', '/')
- # returns
- # '..\\HISTORY.txt' on windows
- # '../HISTORY.txt' on other platforms
- # 'HISTORY.txt' if not called from docutils directory.
+ found = utils.find_file_in_dirs('HISTORY.txt', dirs)
+ self.assertEqual(found, (TEST_ROOT / '..' / 'HISTORY.txt').as_posix())
+ # normalize
+ found = os.path.relpath(found, TEST_ROOT).replace('\\', '/')
self.assertTrue(found.startswith('..'),
'HISTORY.txt not found in "..".')
# Return `path` if the file exists in the cwd or if there is no match
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|