Repository: mkdocs/mkdocs
Pull request #2912 (2022-08-06 12:02:49)

Simplify utils, deprecate unused functions
[(I also searched across GitHub that nobody uses these)](https://cs.github.com/?q=%2F\bis_html_file\b%2F+mkdocs+path%3A%2Fpy%24%2F+NOT+path%3A%2Fmkdocs\%2F(utils|build|nav|test|relative_path_ext|config)%2F)

For `is_markdown_file` instead do a breaking change so it matches the actual behavior of MkDocs build: don't accept uppercase extensions anymore.



Patch:
diff --git a/mkdocs/structure/files.py b/mkdocs/structure/files.py
index ada0c95a..4ab26988 100644
--- a/mkdocs/structure/files.py
+++ b/mkdocs/structure/files.py
@@ -193,16 +193,11 @@ class File:
 
     def is_documentation_page(self):
         """ Return True if file is a Markdown page. """
-        return os.path.splitext(self.src_path)[1] in utils.markdown_extensions
+        return utils.is_markdown_file(self.src_path)
 
     def is_static_page(self):
         """ Return True if file is a static page (html, xml, json). """
-        return os.path.splitext(self.src_path)[1] in (
-            '.html',
-            '.htm',
-            '.xml',
-            '.json',
-        )
+        return self.src_path.endswith(('.html', '.htm', '.xml', '.json'))
 
     def is_media_file(self):
         """ Return True if file is not a documentation or static page. """
@@ -210,16 +205,11 @@ class File:
 
     def is_javascript(self):
         """ Return True if file is a JavaScript file. """
-        return os.path.splitext(self.src_path)[1] in (
-            '.js',
-            '.javascript',
-        )
+        return self.src_path.endswith(('.js', '.javascript'))
 
     def is_css(self):
         """ Return True if file is a CSS file. """
-        return os.path.splitext(self.src_path)[1] in (
-            '.css',
-        )
+        return self.src_path.endswith('.css')
 
 
 def get_files(config):
diff --git a/mkdocs/utils/__init__.py b/mkdocs/utils/__init__.py
index 4a7b6e8a..4006d1b7 100644
--- a/mkdocs/utils/__init__.py
+++ b/mkdocs/utils/__init__.py
@@ -11,9 +11,9 @@ import os
 import shutil
 import re
 import yaml
-import fnmatch
 import posixpath
 import functools
+import warnings
 import importlib_metadata
 from collections import defaultdict
 from datetime import datetime, timezone
@@ -25,13 +25,13 @@ from mkdocs import exceptions
 
 log = logging.getLogger(__name__)
 
-markdown_extensions = [
+markdown_extensions = (
     '.markdown',
     '.mdown',
     '.mkdn',
     '.mkd',
     '.md'
-]
+)
 
 
 def get_yaml_loader(loader=yaml.Loader):
@@ -68,10 +68,9 @@ def yaml_load(source, loader=None):
 
 
 def modified_time(file_path):
-    """
-    Return the modified time of the supplied file. If the file does not exists zero is returned.
-    see build_pages for use.
-    """
+    warnings.warn(
+        "modified_time is never used in MkDocs and will be removed soon.", DeprecationWarning
+    )
     if os.path.exists(file_path):
         return os.path.getmtime(file_path)
     else:
@@ -118,9 +117,7 @@ def get_build_date():
 
 def reduce_list(data_set):
     """ Reduce duplicate items in a list and preserve order """
-    seen = set()
-    return [item for item in data_set if
-            item not in seen and not seen.add(item)]
+    return list(dict.fromkeys(data_set))
 
 
 def copy_file(source_path, output_path):
@@ -168,13 +165,9 @@ def clean_directory(directory):
 
 
 def get_html_path(path):
-    """
-    Map a source file path to an output html path.
-
-    Paths like 'index.md' will be converted to 'index.html'
-    Paths like 'about.md' will be converted to 'about/index.html'
-    Paths like 'api-guide/core.md' will be converted to 'api-guide/core/index.html'
-    """
+    warnings.warn(
+        "get_html_path is never used in MkDocs and will be removed soon.", DeprecationWarning
+    )
     path = os.path.splitext(path)[0]
     if os.path.basename(path) == 'index':
         return path + '.html'
@@ -182,16 +175,9 @@ def get_html_path(path):
 
 
 def get_url_path(path, use_directory_urls=True):
-    """
-    Map a source file path to an output html path.
-
-    Paths like 'index.md' will be converted to '/'
-    Paths like 'about.md' will be converted to '/about/'
-    Paths like 'api-guide/core.md' will be converted to '/api-guide/core/'
-
-    If `use_directory_urls` is `False`, returned URLs will include the a trailing
-    `index.html` rather than just returning the directory path.
-    """
+    warnings.warn(
+        "get_url_path is never used in MkDocs and will be removed soon.", DeprecationWarning
+    )
     path = get_html_path(path)
     url = '/' + path.replace(os.path.sep, '/')
     if use_directory_urls:
@@ -205,30 +191,21 @@ def is_markdown_file(path):
 
     https://superuser.com/questions/249436/file-extension-for-markdown-files
     """
-    return any(fnmatch.fnmatch(path.lower(), f'*{x}') for x in markdown_extensions)
+    return path.endswith(markdown_extensions)
 
 
 def is_html_file(path):
-    """
-    Return True if the given file path is an HTML file.
-    """
-    ext = os.path.splitext(path)[1].lower()
-    return ext in [
-        '.html',
-        '.htm',
-    ]
+    warnings.warn(
+        "is_html_file is never used in MkDocs and will be removed soon.", DeprecationWarning
+    )
+    return path.lower().endswith(('.html', '.htm'))
 
 
 def is_template_file(path):
-    """
-    Return True if the given file path is an HTML file.
-    """
-    ext = os.path.splitext(path)[1].lower()
-    return ext in [
-        '.html',
-        '.htm',
-        '.xml',
-    ]
+    warnings.warn(
+        "is_template_file is never used in MkDocs and will be removed soon.", DeprecationWarning
+    )
+    return path.lower().endswith(('.html', '.htm', '.xml'))
 
 
 _ERROR_TEMPLATE_RE = re.compile(r'^\d{3}\.html?$')


Test patch:
diff --git a/mkdocs/tests/utils/utils_tests.py b/mkdocs/tests/utils/utils_tests.py
index bc4b19d9..1a79fcf0 100644
--- a/mkdocs/tests/utils/utils_tests.py
+++ b/mkdocs/tests/utils/utils_tests.py
@@ -39,32 +39,11 @@ deep1:
 
 
 class UtilsTests(unittest.TestCase):
-    def test_html_path(self):
-        expected_results = {
-            'index.md': 'index.html',
-            'api-guide.md': 'api-guide/index.html',
-            'api-guide/index.md': 'api-guide/index.html',
-            'api-guide/testing.md': 'api-guide/testing/index.html',
-        }
-        for file_path, expected_html_path in expected_results.items():
-            html_path = utils.get_html_path(file_path)
-            self.assertEqual(html_path, expected_html_path)
-
-    def test_url_path(self):
-        expected_results = {
-            'index.md': '/',
-            'api-guide.md': '/api-guide/',
-            'api-guide/index.md': '/api-guide/',
-            'api-guide/testing.md': '/api-guide/testing/',
-        }
-        for file_path, expected_html_path in expected_results.items():
-            html_path = utils.get_url_path(file_path)
-            self.assertEqual(html_path, expected_html_path)
-
     def test_is_markdown_file(self):
         expected_results = {
             'index.md': True,
-            'index.MARKDOWN': True,
+            'index.markdown': True,
+            'index.MARKDOWN': False,
             'index.txt': False,
             'indexmd': False
         }
@@ -72,17 +51,6 @@ class UtilsTests(unittest.TestCase):
             is_markdown = utils.is_markdown_file(path)
             self.assertEqual(is_markdown, expected_result)
 
-    def test_is_html_file(self):
-        expected_results = {
-            'index.htm': True,
-            'index.HTML': True,
-            'index.txt': False,
-            'indexhtml': False
-        }
-        for path, expected_result in expected_results.items():
-            is_html = utils.is_html_file(path)
-            self.assertEqual(is_html, expected_result)
-
     def test_get_relative_url(self):
         expected_results = {
             ('foo/bar', 'foo'): 'bar',