• 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

33.33
/src/python/pants/util/cstutil.py
1
# Copyright 2024 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

4
from __future__ import annotations
1✔
5

6
import importlib.util
1✔
7
import logging
1✔
8

9
import libcst as cst
1✔
10
import libcst.matchers as m
1✔
11

12
logger = logging.getLogger(__name__)
1✔
13

14

15
def make_importfrom(module: str, func: str) -> cst.ImportFrom:
1✔
16
    """Generates a cst.ImportFrom from a module and function string."""
UNCOV
17
    return cst.ImportFrom(
×
18
        module=make_importfrom_attr(module), names=[cst.ImportAlias(cst.Name(func))]
19
    )
20

21

22
def make_importfrom_attr(module: str) -> cst.Attribute | cst.Name:
1✔
23
    """Generates a cst.Attribute or cst.Name from a module string."""
UNCOV
24
    parts = module.split(".")
×
UNCOV
25
    if len(parts) == 1:
×
UNCOV
26
        return cst.Name(parts[0])
×
27

UNCOV
28
    partial_module = ".".join(parts[:-1])
×
UNCOV
29
    return cst.Attribute(value=make_importfrom_attr(partial_module), attr=cst.Name(parts[-1]))
×
30

31

32
def make_importfrom_attr_matcher(module: str) -> m.Attribute | m.Name:
1✔
33
    """Generates a cst matcher.Attribute or matcher.Name from a module string."""
UNCOV
34
    parts = module.split(".")
×
UNCOV
35
    if len(parts) == 1:
×
UNCOV
36
        return m.Name(parts[0])
×
37

UNCOV
38
    partial_module = ".".join(parts[:-1])
×
UNCOV
39
    return m.Attribute(value=make_importfrom_attr_matcher(partial_module), attr=m.Name(parts[-1]))
×
40

41

42
def extract_functiondef_from_module(module: str, func: str) -> cst.FunctionDef | None:
1✔
43
    """Parse the file associated with the module return `func` as a FunctionDef."""
44
    if not (spec := importlib.util.find_spec(module)):
×
45
        logger.warning(f"Failed to find module {module}")
×
46
        return None
×
47

48
    assert spec.origin is not None
×
49
    with open(spec.origin) as f:
×
50
        source_code = f.read()
×
51
        tree = cst.parse_module(source_code)
×
52
        results = m.findall(
×
53
            tree, matcher=m.FunctionDef(m.Name(func), asynchronous=m.Asynchronous())
54
        )
55
        return cst.ensure_type(results[0], cst.FunctionDef) if results else None
×
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