internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: mkdocs/mkdocs

Issue:
GET /%E8%AE%A1%E7%AE%97/HTTP/1.1" code 404  does not support Chinese name md documents
Questions are as follows:
I have encountered a problem when using Chinese to set the navigation, click on the navigation bar to prompt the page to display: 404-Not found

The CLI error is as follows: "GET /%E8%AE%A1%E7%AE%97/ HTTP/1.1" code 404

The mkdocs.yml configuration file is as follows:
```
site_name: My Docs
site_url: https://example.com/
theme:
name: material
nav:
- 首页: index.md
- 测试1: 测试1.md
- 测试2: 测试2.md
```

I tried windows system, ubuntu system, mac system, and I can’t quote markdown documents with using Chinese to set the navigation but I see other people’s blogs support Chinese, but theirs is not the latest version, the author is in the latest version. Do you choose not to support Chinese markdown documents?  

I checked the historical problem records, but did not find a clear instruction, if you know, please help me, thank you very much



Discussion:

Resolving patch:
diff --git a/mkdocs/livereload/__init__.py b/mkdocs/livereload/__init__.py
--- a/mkdocs/livereload/__init__.py
+++ b/mkdocs/livereload/__init__.py
@@ -200,7 +200,9 @@ def serve_request(self, environ, start_response):
         return [error_content]
 
     def _serve_request(self, environ, start_response):
-        path = environ["PATH_INFO"]
+        # https://bugs.python.org/issue16679
+        # https://github.com/bottlepy/bottle/blob/f9b1849db4/bottle.py#L984
+        path = environ["PATH_INFO"].encode("latin-1").decode("utf-8", "ignore")
 
         m = re.fullmatch(r"/livereload/([0-9]+)/[0-9]+", path)
         if m:


Test patch:
diff --git a/mkdocs/tests/livereload_tests.py b/mkdocs/tests/livereload_tests.py
--- a/mkdocs/tests/livereload_tests.py
+++ b/mkdocs/tests/livereload_tests.py
@@ -304,6 +304,23 @@ def test_serves_modified_index(self, site_dir):
             _, output = do_request(server, "GET /foo/")
             self.assertRegex(output, fr"^<body>bbb{SCRIPT_REGEX}</body>$")
 
+    @tempdir({"я.html": "<body>aaa</body>", "测试2/index.html": "<body>bbb</body>"})
+    def test_serves_with_unicode_characters(self, site_dir):
+        with testing_server(site_dir) as server:
+            _, output = do_request(server, "GET /я.html")
+            self.assertRegex(output, fr"^<body>aaa{SCRIPT_REGEX}</body>$")
+            _, output = do_request(server, "GET /%D1%8F.html")
+            self.assertRegex(output, fr"^<body>aaa{SCRIPT_REGEX}</body>$")
+
+            with self.assertLogs("mkdocs.livereload"):
+                headers, _ = do_request(server, "GET /%D1.html")
+            self.assertEqual(headers["_status"], "404 Not Found")
+
+            _, output = do_request(server, "GET /测试2/")
+            self.assertRegex(output, fr"^<body>bbb{SCRIPT_REGEX}</body>$")
+            _, output = do_request(server, "GET /%E6%B5%8B%E8%AF%952/index.html")
+            self.assertRegex(output, fr"^<body>bbb{SCRIPT_REGEX}</body>$")
+
     @tempdir()
     def test_serves_js(self, site_dir):
         with testing_server(site_dir) as server:
Repository: mkdocs/mkdocs

