We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
2.10.17 failure starting prefect agent on a windows machine
### First check

- [X] I added a descriptive title to this issue.
- [X] I used the GitHub search to find a similar issue and didn't find it.
- [X] I searched the Prefect documentation for this issue.
- [X] I checked that this issue is related to Prefect and not one of its dependencies.

### Bug summary

prefect agent won't start in 2.10.17 but it does in 2.10.16

### Reproduction

```python3
(venv) C:\Users\jkang1\PycharmProjects\site_analytics\venv\Scripts>prefect agent start --pool default-agent-pool
```


### Error

```python3
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\jkang1\PycharmProjects\site_analytics\venv\Scripts\prefect.exe\__main__.py", line 4, in <module>
  File "C:\Users\jkang1\PycharmProjects\site_analytics\venv\Lib\site-packages\prefect\__init__.py", line 37, in <module>
    from prefect.states import State
  File "C:\Users\jkang1\PycharmProjects\site_analytics\venv\Lib\site-packages\prefect\states.py", line 14, in <module>
    from prefect.client.schemas import State as State
  File "C:\Users\jkang1\PycharmProjects\site_analytics\venv\Lib\site-packages\prefect\client\schemas\__init__.py", line 4, in <module>
    from .actions import BlockTypeUpdate, StateCreate
  File "C:\Users\jkang1\PycharmProjects\site_analytics\venv\Lib\site-packages\prefect\client\schemas\actions.py", line 9, in <module>
    import prefect.client.schemas.objects as objects
  File "C:\Users\jkang1\PycharmProjects\site_analytics\venv\Lib\site-packages\prefect\client\schemas\objects.py", line 20, in <module>
    from prefect._internal.schemas.bases import ObjectBaseModel, PrefectBaseModel
  File "C:\Users\jkang1\PycharmProjects\site_analytics\venv\Lib\site-packages\prefect\_internal\schemas\bases.py", line 18, in <module>
    from prefect._internal.compatibility.experimental import experiment_enabled
  File "C:\Users\jkang1\PycharmProjects\site_analytics\venv\Lib\site-packages\prefect\_internal\compatibility\experimental.py", line 19, in <module>
    from prefect.settings import PREFECT_EXPERIMENTAL_WARN, SETTING_VARIABLES, Setting
  File "C:\Users\jkang1\PycharmProjects\site_analytics\venv\Lib\site-packages\prefect\settings.py", line 70, in <module>
    from prefect._internal.compatibility.deprecated import generate_deprecation_message
  File "C:\Users\jkang1\PycharmProjects\site_analytics\venv\Lib\site-packages\prefect\_internal\compatibility\deprecated.py", line 21, in <module>
    from prefect.utilities.importtools import (
  File "C:\Users\jkang1\PycharmProjects\site_analytics\venv\Lib\site-packages\prefect\utilities\importtools.py", line 17, in <module>
    from prefect.utilities.filesystem import filename, is_local_path, tmpchdir
  File "C:\Users\jkang1\PycharmProjects\site_analytics\venv\Lib\site-packages\prefect\utilities\filesystem.py", line 5, in <module>
    import resource
ModuleNotFoundError: No module named 'resource'
```


### Versions

