Skip to content

Commit

Permalink
dump commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Dyas committed May 7, 2022
1 parent 40163e8 commit e653deb
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 40 deletions.
75 changes: 35 additions & 40 deletions build-support/bin/_release_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from xml.etree import ElementTree

import requests
from common import banner, die, green
from common import banner, debug, die, green
from packaging.version import Version
from reversion import reversion

Expand Down Expand Up @@ -280,14 +280,19 @@ def _pip_args(extra_pip_args: list[str]) -> tuple[str, ...]:
return (*extra_pip_args, "--quiet", "--no-cache-dir")


def run(args, **kwargs) -> subprocess.CompletedProcess[bytes]:
debug(f"Running: {' '.join([str(arg) for arg in args])}")
return subprocess.run(args, **kwargs)


def validate_pants_pkg(version: str, venv_bin_dir: Path, extra_pip_args: list[str]) -> None:
def run_venv_pants(args: list[str]) -> str:
# When we do (dry-run) testing, we need to run the packaged pants. It doesn't have internal
# backend plugins embedded (but it does have all other backends): to load only the internal
# packages, we override the `--python-path` to include them (and to implicitly exclude
# `src/python`).
return (
subprocess.run(
run(
[
venv_bin_dir / "pants",
"--no-remote-cache-read",
Expand All @@ -303,7 +308,7 @@ def run_venv_pants(args: list[str]) -> str:
.strip()
)

subprocess.run(
run(
[
venv_bin_dir / "pip",
"install",
Expand Down Expand Up @@ -338,7 +343,7 @@ def install_exercising_namespace_packages(
tempdir = Path(td)
wheel_dir = tempdir / "wheels"
pip = venv_bin_dir / "pip"
subprocess.run(
run(
[
pip,
"wheel",
Expand All @@ -352,7 +357,7 @@ def install_exercising_namespace_packages(
sys_path_entries = []
for index, wheel in enumerate(wheel_dir.iterdir()):
sys_path_entry = tempdir / f"entry_{index}"
subprocess.run(
run(
[
pip,
"install",
Expand All @@ -375,7 +380,7 @@ def validate_testutil_pkg(version: str, venv_bin_dir: Path, extra_pip_args: list
with install_exercising_namespace_packages(
venv_bin_dir, f"pantsbuild.pants.testutil=={version}", extra_pip_args=extra_pip_args
) as pythonpath:
subprocess.run(
run(
[
venv_bin_dir / "python",
"-c",
Expand Down Expand Up @@ -421,9 +426,7 @@ def validate_testutil_pkg(version: str, venv_bin_dir: Path, extra_pip_args: list
class _Constants:
def __init__(self) -> None:
self._head_sha = (
subprocess.run(
["git", "rev-parse", "--verify", "HEAD"], stdout=subprocess.PIPE, check=True
)
run(["git", "rev-parse", "--verify", "HEAD"], stdout=subprocess.PIPE, check=True)
.stdout.decode()
.strip()
)
Expand Down Expand Up @@ -480,29 +483,23 @@ def get_pypi_config(section: str, option: str) -> str:

def get_git_branch() -> str:
return (
subprocess.run(
["git", "rev-parse", "--abbrev-ref", "HEAD"], stdout=subprocess.PIPE, check=True
)
run(["git", "rev-parse", "--abbrev-ref", "HEAD"], stdout=subprocess.PIPE, check=True)
.stdout.decode()
.strip()
)


def get_pgp_key_id() -> str:
return (
subprocess.run(
["git", "config", "--get", "user.signingkey"], stdout=subprocess.PIPE, check=False
)
run(["git", "config", "--get", "user.signingkey"], stdout=subprocess.PIPE, check=False)
.stdout.decode()
.strip()
)


def get_pgp_program_name() -> str:
configured_name = (
subprocess.run(
["git", "config", "--get", "gpg.program"], stdout=subprocess.PIPE, check=False
)
run(["git", "config", "--get", "gpg.program"], stdout=subprocess.PIPE, check=False)
.stdout.decode()
.strip()
)
Expand All @@ -527,7 +524,7 @@ def is_cross_platform(wheel_paths: Iterable[Path]) -> bool:
def create_venv(venv_dir: Path) -> Path:
venv.create(venv_dir, with_pip=True, clear=True, symlinks=True)
bin_dir = venv_dir / "bin"
subprocess.run(
run(
[bin_dir / "pip", "install", "--quiet", "--disable-pip-version-check", "--upgrade", "pip"],
check=True,
)
Expand All @@ -543,7 +540,7 @@ def create_tmp_venv() -> Iterator[Path]:
"""
with TemporaryDirectory() as tempdir:
bin_dir = create_venv(Path(tempdir))
subprocess.run([(bin_dir / "pip"), "install", "--quiet", "wheel"], check=True)
run([(bin_dir / "pip"), "install", "--quiet", "wheel"], check=True)
yield bin_dir


Expand All @@ -552,7 +549,7 @@ def create_twine_venv() -> None:
if CONSTANTS.twine_venv_dir.exists():
shutil.rmtree(CONSTANTS.twine_venv_dir)
bin_dir = create_venv(CONSTANTS.twine_venv_dir)
subprocess.run([bin_dir / "pip", "install", "--quiet", "twine"], check=True)
run([bin_dir / "pip", "install", "--quiet", "twine"], check=True)


@contextmanager
Expand Down Expand Up @@ -624,7 +621,7 @@ def build_pants_wheels() -> None:

with set_pants_version(CONSTANTS.pants_unstable_version):
try:
subprocess.run(args, check=True)
run(args, check=True)
except subprocess.CalledProcessError as e:
failed_packages = ",".join(package.name for package in PACKAGES)
failed_targets = " ".join(package.target for package in PACKAGES)
Expand Down Expand Up @@ -665,7 +662,7 @@ def build_pants_wheels() -> None:

banner(f"Validating Pants wheels for {CONSTANTS.python_version}.")
create_twine_venv()
subprocess.run([CONSTANTS.twine_venv_dir / "bin/twine", "check", dest / "*.whl"], check=True)
run([CONSTANTS.twine_venv_dir / "bin/twine", "check", dest / "*.whl"], check=True)
green(f"Validated Pants wheels for {CONSTANTS.python_version}.")


Expand All @@ -675,7 +672,7 @@ def build_3rdparty_wheels() -> None:
pkg_tgts = [pkg.target for pkg in PACKAGES]
with create_tmp_venv() as bin_dir:
deps = (
subprocess.run(
run(
[
"./pants",
"--concurrent",
Expand All @@ -691,7 +688,7 @@ def build_3rdparty_wheels() -> None:
.splitlines()
)
python_requirements = (
subprocess.run(
run(
[
"./pants",
"--concurrent",
Expand All @@ -718,7 +715,7 @@ def build_3rdparty_wheels() -> None:
reqs = itertools.chain.from_iterable(
obj["requirements"]
for obj in json.loads(
subprocess.run(
run(
[
"./pants",
"--concurrent",
Expand All @@ -730,7 +727,7 @@ def build_3rdparty_wheels() -> None:
).stdout
)
)
subprocess.run(
run(
[bin_dir / "pip", "wheel", f"--wheel-dir={dest}", *reqs],
check=True,
)
Expand All @@ -745,9 +742,9 @@ def build_fs_util() -> None:
release_mode = os.environ.get("MODE", "") != "debug"
if release_mode:
command.append("--release")
subprocess.run(command, check=True, env={**os.environ, "RUST_BACKTRACE": "1"})
run(command, check=True, env={**os.environ, "RUST_BACKTRACE": "1"})
current_os = (
subprocess.run(["build-support/bin/get_os.sh"], stdout=subprocess.PIPE, check=True)
run(["build-support/bin/get_os.sh"], stdout=subprocess.PIPE, check=True)
.stdout.decode()
.strip()
)
Expand Down Expand Up @@ -817,7 +814,7 @@ def build_pex(fetch: bool) -> None:

dest = Path("dist") / pex_name
with download_pex_bin() as pex_bin:
subprocess.run(
run(
[
sys.executable,
str(pex_bin),
Expand Down Expand Up @@ -854,7 +851,7 @@ def build_pex(fetch: bool) -> None:
Path(tmpdir, "BUILD_ROOT").touch()
# We also need to filter out Pants options like `PANTS_CONFIG_FILES`.
env = {k: v for k, v in env.items() if not k.startswith("PANTS_")}
subprocess.run([validated_pex_path, "--version"], env=env, check=True, cwd=dest.parent)
run([validated_pex_path, "--version"], env=env, check=True, cwd=dest.parent)
green(f"Validated {dest}")


Expand Down Expand Up @@ -900,7 +897,7 @@ def publish_apple_silicon() -> None:
dest_dir = CONSTANTS.deploy_pants_wheel_dir / CONSTANTS.pants_stable_version
if dest_dir.exists():
shutil.rmtree(dest_dir)
subprocess.run(
run(
[
"./pants",
"--concurrent",
Expand All @@ -925,15 +922,15 @@ def publish_apple_silicon() -> None:
)

create_twine_venv()
subprocess.run([CONSTANTS.twine_venv_dir / "bin/twine", "check", expected_whl], check=True)
run([CONSTANTS.twine_venv_dir / "bin/twine", "check", expected_whl], check=True)
upload_wheels_via_twine()
banner("Successfully released Apple Silicon wheel to PyPI")


def check_clean_git_branch() -> None:
banner("Checking for a clean Git branch")
git_status = (
subprocess.run(["git", "status", "--porcelain"], stdout=subprocess.PIPE, check=True)
run(["git", "status", "--porcelain"], stdout=subprocess.PIPE, check=True)
.stdout.decode()
.strip()
)
Expand Down Expand Up @@ -965,7 +962,7 @@ def check_pgp() -> None:
if not key:
die("You must set up a PGP key. See https://www.pantsbuild.org/docs/release-process.")
print("Found the following key for release signing:\n")
subprocess.run([get_pgp_program_name(), "-k", key], check=True)
run([get_pgp_program_name(), "-k", key], check=True)
key_confirmation = input("\nIs this the correct key? [Y/n]: ")
if key_confirmation and key_confirmation.lower() != "y":
die(
Expand Down Expand Up @@ -1019,7 +1016,7 @@ def reversion_prebuilt_wheels() -> None:

def tag_release() -> None:
tag_name = f"release_{CONSTANTS.pants_stable_version}"
subprocess.run(
run(
[
"git",
"tag",
Expand All @@ -1031,13 +1028,11 @@ def tag_release() -> None:
],
check=True,
)
subprocess.run(
["git", "push", "-f", "git@github.com:pantsbuild/pants.git", tag_name], check=True
)
run(["git", "push", "-f", "git@github.com:pantsbuild/pants.git", tag_name], check=True)


def upload_wheels_via_twine() -> None:
subprocess.run(
run(
[
str(CONSTANTS.twine_venv_dir / "bin/twine"),
"upload",
Expand Down
5 changes: 5 additions & 0 deletions build-support/bin/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
_COLOR_BLUE = "\x1b[34m"
_COLOR_RED = "\x1b[31m"
_COLOR_GREEN = "\x1b[32m"
_COLOR_YELLOW = "\x1b[33m"
_COLOR_RESET = "\x1b[0m"


Expand All @@ -44,6 +45,10 @@ def banner(message: str) -> None:
print(f"{_COLOR_BLUE}[=== {minutes:02d}:{seconds:02d} {message} ===]{_COLOR_RESET}")


def debug(message: str) -> None:
print(f"{_COLOR_YELLOW}{message}{_COLOR_RESET}")


def elapsed_time() -> tuple[int, int]:
now = time.time()
elapsed_seconds = int(now - _SCRIPT_START_TIME)
Expand Down

0 comments on commit e653deb

Please sign in to comment.