Skip to content

Commit

Permalink
Debugging...
Browse files Browse the repository at this point in the history
  • Loading branch information
grihabor committed Sep 30, 2024
1 parent 6c72255 commit 19b26d0
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -369,4 +369,4 @@ def main():
]
result = run_pants(args, use_pantsd=False)

assert "No such file or directory" not in result.stderr
assert "No such file or directory" not in result.stderr, result.stderr
5 changes: 5 additions & 0 deletions src/python/pants/backend/python/util_rules/python_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from dataclasses import dataclass
from typing import Iterable
import sys

from pants.backend.python.target_types import PythonSourceField
from pants.backend.python.util_rules import ancestor_files
Expand Down Expand Up @@ -134,6 +135,7 @@ async def prepare_python_sources(
)
for tgt in codegen_targets
)
sys.stderr.write(f"{codegen_sources=}\n")
source_root_requests = [
*(SourceRootRequest.for_target(tgt) for tgt in python_and_resources_targets),
*(
Expand All @@ -142,11 +144,14 @@ async def prepare_python_sources(
for f in sources.snapshot.files
),
]
sys.stderr.write(f"{source_root_requests=}\n")

source_root_objs = await MultiGet(
Get(SourceRoot, SourceRootRequest, req) for req in source_root_requests
)
source_root_paths = {source_root_obj.path for source_root_obj in source_root_objs}
sys.stderr.write(f"{sources.unrooted_files=}\n")
sys.stderr.write(f"{init_injected=}\n")
return PythonSourceFiles(
SourceFiles(init_injected, sources.unrooted_files), tuple(sorted(source_root_paths))
)
Expand Down
7 changes: 6 additions & 1 deletion src/python/pants/core/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
These are always activated and cannot be disabled.
"""

from pants.backend.codegen import export_codegen_goal
from pants.build_graph.build_file_aliases import BuildFileAliases
from pants.core.goals import (
Expand Down Expand Up @@ -63,7 +64,11 @@
from pants.vcs import git
from pants.version import PANTS_SEMVER

wrap_as_resources = wrap_source_rule_and_target(ResourceSourceField, "resources")
wrap_as_resources = wrap_source_rule_and_target(
ResourceSourceField,
"resources",
uses_source_roots=True,
)


def rules():
Expand Down
3 changes: 3 additions & 0 deletions src/python/pants/core/util_rules/source_files.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright 2020 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

import sys
from dataclasses import dataclass
from pathlib import PurePath
from typing import Collection, Iterable, Set, Tuple, Type, Union
Expand Down Expand Up @@ -60,6 +61,8 @@ async def determine_source_files(request: SourceFilesRequest) -> SourceFiles:
)

for hydrated_sources, sources_field in zip(all_hydrated_sources, request.sources_fields):
sys.stderr.write(f"{type(sources_field)=}\n")
sys.stderr.write(f"{sources_field.uses_source_roots=}\n")
if not sources_field.uses_source_roots:
unrooted_files.update(hydrated_sources.snapshot.files)

Expand Down
10 changes: 9 additions & 1 deletion src/python/pants/core/util_rules/wrap_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ class ActivateWrapSourceTargetFieldBase(MultipleSourcesField):
uses_source_roots = False
expected_num_files = 0

class ActivateWrapSourceTargetFieldBase(MultipleSourcesField):
# We solely register so that codegen can match a fieldset.
# One unique subclass must be defined per target type.
alias = "_sources"
uses_source_roots = False
expected_num_files = 0

class WrapSourceInputsField(SpecialCasedDependencies):
alias = "inputs"
Expand Down Expand Up @@ -99,7 +105,9 @@ async def _wrap_source(wrapper: GenerateSourcesRequest) -> GeneratedSources:


def wrap_source_rule_and_target(
source_field_type: type[SourcesField], target_name_suffix: str
source_field_type: type[SourcesField],
target_name_suffix: str,
uses_source_roots: bool = False,
) -> WrapSource:
if source_field_type.expected_file_extensions:
outputs_help = (
Expand Down

0 comments on commit 19b26d0

Please sign in to comment.