```Text
If I try to call it I receive the same error:

(venv) C:\Users\jkang1\PycharmProjects\site_analytics\venv\Scripts>prefect version
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\jkang1\PycharmProjects\site_analytics\venv\Scripts\prefect.exe\__main__.py", line 4, in <module>
  File "C:\Users\jkang1\PycharmProjects\site_analytics\venv\Lib\site-packages\prefect\__init__.py", line 37, in <module>
    from prefect.states import State
  File "C:\Users\jkang1\PycharmProjects\site_analytics\venv\Lib\site-packages\prefect\states.py", line 14, in <module>
    from prefect.client.schemas import State as State
  File "C:\Users\jkang1\PycharmProjects\site_analytics\venv\Lib\site-packages\prefect\client\schemas\__init__.py", line 4, in <module>
    from .actions import BlockTypeUpdate, StateCreate
  File "C:\Users\jkang1\PycharmProjects\site_analytics\venv\Lib\site-packages\prefect\client\schemas\actions.py", line 9, in <module>
    import prefect.client.schemas.objects as objects
  File "C:\Users\jkang1\PycharmProjects\site_analytics\venv\Lib\site-packages\prefect\client\schemas\objects.py", line 20, in <module>
    from prefect._internal.schemas.bases import ObjectBaseModel, PrefectBaseModel
  File "C:\Users\jkang1\PycharmProjects\site_analytics\venv\Lib\site-packages\prefect\_internal\schemas\bases.py", line 18, in <module>
    from prefect._internal.compatibility.experimental import experiment_enabled
  File "C:\Users\jkang1\PycharmProjects\site_analytics\venv\Lib\site-packages\prefect\_internal\compatibility\experimental.py", line 19, in <module>
    from prefect.settings import PREFECT_EXPERIMENTAL_WARN, SETTING_VARIABLES, Setting
  File "C:\Users\jkang1\PycharmProjects\site_analytics\venv\Lib\site-packages\prefect\settings.py", line 70, in <module>
    from prefect._internal.compatibility.deprecated import generate_deprecation_message
  File "C:\Users\jkang1\PycharmProjects\site_analytics\venv\Lib\site-packages\prefect\_internal\compatibility\deprecated.py", line 21, in <module>
    from prefect.utilities.importtools import (
  File "C:\Users\jkang1\PycharmProjects\site_analytics\venv\Lib\site-packages\prefect\utilities\importtools.py", line 17, in <module>
    from prefect.utilities.filesystem import filename, is_local_path, tmpchdir
  File "C:\Users\jkang1\PycharmProjects\site_analytics\venv\Lib\site-packages\prefect\utilities\filesystem.py", line 5, in <module>
    import resource
ModuleNotFoundError: No module named 'resource'

When I downgrade to 2.10.16 and run it:
(venv) C:\Users\jkang1\PycharmProjects\site_analytics\venv\Scripts>prefect version
Version:             2.10.16
API version:         0.8.4
Python version:      3.11.3
Git commit:          6cd7c3ee
Built:               Tue, Jun 20, 2023 2:59 PM
OS/Arch:             win32/AMD64
Profile:             remote-desktop
Server type:         cloud
```


### Additional context

