Skip to content

Commit 85c3dc1

Browse files
committed
feat: do not use pathlib.Path.resolve because it is slow and we don't need to resolve links
1 parent d08453f commit 85c3dc1

File tree

7 files changed

+35
-32
lines changed

7 files changed

+35
-32
lines changed

packages/core/src/robotcode/core/uri.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,6 @@ def __iter__(self) -> Iterator[str]:
181181

182182
def normalized(self) -> Uri:
183183
if self.scheme == "file":
184-
return Uri.from_path(self.to_path().resolve())
184+
return Uri.from_path(self.to_path().absolute())
185185

186186
return Uri(str(self))

packages/debugger/src/robotcode/debugger/listeners.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ def log_message(self, message: Dict[str, Any]) -> None:
142142
item_id = next(
143143
(
144144
(
145-
f"{Path(item.source).resolve() if item.source is not None else ''};{item.longname}"
145+
f"{Path(item.source).absolute() if item.source is not None else ''};{item.longname}"
146146
if item.type == "SUITE"
147-
else f"{Path(item.source).resolve() if item.source is not None else ''};"
147+
else f"{Path(item.source).absolute() if item.source is not None else ''};"
148148
f"{item.longname};{item.line}"
149149
)
150150
for item in Debugger.instance().full_stack_frames
@@ -189,9 +189,9 @@ def message(self, message: Dict[str, Any]) -> None:
189189
item_id = next(
190190
(
191191
(
192-
f"{Path(item.source).resolve() if item.source is not None else ''};{item.longname}"
192+
f"{Path(item.source).absolute() if item.source is not None else ''};{item.longname}"
193193
if item.type == "SUITE"
194-
else f"{Path(item.source).resolve() if item.source is not None else ''};"
194+
else f"{Path(item.source).absolute() if item.source is not None else ''};"
195195
f"{item.longname};{item.line}"
196196
)
197197
for item in Debugger.instance().full_stack_frames
@@ -264,15 +264,15 @@ def start_suite(self, data: running.TestSuite, result: result.TestSuite) -> None
264264

265265
def enqueue(item: Union[running.TestSuite, running.TestCase]) -> Iterator[str]:
266266
if isinstance(item, running.TestSuite):
267-
yield f"{Path(item.source).resolve() if item.source is not None else ''};{item.longname}"
267+
yield f"{Path(item.source).absolute() if item.source is not None else ''};{item.longname}"
268268

269269
for s in item.suites:
270270
yield from enqueue(s)
271271
for s in item.tests:
272272
yield from enqueue(s)
273273
return
274274

275-
yield f"{Path(item.source).resolve() if item.source is not None else ''};{item.longname};{item.lineno}"
275+
yield f"{Path(item.source).absolute() if item.source is not None else ''};{item.longname};{item.lineno}"
276276

277277
if self._event_sended:
278278
return

packages/language_server/src/robotcode/language_server/robotframework/diagnostics/imports_manager.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ async def check_file_changed(self, changes: List[FileEvent]) -> Optional[FileCha
315315
path = uri.to_path()
316316
if (
317317
self._document is not None
318-
and (path.resolve() == self._document.uri.to_path().resolve())
318+
and (path.absolute() == self._document.uri.to_path().absolute())
319319
or self._document is None
320320
):
321321
await self._invalidate()
@@ -426,7 +426,7 @@ async def check_file_changed(self, changes: List[FileEvent]) -> Optional[FileCha
426426
if (
427427
self._lib_doc.source
428428
and path.exists()
429-
and path.resolve().samefile(Path(self._lib_doc.source).resolve())
429+
and path.absolute().samefile(Path(self._lib_doc.source).absolute())
430430
):
431431
await self._invalidate()
432432

@@ -857,14 +857,14 @@ async def get_library_meta(
857857
return None, import_name
858858

859859
if result.origin is not None:
860-
result.mtimes = {result.origin: Path(result.origin).resolve().stat().st_mtime_ns}
860+
result.mtimes = {result.origin: Path(result.origin).absolute().stat().st_mtime_ns}
861861

862862
if result.submodule_search_locations:
863863
if result.mtimes is None:
864864
result.mtimes = {}
865865
result.mtimes.update(
866866
{
867-
str(f): f.resolve().stat().st_mtime_ns
867+
str(f): f.absolute().stat().st_mtime_ns
868868
for f in itertools.chain(
869869
*(iter_files(loc, "**/*.py") for loc in result.submodule_search_locations)
870870
)
@@ -925,14 +925,14 @@ async def get_variables_meta(
925925
return None, import_name
926926

927927
if result.origin is not None:
928-
result.mtimes = {result.origin: Path(result.origin).resolve().stat().st_mtime_ns}
928+
result.mtimes = {result.origin: Path(result.origin).absolute().stat().st_mtime_ns}
929929

930930
if result.submodule_search_locations:
931931
if result.mtimes is None:
932932
result.mtimes = {}
933933
result.mtimes.update(
934934
{
935-
str(f): f.resolve().stat().st_mtime_ns
935+
str(f): f.absolute().stat().st_mtime_ns
936936
for f in itertools.chain(
937937
*(iter_files(loc, "**/*.py") for loc in result.submodule_search_locations)
938938
)
@@ -1307,7 +1307,7 @@ async def _get_entry_for_resource_import(
13071307
async def _get_document() -> TextDocument:
13081308
self._logger.debug(lambda: f"Load resource {name} from source {source}")
13091309

1310-
source_path = Path(source).resolve()
1310+
source_path = Path(source).absolute()
13111311
extension = source_path.suffix
13121312
if extension.lower() not in RESOURCE_EXTENSIONS:
13131313
raise ImportError(

packages/language_server/src/robotcode/language_server/robotframework/diagnostics/library_doc.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,9 +2200,9 @@ def complete_library_import(
22002200
if name is None or (is_file_like(name) and (name.endswith(("/", os.sep)))):
22012201
name_path = Path(name if name else base_dir)
22022202
if name_path.is_absolute():
2203-
path = name_path.resolve()
2203+
path = name_path.absolute()
22042204
else:
2205-
path = Path(base_dir, name if name else base_dir).resolve()
2205+
path = Path(base_dir, name if name else base_dir).absolute()
22062206

22072207
if path.exists() and path.is_dir():
22082208
result += [
@@ -2263,9 +2263,9 @@ def complete_resource_import(
22632263
if name is None or name.startswith((".", "/", os.sep)):
22642264
name_path = Path(name if name else base_dir)
22652265
if name_path.is_absolute():
2266-
path = name_path.resolve()
2266+
path = name_path.absolute()
22672267
else:
2268-
path = Path(base_dir, name if name else base_dir).resolve()
2268+
path = Path(base_dir, name if name else base_dir).absolute()
22692269

22702270
if path.exists() and (path.is_dir()):
22712271
result += [
@@ -2359,9 +2359,9 @@ def complete_variables_import(
23592359
if name is None or name.startswith((".", "/", os.sep)):
23602360
name_path = Path(name if name else base_dir)
23612361
if name_path.is_absolute():
2362-
path = name_path.resolve()
2362+
path = name_path.absolute()
23632363
else:
2364-
path = Path(base_dir, name if name else base_dir).resolve()
2364+
path = Path(base_dir, name if name else base_dir).absolute()
23652365

23662366
if path.exists() and (path.is_dir()):
23672367
result += [

packages/robot/src/robotcode/robot/config/loader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ def load_robot_config_from_path(*__paths: Union[Path, Tuple[Path, ConfigType]])
128128

129129
def find_project_root(*sources: Union[str, Path]) -> Tuple[Optional[Path], DiscoverdBy]:
130130
if not sources:
131-
sources = (str(Path.cwd().resolve()),)
131+
sources = (str(Path.cwd().absolute()),)
132132

133-
path_srcs = [Path(Path.cwd(), src).resolve() for src in sources]
133+
path_srcs = [Path(Path.cwd(), src).absolute() for src in sources]
134134

135135
src_parents = [list(path.parents) + ([path] if path.is_dir() else []) for path in path_srcs]
136136

packages/runner/src/robotcode/runner/cli/discover/discover.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,13 @@ def get_rel_source(source: Optional[str]) -> Optional[str]:
224224
class Collector(SuiteVisitor):
225225
def __init__(self) -> None:
226226
super().__init__()
227+
absolute_path = Path.cwd()
227228
self.all: TestItem = TestItem(
228229
type="workspace",
229-
id=str(Path.cwd().resolve()),
230-
name=Path.cwd().name,
231-
longname=Path.cwd().name,
232-
uri=str(Uri.from_path(Path.cwd())),
230+
id=str(absolute_path),
231+
name=absolute_path.name,
232+
longname=absolute_path.name,
233+
uri=str(Uri.from_path(absolute_path)),
233234
needs_parse_include=get_robot_version() >= (6, 1),
234235
)
235236
self._current = self.all
@@ -255,12 +256,13 @@ def visit_suite(self, suite: TestSuite) -> None:
255256
self._collected[-1][suite.name] = True
256257
self._collected.append(NormalizedDict(ignore="_"))
257258
try:
259+
absolute_path = Path(suite.source).absolute() if suite.source else None
258260
item = TestItem(
259261
type="suite",
260-
id=f"{Path(suite.source).resolve() if suite.source is not None else ''};{suite.longname}",
262+
id=f"{absolute_path or ''};{suite.longname}",
261263
name=suite.name,
262264
longname=suite.longname,
263-
uri=str(Uri.from_path(Path(suite.source).resolve())) if suite.source else None,
265+
uri=str(Uri.from_path(absolute_path)) if absolute_path else None,
264266
source=str(suite.source),
265267
rel_source=get_rel_source(suite.source),
266268
range=Range(
@@ -307,12 +309,13 @@ def visit_test(self, test: TestCase) -> None:
307309
if self._current.children is None:
308310
self._current.children = []
309311
try:
312+
absolute_path = Path(test.source).absolute() if test.source is not None else None
310313
item = TestItem(
311314
type="test",
312-
id=f"{Path(test.source).resolve() if test.source is not None else ''};{test.longname};{test.lineno}",
315+
id=f"{absolute_path or ''};{test.longname};{test.lineno}",
313316
name=test.name,
314317
longname=test.longname,
315-
uri=str(Uri.from_path(Path(test.source).resolve())) if test.source else None,
318+
uri=str(Uri.from_path(absolute_path)) if absolute_path else None,
316319
source=str(test.source),
317320
rel_source=get_rel_source(test.source),
318321
range=Range(
@@ -383,7 +386,7 @@ def add_diagnostic(
383386
line: Optional[int] = None,
384387
text: Optional[str] = None,
385388
) -> None:
386-
source_uri = str(Uri.from_path(Path(source_uri).resolve() if source_uri else Path.cwd()))
389+
source_uri = str(Uri.from_path(Path(source_uri).absolute() if source_uri else Path.cwd()))
387390

388391
if source_uri not in result:
389392
result[source_uri] = []

tests/robotcode/language_server/robotframework/parts/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
@pytest_asyncio.fixture(scope="package", ids=generate_test_id)
3434
async def protocol(request: Any) -> AsyncIterator[RobotLanguageServerProtocol]:
35-
root_path = Path(Path(__file__).resolve().parent, "data")
35+
root_path = Path(Path(__file__).absolute().parent, "data")
3636
robotcode_cache_path = root_path / ".robotcode_cache"
3737

3838
if robotcode_cache_path.exists():

0 commit comments

Comments
 (0)