• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pantsbuild / pants / 19015773527

02 Nov 2025 05:33PM UTC coverage: 17.872% (-62.4%) from 80.3%
19015773527

Pull #22816

github

web-flow
Merge a12d75757 into 6c024e162
Pull Request #22816: Update Pants internal Python to 3.14

4 of 5 new or added lines in 3 files covered. (80.0%)

28452 existing lines in 683 files now uncovered.

9831 of 55007 relevant lines covered (17.87%)

0.18 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/python/pants/backend/openapi/codegen/python/package_mapper.py
1
# Copyright 2024 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
UNCOV
3
from __future__ import annotations
×
4

UNCOV
5
import logging
×
UNCOV
6
from collections import defaultdict
×
UNCOV
7
from pathlib import PurePath
×
UNCOV
8
from typing import DefaultDict
×
9

UNCOV
10
from pants.backend.openapi.codegen.python.generate import (
×
11
    GeneratePythonFromOpenAPIRequest,
12
    generate_python_from_openapi,
13
)
UNCOV
14
from pants.backend.openapi.target_types import AllOpenApiDocumentTargets, OpenApiDocumentField
×
UNCOV
15
from pants.backend.python.dependency_inference.module_mapper import (
×
16
    FirstPartyPythonMappingImpl,
17
    FirstPartyPythonMappingImplMarker,
18
    ModuleProvider,
19
    ModuleProviderType,
20
    ResolveName,
21
    module_from_stripped_path,
22
)
UNCOV
23
from pants.backend.python.subsystems.setup import PythonSetup
×
UNCOV
24
from pants.backend.python.target_types import PythonResolveField
×
UNCOV
25
from pants.core.util_rules.stripped_source_files import StrippedFileNameRequest, strip_file_name
×
UNCOV
26
from pants.engine.internals.graph import hydrate_sources
×
UNCOV
27
from pants.engine.internals.selectors import concurrently
×
UNCOV
28
from pants.engine.rules import collect_rules, implicitly, rule
×
UNCOV
29
from pants.engine.target import HydrateSourcesRequest
×
UNCOV
30
from pants.engine.unions import UnionRule
×
31

UNCOV
32
logger = logging.getLogger(__name__)
×
33

34

UNCOV
35
class PythonOpenApiMappingMarker(FirstPartyPythonMappingImplMarker):
×
UNCOV
36
    pass
×
37

38

UNCOV
39
@rule
×
UNCOV
40
async def map_openapi_documents_to_python_modules(
×
41
    all_openapi_document_targets: AllOpenApiDocumentTargets,
42
    python_setup: PythonSetup,
43
    _: PythonOpenApiMappingMarker,
44
) -> FirstPartyPythonMappingImpl:
45
    hydrated_sources = await concurrently(
×
46
        hydrate_sources(HydrateSourcesRequest(target[OpenApiDocumentField]), **implicitly())
47
        for target in all_openapi_document_targets
48
    )
49
    generated_sources = await concurrently(
×
50
        generate_python_from_openapi(GeneratePythonFromOpenAPIRequest(sources.snapshot, target))
51
        for (target, sources) in zip(all_openapi_document_targets, hydrated_sources)
52
    )
53
    stripped_file_per_target_sources = await concurrently(
×
54
        concurrently(
55
            strip_file_name(StrippedFileNameRequest(file)) for file in sources.snapshot.files
56
        )
57
        for sources in generated_sources
58
    )
59

60
    resolves_to_modules_to_providers: DefaultDict[
×
61
        ResolveName, DefaultDict[str, list[ModuleProvider]]
62
    ] = defaultdict(lambda: defaultdict(list))
63

64
    for target, files in zip(all_openapi_document_targets, stripped_file_per_target_sources):
×
65
        resolve_name = target[PythonResolveField].normalized_value(python_setup)
×
66
        provider = ModuleProvider(target.address, ModuleProviderType.IMPL)
×
67
        for stripped_file in files:
×
68
            stripped_f = PurePath(stripped_file.value)
×
69
            module = module_from_stripped_path(stripped_f)
×
70
            resolves_to_modules_to_providers[resolve_name][module].append(provider)
×
71

72
    return FirstPartyPythonMappingImpl.create(resolves_to_modules_to_providers)
×
73

74

UNCOV
75
def rules():
×
UNCOV
76
    return [
×
77
        *collect_rules(),
78
        UnionRule(FirstPartyPythonMappingImplMarker, PythonOpenApiMappingMarker),
79
    ]
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc