From 1d11a297a36e582e7e6ba191e6a3e7686630d64d Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Sat, 8 Sep 2018 13:02:24 -0700 Subject: [PATCH] Remove use of Python 2 os.getcwdu() os.getcwdu() is Python 2 only. It was removed from Python 3. As Sphinx is now Python 3 only, can remove the workaround. $ python2 -c 'import os; print(os.getcwdu)' $ python3 -c 'import os; print(os.getcwdu)' Traceback (most recent call last): File "", line 1, in AttributeError: module 'os' has no attribute 'getcwdu' sphinx.util.osutil.getcwd() is now deprecated for removal. --- sphinx/environment/collectors/dependencies.py | 5 +++-- sphinx/util/osutil.py | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/sphinx/environment/collectors/dependencies.py b/sphinx/environment/collectors/dependencies.py index de0b7c080..761a51e38 100644 --- a/sphinx/environment/collectors/dependencies.py +++ b/sphinx/environment/collectors/dependencies.py @@ -9,12 +9,13 @@ :license: BSD, see LICENSE for details. """ +import os from os import path from docutils.utils import relative_path from sphinx.environment.collectors import EnvironmentCollector -from sphinx.util.osutil import getcwd, fs_encoding +from sphinx.util.osutil import fs_encoding if False: # For type annotation @@ -40,7 +41,7 @@ class DependenciesCollector(EnvironmentCollector): def process_doc(self, app, doctree): # type: (Sphinx, nodes.Node) -> None """Process docutils-generated dependency info.""" - cwd = getcwd() + cwd = os.getcwd() frompath = path.join(path.normpath(app.srcdir), 'dummy') deps = doctree.settings.record_dependencies if not deps: diff --git a/sphinx/util/osutil.py b/sphinx/util/osutil.py index 986171293..ab56d749e 100644 --- a/sphinx/util/osutil.py +++ b/sphinx/util/osutil.py @@ -25,7 +25,7 @@ from os import path from six import PY2, PY3, text_type -from sphinx.deprecation import RemovedInSphinx30Warning +from sphinx.deprecation import RemovedInSphinx30Warning, RemovedInSphinx40Warning if False: # For type annotation @@ -243,15 +243,16 @@ def abspath(pathdir): def getcwd(): # type: () -> unicode - if hasattr(os, 'getcwdu'): - return os.getcwdu() + warnings.warn('sphinx.util.osutil.getcwd() is deprecated. ' + 'Please use os.getcwd() instead.', + RemovedInSphinx40Warning) return os.getcwd() @contextlib.contextmanager def cd(target_dir): # type: (unicode) -> Iterator[None] - cwd = getcwd() + cwd = os.getcwd() try: os.chdir(target_dir) yield