Skip to content

Commit

Permalink
Merge pull request sphinx-doc#8538 from jdufresne/os-replace
Browse files Browse the repository at this point in the history
Deprecate sphinx.util.osutil.movefile() in favor of os.replace()
  • Loading branch information
tk0miya authored Dec 14, 2020
2 parents edb1999 + cb4f76f commit 00db1ea
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Deprecated
* ``sphinx.ext.autodoc.TypeVarDocumenter``
* ``sphinx.ext.autodoc.importer._getannotations()``
* ``sphinx.pycode.ModuleAnalyzer.parse()``
* ``sphinx.util.osutil.movefile()``
* ``sphinx.util.requests.is_ssl_error()``

Features added
Expand Down
5 changes: 5 additions & 0 deletions doc/extdev/deprecated.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ The following is a list of deprecated interfaces.
- 5.0
- ``sphinx.pycode.ModuleAnalyzer.analyze()``

* - ``sphinx.util.osutil.movefile()``
- 3.4
- 5.0
- ``os.replace()``

* - ``sphinx.util.requests.is_ssl_error()``
- 3.4
- 5.0
Expand Down
5 changes: 3 additions & 2 deletions sphinx/builders/html/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""

import html
import os
import posixpath
import re
import sys
Expand Down Expand Up @@ -44,7 +45,7 @@
from sphinx.util.i18n import format_date
from sphinx.util.inventory import InventoryFile
from sphinx.util.matching import DOTFILES, Matcher, patmatch
from sphinx.util.osutil import copyfile, ensuredir, movefile, os_path, relative_uri
from sphinx.util.osutil import copyfile, ensuredir, os_path, relative_uri
from sphinx.util.tags import Tags
from sphinx.writers.html import HTMLTranslator, HTMLWriter

Expand Down Expand Up @@ -1070,7 +1071,7 @@ def dump_search_index(self) -> None:
else:
with open(searchindexfn + '.tmp', 'wb') as fb:
self.indexer.dump(fb, self.indexer_format)
movefile(searchindexfn + '.tmp', searchindexfn)
os.replace(searchindexfn + '.tmp', searchindexfn)


def convert_html_css_files(app: Sphinx, config: Config) -> None:
Expand Down
4 changes: 2 additions & 2 deletions sphinx/transforms/post_transforms/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from sphinx.transforms import SphinxTransform
from sphinx.util import epoch_to_rfc1123, logging, requests, rfc1123_to_epoch, sha1
from sphinx.util.images import get_image_extension, guess_mimetype, parse_data_uri
from sphinx.util.osutil import ensuredir, movefile
from sphinx.util.osutil import ensuredir

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -99,7 +99,7 @@ def handle(self, node: nodes.image) -> None:
# append a suffix if URI does not contain suffix
ext = get_image_extension(mimetype)
newpath = os.path.join(self.imagedir, dirname, basename + ext)
movefile(path, newpath)
os.replace(path, newpath)
self.app.env.original_image_uri.pop(path)
self.app.env.original_image_uri[newpath] = node['uri']
path = newpath
Expand Down
5 changes: 4 additions & 1 deletion sphinx/util/osutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from os import path
from typing import Any, Generator, Iterator, List, Optional, Tuple

from sphinx.deprecation import RemovedInSphinx40Warning
from sphinx.deprecation import RemovedInSphinx40Warning, RemovedInSphinx50Warning

try:
# for ALT Linux (#6712)
Expand Down Expand Up @@ -103,6 +103,9 @@ def mtimes_of_files(dirnames: List[str], suffix: str) -> Iterator[float]:

def movefile(source: str, dest: str) -> None:
"""Move a file, removing the destination if it exists."""
warnings.warn('sphinx.util.osutil.movefile() is deprecated for removal. '
'Please use os.replace() instead.',
RemovedInSphinx50Warning, stacklevel=2)
if os.path.exists(dest):
try:
os.unlink(dest)
Expand Down

0 comments on commit 00db1ea

Please sign in to comment.