Skip to content

Commit

Permalink
[internal] Use fast_relpath_optional for source root calculation in…
Browse files Browse the repository at this point in the history
… `local_dists`. (#13091)

This usage of `os.path.relpath` was showing up in profiles: it's a notoriously expensive function due to its support for relativizing non-contained paths, and use of `os.getcwd` (which releases the GIL to execute a syscall, and then needs to re-acquire it).

Switch to `fast_relpath_optional`.

[ci skip-rust]
[ci skip-build-wheels]
  • Loading branch information
stuhood authored Oct 3, 2021
1 parent 724615b commit 6f3e6eb
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/python/pants/backend/python/util_rules/local_dists.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from __future__ import annotations

import logging
import os
import zipfile
from dataclasses import dataclass
from io import BytesIO
Expand All @@ -30,6 +29,7 @@
)
from pants.engine.rules import Get, MultiGet, collect_rules, rule
from pants.engine.target import TransitiveTargets, TransitiveTargetsRequest
from pants.util.dirutil import fast_relpath_optional
from pants.util.docutil import doc_url
from pants.util.meta import frozen_after_init

Expand Down Expand Up @@ -150,10 +150,8 @@ async def build_local_dists(
for source in request.sources.source_files.files:
if source not in unrooted_files_set:
for source_root in source_roots:
if (
source.startswith(source_root)
and os.path.relpath(source, source_root) in provided_files
):
source_relpath = fast_relpath_optional(source, source_root)
if source_relpath is not None and source_relpath in provided_files:
remaining_sources.remove(source)
remaining_sources_snapshot = await Get(
Snapshot,
Expand Down

0 comments on commit 6f3e6eb

Please sign in to comment.