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

pantsbuild / pants / 22285099215

22 Feb 2026 08:52PM UTC coverage: 75.854% (-17.1%) from 92.936%
22285099215

Pull #23121

github

web-flow
Merge c7299df9c into ba8359840
Pull Request #23121: fix issue with optional fields in dependency validator

28 of 29 new or added lines in 2 files covered. (96.55%)

11174 existing lines in 400 files now uncovered.

53694 of 70786 relevant lines covered (75.85%)

1.88 hits per line

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

75.0
/src/python/pants/backend/python/subsystems/setup_py_generation.py
1
# Copyright 2023 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3
import enum
3✔
4

5
from pants.option.option_types import BoolOption, EnumOption
3✔
6
from pants.option.subsystem import Subsystem
3✔
7
from pants.util.strutil import softwrap
3✔
8

9

10
@enum.unique
3✔
11
class FirstPartyDependencyVersionScheme(enum.Enum):
3✔
12
    EXACT = "exact"  # i.e., ==
3✔
13
    COMPATIBLE = "compatible"  # i.e., ~=
3✔
14
    ANY = "any"  # i.e., no specifier
3✔
15

16

17
class SetupPyGeneration(Subsystem):
3✔
18
    options_scope = "setup-py-generation"
3✔
19
    help = "Options to control how setup.py is generated from a `python_distribution` target."
3✔
20

21
    # Generating setup is the more aggressive thing to do, so we'd prefer that the default
22
    # be False. However that would break widespread existing usage, so we'll make that
23
    # change in a future deprecation cycle.
24
    generate_setup_default = BoolOption(
3✔
25
        default=True,
26
        help=softwrap(
27
            """
28
            The default value for the `generate_setup` field on `python_distribution` targets.
29
            Can be overridden per-target by setting that field explicitly. Set this to False
30
            if you mostly rely on handwritten setup files (`setup.py`, `setup.cfg` and similar).
31
            Leave as True if you mostly rely on Pants generating setup files for you.
32
            """
33
        ),
34
    )
35

36
    first_party_dependency_version_scheme = EnumOption(
3✔
37
        default=FirstPartyDependencyVersionScheme.EXACT,
38
        help=softwrap(
39
            """
40
            What version to set in `install_requires` when a `python_distribution` depends on
41
            other `python_distribution`s. If `exact`, will use `==`. If `compatible`, will
42
            use `~=`. If `any`, will leave off the version. See
43
            https://www.python.org/dev/peps/pep-0440/#version-specifiers.
44
            """
45
        ),
46
    )
47

48
    def first_party_dependency_version(self, version: str) -> str:
3✔
49
        """Return the version string (e.g. '~=4.0') for a first-party dependency.
50

51
        If the user specified to use "any" version, then this will return an empty string.
52
        """
UNCOV
53
        scheme = self.first_party_dependency_version_scheme
×
UNCOV
54
        if scheme == FirstPartyDependencyVersionScheme.ANY:
×
UNCOV
55
            return ""
×
UNCOV
56
        specifier = "==" if scheme == FirstPartyDependencyVersionScheme.EXACT else "~="
×
UNCOV
57
        return f"{specifier}{version}"
×
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

© 2026 Coveralls, Inc