|
2 | 2 |
|
3 | 3 | from ctypes import c_void_p, cdll
|
4 | 4 | from enum import IntEnum
|
5 |
| -from os import path |
| 5 | +from os import PathLike, fspath, path |
6 | 6 | from platform import system
|
7 | 7 | from tempfile import TemporaryDirectory
|
8 | 8 | from typing import List, Optional, Union
|
@@ -120,24 +120,24 @@ def build_library(output_path: str, repo_paths: List[str]) -> bool:
|
120 | 120 | )
|
121 | 121 | return True
|
122 | 122 |
|
123 |
| - def __init__(self, path_or_ptr: Union[str, int], name: str): |
| 123 | + def __init__(self, path_or_ptr: Union[PathLike, str, int], name: str): |
124 | 124 | """
|
125 | 125 | Load the language with the given language pointer from the dynamic library,
|
126 | 126 | or load the language with the given name from the dynamic library at the
|
127 | 127 | given path.
|
128 | 128 | """
|
129 |
| - if isinstance(path_or_ptr, str): |
| 129 | + if isinstance(path_or_ptr, (str, PathLike)): |
130 | 130 | _deprecate("Language(path, name)", "Language(ptr, name)")
|
131 | 131 | self.name = name
|
132 |
| - self.lib = cdll.LoadLibrary(path_or_ptr) |
| 132 | + self.lib = cdll.LoadLibrary(fspath(path_or_ptr)) |
133 | 133 | language_function = getattr(self.lib, "tree_sitter_%s" % name)
|
134 | 134 | language_function.restype = c_void_p
|
135 | 135 | self.language_id = language_function()
|
136 | 136 | elif isinstance(path_or_ptr, int):
|
137 | 137 | self.name = name
|
138 | 138 | self.language_id = path_or_ptr
|
139 | 139 | else:
|
140 |
| - raise TypeError("Expected a string or int for the first argument") |
| 140 | + raise TypeError("Expected a path or pointer for the first argument") |
141 | 141 |
|
142 | 142 | @property
|
143 | 143 | def version(self) -> int:
|
|
0 commit comments