_No response_

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/prefect/utilities/filesystem.py`
Content:
```
1 """
2 Utilities for working with file systems
3 """
4 import os
5 import resource
6 import pathlib
7 from contextlib import contextmanager
8 from pathlib import Path, PureWindowsPath
9 from typing import Union
10 
11 import fsspec
12 import pathspec
13 import prefect
14 from fsspec.core import OpenFile
15 from fsspec.implementations.local import LocalFileSystem
16 
17 
18 def create_default_ignore_file(path: str) -> bool:
19     """
20     Creates default ignore file in the provided path if one does not already exist; returns boolean specifying
21     whether a file was created.
22     """
23     path = pathlib.Path(path)
24     ignore_file = path / ".prefectignore"
25     if ignore_file.exists():
26         return False
27     default_file = pathlib.Path(prefect.__module_path__) / ".prefectignore"
28     with ignore_file.open(mode="w") as f:
29         f.write(default_file.read_text())
30     return True
31 
32 
33 def filter_files(
34     root: str = ".", ignore_patterns: list = None, include_dirs: bool = True
35 ) -> set:
36     """
37     This function accepts a root directory path and a list of file patterns to ignore, and returns
38     a list of files that excludes those that should be ignored.
39 
40     The specification matches that of [.gitignore files](https://git-scm.com/docs/gitignore).
41     """
42     if ignore_patterns is None:
43         ignore_patterns = []
44     spec = pathspec.PathSpec.from_lines("gitwildmatch", ignore_patterns)
45     ignored_files = {p.path for p in spec.match_tree_entries(root)}
46     if include_dirs:
47         all_files = {p.path for p in pathspec.util.iter_tree_entries(root)}
48     else:
49         all_files = set(pathspec.util.iter_tree_files(root))
50     included_files = all_files - ignored_files
51     return included_files
52 
53 
54 @contextmanager
55 def tmpchdir(path: str):
56     """
57     Change current-working directories for the duration of the context
58     """
59     path = os.path.abspath(path)
60     if os.path.isfile(path) or (not os.path.exists(path) and not path.endswith("/")):
61         path = os.path.dirname(path)
62 
63     owd = os.getcwd()
64 
65     try:
66         os.chdir(path)
67         yield path
68     finally:
69         os.chdir(owd)
70 
71 
72 def filename(path: str) -> str:
73     """Extract the file name from a path with remote file system support"""
74     try:
75         of: OpenFile = fsspec.open(path)
76         sep = of.fs.sep
77     except (ImportError, AttributeError):
78         sep = "\\" if "\\" in path else "/"
79     return path.split(sep)[-1]
80 
81 
82 def is_local_path(path: Union[str, pathlib.Path, OpenFile]):
83     """Check if the given path points to a local or remote file system"""
84     if isinstance(path, str):
85         try:
86             of = fsspec.open(path)
87         except ImportError:
88             # The path is a remote file system that uses a lib that is not installed
89             return False
90     elif isinstance(path, pathlib.Path):
91         return True
92     elif isinstance(path, OpenFile):
93         of = path
94     else:
95         raise TypeError(f"Invalid path of type {type(path).__name__!r}")
96 
97     return type(of.fs) == LocalFileSystem
98 
99 
100 def to_display_path(
101     path: Union[pathlib.Path, str], relative_to: Union[pathlib.Path, str] = None
102 ) -> str:
103     """
104     Convert a path to a displayable path. The absolute path or relative path to the
105     current (or given) directory will be returned, whichever is shorter.
106     """
107     path, relative_to = (
108         pathlib.Path(path).resolve(),
109         pathlib.Path(relative_to or ".").resolve(),
110     )
111     relative_path = str(path.relative_to(relative_to))
112     absolute_path = str(path)
113     return relative_path if len(relative_path) < len(absolute_path) else absolute_path
114 
115 
116 def relative_path_to_current_platform(path_str: str) -> Path:
117     """
118     Converts a relative path generated on any platform to a relative path for the
119     current platform.
120     """
121 
122     return Path(PureWindowsPath(path_str).as_posix())
123 
124 
125 def get_open_file_limit():
126     soft_limit, _ = resource.getrlimit(resource.RLIMIT_NOFILE)
127     return soft_limit
128
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/prefect/utilities/filesystem.py b/src/prefect/utilities/filesystem.py
--- a/src/prefect/utilities/filesystem.py
+++ b/src/prefect/utilities/filesystem.py
@@ -2,7 +2,6 @@
 Utilities for working with file systems
 """
 import os
-import resource
 import pathlib
 from contextlib import contextmanager
 from pathlib import Path, PureWindowsPath
@@ -122,6 +121,21 @@
     return Path(PureWindowsPath(path_str).as_posix())
 
 
-def get_open_file_limit():
-    soft_limit, _ = resource.getrlimit(resource.RLIMIT_NOFILE)
-    return soft_limit
+def get_open_file_limit() -> int:
+    """Get the maximum number of open files allowed for the current process"""
+
+    try:
+        if os.name == "nt":
+            import ctypes
+
+            return ctypes.cdll.ucrtbase._getmaxstdio()
+        else:
+            import resource
+
+            soft_limit, _ = resource.getrlimit(resource.RLIMIT_NOFILE)
+            return soft_limit
+    except Exception:
+        # Catch all exceptions, as ctypes can raise several errors
+        # depending on what went wrong. Return a safe default if we
+        # can't get the limit from the OS.
+        return 200

{"golden_diff": "diff --git a/src/prefect/utilities/filesystem.py b/src/prefect/utilities/filesystem.py\n--- a/src/prefect/utilities/filesystem.py\n+++ b/src/prefect/utilities/filesystem.py\n@@ -2,7 +2,6 @@\n Utilities for working with file systems\n \"\"\"\n import os\n-import resource\n import pathlib\n from contextlib import contextmanager\n from pathlib import Path, PureWindowsPath\n@@ -122,6 +121,21 @@\n     return Path(PureWindowsPath(path_str).as_posix())\n \n \n-def get_open_file_limit():\n-    soft_limit, _ = resource.getrlimit(resource.RLIMIT_NOFILE)\n-    return soft_limit\n+def get_open_file_limit() -> int:\n+    \"\"\"Get the maximum number of open files allowed for the current process\"\"\"\n+\n+    try:\n+        if os.name == \"nt\":\n+            import ctypes\n+\n+            return ctypes.cdll.ucrtbase._getmaxstdio()\n+        else:\n+            import resource\n+\n+            soft_limit, _ = resource.getrlimit(resource.RLIMIT_NOFILE)\n+            return soft_limit\n+    except Exception:\n+        # Catch all exceptions, as ctypes can raise several errors\n+        # depending on what went wrong. Return a safe default if we\n+        # can't get the limit from the OS.\n+        return 200\n", "issue": "2.10.17 failure starting prefect agent on a windows machine\n### First check\n\n- [X] I added a descriptive title to this issue.\n- [X] I used the GitHub search to find a similar issue and didn't find it.\n- [X] I searched the Prefect documentation for this issue.\n- [X] I checked that this issue is related to Prefect and not one of its dependencies.\n\n### Bug summary\n\nprefect agent won't start in 2.10.17 but it does in 2.10.16\n\n### Reproduction\n\n```python3\n(venv) C:\\Users\\jkang1\\PycharmProjects\\site_analytics\\venv\\Scripts>prefect agent start --pool default-agent-pool\n```\n\n\n### Error\n\n```python3\nTraceback (most recent call last):\r\n  File \"<frozen runpy>\", line 198, in _run_module_as_main\r\n  File \"<frozen runpy>\", line 88, in _run_code\r\n  File \"C:\\Users\\jkang1\\PycharmProjects\\site_analytics\\venv\\Scripts\\prefect.exe\\__main__.py\", line 4, in <module>\r\n  File \"C:\\Users\\jkang1\\PycharmProjects\\site_analytics\\venv\\Lib\\site-packages\\prefect\\__init__.py\", line 37, in <module>\r\n    from prefect.states import State\r\n  File \"C:\\Users\\jkang1\\PycharmProjects\\site_analytics\\venv\\Lib\\site-packages\\prefect\\states.py\", line 14, in <module>\r\n    from prefect.client.schemas import State as State\r\n  File \"C:\\Users\\jkang1\\PycharmProjects\\site_analytics\\venv\\Lib\\site-packages\\prefect\\client\\schemas\\__init__.py\", line 4, in <module>\r\n    from .actions import BlockTypeUpdate, StateCreate\r\n  File \"C:\\Users\\jkang1\\PycharmProjects\\site_analytics\\venv\\Lib\\site-packages\\prefect\\client\\schemas\\actions.py\", line 9, in <module>\r\n    import prefect.client.schemas.objects as objects\r\n  File \"C:\\Users\\jkang1\\PycharmProjects\\site_analytics\\venv\\Lib\\site-packages\\prefect\\client\\schemas\\objects.py\", line 20, in <module>\r\n    from prefect._internal.schemas.bases import ObjectBaseModel, PrefectBaseModel\r\n  File \"C:\\Users\\jkang1\\PycharmProjects\\site_analytics\\venv\\Lib\\site-packages\\prefect\\_internal\\schemas\\bases.py\", line 18, in <module>\r\n    from prefect._internal.compatibility.experimental import experiment_enabled\r\n  File \"C:\\Users\\jkang1\\PycharmProjects\\site_analytics\\venv\\Lib\\site-packages\\prefect\\_internal\\compatibility\\experimental.py\", line 19, in <module>\r\n    from prefect.settings import PREFECT_EXPERIMENTAL_WARN, SETTING_VARIABLES, Setting\r\n  File \"C:\\Users\\jkang1\\PycharmProjects\\site_analytics\\venv\\Lib\\site-packages\\prefect\\settings.py\", line 70, in <module>\r\n    from prefect._internal.compatibility.deprecated import generate_deprecation_message\r\n  File \"C:\\Users\\jkang1\\PycharmProjects\\site_analytics\\venv\\Lib\\site-packages\\prefect\\_internal\\compatibility\\deprecated.py\", line 21, in <module>\r\n    from prefect.utilities.importtools import (\r\n  File \"C:\\Users\\jkang1\\PycharmProjects\\site_analytics\\venv\\Lib\\site-packages\\prefect\\utilities\\importtools.py\", line 17, in <module>\r\n    from prefect.utilities.filesystem import filename, is_local_path, tmpchdir\r\n  File \"C:\\Users\\jkang1\\PycharmProjects\\site_analytics\\venv\\Lib\\site-packages\\prefect\\utilities\\filesystem.py\", line 5, in <module>\r\n    import resource\r\nModuleNotFoundError: No module named 'resource'\n```\n\n\n### Versions\n\n```Text\nIf I try to call it I receive the same error:\r\n\r\n(venv) C:\\Users\\jkang1\\PycharmProjects\\site_analytics\\venv\\Scripts>prefect version\r\nTraceback (most recent call last):\r\n  File \"<frozen runpy>\", line 198, in _run_module_as_main\r\n  File \"<frozen runpy>\", line 88, in _run_code\r\n  File \"C:\\Users\\jkang1\\PycharmProjects\\site_analytics\\venv\\Scripts\\prefect.exe\\__main__.py\", line 4, in <module>\r\n  File \"C:\\Users\\jkang1\\PycharmProjects\\site_analytics\\venv\\Lib\\site-packages\\prefect\\__init__.py\", line 37, in <module>\r\n    from prefect.states import State\r\n  File \"C:\\Users\\jkang1\\PycharmProjects\\site_analytics\\venv\\Lib\\site-packages\\prefect\\states.py\", line 14, in <module>\r\n    from prefect.client.schemas import State as State\r\n  File \"C:\\Users\\jkang1\\PycharmProjects\\site_analytics\\venv\\Lib\\site-packages\\prefect\\client\\schemas\\__init__.py\", line 4, in <module>\r\n    from .actions import BlockTypeUpdate, StateCreate\r\n  File \"C:\\Users\\jkang1\\PycharmProjects\\site_analytics\\venv\\Lib\\site-packages\\prefect\\client\\schemas\\actions.py\", line 9, in <module>\r\n    import prefect.client.schemas.objects as objects\r\n  File \"C:\\Users\\jkang1\\PycharmProjects\\site_analytics\\venv\\Lib\\site-packages\\prefect\\client\\schemas\\objects.py\", line 20, in <module>\r\n    from prefect._internal.schemas.bases import ObjectBaseModel, PrefectBaseModel\r\n  File \"C:\\Users\\jkang1\\PycharmProjects\\site_analytics\\venv\\Lib\\site-packages\\prefect\\_internal\\schemas\\bases.py\", line 18, in <module>\r\n    from prefect._internal.compatibility.experimental import experiment_enabled\r\n  File \"C:\\Users\\jkang1\\PycharmProjects\\site_analytics\\venv\\Lib\\site-packages\\prefect\\_internal\\compatibility\\experimental.py\", line 19, in <module>\r\n    from prefect.settings import PREFECT_EXPERIMENTAL_WARN, SETTING_VARIABLES, Setting\r\n  File \"C:\\Users\\jkang1\\PycharmProjects\\site_analytics\\venv\\Lib\\site-packages\\prefect\\settings.py\", line 70, in <module>\r\n    from prefect._internal.compatibility.deprecated import generate_deprecation_message\r\n  File \"C:\\Users\\jkang1\\PycharmProjects\\site_analytics\\venv\\Lib\\site-packages\\prefect\\_internal\\compatibility\\deprecated.py\", line 21, in <module>\r\n    from prefect.utilities.importtools import (\r\n  File \"C:\\Users\\jkang1\\PycharmProjects\\site_analytics\\venv\\Lib\\site-packages\\prefect\\utilities\\importtools.py\", line 17, in <module>\r\n    from prefect.utilities.filesystem import filename, is_local_path, tmpchdir\r\n  File \"C:\\Users\\jkang1\\PycharmProjects\\site_analytics\\venv\\Lib\\site-packages\\prefect\\utilities\\filesystem.py\", line 5, in <module>\r\n    import resource\r\nModuleNotFoundError: No module named 'resource'\r\n\r\nWhen I downgrade to 2.10.16 and run it:\r\n(venv) C:\\Users\\jkang1\\PycharmProjects\\site_analytics\\venv\\Scripts>prefect version\r\nVersion:             2.10.16\r\nAPI version:         0.8.4\r\nPython version:      3.11.3\r\nGit commit:          6cd7c3ee\r\nBuilt:               Tue, Jun 20, 2023 2:59 PM\r\nOS/Arch:             win32/AMD64\r\nProfile:             remote-desktop\r\nServer type:         cloud\n```\n\n\n### Additional context\n\n_No response_\n", "before_files": [{"content": "\"\"\"\nUtilities for working with file systems\n\"\"\"\nimport os\nimport resource\nimport pathlib\nfrom contextlib import contextmanager\nfrom pathlib import Path, PureWindowsPath\nfrom typing import Union\n\nimport fsspec\nimport pathspec\nimport prefect\nfrom fsspec.core import OpenFile\nfrom fsspec.implementations.local import LocalFileSystem\n\n\ndef create_default_ignore_file(path: str) -> bool:\n    \"\"\"\n    Creates default ignore file in the provided path if one does not already exist; returns boolean specifying\n    whether a file was created.\n    \"\"\"\n    path = pathlib.Path(path)\n    ignore_file = path / \".prefectignore\"\n    if ignore_file.exists():\n        return False\n    default_file = pathlib.Path(prefect.__module_path__) / \".prefectignore\"\n    with ignore_file.open(mode=\"w\") as f:\n        f.write(default_file.read_text())\n    return True\n\n\ndef filter_files(\n    root: str = \".\", ignore_patterns: list = None, include_dirs: bool = True\n) -> set:\n    \"\"\"\n    This function accepts a root directory path and a list of file patterns to ignore, and returns\n    a list of files that excludes those that should be ignored.\n\n    The specification matches that of [.gitignore files](https://git-scm.com/docs/gitignore).\n    \"\"\"\n    if ignore_patterns is None:\n        ignore_patterns = []\n    spec = pathspec.PathSpec.from_lines(\"gitwildmatch\", ignore_patterns)\n    ignored_files = {p.path for p in spec.match_tree_entries(root)}\n    if include_dirs:\n        all_files = {p.path for p in pathspec.util.iter_tree_entries(root)}\n    else:\n        all_files = set(pathspec.util.iter_tree_files(root))\n    included_files = all_files - ignored_files\n    return included_files\n\n\n@contextmanager\ndef tmpchdir(path: str):\n    \"\"\"\n    Change current-working directories for the duration of the context\n    \"\"\"\n    path = os.path.abspath(path)\n    if os.path.isfile(path) or (not os.path.exists(path) and not path.endswith(\"/\")):\n        path = os.path.dirname(path)\n\n    owd = os.getcwd()\n\n    try:\n        os.chdir(path)\n        yield path\n    finally:\n        os.chdir(owd)\n\n\ndef filename(path: str) -> str:\n    \"\"\"Extract the file name from a path with remote file system support\"\"\"\n    try:\n        of: OpenFile = fsspec.open(path)\n        sep = of.fs.sep\n    except (ImportError, AttributeError):\n        sep = \"\\\\\" if \"\\\\\" in path else \"/\"\n    return path.split(sep)[-1]\n\n\ndef is_local_path(path: Union[str, pathlib.Path, OpenFile]):\n    \"\"\"Check if the given path points to a local or remote file system\"\"\"\n    if isinstance(path, str):\n        try:\n            of = fsspec.open(path)\n        except ImportError:\n            # The path is a remote file system that uses a lib that is not installed\n            return False\n    elif isinstance(path, pathlib.Path):\n        return True\n    elif isinstance(path, OpenFile):\n        of = path\n    else:\n        raise TypeError(f\"Invalid path of type {type(path).__name__!r}\")\n\n    return type(of.fs) == LocalFileSystem\n\n\ndef to_display_path(\n    path: Union[pathlib.Path, str], relative_to: Union[pathlib.Path, str] = None\n) -> str:\n    \"\"\"\n    Convert a path to a displayable path. The absolute path or relative path to the\n    current (or given) directory will be returned, whichever is shorter.\n    \"\"\"\n    path, relative_to = (\n        pathlib.Path(path).resolve(),\n        pathlib.Path(relative_to or \".\").resolve(),\n    )\n    relative_path = str(path.relative_to(relative_to))\n    absolute_path = str(path)\n    return relative_path if len(relative_path) < len(absolute_path) else absolute_path\n\n\ndef relative_path_to_current_platform(path_str: str) -> Path:\n    \"\"\"\n    Converts a relative path generated on any platform to a relative path for the\n    current platform.\n    \"\"\"\n\n    return Path(PureWindowsPath(path_str).as_posix())\n\n\ndef get_open_file_limit():\n    soft_limit, _ = resource.getrlimit(resource.RLIMIT_NOFILE)\n    return soft_limit\n", "path": "src/prefect/utilities/filesystem.py"}], "after_files": [{"content": "\"\"\"\nUtilities for working with file systems\n\"\"\"\nimport os\nimport pathlib\nfrom contextlib import contextmanager\nfrom pathlib import Path, PureWindowsPath\nfrom typing import Union\n\nimport fsspec\nimport pathspec\nimport prefect\nfrom fsspec.core import OpenFile\nfrom fsspec.implementations.local import LocalFileSystem\n\n\ndef create_default_ignore_file(path: str) -> bool:\n    \"\"\"\n    Creates default ignore file in the provided path if one does not already exist; returns boolean specifying\n    whether a file was created.\n    \"\"\"\n    path = pathlib.Path(path)\n    ignore_file = path / \".prefectignore\"\n    if ignore_file.exists():\n        return False\n    default_file = pathlib.Path(prefect.__module_path__) / \".prefectignore\"\n    with ignore_file.open(mode=\"w\") as f:\n        f.write(default_file.read_text())\n    return True\n\n\ndef filter_files(\n    root: str = \".\", ignore_patterns: list = None, include_dirs: bool = True\n) -> set:\n    \"\"\"\n    This function accepts a root directory path and a list of file patterns to ignore, and returns\n    a list of files that excludes those that should be ignored.\n\n    The specification matches that of [.gitignore files](https://git-scm.com/docs/gitignore).\n    \"\"\"\n    if ignore_patterns is None:\n        ignore_patterns = []\n    spec = pathspec.PathSpec.from_lines(\"gitwildmatch\", ignore_patterns)\n    ignored_files = {p.path for p in spec.match_tree_entries(root)}\n    if include_dirs:\n        all_files = {p.path for p in pathspec.util.iter_tree_entries(root)}\n    else:\n        all_files = set(pathspec.util.iter_tree_files(root))\n    included_files = all_files - ignored_files\n    return included_files\n\n\n@contextmanager\ndef tmpchdir(path: str):\n    \"\"\"\n    Change current-working directories for the duration of the context\n    \"\"\"\n    path = os.path.abspath(path)\n    if os.path.isfile(path) or (not os.path.exists(path) and not path.endswith(\"/\")):\n        path = os.path.dirname(path)\n\n    owd = os.getcwd()\n\n    try:\n        os.chdir(path)\n        yield path\n    finally:\n        os.chdir(owd)\n\n\ndef filename(path: str) -> str:\n    \"\"\"Extract the file name from a path with remote file system support\"\"\"\n    try:\n        of: OpenFile = fsspec.open(path)\n        sep = of.fs.sep\n    except (ImportError, AttributeError):\n        sep = \"\\\\\" if \"\\\\\" in path else \"/\"\n    return path.split(sep)[-1]\n\n\ndef is_local_path(path: Union[str, pathlib.Path, OpenFile]):\n    \"\"\"Check if the given path points to a local or remote file system\"\"\"\n    if isinstance(path, str):\n        try:\n            of = fsspec.open(path)\n        except ImportError:\n            # The path is a remote file system that uses a lib that is not installed\n            return False\n    elif isinstance(path, pathlib.Path):\n        return True\n    elif isinstance(path, OpenFile):\n        of = path\n    else:\n        raise TypeError(f\"Invalid path of type {type(path).__name__!r}\")\n\n    return type(of.fs) == LocalFileSystem\n\n\ndef to_display_path(\n    path: Union[pathlib.Path, str], relative_to: Union[pathlib.Path, str] = None\n) -> str:\n    \"\"\"\n    Convert a path to a displayable path. The absolute path or relative path to the\n    current (or given) directory will be returned, whichever is shorter.\n    \"\"\"\n    path, relative_to = (\n        pathlib.Path(path).resolve(),\n        pathlib.Path(relative_to or \".\").resolve(),\n    )\n    relative_path = str(path.relative_to(relative_to))\n    absolute_path = str(path)\n    return relative_path if len(relative_path) < len(absolute_path) else absolute_path\n\n\ndef relative_path_to_current_platform(path_str: str) -> Path:\n    \"\"\"\n    Converts a relative path generated on any platform to a relative path for the\n    current platform.\n    \"\"\"\n\n    return Path(PureWindowsPath(path_str).as_posix())\n\n\ndef get_open_file_limit() -> int:\n    \"\"\"Get the maximum number of open files allowed for the current process\"\"\"\n\n    try:\n        if os.name == \"nt\":\n            import ctypes\n\n            return ctypes.cdll.ucrtbase._getmaxstdio()\n        else:\n            import resource\n\n            soft_limit, _ = resource.getrlimit(resource.RLIMIT_NOFILE)\n            return soft_limit\n    except Exception:\n        # Catch all exceptions, as ctypes can raise several errors\n        # depending on what went wrong. Return a safe default if we\n        # can't get the limit from the OS.\n        return 200\n", "path": "src/prefect/utilities/filesystem.py"}]}