Issue:
gh_deploy doesn't work when a config file is supplied
```
$ mkdocs gh-deploy --force --config-file mkdocs-editable.yml
...
Traceback (most recent call last):
  File "/usr/local/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1062, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1668, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 763, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/mkdocs/__main__.py", line 205, in gh_deploy_command
    gh_deploy.gh_deploy(cfg, message=message, force=force, ignore_version=ignore_version, shell=shell)
  File "/usr/local/lib/python3.9/site-packages/mkdocs/commands/gh_deploy.py", line 102, in gh_deploy
    sha = _get_current_sha(os.path.dirname(config.config_file_path))
  File "/usr/local/lib/python3.9/site-packages/mkdocs/commands/gh_deploy.py", line 32, in _get_current_sha
    proc = subprocess.Popen(['git', 'rev-parse', '--short', 'HEAD'], cwd=repo_path,
  File "/usr/local/Cellar/python@3.9/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/local/Cellar/python@3.9/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 1821, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: ''
```

The issue is that `sha = _get_current_sha(os.path.dirname(config.config_file_path))` from `gh_deploy.py` returns an empty string for `dirname` if a relative config file path is passed in.

Workaround: `--config-file $(pwd)/mkdocs-editable.yml`



Discussion:

Resolving patch:
diff --git a/mkdocs/commands/gh_deploy.py b/mkdocs/commands/gh_deploy.py
--- a/mkdocs/commands/gh_deploy.py
+++ b/mkdocs/commands/gh_deploy.py
@@ -29,7 +29,7 @@ def _is_cwd_git_repo():
 
 def _get_current_sha(repo_path):
 
-    proc = subprocess.Popen(['git', 'rev-parse', '--short', 'HEAD'], cwd=repo_path,
+    proc = subprocess.Popen(['git', 'rev-parse', '--short', 'HEAD'], cwd=repo_path or None,
                             stdout=subprocess.PIPE, stderr=subprocess.PIPE)
 
     stdout, _ = proc.communicate()


Test patch:
Repository: mkdocs/mkdocs

Issue:
CVE-2021-40978 - Path Traversal.
Hey!

We have verified a security flaw in the current version of MKdocs, a path traversal failure affecting the built-in dev-server.

That flaw turns the server susceptible to providing data outside the scope of the application allowing anyone to request sensitive files.

If you need further information, don't hesitate to get in touch with me.

https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-40978
https://github.com/nisdn/CVE-2021-40978



Discussion:
It should be mentioned the dev server is known to not be secure and should not be used in a sensitive environment. The security flaw is using the dev-server in an unsafe way, e.g., as a public server and not just as a development server.

Resolving patch:
diff --git a/mkdocs/livereload/__init__.py b/mkdocs/livereload/__init__.py
--- a/mkdocs/livereload/__init__.py
+++ b/mkdocs/livereload/__init__.py
@@ -4,6 +4,7 @@
 import mimetypes
 import os
 import os.path
+import posixpath
 import re
 import socketserver
 import threading
@@ -183,9 +184,11 @@ def condition():
         if path == "/js/livereload.js":
             file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "livereload.js")
         elif path.startswith(self.mount_path):
-            rel_file_path = path[len(self.mount_path):].lstrip("/")
+            rel_file_path = path[len(self.mount_path):]
             if path.endswith("/"):
                 rel_file_path += "index.html"
+            # Prevent directory traversal - normalize the path.
+            rel_file_path = posixpath.normpath("/" + rel_file_path).lstrip("/")
             file_path = os.path.join(self.root, rel_file_path)
         elif path == "/":
             start_response("302 Found", [("Location", self.mount_path)])


Test patch:
Repository: mkdocs/mkdocs

