• 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

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

4
import os
1✔
5
from typing import cast
1✔
6

7
from pants.fs.fs import safe_filename_from_path
1✔
8
from pants.option.option_value_container import OptionValueContainer
1✔
9
from pants.util.dirutil import absolute_symlink, safe_mkdir, safe_rmtree
1✔
10

11

12
def init_workdir(global_options: OptionValueContainer) -> str:
1✔
13
    """Given the bootstrap options (generally immediately after bootstrap), initialize the workdir.
14

15
    If it is in use, the "physical" workdir is a directory under the `pants_physical_workdir_base`
16
    that is unique to each working copy (via including the entire path to the working copy in its
17
    name using `safe_filename_from_path`).
18
    """
UNCOV
19
    workdir_src = cast(str, global_options.pants_workdir)
×
UNCOV
20
    if not global_options.pants_physical_workdir_base:
×
21
        safe_mkdir(workdir_src)
×
22
        return workdir_src
×
23

UNCOV
24
    workdir_base = global_options.pants_physical_workdir_base
×
UNCOV
25
    workdir_dst = os.path.join(workdir_base, safe_filename_from_path(workdir_src))
×
26

UNCOV
27
    def create_symlink_to_clean_workdir():
×
28
        # Executed when no link exists. We treat this as equivalent to a request to have deleted
29
        # this state. Operations like `clean-all` will already have purged the destination, but in
30
        # cases like manual removal of the symlink, we want to treat the case as equivalent.
UNCOV
31
        safe_mkdir(workdir_dst, clean=True)
×
UNCOV
32
        absolute_symlink(workdir_dst, workdir_src)
×
33

UNCOV
34
    if not os.path.lexists(workdir_src):
×
35
        # Does not exist.
36
        create_symlink_to_clean_workdir()
×
UNCOV
37
    elif os.path.islink(workdir_src):
×
38
        if os.readlink(workdir_src) != workdir_dst:
×
39
            # Exists but is incorrect.
40
            os.unlink(workdir_src)
×
41
            create_symlink_to_clean_workdir()
×
42
        else:
43
            # Exists and is correct: ensure that the destination exists.
44
            safe_mkdir(workdir_dst)
×
45
    else:
46
        # Remove existing physical workdir (.pants.d/workdir dir)
UNCOV
47
        safe_rmtree(workdir_src)
×
48
        # Create both symlink workdir (.pants.d/workdir dir) and its destination/physical workdir
UNCOV
49
        create_symlink_to_clean_workdir()
×
UNCOV
50
    return workdir_src
×
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