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

pantsbuild / pants / 22740642519

05 Mar 2026 11:00PM UTC coverage: 52.677% (-40.3%) from 92.931%
22740642519

Pull #23157

github

web-flow
Merge 2aa18e6d4 into f0030f5e7
Pull Request #23157: [pants ng] Partition source files by config.

31678 of 60136 relevant lines covered (52.68%)

0.53 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
1✔
4

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

9

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

16

17
class SetupPyGeneration(Subsystem):
1✔
18
    options_scope = "setup-py-generation"
1✔
19
    help = "Options to control how setup.py is generated from a `python_distribution` target."
1✔
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(
1✔
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(
1✔
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:
1✔
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
        """
53
        scheme = self.first_party_dependency_version_scheme
×
54
        if scheme == FirstPartyDependencyVersionScheme.ANY:
×
55
            return ""
×
56
        specifier = "==" if scheme == FirstPartyDependencyVersionScheme.EXACT else "~="
×
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