Skip to content

Commit

Permalink
python: Remove the old Python build
Browse files Browse the repository at this point in the history
Change-Id: I835943f418a7677bf3fcf79912d95a6bb29926c0
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/107890
Commit-Queue: Anthony DiGirolamo <[email protected]>
Reviewed-by: Rob Mohr <[email protected]>
Reviewed-by: Armando Montanez <[email protected]>
Reviewed-by: Wyatt Hepler <[email protected]>
  • Loading branch information
AnthonyDiGirolamo authored and CQ Bot Account committed Aug 25, 2022
1 parent 0a3c752 commit 28e3e78
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 396 deletions.
3 changes: 0 additions & 3 deletions .gn
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,4 @@ default_args = {
# Code generated by third-party tool.
"pw_tls_client/generate_test_data",
]

# Use the new Python build and merged 'pigweed' Python package.
pw_build_USE_NEW_PYTHON_BUILD = true
}
16 changes: 0 additions & 16 deletions pw_build/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -237,22 +237,6 @@ group("link_deps") {
group("empty") {
}

# TODO(b/232800695): Remove when all projects are on the new Python build.
# Requirements for the pw_python_package lint targets.
pw_python_requirements("python_lint") {
requirements = [
"build",

# NOTE: mypy needs to stay in sync with mypy-protobuf
# Currently using mypy 0.971 and mypy-protobuf 3.2.0
"mypy==0.971",

# typeshed packages (required by mypy > 0.9)
"types-setuptools",
"pylint==2.9.3",
]
}

pw_doc_group("docs") {
sources = [
"docs.rst",
Expand Down
107 changes: 5 additions & 102 deletions pw_build/python.gni
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,6 @@ template("pw_python_package") {
_is_package = !(defined(invoker._pw_standalone) && invoker._pw_standalone)

_generate_package = false
if (_is_package) {
_pip_install_package = true

# Always run pip installs if not opting into the new Pigweed Python Build.
if (pw_build_USE_NEW_PYTHON_BUILD) {
_pip_install_package = false
}
}

_pydeplabel = get_label_info(":$target_name", "label_with_toolchain")

Expand Down Expand Up @@ -516,66 +508,8 @@ template("pw_python_package") {
}

if (_is_package) {
if (_pip_install_package) {
# Install this Python package and its dependencies in the current Python
# environment using pip.
pw_python_action("$target_name._run_pip_install") {
module = "pip"
public_deps = []
if (defined(invoker.public_deps)) {
public_deps += invoker.public_deps
}

args = [
"install",

# This speeds up pip installs. Build isolation isn't required for
# in-tree packages unless that package includes C/C++ extension
# modules:
# https://setuptools.pypa.io/en/latest/userguide/ext_modules.html
# For packages witout extensions this option requires that pip,
# setuptools, and wheel packages are available.
"--no-build-isolation",
]

inputs = pw_build_PIP_CONSTRAINTS
foreach(_constraints_file, pw_build_PIP_CONSTRAINTS) {
args += [
"--constraint",
rebase_path(_constraints_file, root_build_dir),
]
}

# For generated packages, reinstall when any files change. For regular
# packages, only reinstall when setup.py changes.
if (_generate_package) {
public_deps += [ ":${invoker.target_name}" ]
} else {
inputs += invoker.setup

# Install with --editable since the complete package is in source.
args += [ "--editable" ]
}

args += [ rebase_path(_setup_dir, root_build_dir) ]

stamp = true

# Parallel pip installations don't work, so serialize pip invocations.
pool = "$dir_pw_build/pool:pip($default_toolchain)"

foreach(dep, _python_deps) {
# We need to add a suffix to the target name, but the label is
# formatted as "//path/to:target(toolchain)", so we can't just append
# ".subtarget". Instead, we replace the opening parenthesis of the
# toolchain with ".suffix(".
public_deps += [ string_replace(dep, "(", "._run_pip_install(") ]
}
}
} else {
# Stubs for non-package targets.
group("$target_name._run_pip_install") {
}
# Stubs for non-package targets.
group("$target_name._run_pip_install") {
}

# Builds a Python wheel for this package. Records the output directory
Expand Down Expand Up @@ -652,12 +586,7 @@ template("pw_python_package") {
# All packages to install for either general use or test running.
_test_install_deps = [ ":$target_name.install" ]

foreach(dep,
_python_test_deps + [
# TODO(b/232800695): Remove when all projects are on the new
# Python build.
"$dir_pw_build:python_lint",
]) {
foreach(dep, _python_test_deps) {
_test_install_deps += [ string_replace(dep, "(", ".install(") ]
_test_install_deps += [ dep ]
}
Expand Down Expand Up @@ -930,34 +859,8 @@ template("pw_python_requirements") {

# Use the same subtargets as pw_python_package so these targets can be listed
# as python_deps of pw_python_packages.
pw_python_action("$target_name.install") {
inputs = _requirements_files

if (pw_build_USE_NEW_PYTHON_BUILD) {
# This template is a no-op if the new Python build is enabled.
script = "$dir_pw_build/py/pw_build/nop.py"
} else {
module = "pip"
args = [ "install" ]

foreach(_requirements_file, inputs) {
args += [
"--requirement",
rebase_path(_requirements_file, root_build_dir),
]
}

inputs += pw_build_PIP_CONSTRAINTS
foreach(_constraints_file, pw_build_PIP_CONSTRAINTS) {
args += [
"--constraint",
rebase_path(_constraints_file, root_build_dir),
]
}

pool = "$dir_pw_build/pool:pip($default_toolchain)"
}
stamp = true
group("$target_name.install") {
# TODO(b/232800695): Remove reliance on this subtarget existing.
}

# Create stubs for the unused subtargets so that pw_python_requirements can be
Expand Down
59 changes: 20 additions & 39 deletions pw_build/python_action.gni
Original file line number Diff line number Diff line change
Expand Up @@ -203,42 +203,28 @@ template("pw_python_action") {
}
_deps += [ ":${_metadata_path_list_target}" ]

if (pw_build_USE_NEW_PYTHON_BUILD) {
# Set venv options if needed.
if (_use_build_dir_virtualenv) {
_venv_target_label = pw_build_PYTHON_BUILD_VENV
if (defined(invoker.venv)) {
_venv_target_label = invoker.venv
}
_venv_target_label =
get_label_info(_venv_target_label, "label_no_toolchain") +
"($pw_build_PYTHON_TOOLCHAIN)"

_venv_json =
get_label_info(_venv_target_label, "target_gen_dir") + "/" +
get_label_info(_venv_target_label, "name") + "/venv_metadata.json"
_script_args += [
"--python-virtualenv-config",
rebase_path(_venv_json, root_build_dir),
]
# Set venv options if needed.
if (_use_build_dir_virtualenv) {
_venv_target_label = pw_build_PYTHON_BUILD_VENV
if (defined(invoker.venv)) {
_venv_target_label = invoker.venv
}
_venv_target_label =
get_label_info(_venv_target_label, "label_no_toolchain") +
"($pw_build_PYTHON_TOOLCHAIN)"

_venv_json =
get_label_info(_venv_target_label, "target_gen_dir") + "/" +
get_label_info(_venv_target_label, "name") + "/venv_metadata.json"
_script_args += [
"--python-dep-list-files",
rebase_path(_metadata_path_list_file, root_build_dir),
]
}

if (!pw_build_USE_NEW_PYTHON_BUILD) {
_script_args += [
# pip lockfile, prevents pip from running in parallel with other Python
# actions.
"--lockfile",

# Use a single lockfile for the entire out directory.
"pip.lock",
"--python-virtualenv-config",
rebase_path(_venv_json, root_build_dir),
]
}
_script_args += [
"--python-dep-list-files",
rebase_path(_metadata_path_list_file, root_build_dir),
]

# "--" indicates the end of arguments to the runner script.
# Everything beyond this point is interpreted as the command and arguments
Expand Down Expand Up @@ -272,9 +258,6 @@ template("pw_python_action") {
_install_venv_3p_deps = false
}

# If pw_build_USE_NEW_PYTHON_BUILD is false this variable is not needed.
not_needed([ "_install_venv_3p_deps" ])

# Check that script or module is a present and not a no-op.
_run_script_or_module = false
if (defined(invoker.script) || defined(invoker.module)) {
Expand All @@ -297,11 +280,9 @@ template("pw_python_action") {
outputs = _outputs
deps = _deps

if (pw_build_USE_NEW_PYTHON_BUILD) {
if (_install_venv_3p_deps && _run_script_or_module) {
deps += [ get_label_info(_venv_target_label, "label_no_toolchain") +
"._install_3p_deps($pw_build_PYTHON_TOOLCHAIN)" ]
}
if (_install_venv_3p_deps && _run_script_or_module) {
deps += [ get_label_info(_venv_target_label, "label_no_toolchain") +
"._install_3p_deps($pw_build_PYTHON_TOOLCHAIN)" ]
}
}
}
Expand Down
Loading

0 comments on commit 28e3e78

Please sign in to comment.