Issue:
Support terminal coloring on Windows
E.g. we might use the [colorama](https://pypi.org/project/colorama/) library, otherwise the output looks like this in cmd.exe:

```
←[33mWARNING  -  ←[0mmkdocs_autorefs.plugin: cookbook-reference.md: Could not find cross-reference target '['a']'
←[33mWARNING  -  ←[0mmkdocs_autorefs.plugin: cookbook-reference.md: Could not find cross-reference target '['a']'
```


Discussion:
MkDocs colorizes the logs using Click. Click uses colorama. But Click's docs are a bit confusing:

https://click.palletsprojects.com/en/8.0.x/quickstart/?highlight=colorama#echoing

> The echo function also supports color and other styles in output. It will automatically remove styles if the output stream is a file. On Windows, colorama is automatically installed and used. See ANSI Colors.

https://click.palletsprojects.com/en/8.0.x/utils/#ansi-colors

> On Windows, Click uses colorama without calling colorama.init(). You can still call that in your code, but it’s not required for Click.

So, is it automatically supported or is it not? Maybe MkDocs should call `colorama.init()` itself when on a Windows OS:

```python
import os
import colorama

if os.name == 'nt':
    colorama.init()
```
Wow, that's great news, and this works for me:
![grafik](https://user-images.githubusercontent.com/54819781/133672301-434673ae-6622-436a-ae5a-4d5288b1d161.png)

Just added this somewhere at the top of `mkdocs/__main__.py`:
```python
if os.name == 'nt': import colorama; colorama.init()
```
except that I usually check `sys.platform == 'win32`, but I might be wrong.

Resolving patch:
diff --git a/mkdocs/__main__.py b/mkdocs/__main__.py
--- a/mkdocs/__main__.py
+++ b/mkdocs/__main__.py
@@ -12,6 +12,15 @@
 from mkdocs import config
 from mkdocs.commands import build, gh_deploy, new, serve
 
+
+if sys.platform.startswith("win"):
+    try:
+        import colorama
+    except ImportError:
+        pass
+    else:
+        colorama.init()
+
 log = logging.getLogger(__name__)
 
 


Test patch:
Repository: mkdocs/mkdocs

Issue:
` SubConfig` ignore configuration failures
While developing [mkdocs-gallery]() I found out that the `SubConfig` class does not retrieve the failures and warnings from the nested options.

This is because `run_validation` executes `Config.validate` but does not look at its results (`failures, warnings`):
https://github.com/mkdocs/mkdocs/blob/97eafb9094fdd56d19022ae8fda332e728df674b/mkdocs/config/config_options.py#L61



Discussion:

Resolving patch:
diff --git a/mkdocs/config/config_options.py b/mkdocs/config/config_options.py
--- a/mkdocs/config/config_options.py
+++ b/mkdocs/config/config_options.py
@@ -59,7 +59,12 @@ def validate(self, value):
         return self.run_validation(value)
 
     def run_validation(self, value):
-        Config.validate(self)
+        failed, self.warnings = Config.validate(self)
+        if len(failed) > 0:
+            # get the first failing one
+            key, err = failed[0]
+            raise ValidationError(f"Sub-option {key!r} configuration error: {err}")
+
         return self
 
 


Test patch:
Repository: mkdocs/mkdocs

Issue:
Defining `edit_uri` as anything other than an empty string modifies the `repo_url`
### Description

Defining `edit_uri` as anything other than an empty string adds a forward slash to the `repo_url` link for the button on the top right

### Expected behavior

The `repo_url` link for the button on the top right is what is defined in config

### Versions

- Python: `3.8.1`
- MkDocs: `1.2.3`

### System information

- Operating system: Windows 10
- Browser: Chrome


Discussion:

Resolving patch:
diff --git a/mkdocs/config/config_options.py b/mkdocs/config/config_options.py
--- a/mkdocs/config/config_options.py
+++ b/mkdocs/config/config_options.py
@@ -354,12 +354,8 @@ def post_validation(self, config, key_name):
                 edit_uri = ''
 
         # ensure a well-formed edit_uri
-        if edit_uri:
-            if not edit_uri.startswith(('?', '#')) \
-                    and not config['repo_url'].endswith('/'):
-                config['repo_url'] += '/'
-            if not edit_uri.endswith('/'):
-                edit_uri += '/'
+        if edit_uri and not edit_uri.endswith('/'):
+            edit_uri += '/'
 
         config['edit_uri'] = edit_uri
 
diff --git a/mkdocs/structure/pages.py b/mkdocs/structure/pages.py
--- a/mkdocs/structure/pages.py
+++ b/mkdocs/structure/pages.py
@@ -104,6 +104,9 @@ def _set_canonical_url(self, base):
     def _set_edit_url(self, repo_url, edit_uri):
         if repo_url and edit_uri:
             src_path = self.file.src_path.replace('\\', '/')
+            # Ensure urljoin behavior is correct
+            if not edit_uri.startswith(('?', '#')) and not repo_url.endswith('/'):
+                repo_url += '/'
             self.edit_url = urljoin(repo_url, edit_uri + src_path)
         else:
             self.edit_url = None


Test patch:
diff --git a/mkdocs/tests/config/config_options_tests.py b/mkdocs/tests/config/config_options_tests.py
--- a/mkdocs/tests/config/config_options_tests.py
+++ b/mkdocs/tests/config/config_options_tests.py
@@ -323,6 +323,7 @@ def test_edit_uri_github(self):
         config = {'repo_url': "https://github.com/mkdocs/mkdocs"}
         option.post_validation(config, 'repo_url')
         self.assertEqual(config['edit_uri'], 'edit/master/docs/')
+        self.assertEqual(config['repo_url'], "https://github.com/mkdocs/mkdocs")
 
     def test_edit_uri_bitbucket(self):
 
@@ -330,6 +331,7 @@ def test_edit_uri_bitbucket(self):
         config = {'repo_url': "https://bitbucket.org/gutworth/six/"}
         option.post_validation(config, 'repo_url')
         self.assertEqual(config['edit_uri'], 'src/default/docs/')
+        self.assertEqual(config['repo_url'], "https://bitbucket.org/gutworth/six/")
 
     def test_edit_uri_gitlab(self):
 
@@ -344,6 +346,7 @@ def test_edit_uri_custom(self):
         config = {'repo_url': "https://launchpad.net/python-tuskarclient"}
         option.post_validation(config, 'repo_url')
         self.assertEqual(config.get('edit_uri'), '')
+        self.assertEqual(config['repo_url'], "https://launchpad.net/python-tuskarclient")
 
     def test_repo_name_custom_and_empty_edit_uri(self):
Repository: mkdocs/mkdocs

Issue:
What is the expected behavior of `readme.md`?
According to the docs, [Writing-your-docs:Index-pages](https://www.mkdocs.org/user-guide/writing-your-docs/#index-pages), `README.md` will render into `index.html`. There is no mention of `readme.md`. The implementation reflects this behavior: https://github.com/mkdocs/mkdocs/blob/dc35569ade5e101c8c48b78bbed8708dd0b1b49a/mkdocs/structure/files.py#L151

But the check in [get_files()](https://github.com/mkdocs/mkdocs/blob/dc35569ade5e101c8c48b78bbed8708dd0b1b49a/mkdocs/structure/files.py#L225) ignores casing:
https://github.com/mkdocs/mkdocs/blob/dc35569ade5e101c8c48b78bbed8708dd0b1b49a/mkdocs/structure/files.py#L246-L247

I believe it should be:
```python
if filename == 'README.md' and 'index.md' in filenames:
    log.warning(f"Both index.md and README.md found. Skipping README.md from {source_dir}")
```


Discussion:
Yes, I think this can be treated as a bug; the lowercasing makes no sense.

Would you like to send out the fix to make it so?

> ```python
> if filename == 'README.md' and 'index.md' in filenames:
> ```

Maybe add a new unittest too? Something around https://github.com/mkdocs/mkdocs/blob/82bd8ba5ff177347d094b095bd623a85aaa4c80f/mkdocs/tests/structure/file_tests.py#L628
on it :)

Resolving patch:
diff --git a/mkdocs/structure/files.py b/mkdocs/structure/files.py
--- a/mkdocs/structure/files.py
+++ b/mkdocs/structure/files.py
@@ -243,8 +243,8 @@ def get_files(config):
             if _filter_paths(basename=filename, path=path, is_dir=False, exclude=exclude):
                 continue
             # Skip README.md if an index file also exists in dir
-            if filename.lower() == 'readme.md' and 'index.md' in filenames:
-                log.warning(f"Both index.md and readme.md found. Skipping readme.md from {source_dir}")
+            if filename == 'README.md' and 'index.md' in filenames:
+                log.warning(f"Both index.md and README.md found. Skipping README.md from {source_dir}")
                 continue
             files.append(File(path, config['docs_dir'], config['site_dir'], config['use_directory_urls']))
 


Test patch:
diff --git a/mkdocs/tests/structure/file_tests.py b/mkdocs/tests/structure/file_tests.py
--- a/mkdocs/tests/structure/file_tests.py
+++ b/mkdocs/tests/structure/file_tests.py
@@ -592,6 +592,7 @@ def test_get_relative_url(self):
 
     @tempdir(files=[
         'index.md',
+        'readme.md',
         'bar.css',
         'bar.html',
         'bar.jpg',
@@ -603,7 +604,7 @@ def test_get_relative_url(self):
     def test_get_files(self, tdir):
         config = load_config(docs_dir=tdir, extra_css=['bar.css'], extra_javascript=['bar.js'])
         files = get_files(config)
-        expected = ['index.md', 'bar.css', 'bar.html', 'bar.jpg', 'bar.js', 'bar.md']
+        expected = ['index.md', 'bar.css', 'bar.html', 'bar.jpg', 'bar.js', 'bar.md', 'readme.md']
         self.assertIsInstance(files, Files)
         self.assertEqual(len(files), len(expected))
         self.assertEqual([f.src_path for f in files], expected)
Repository: mkdocs/mkdocs

Issue:
v1.5.0 Attempts to Remove Files Twice, throws `ValueError`
I have a somewhat strange/niche site folder with an `index.html`, `index.md`, _and_ a `README.md`.

After upgrading to v1.5.0, `mkdocs build` throws a ValueError with the trace below.

`get_files` will attempt to remove a file multiple times if there are multiple conflicts.

```python
WARNING -  Excluding 'README.md' from the site because it conflicts with 'index.html'.
WARNING -  Excluding 'README.md' from the site because it conflicts with 'index.md'.
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/jakecarter/repos/fork/msdk/venv/lib/python3.11/site-packages/mkdocs/__main__.py", line 361, in <module>
    cli()
  File "/home/jakecarter/repos/fork/msdk/venv/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jakecarter/repos/fork/msdk/venv/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/home/jakecarter/repos/fork/msdk/venv/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jakecarter/repos/fork/msdk/venv/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jakecarter/repos/fork/msdk/venv/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jakecarter/repos/fork/msdk/venv/lib/python3.11/site-packages/mkdocs/__main__.py", line 286, in build_command
    build.build(cfg, dirty=not clean)
  File "/home/jakecarter/repos/fork/msdk/venv/lib/python3.11/site-packages/mkdocs/commands/build.py", line 299, in build
    files = get_files(config)
            ^^^^^^^^^^^^^^^^^
  File "/home/jakecarter/repos/fork/msdk/venv/lib/python3.11/site-packages/mkdocs/structure/files.py", line 371, in get_files
    files.remove(a)
ValueError: list.remove(x): x not in list
```


Discussion:

Resolving patch:
diff --git a/mkdocs/structure/files.py b/mkdocs/structure/files.py
--- a/mkdocs/structure/files.py
+++ b/mkdocs/structure/files.py
@@ -367,9 +367,15 @@ def get_files(config: MkDocsConfig) -> Files:
                 log.warning(
                     f"Excluding '{a.src_uri}' from the site because it conflicts with '{b.src_uri}'."
                 )
-            files.remove(a)
+            try:
+                files.remove(a)
+            except ValueError:
+                pass  # Catching this to avoid errors if attempting to remove the same file twice.
         else:
-            files.remove(b)
+            try:
+                files.remove(b)
+            except ValueError:
+                pass
 
     return Files(files)
 


Test patch:
Repository: mkdocs/mkdocs

Issue:
`mkdocs serve --livereload` hangs, forces to CTRL-C and restart
Whenever we use `mkdocs serve --livereload`, the livereload server blocks, as MkDocs waits for changes to files that can be reported back to the browser. This technique is known as long polling, and albeit we now have wide support for websockets which are a superior solution, it's a perfectly fine implementation for livereload functionality.

Blocking is implemented here:

https://github.com/mkdocs/mkdocs/blob/347c3a91dd3e82937ce2b4783c60abf2477ff844/mkdocs/livereload/__init__.py#L262

However, sometimes when I navigate the site while working on it, MkDocs gets stuck in this condition and waits for changes to files. There are three ways to unblock it:

1. Change and save a file, so MkDocs rebuilds it and returns it to the browser
2. Press <kbd>ESC</kbd> in the browser to cancel the `/livereload` request
3. Wait for a minute until it times out

I'm not very familiar with the livereload implementation, but the problem seems to be that the server is occupied with waiting for the livereload request to finish hitting one of the conditions mentioned above, which prohibits the navigation from happening – see the loading indicator after navigating for the third time:

https://github.com/mkdocs/mkdocs/assets/932156/04869d26-3e17-4cee-b7e5-0917c95e150d

My testing shows that this problem can be solved by cancelling the pending `/livereload` request before navigation.


Discussion:

Resolving patch:
diff --git a/mkdocs/livereload/__init__.py b/mkdocs/livereload/__init__.py
--- a/mkdocs/livereload/__init__.py
+++ b/mkdocs/livereload/__init__.py
@@ -30,6 +30,7 @@
 var livereload = function(epoch, requestId) {
     var req = new XMLHttpRequest();
     req.onloadend = function() {
+        window.removeEventListener("beforeunload", abort);
         if (parseFloat(this.responseText) > epoch) {
             location.reload();
             return;
@@ -41,6 +42,8 @@
             setTimeout(launchNext, 3000);
         }
     };
+    var abort = req.abort.bind(req);
+    window.addEventListener("beforeunload", abort);
     req.open("GET", "/livereload/" + epoch + "/" + requestId);
     req.send();
 


Test patch:
Repository: mkdocs/mkdocs

Issue:
Hooks scripts can't really use imports
It would be nice if the files that are used as hooks would have the ability to import files relative to them or maybe relative to the root. But currently the only way to achieve this is with this workaround first:

```python
import sys, os
sys.path.insert(0, os.path.dirname(__file__))

import something_from_the_directory
```


Discussion:
What exactly does that mean? Putting the `sys.path.insert(...)` at the top of the file above the imports or smth?
Yes, if they don't work otherwise
Okay. Tho this one doesn't seem right because `sys` and `os` aren't recognized and throw errors when using `mkdocs serve`, so this may not work reliably or for all python versions?

I have Python 11 on a windows 10 PC.
OK I'll edit the example to be clearer

Resolving patch:
diff --git a/mkdocs/config/config_options.py b/mkdocs/config/config_options.py
--- a/mkdocs/config/config_options.py
+++ b/mkdocs/config/config_options.py
@@ -1208,7 +1208,14 @@ def _load_hook(self, name, path):
         sys.modules[name] = module
         if spec.loader is None:
             raise ValidationError(f"Cannot import path '{path}' as a Python module")
-        spec.loader.exec_module(module)
+
+        old_sys_path = sys.path.copy()
+        sys.path.insert(0, os.path.dirname(path))
+        try:
+            spec.loader.exec_module(module)
+        finally:
+            sys.path[:] = old_sys_path
+
         return module
 
     def post_validation(self, config: Config, key_name: str):


Test patch: