Skip to content

Commit

Permalink
diff with previous versions when generating builtin lockfiles
Browse files Browse the repository at this point in the history
By copying the prior version, we get the same Lockfile diff as one
would for a "regular" lockfile.

Demo:
```
$ pants run build-support/bin/generate_builtin_lockfiles.py -- semgrep
Lockfile diff: semgrep.lock [semgrep]

==                    Upgraded dependencies                     ==

  semgrep                        1.86.0       -->   1.87.0
  zipp                           3.20.1       -->   3.20.2

==                !! Downgraded dependencies !!                 ==

  rich                           13.8.1       -->   13.5.3

==                     Removed dependencies                     ==

  annotated-types                0.7.0
  pydantic                       2.8.2
  pydantic-core                  2.20.1
```

fixes pantsbuild#21388
  • Loading branch information
cburroughs committed Sep 13, 2024
1 parent caa3405 commit d2f7d9b
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions build-support/bin/generate_builtin_lockfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,17 @@ def generate_jvm_tool_lockfiles(tools: Sequence[JvmTool], dry_run: bool) -> None


def generate(buildroot: str, tools: Sequence[Tool], args: Sequence[str], dry_run: bool) -> None:
def lockfile_inrepo_dest(lockfile_pkg, lockfile_filename):
return os.path.join(
"src",
"python",
lockfile_pkg.replace(".", os.path.sep),
lockfile_filename,
)

def lockfile_buildroot_filename(lockfile_name):
return os.path.join(buildroot, lockfile_name)

pants_repo_root = get_buildroot()
touch(os.path.join(buildroot, "pants.toml"))
backends = sorted({tool.backend for tool in tools})
Expand All @@ -287,19 +298,24 @@ def generate(buildroot: str, tools: Sequence[Tool], args: Sequence[str], dry_run
logger.info("Would run: " + " ".join(args))
return

# If there is a pre-existing lockfile, seed it so we get the pretty lockfile diff
for tool in tools:
lockfile_pkg, lockfile_filename = tool.cls.default_lockfile_resource
lockfile_dest = lockfile_inrepo_dest(lockfile_pkg, lockfile_filename)
if os.path.isfile(lockfile_dest):
logger.debug(f"copying existing lockfile from {lockfile_dest}")
shutil.copy(lockfile_dest, lockfile_buildroot_filename(tool.lockfile_name))

logger.debug("Running: " + " ".join(args))
subprocess.run(args, cwd=buildroot, check=True)

# Copy the generated lockfiles from the tmp repo to the Pants repo.
for tool in tools:
lockfile_pkg, lockfile_filename = tool.cls.default_lockfile_resource
lockfile_dest = os.path.join(
"src",
"python",
lockfile_pkg.replace(".", os.path.sep),
lockfile_filename,
shutil.copy(
lockfile_buildroot_filename(tool.lockfile_name),
lockfile_inrepo_dest(lockfile_pkg, lockfile_filename),
)
shutil.copy(os.path.join(buildroot, tool.lockfile_name), lockfile_dest)


def main() -> None:
Expand Down

0 comments on commit d2f7d9b

Please sign in to comment.