From 519e754819cb63c7c8ec367782bbc10bedef62a1 Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Fri, 12 Jun 2020 11:01:58 -0700 Subject: [PATCH 01/96] Upgrade to 1.29.0rc0 (#20) This demonstrates some new features: * `--` style passthrough args for Pytest * Dependency injection for Protobuf * `lint` batching based on interpreter constraints * Pantsd --- README.md | 7 ++++--- constraints.txt | 3 ++- helloworld/protos/BUILD | 10 +++------- pants | 14 ++++++++------ pants.ci.toml | 4 ++-- pants.toml | 13 +++++-------- 6 files changed, 24 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 44cd996..d15c586 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,6 @@ Try these out in this repo! ``` ./pants list helloworld:: # All targets. - ./pants list 'helloworld/**/*.py' # Just targets containing Python code. ``` @@ -117,7 +116,7 @@ Try these out in this repo! ./pants test :: # Run all tests in the repo. ./pants test helloworld/util:test # Run all the tests in this target. ./pants test helloworld/util/lang_test.py # Run just the tests in this file. -./pants test helloworld/util/lang_test.py --pytest-args='-k test_language_translator' # Run just this one test. +./pants test helloworld/util/lang_test.py -- -k test_language_translator # Run just this one test. ``` ## Create a runnable binary @@ -147,8 +146,10 @@ Try these out in this repo! ## Build an AWS Lambda +(This example only works on Linux because it has an sdist. See https://pants.readme.io/docs/awslambda-python.) + ``` -./pants awslambda helloworld:helloworld-awslambda # Has sdist requirements, so must be built on Linux. +./pants awslambda helloworld:helloworld-awslambda ``` ## Count lines of code diff --git a/constraints.txt b/constraints.txt index 443d4e7..4625cb3 100644 --- a/constraints.txt +++ b/constraints.txt @@ -31,4 +31,5 @@ tox==3.15.0 translate==3.5.0 urllib3==1.25.9 virtualenv==20.0.20 -zipp==3.1.0 +zipp==1.2.0 ; python_version == '2.7' +zipp==3.1.0 ; python_version > '2.7' diff --git a/helloworld/protos/BUILD b/helloworld/protos/BUILD index 317138f..6212f61 100644 --- a/helloworld/protos/BUILD +++ b/helloworld/protos/BUILD @@ -1,10 +1,6 @@ # Copyright 2020 Pants project contributors. # Licensed under the Apache License, Version 2.0 (see LICENSE). -protobuf_library( - # `name` defaults to the name of this directory, i.e., `protos`. - # `sources` defaults to ["*.proto"]. - dependencies=[ - "//:protobuf", - ], -) +# `name` defaults to the name of this directory, i.e., `protos`. +# `sources` defaults to ["*.proto"]. +protobuf_library() diff --git a/pants b/pants index 2e265e6..ef0905c 100755 --- a/pants +++ b/pants @@ -77,11 +77,11 @@ EOF } # The high-level flow: -# 1.) Resolve the Pants version from pants.ini or from the latest stable +# 1.) Resolve the Python interpreter, first reading from the env var $PYTHON, +# then defaulting to Python 3.6+. +# 2.) Resolve the Pants version from pants.ini or from the latest stable # release to PyPI, so that we know what to name the venv (virtual environment) folder and what # to install with Pip. -# 2.) Resolve the Python interpreter, first reading from the env var $PYTHON, -# then defaulting to Python 3.6+. # 3.) Check if the venv already exists via a naming convention, and create the venv if not found. # 4.) Execute Pants with the resolved Python interpreter and venv. # @@ -89,10 +89,12 @@ EOF # are installed and up to date. function determine_pants_version { + python="$1" + pants_version="$(get_pants_config_value 'pants_version')" if [[ -z "${pants_version}" ]]; then pants_version="$(curl -sSL https://pypi.python.org/pypi/pantsbuild.pants/json | - python -c "import json, sys; print(json.load(sys.stdin)['info']['version'])")" + "${python}" -c "import json, sys; print(json.load(sys.stdin)['info']['version'])")" fi pants_major_version="$(echo "${pants_version}" | cut -d '.' -f1)" pants_minor_version="$(echo "${pants_version}" | cut -d '.' -f2)" @@ -169,7 +171,7 @@ function bootstrap_pants { staging_dir=$(tempdir "${PANTS_BOOTSTRAP}") "${python}" "${venv_path}/virtualenv.py" --no-download "${staging_dir}/install" "${staging_dir}/install/bin/pip" install -U pip - "${staging_dir}/install/bin/pip" install "${pants_requirement}" + "${staging_dir}/install/bin/pip" install --progress-bar off "${pants_requirement}" ln -s "${staging_dir}/install" "${staging_dir}/${target_folder_name}" mv "${staging_dir}/${target_folder_name}" "${PANTS_BOOTSTRAP}/${target_folder_name}" green "New virtual environment successfully created at ${PANTS_BOOTSTRAP}/${target_folder_name}." @@ -180,8 +182,8 @@ function bootstrap_pants { # Ensure we operate from the context of the ./pants buildroot. cd "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" -pants_version="$(determine_pants_version)" python="$(determine_python_exe)" +pants_version="$(determine_pants_version "${python}")" pants_dir="$(bootstrap_pants "${pants_version}" "${python}")" diff --git a/pants.ci.toml b/pants.ci.toml index 9050246..2c1941b 100644 --- a/pants.ci.toml +++ b/pants.ci.toml @@ -1,8 +1,8 @@ # See https://pants.readme.io/docs/using-pants-in-ci. [GLOBAL] -# Turn off the interactive UI. -v2_ui = false +dynamic_ui = false +enable_pantsd = false # Limit the maximum number of concurrent processes. Change this # to a number that makes sense for your CI setup, based on diff --git a/pants.toml b/pants.toml index ca4dbae..0342b52 100644 --- a/pants.toml +++ b/pants.toml @@ -2,10 +2,11 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "1.28.0" +pants_version = "1.29.0rc0" v1 = false # Turn off the v1 execution engine. v2 = true # Enable the v2 execution engine. -v2_ui = true # Enable the v2 execution engine's terminal-based UI. +dynamic_ui = true +enable_pantsd = true # Enable the Pants daemon for better performance. backend_packages = [] # Deregister all v1 backends. @@ -35,12 +36,8 @@ interpreter_constraints = [">=3.7"] # Use a lockfile. See https://pants.readme.io/docs/python-third-party-dependencies. requirement_constraints = "constraints.txt" -[lint] -# We use `per_target_caching` because we have some Python 2-only targets and some Python 3-only -# targets, so we need to run each target as a separate process to avoid interpreter compatibility -# conflicts. If you only have one Python version in your repository, do not use this setting. See -# https://pants.readme.io/docs/python-lint-goal. -per_target_caching = true +[protoc] +runtime_targets = ["//:protobuf"] [flake8] config = ".flake8" From 44f0bd76b7d53b64d821f90da2f9674c42eb2628 Mon Sep 17 00:00:00 2001 From: Asher Foa Date: Fri, 19 Jun 2020 09:30:13 -0700 Subject: [PATCH 02/96] Upgrade to pants 1.29.0 (#22) --- pants.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pants.toml b/pants.toml index 0342b52..b67e99f 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "1.29.0rc0" +pants_version = "1.29.0" v1 = false # Turn off the v1 execution engine. v2 = true # Enable the v2 execution engine. dynamic_ui = true From 0301890d0e3ddce6756f91485198a18690e84a3e Mon Sep 17 00:00:00 2001 From: Stu Hood Date: Thu, 16 Jul 2020 22:14:17 -0700 Subject: [PATCH 03/96] Bump to 1.30.0rc2. (#23) --- pants.ci.toml | 3 +-- pants.toml | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/pants.ci.toml b/pants.ci.toml index 2c1941b..ec64bf1 100644 --- a/pants.ci.toml +++ b/pants.ci.toml @@ -1,8 +1,7 @@ # See https://pants.readme.io/docs/using-pants-in-ci. [GLOBAL] -dynamic_ui = false -enable_pantsd = false +pantsd = false # Limit the maximum number of concurrent processes. Change this # to a number that makes sense for your CI setup, based on diff --git a/pants.toml b/pants.toml index b67e99f..35c71e1 100644 --- a/pants.toml +++ b/pants.toml @@ -2,11 +2,10 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "1.29.0" +pants_version = "1.30.0rc2" v1 = false # Turn off the v1 execution engine. v2 = true # Enable the v2 execution engine. -dynamic_ui = true -enable_pantsd = true # Enable the Pants daemon for better performance. +pantsd = true # Enable the Pants daemon for better performance. backend_packages = [] # Deregister all v1 backends. From d1b3c53d204c01013ca1fb34bd6cf50927c0c38b Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Wed, 22 Jul 2020 09:18:44 -0700 Subject: [PATCH 04/96] Upgrade to 1.30.0 (#24) We also use the newest `./pants` script. --- README.md | 4 ++-- pants | 46 +++++++++++++++++++++++++++++++++------------- pants.toml | 2 +- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index d15c586..9af10e0 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # example-python -An example repository to demonstrate Python support in Pants v2. +An example repository to demonstrate Python support in Pants. -See https://pants.readme.io/ for much more detailed documentation. +See [pantsbuild.org](https://www.pantsbuild.org/docs) for much more detailed documentation. # Running Pants diff --git a/pants b/pants index ef0905c..ba90e1d 100755 --- a/pants +++ b/pants @@ -4,18 +4,30 @@ # =============================== NOTE =============================== # This ./pants bootstrap script comes from the pantsbuild/setup -# project and is intended to be checked into your code repository so -# that any developer can check out your code and be building it with -# Pants with no prior setup needed. +# project. It is intended to be checked into your code repository so +# that other developers have the same setup. # -# You can learn more here: https://www.pantsbuild.org/install.html +# Learn more here: https://www.pantsbuild.org/docs/installation # ==================================================================== set -eou pipefail PYTHON_BIN_NAME="${PYTHON:-unspecified}" +# Set one of these to specify a non-standard location for this script to read the pants version from. +# NB: This will *not* cause Pants itself to use this location as a config file. +# You can use PANTS_CONFIG_FILES or --pants-config-files to do so. +PANTS_INI=${PANTS_INI:-pants.ini} +PANTS_TOML=${PANTS_TOML:-pants.toml} + +PANTS_BIN_NAME="${PANTS_BIN_NAME:-$0}" + PANTS_HOME="${PANTS_HOME:-${XDG_CACHE_HOME:-$HOME/.cache}/pants/setup}" +# If given a relative path, we fix it to be absolute. +if [[ "$PANTS_HOME" != /* ]]; then + PANTS_HOME="${PWD}/${PANTS_HOME}" +fi + PANTS_BOOTSTRAP="${PANTS_HOME}/bootstrap-$(uname -s)-$(uname -m)" VENV_VERSION=${VENV_VERSION:-16.4.3} @@ -51,17 +63,25 @@ function get_exe_path_or_die { fi } +pants_config_file="" +if [[ -f "${PANTS_INI}" ]]; then + pants_config_file="${PANTS_INI}" +fi +if [[ -f "${PANTS_TOML}" ]]; then + pants_config_file="${PANTS_TOML}" +fi + function get_pants_config_value { config_key="$1" optional_space="[[:space:]]*" - if [[ -f 'pants.ini' ]]; then + if [[ "${pants_config_file}" == *.ini ]]; then valid_delimiters="[:=]" prefix="^${config_key}${optional_space}${valid_delimiters}${optional_space}" - sed -ne "/${prefix}/ s#${prefix}##p" pants.ini && return 0 + sed -ne "/${prefix}/ s#${prefix}##p" "${PANTS_INI}" && return 0 fi - if [[ -f 'pants.toml' ]]; then + if [[ "${pants_config_file}" == *.toml ]]; then prefix="^${config_key}${optional_space}=${optional_space}" - raw_value="$(sed -ne "/${prefix}/ s#${prefix}##p" pants.toml)" + raw_value="$(sed -ne "/${prefix}/ s#${prefix}##p" "${PANTS_TOML}")" echo "${raw_value}" | tr -d \"\' && return 0 fi return 0 @@ -79,7 +99,7 @@ EOF # The high-level flow: # 1.) Resolve the Python interpreter, first reading from the env var $PYTHON, # then defaulting to Python 3.6+. -# 2.) Resolve the Pants version from pants.ini or from the latest stable +# 2.) Resolve the Pants version from config or from the latest stable # release to PyPI, so that we know what to name the venv (virtual environment) folder and what # to install with Pip. # 3.) Check if the venv already exists via a naming convention, and create the venv if not found. @@ -98,10 +118,10 @@ function determine_pants_version { fi pants_major_version="$(echo "${pants_version}" | cut -d '.' -f1)" pants_minor_version="$(echo "${pants_version}" | cut -d '.' -f2)" - if [[ "${pants_major_version}" -eq 1 && "${pants_minor_version}" -le 16 ]]; then - die "This version of the \`./pants\` script does not work with Pants <= 1.16.0. Instead, + if [[ "${pants_major_version}" -eq 1 && "${pants_minor_version}" -le 22 ]]; then + die "This version of the \`./pants\` script does not work with Pants <= 1.22.0. Instead, either upgrade your \`pants_version\` or use the version of the \`./pants\` script at -https://raw.githubusercontent.com/pantsbuild/setup/3bb006e4a792ae83d7059ea76c0372ece7c1069d/pants." +https://raw.githubusercontent.com/pantsbuild/setup/d1da382f6de0420940ec6007a39cba87c21075c6/pants." fi echo "${pants_version}" } @@ -193,4 +213,4 @@ pants_dir="$(bootstrap_pants "${pants_version}" "${python}")" # See https://blog.phusion.nl/2017/10/13/why-ruby-app-servers-break-on-macos-high-sierra-and-what-can-be-done-about-it/ export no_proxy='*' -exec "${pants_dir}/bin/python" "${pants_dir}/bin/pants" "$@" +exec "${pants_dir}/bin/python" "${pants_dir}/bin/pants" --pants-bin-name="${PANTS_BIN_NAME}" "$@" diff --git a/pants.toml b/pants.toml index 35c71e1..5b4442e 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "1.30.0rc2" +pants_version = "1.30.0" v1 = false # Turn off the v1 execution engine. v2 = true # Enable the v2 execution engine. pantsd = true # Enable the Pants daemon for better performance. From 6ca87cb3203fca2dfbfc880c382b7fdb2fdb011a Mon Sep 17 00:00:00 2001 From: "Daniel J. Beutel" Date: Fri, 24 Jul 2020 17:49:05 +0200 Subject: [PATCH 05/96] Update `pants` and `pants.toml` for 2.0 release (#26) --- pants | 2 +- pants.toml | 14 +++++--------- pants_from_sources | 6 +++--- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/pants b/pants index ba90e1d..e2217aa 100755 --- a/pants +++ b/pants @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Copyright 2020 Pants project contributors. +# Copyright 2020 Pants project contributors (see CONTRIBUTORS.md). # Licensed under the Apache License, Version 2.0 (see LICENSE). # =============================== NOTE =============================== diff --git a/pants.toml b/pants.toml index 5b4442e..ee666c6 100644 --- a/pants.toml +++ b/pants.toml @@ -2,15 +2,11 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "1.30.0" -v1 = false # Turn off the v1 execution engine. -v2 = true # Enable the v2 execution engine. +pants_version = "2.0.0.dev5" pantsd = true # Enable the Pants daemon for better performance. -backend_packages = [] # Deregister all v1 backends. - -# List v2 backends here. -backend_packages2.add = [ +# List backends here. +backend_packages.add = [ 'pants.backend.awslambda.python', 'pants.backend.codegen.protobuf.python', 'pants.backend.python', @@ -20,8 +16,8 @@ backend_packages2.add = [ 'pants.backend.python.lint.isort', ] -# List v2 plugins here. -plugins2 = [] +# List plugins here. +plugins = [] [source] # The Python source root is the repo root. See https://pants.readme.io/docs/source-roots. diff --git a/pants_from_sources b/pants_from_sources index 08de322..733aae1 100755 --- a/pants_from_sources +++ b/pants_from_sources @@ -36,10 +36,10 @@ function string_list() { } export PANTS_VERSION="$(cat "${PANTS_SOURCE}/src/python/pants/VERSION")" -export PANTS_PLUGINS2="$(string_list plugins)" +export PANTS_PLUGINS="$(string_list plugins)" export PANTS_PYTHONPATH="+$(string_list pythonpath)" -export PANTS_BACKEND_PACKAGES2="+$(string_list backend_packages)" -export PANTS_ENABLE_PANTSD="${ENABLE_PANTSD}" +export PANTS_BACKEND_PACKAGES="+$(string_list backend_packages)" +export PANTS_PANTSD="${ENABLE_PANTSD}" export no_proxy="*" exec "${PANTS_SOURCE}/pants" "--no-verify-config" "$@" From 14e467ce54e3e918fb2321aa2d79974397558adb Mon Sep 17 00:00:00 2001 From: Benjy Weinberger Date: Wed, 29 Jul 2020 23:17:26 -0700 Subject: [PATCH 06/96] Fix the setup-py part of the example. (#30) Required moving the .proto files to be below the exported target (in the filesystem sense). If we support setting a source root on generated protos in the future, we can modify this further to demo that. --- .gitignore | 4 ++++ helloworld/BUILD | 2 +- helloworld/config.py | 2 +- helloworld/util/BUILD | 4 ++-- helloworld/util/config_loader.py | 2 +- helloworld/{protos => util/proto}/BUILD | 2 +- helloworld/{protos => util/proto}/config.proto | 2 +- 7 files changed, 11 insertions(+), 7 deletions(-) rename helloworld/{protos => util/proto}/BUILD (71%) rename helloworld/{protos => util/proto}/config.proto (87%) diff --git a/.gitignore b/.gitignore index f7a6370..97b1dfa 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,7 @@ __pycache__/ # Editors .idea/ +*.iml + +# Local databases. +*.sqlite3 diff --git a/helloworld/BUILD b/helloworld/BUILD index bf588a4..b4b9546 100644 --- a/helloworld/BUILD +++ b/helloworld/BUILD @@ -40,8 +40,8 @@ python_library( sources = ["config.py"], dependencies = [ ":config_file", - "helloworld/protos", "helloworld/util", + "helloworld/util/proto", ], ) diff --git a/helloworld/config.py b/helloworld/config.py index d3cdc96..7d56799 100644 --- a/helloworld/config.py +++ b/helloworld/config.py @@ -1,8 +1,8 @@ # Copyright 2020 Pants project contributors. # Licensed under the Apache License, Version 2.0 (see LICENSE). -from helloworld.protos.config_pb2 import Config from helloworld.util.config_loader import load_config_from_json +from helloworld.util.proto.config_pb2 import Config def load_config() -> Config: diff --git a/helloworld/util/BUILD b/helloworld/util/BUILD index ceed705..59f523c 100644 --- a/helloworld/util/BUILD +++ b/helloworld/util/BUILD @@ -7,13 +7,13 @@ python_library( dependencies = [ "//:setuptools", "//:translate", - "helloworld/protos", + "helloworld/util/proto", ], # See https://pants.readme.io/docs/python-setup-py-goal. provides = setup_py( name='helloworld.util', version='0.0.1', - description='Greeting library utilities', + description='Greeting library utilities.', ), ) diff --git a/helloworld/util/config_loader.py b/helloworld/util/config_loader.py index ce2f9de..74ac450 100644 --- a/helloworld/util/config_loader.py +++ b/helloworld/util/config_loader.py @@ -4,7 +4,7 @@ import pkg_resources from google.protobuf.json_format import Parse as parse_json -from helloworld.protos.config_pb2 import Config +from helloworld.util.proto.config_pb2 import Config def load_config_from_json(pkg_name: str, resource_name: str) -> Config: diff --git a/helloworld/protos/BUILD b/helloworld/util/proto/BUILD similarity index 71% rename from helloworld/protos/BUILD rename to helloworld/util/proto/BUILD index 6212f61..3ddf1d9 100644 --- a/helloworld/protos/BUILD +++ b/helloworld/util/proto/BUILD @@ -1,6 +1,6 @@ # Copyright 2020 Pants project contributors. # Licensed under the Apache License, Version 2.0 (see LICENSE). -# `name` defaults to the name of this directory, i.e., `protos`. +# `name` defaults to the name of this directory, i.e., `proto`. # `sources` defaults to ["*.proto"]. protobuf_library() diff --git a/helloworld/protos/config.proto b/helloworld/util/proto/config.proto similarity index 87% rename from helloworld/protos/config.proto rename to helloworld/util/proto/config.proto index 8fd242c..9db68bd 100644 --- a/helloworld/protos/config.proto +++ b/helloworld/util/proto/config.proto @@ -3,7 +3,7 @@ syntax = "proto3"; -package helloworld.protos; +package helloworld.util.proto; message Config { repeated string languages = 1; From 8aeb3a5f9e3d84cf0286ac877364ad22e760404f Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Tue, 11 Aug 2020 10:30:34 -0700 Subject: [PATCH 07/96] Upgrade to 2.0.0.dev7 (#33) Remaining followups: * [ ] Fix `./pants run helloworld/main.py` failing due to import error. Test it in CI. * [ ] Turn on dependency inference. Needs docs update. * [ ] Enable MyPy. * [ ] Possibly change Protobuf structure to show off the new `python_source_root` plugin field. Needs docs update. * [ ] Use `resolve_all_constraints`. Needs docs update. * [ ] Fix all references to readme.io. Fix the `master` branch too. * [ ] Update the `./pants` script. Fix the `master` branch too. --- .travis.yml | 4 ++++ README.md | 2 +- helloworld/util/BUILD | 27 ++++++++++++++++----------- pants.ci.toml | 5 ++++- pants.toml | 9 ++++----- 5 files changed, 29 insertions(+), 18 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8c62824..71d8db1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,3 +23,7 @@ install: script: - ./pants --changed-since=origin/master lint - ./pants --changed-since=origin/master --changed-include-dependees=transitive test + # Smoke test that our release process will work. + - ./pants binary helloworld/main.py helloworld/main_py2.py + - ./pants setup-py --args="bdist_wheel" helloworld/util:dist + - ./pants awslambda helloworld:helloworld-awslambda diff --git a/README.md b/README.md index 9af10e0..e4c64ea 100644 --- a/README.md +++ b/README.md @@ -141,7 +141,7 @@ Try these out in this repo! ## Run `setup.py` commands ``` -./pants setup-py --args="bdist_wheel" helloworld/util # Build a wheel. +./pants setup-py --args="bdist_wheel" helloworld/util:dist # Build a wheel. ``` ## Build an AWS Lambda diff --git a/helloworld/util/BUILD b/helloworld/util/BUILD index 59f523c..aea9ea6 100644 --- a/helloworld/util/BUILD +++ b/helloworld/util/BUILD @@ -1,32 +1,37 @@ # Copyright 2020 Pants project contributors. # Licensed under the Apache License, Version 2.0 (see LICENSE). +# See https://pants.readme.io/docs/python-setup-py-goal. +python_distribution( + name="dist", + dependencies=[":util"], + provides=setup_py( + name='helloworld.util', + version='0.0.1', + description='Greeting library utilities.', + ), +) + python_library( # `name` defaults to the name of this directory, i.e., `util`. # `sources` defaults to ['*.py', '!*_test.py', '!test_*.py', '!conftest.py']. - dependencies = [ + dependencies=[ "//:setuptools", "//:translate", "helloworld/util/proto", ], - # See https://pants.readme.io/docs/python-setup-py-goal. - provides = setup_py( - name='helloworld.util', - version='0.0.1', - description='Greeting library utilities.', - ), ) python_tests( - name = 'tests', + name='tests', # `sources` defaults to ['*_test.py', 'test_*.py', 'conftest.py']. - dependencies = [ + dependencies=[ ":config_loader_test_data", ":util", ], ) resources( - name = 'config_loader_test_data', - sources = ['config_loader_test_data.json'], + name='config_loader_test_data', + sources=['config_loader_test_data.json'], ) diff --git a/pants.ci.toml b/pants.ci.toml index ec64bf1..9a3c672 100644 --- a/pants.ci.toml +++ b/pants.ci.toml @@ -1,3 +1,6 @@ +# Copyright 2020 Pants project contributors. +# Licensed under the Apache License, Version 2.0 (see LICENSE). + # See https://pants.readme.io/docs/using-pants-in-ci. [GLOBAL] @@ -6,7 +9,7 @@ pantsd = false # Limit the maximum number of concurrent processes. Change this # to a number that makes sense for your CI setup, based on # the number of cores/threads. -process_execution_local_parallelism = 4 +process_execution_local_parallelism = 2 [python-setup] # Limit the maximum number of concurrent jobs used to resolve third diff --git a/pants.toml b/pants.toml index ee666c6..8490e91 100644 --- a/pants.toml +++ b/pants.toml @@ -2,10 +2,9 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.0.0.dev5" +pants_version = "2.0.0.dev7" pantsd = true # Enable the Pants daemon for better performance. -# List backends here. backend_packages.add = [ 'pants.backend.awslambda.python', 'pants.backend.codegen.protobuf.python', @@ -16,9 +15,6 @@ backend_packages.add = [ 'pants.backend.python.lint.isort', ] -# List plugins here. -plugins = [] - [source] # The Python source root is the repo root. See https://pants.readme.io/docs/source-roots. root_patterns = ["/"] @@ -39,3 +35,6 @@ config = ".flake8" [isort] config = [".isort.cfg"] + +[python-infer] +imports = false From 0867732bec962c4fc3866b64359925fb6083d2bd Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Tue, 11 Aug 2020 11:09:41 -0700 Subject: [PATCH 08/96] Update doc URLs to pantsbuild.org (#35) --- README.md | 2 +- helloworld/util/BUILD | 2 +- pants.ci.toml | 2 +- pants.toml | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e4c64ea..b8a7923 100644 --- a/README.md +++ b/README.md @@ -146,7 +146,7 @@ Try these out in this repo! ## Build an AWS Lambda -(This example only works on Linux because it has an sdist. See https://pants.readme.io/docs/awslambda-python.) +(This example only works on Linux because it has an sdist. See https://www.pantsbuild.org/docs/awslambda-python.) ``` ./pants awslambda helloworld:helloworld-awslambda diff --git a/helloworld/util/BUILD b/helloworld/util/BUILD index aea9ea6..e1c97d7 100644 --- a/helloworld/util/BUILD +++ b/helloworld/util/BUILD @@ -1,7 +1,7 @@ # Copyright 2020 Pants project contributors. # Licensed under the Apache License, Version 2.0 (see LICENSE). -# See https://pants.readme.io/docs/python-setup-py-goal. +# See https://www.pantsbuild.org/docs/python-setup-py-goal. python_distribution( name="dist", dependencies=[":util"], diff --git a/pants.ci.toml b/pants.ci.toml index 9a3c672..ea1e6b1 100644 --- a/pants.ci.toml +++ b/pants.ci.toml @@ -1,7 +1,7 @@ # Copyright 2020 Pants project contributors. # Licensed under the Apache License, Version 2.0 (see LICENSE). -# See https://pants.readme.io/docs/using-pants-in-ci. +# See https://www.pantsbuild.org/docs/using-pants-in-ci. [GLOBAL] pantsd = false diff --git a/pants.toml b/pants.toml index 8490e91..d45f325 100644 --- a/pants.toml +++ b/pants.toml @@ -16,15 +16,15 @@ backend_packages.add = [ ] [source] -# The Python source root is the repo root. See https://pants.readme.io/docs/source-roots. +# The Python source root is the repo root. See https://www.pantsbuild.org/docs/source-roots. root_patterns = ["/"] [python-setup] # The default interpreter compatibility for code in this repo. Individual targets can ovverride # this with the `compatibility` field. See -# https://pants.readme.io/docs/python-interpreter-compatibility. +# https://www.pantsbuild.org/docs/python-interpreter-compatibility. interpreter_constraints = [">=3.7"] -# Use a lockfile. See https://pants.readme.io/docs/python-third-party-dependencies. +# Use a lockfile. See https://www.pantsbuild.org/docs/python-third-party-dependencies. requirement_constraints = "constraints.txt" [protoc] From 5d041c0ce8c6bf0d19f798a7be77201dd790b8aa Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Fri, 14 Aug 2020 09:17:54 -0700 Subject: [PATCH 09/96] Upgrade to 2.0.0.dev8 (#37) --- .travis.yml | 5 +++-- pants.toml | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 71d8db1..77a071f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,9 +21,10 @@ install: - ./pants --version # This will bootstrap Pants script: - - ./pants --changed-since=origin/master lint - - ./pants --changed-since=origin/master --changed-include-dependees=transitive test + - ./pants lint test '**' # Smoke test that our release process will work. - ./pants binary helloworld/main.py helloworld/main_py2.py + - ./pants run helloworld/main.py + - ./pants run helloworld/main_pb2.py - ./pants setup-py --args="bdist_wheel" helloworld/util:dist - ./pants awslambda helloworld:helloworld-awslambda diff --git a/pants.toml b/pants.toml index d45f325..4cd4306 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.0.0.dev7" +pants_version = "2.0.0.dev8" pantsd = true # Enable the Pants daemon for better performance. backend_packages.add = [ From 2392d9a2676b78702710eca7eb235d0152e6bd02 Mon Sep 17 00:00:00 2001 From: Benjy Weinberger Date: Thu, 20 Aug 2020 13:02:24 -0700 Subject: [PATCH 10/96] Add py2 __init__.py files. (#39) Otherwise `./pants run helloworld:helloworld_py2` doesn't work. --- .travis.yml | 2 +- constraints.txt | 3 ++- helloworld/__init__.py | 0 helloworld/greet_py2/__init__.py | 0 4 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 helloworld/__init__.py create mode 100644 helloworld/greet_py2/__init__.py diff --git a/.travis.yml b/.travis.yml index 77a071f..100e799 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,6 +25,6 @@ script: # Smoke test that our release process will work. - ./pants binary helloworld/main.py helloworld/main_py2.py - ./pants run helloworld/main.py - - ./pants run helloworld/main_pb2.py + - ./pants run helloworld/main_py2.py - ./pants setup-py --args="bdist_wheel" helloworld/util:dist - ./pants awslambda helloworld:helloworld-awslambda diff --git a/constraints.txt b/constraints.txt index 4625cb3..da1a0b9 100644 --- a/constraints.txt +++ b/constraints.txt @@ -7,7 +7,8 @@ ansicolors==1.1.8 appdirs==1.4.3 certifi==2020.4.5.1 -cfgv==3.1.0 +cfgv==2.0.1 ; python_version == '2.7' +cfgv==3.1.0 ; python_version > '2.7' chardet==3.0.4 click==7.1.2 distlib==0.3.0 diff --git a/helloworld/__init__.py b/helloworld/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/helloworld/greet_py2/__init__.py b/helloworld/greet_py2/__init__.py new file mode 100644 index 0000000..e69de29 From 5102d8da9be721210d8abf4c3337ab0d9c978592 Mon Sep 17 00:00:00 2001 From: Tom Dyas Date: Thu, 20 Aug 2020 23:52:09 -0700 Subject: [PATCH 11/96] Upgrade to Pants 2.0.0.dev9 (#38) --- constraints.txt | 4 +++- pants.toml | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/constraints.txt b/constraints.txt index da1a0b9..0d1442e 100644 --- a/constraints.txt +++ b/constraints.txt @@ -16,11 +16,13 @@ filelock==3.0.12 identify==1.4.15 idna==2.9 importlib-metadata==1.6.0 +importlib-resources==1.5.0 ; python_version < '3.7' lxml==4.5.0 nodeenv==1.3.5 packaging==20.3 pluggy==0.13.1 -pre-commit==2.3.0 +pre-commit==1.21.0 ; python_version == '2.7' +pre-commit==2.3.0 ; python_version > '2.7' protobuf==3.11.3 py==1.8.1 pyparsing==2.4.7 diff --git a/pants.toml b/pants.toml index 4cd4306..db2d8ed 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.0.0.dev8" +pants_version = "2.0.0.dev9" pantsd = true # Enable the Pants daemon for better performance. backend_packages.add = [ From acdf3a7bca3476b86e277f2687a697fa8e5cc171 Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Wed, 16 Sep 2020 12:37:53 -0700 Subject: [PATCH 12/96] Upgrade to 2.0.0b0 (#40) --- .gitignore | 5 +-- .travis.yml | 5 +-- build-support/generate_constraints.sh | 25 ++++++++++++++ constraints.txt | 48 +++++++++++++-------------- pants.toml | 9 ++++- 5 files changed, 60 insertions(+), 32 deletions(-) create mode 100755 build-support/generate_constraints.sh diff --git a/.gitignore b/.gitignore index 97b1dfa..08c35f4 100644 --- a/.gitignore +++ b/.gitignore @@ -10,11 +10,8 @@ # Python files __pycache__/ *.pyc -/.venv/ +.venv/ # Editors .idea/ *.iml - -# Local databases. -*.sqlite3 diff --git a/.travis.yml b/.travis.yml index 100e799..8579509 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,5 +26,6 @@ script: - ./pants binary helloworld/main.py helloworld/main_py2.py - ./pants run helloworld/main.py - ./pants run helloworld/main_py2.py - - ./pants setup-py --args="bdist_wheel" helloworld/util:dist - - ./pants awslambda helloworld:helloworld-awslambda + # TODO: Fix PEX bug causing these to fail in CI, then reactivate when 2.0.0b1 is released. +# - ./pants setup-py --args="bdist_wheel" helloworld/util:dist +# - ./pants awslambda helloworld:helloworld-awslambda diff --git a/build-support/generate_constraints.sh b/build-support/generate_constraints.sh new file mode 100755 index 0000000..d4d352c --- /dev/null +++ b/build-support/generate_constraints.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +# Copyright 2020 Pants project contributors (see CONTRIBUTORS.md). +# Licensed under the Apache License, Version 2.0 (see LICENSE). + +# See https://www.pantsbuild.org/v2.0/docs/python-third-party-dependencies. + +set -euo pipefail + +PYTHON_BIN=python3 +VIRTUALENV=build-support/.venv +PIP="${VIRTUALENV}/bin/pip" +CONSTRAINTS_FILE=constraints.txt + +"${PYTHON_BIN}" -m venv "${VIRTUALENV}" +"${PIP}" install pip --upgrade +"${PIP}" install -r <(./pants dependencies --type=3rdparty ::) +echo "# Generated by build-support/generate_constraints.sh on $(date)" > "${CONSTRAINTS_FILE}" +"${PIP}" freeze --all >> "${CONSTRAINTS_FILE}" + +# This example repo includes some Python 2-only code for demonstration. Because we generated +# the constraints using Python 3.7, we must manually ensure things still work with Python 2.7. So, +# we warn to the user that they should check the diff. You can delete this if you don't use Python 2. +echo "Check the diff for ${CONSTRAINTS_FILE} and restore any entries that were specific to" \ + "Python 2, i.e. entries ending in \`python_version == '2.7'\`. Those are needed for Python 2 to" \ + "work properly, and this script will overwrite it." 1>&2 diff --git a/constraints.txt b/constraints.txt index 0d1442e..2e7e886 100644 --- a/constraints.txt +++ b/constraints.txt @@ -1,38 +1,36 @@ -# Copyright 2020 Pants project contributors. -# Licensed under the Apache License, Version 2.0 (see LICENSE). - -# Generated by first creating a virtual environment with `python3.7 -m venv .venv`, then running -# `.venv/bin/pip install -r requirements.txt` and `.venv/bin/pip freeze`. - +# Generated by build-support/generate_constraints.sh on Wed Sep 16 11:30:54 MST 2020 ansicolors==1.1.8 -appdirs==1.4.3 -certifi==2020.4.5.1 +appdirs==1.4.4 +certifi==2020.6.20 cfgv==2.0.1 ; python_version == '2.7' cfgv==3.1.0 ; python_version > '2.7' chardet==3.0.4 click==7.1.2 -distlib==0.3.0 +distlib==0.3.1 filelock==3.0.12 -identify==1.4.15 -idna==2.9 -importlib-metadata==1.6.0 -importlib-resources==1.5.0 ; python_version < '3.7' -lxml==4.5.0 -nodeenv==1.3.5 -packaging==20.3 +identify==1.5.2 +idna==2.10 +importlib-metadata==1.7.0 +importlib-resources==3.0.0 +lxml==4.5.2 +nodeenv==1.5.0 +packaging==20.4 +pip==20.2.3 pluggy==0.13.1 pre-commit==1.21.0 ; python_version == '2.7' -pre-commit==2.3.0 ; python_version > '2.7' -protobuf==3.11.3 -py==1.8.1 +pre-commit==2.7.1 ; python_version > '2.7' +protobuf==3.13.0 +py==1.9.0 pyparsing==2.4.7 PyYAML==5.3.1 -requests==2.23.0 -six==1.14.0 -toml==0.10.0 -tox==3.15.0 +requests==2.24.0 +setuptools==44.1.1 ; python_version == '2.7' +setuptools==50.3.0 ; python_version > '2.7' +six==1.15.0 +toml==0.10.1 +tox==3.20.0 translate==3.5.0 -urllib3==1.25.9 -virtualenv==20.0.20 +urllib3==1.25.10 +virtualenv==20.0.31 zipp==1.2.0 ; python_version == '2.7' zipp==3.1.0 ; python_version > '2.7' diff --git a/pants.toml b/pants.toml index db2d8ed..7269ea8 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.0.0.dev9" +pants_version = "2.0.0b0" pantsd = true # Enable the Pants daemon for better performance. backend_packages.add = [ @@ -15,10 +15,17 @@ backend_packages.add = [ 'pants.backend.python.lint.isort', ] +# This ensures that the result of `./pants binary` is always unique. +pants_distdir_legacy_paths = false + [source] # The Python source root is the repo root. See https://www.pantsbuild.org/docs/source-roots. root_patterns = ["/"] +[subprocess-environment] +# We pass through these environment variables to subprocesses. +env_vars = ["LANG", "LC_ALL"] + [python-setup] # The default interpreter compatibility for code in this repo. Individual targets can ovverride # this with the `compatibility` field. See From 807244288d16568ed80b0251e3100527be1da502 Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Wed, 16 Sep 2020 18:29:00 -0700 Subject: [PATCH 13/96] Turn on dependency inference (#41) --- BUILD | 10 ++++++++- README.md | 2 +- helloworld/BUILD | 46 ++++++++++++++++-------------------------- helloworld/greet/BUILD | 22 +++++++------------- helloworld/util/BUILD | 16 +++++++-------- pants.toml | 5 +---- 6 files changed, 43 insertions(+), 58 deletions(-) diff --git a/BUILD b/BUILD index 5f81ec9..932d9e4 100644 --- a/BUILD +++ b/BUILD @@ -12,5 +12,13 @@ # python_requirement('translate>=3.2.1') # ] # ) +# +# Refer to https://www.pantsbuild.org/v2.0/docs/python-third-party-dependencies. -python_requirements() +python_requirements( + # `setuptools` exposes a module different than the project name. We teach this to Pants so that + # it can correctly infer dependencies. + module_mapping={ + "setuptools": ["pkg_resources"], + }, +) diff --git a/README.md b/README.md index b8a7923..55446da 100644 --- a/README.md +++ b/README.md @@ -155,5 +155,5 @@ Try these out in this repo! ## Count lines of code ``` -./pants cloc '**/*' +./pants count-loc '**/*' ``` diff --git a/helloworld/BUILD b/helloworld/BUILD index b4b9546..791bec5 100644 --- a/helloworld/BUILD +++ b/helloworld/BUILD @@ -3,49 +3,37 @@ python_binary( # name defaults to the name of this directory, i.e., `helloworld`. - sources = ["main.py"], - entry_point = "helloworld.main", - dependencies = [ - ":config", - "//:ansicolors", - "helloworld/greet", - ], + sources=["main.py"], + entry_point="helloworld.main", ) # Note: Has sdist dependencies, so must be built on Linux. python_awslambda( - name='helloworld-awslambda', - sources = ["awslambda.py"], - dependencies=[ - ":config", - "helloworld/greet", - ], - handler='helloworld.awslambda:handler', - runtime='python3.7', + name="helloworld-awslambda", + sources=["awslambda.py"], + handler="helloworld.awslambda:handler", + runtime="python3.7", ) python_binary( - name = "helloworld_py2", - sources = ["main_py2.py"], - entry_point = "helloworld.main_py2", - compatibility = ">=2.7,<3", - dependencies = [ - "//:ansicolors", - "helloworld/greet_py2", - ], + name="helloworld_py2", + sources=["main_py2.py"], + entry_point="helloworld.main_py2", + compatibility=">=2.7,<3", ) python_library( - name = "config", - sources = ["config.py"], - dependencies = [ + name="config", + sources=["config.py"], + dependencies=[ + # Pants cannot infer dependencies on resources targets and Protobuf, so we explicitly + # add them. ":config_file", - "helloworld/util", "helloworld/util/proto", ], ) resources( - name = "config_file", - sources = ["config.json"], + name="config_file", + sources=["config.json"], ) diff --git a/helloworld/greet/BUILD b/helloworld/greet/BUILD index 75366c7..899ae49 100644 --- a/helloworld/greet/BUILD +++ b/helloworld/greet/BUILD @@ -1,19 +1,11 @@ # Copyright 2020 Pants project contributors. # Licensed under the Apache License, Version 2.0 (see LICENSE). -python_library( - # `name` defaults to the name of this directory, i.e., `greet`. - # `sources` defaults to ['*.py', '!*_test.py', '!test_*.py', '!conftest.py']. - dependencies = [ - "//:translate", - "helloworld/util", - ], -) +# `name` defaults to the name of this directory, i.e., `greet`. +# `sources` defaults to ['*.py', '!*_test.py', '!test_*.py', '!conftest.py']. +# `dependencies` are inferred. +python_library() -python_tests( - name = 'tests', - # `sources` defaults to ['*_test.py', 'test_*.py', 'conftest.py']. - dependencies = [ - ":greet", - ] -) +# `sources` defaults to ['*_test.py', 'test_*.py', 'conftest.py']. +# `dependencies` are inferred. +python_tests(name = 'tests') diff --git a/helloworld/util/BUILD b/helloworld/util/BUILD index e1c97d7..caaa0c2 100644 --- a/helloworld/util/BUILD +++ b/helloworld/util/BUILD @@ -4,6 +4,7 @@ # See https://www.pantsbuild.org/docs/python-setup-py-goal. python_distribution( name="dist", + # Because this has no source code, Pants cannot infer dependencies. dependencies=[":util"], provides=setup_py( name='helloworld.util', @@ -12,22 +13,21 @@ python_distribution( ), ) +# `name` defaults to the name of this directory, i.e., `util`. +# `sources` defaults to ['*.py', '!*_test.py', '!test_*.py', '!conftest.py']. python_library( - # `name` defaults to the name of this directory, i.e., `util`. - # `sources` defaults to ['*.py', '!*_test.py', '!test_*.py', '!conftest.py']. - dependencies=[ - "//:setuptools", - "//:translate", - "helloworld/util/proto", - ], + # Pants cannot infer dependencies on Protobuf, so we explicitly add it. + dependencies=[ + "helloworld/util/proto", + ], ) python_tests( name='tests', # `sources` defaults to ['*_test.py', 'test_*.py', 'conftest.py']. + # Pants cannot infer dependencies on `resources` targets, so we explicitly add it. dependencies=[ ":config_loader_test_data", - ":util", ], ) diff --git a/pants.toml b/pants.toml index 7269ea8..289e50c 100644 --- a/pants.toml +++ b/pants.toml @@ -27,7 +27,7 @@ root_patterns = ["/"] env_vars = ["LANG", "LC_ALL"] [python-setup] -# The default interpreter compatibility for code in this repo. Individual targets can ovverride +# The default interpreter compatibility for code in this repo. Individual targets can override # this with the `compatibility` field. See # https://www.pantsbuild.org/docs/python-interpreter-compatibility. interpreter_constraints = [">=3.7"] @@ -42,6 +42,3 @@ config = ".flake8" [isort] config = [".isort.cfg"] - -[python-infer] -imports = false From 817f5877b721ff6bc2eb664f54d6c2fe22a22837 Mon Sep 17 00:00:00 2001 From: Tom Dyas Date: Wed, 16 Sep 2020 20:08:48 -0700 Subject: [PATCH 14/96] update ./pants wrapper with PANTS_SHA support (#42) Update the ./pants wrapper to add support for specifying a main branch version of Pants via PANTS_SHA. --- pants | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/pants b/pants index e2217aa..00c0843 100755 --- a/pants +++ b/pants @@ -6,6 +6,7 @@ # This ./pants bootstrap script comes from the pantsbuild/setup # project. It is intended to be checked into your code repository so # that other developers have the same setup. + # # Learn more here: https://www.pantsbuild.org/docs/installation # ==================================================================== @@ -20,6 +21,11 @@ PYTHON_BIN_NAME="${PYTHON:-unspecified}" PANTS_INI=${PANTS_INI:-pants.ini} PANTS_TOML=${PANTS_TOML:-pants.toml} +# NOTE: To use an unreleased version of Pants from the pantsbuild/pants master branch, +# locate the master branch SHA, set PANTS_SHA= in the environment, and run this script as usual. +# +# E.g., PANTS_SHA=725fdaf504237190f6787dda3d72c39010a4c574 ./pants --version + PANTS_BIN_NAME="${PANTS_BIN_NAME:-$0}" PANTS_HOME="${PANTS_HOME:-${XDG_CACHE_HOME:-$HOME/.cache}/pants/setup}" @@ -109,6 +115,13 @@ EOF # are installed and up to date. function determine_pants_version { + + if [ -n "${PANTS_SHA:-}" ]; then + # get_version_for_sha will echo the version, thus "returning" it from this function. + get_version_for_sha "$PANTS_SHA" + return + fi + python="$1" pants_version="$(get_pants_config_value 'pants_version')" @@ -177,11 +190,36 @@ function bootstrap_venv { echo "${PANTS_BOOTSTRAP}/${VENV_PACKAGE}" } +function find_links_url { + local pants_version="$1" + local pants_sha="$2" + + echo -n "https://binaries.pantsbuild.org/wheels/pantsbuild.pants/${pants_sha}/${pants_version/+/%2B}/index.html" +} + +function get_version_for_sha { + local sha="$1" + + # Retrieve the Pants version associated with this commit. + local pants_version + pants_version="$(curl --fail -sL "https://raw.githubusercontent.com/pantsbuild/pants/${sha}/src/python/pants/VERSION")" + + # Construct the version as the release version from src/python/pants/VERSION, plus the string `+gitXXXXXXXX`, + # where the XXXXXXXX is the first 8 characters of the SHA. + echo "${pants_version}+git${sha:0:8}" +} + function bootstrap_pants { pants_version="$1" python="$2" + pants_sha="${3:-}" pants_requirement="pantsbuild.pants==${pants_version}" + if [[ -z "${pants_sha}" ]]; then + maybe_find_links="" + else + maybe_find_links="--find-links=$(find_links_url "${pants_version}" "${pants_sha}")" + fi python_major_minor_version="$(get_python_major_minor_version "${python}")" target_folder_name="${pants_version}_py${python_major_minor_version}" @@ -189,11 +227,12 @@ function bootstrap_pants { ( venv_path="$(bootstrap_venv)" staging_dir=$(tempdir "${PANTS_BOOTSTRAP}") - "${python}" "${venv_path}/virtualenv.py" --no-download "${staging_dir}/install" - "${staging_dir}/install/bin/pip" install -U pip - "${staging_dir}/install/bin/pip" install --progress-bar off "${pants_requirement}" - ln -s "${staging_dir}/install" "${staging_dir}/${target_folder_name}" - mv "${staging_dir}/${target_folder_name}" "${PANTS_BOOTSTRAP}/${target_folder_name}" + # shellcheck disable=SC2086 + "${python}" "${venv_path}/virtualenv.py" --no-download "${staging_dir}/install" && \ + "${staging_dir}/install/bin/pip" install -U pip && \ + "${staging_dir}/install/bin/pip" install ${maybe_find_links} --progress-bar off "${pants_requirement}" && \ + ln -s "${staging_dir}/install" "${staging_dir}/${target_folder_name}" && \ + mv "${staging_dir}/${target_folder_name}" "${PANTS_BOOTSTRAP}/${target_folder_name}" && \ green "New virtual environment successfully created at ${PANTS_BOOTSTRAP}/${target_folder_name}." ) 1>&2 fi @@ -204,8 +243,13 @@ function bootstrap_pants { cd "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" python="$(determine_python_exe)" pants_version="$(determine_pants_version "${python}")" -pants_dir="$(bootstrap_pants "${pants_version}" "${python}")" - +pants_dir="$(bootstrap_pants "${pants_version}" "${python}" "${PANTS_SHA:-}")" +pants_python="${pants_dir}/bin/python" +pants_binary="${pants_dir}/bin/pants" +pants_extra_args="" +if [[ -n "${PANTS_SHA:-}" ]]; then + pants_extra_args="${pants_extra_args} --python-repos-repos=$(find_links_url "$pants_version" "$PANTS_SHA")" +fi # We set the env var no_proxy to '*', to work around an issue with urllib using non # async-signal-safe syscalls after we fork a process that has already spawned threads. @@ -213,4 +257,6 @@ pants_dir="$(bootstrap_pants "${pants_version}" "${python}")" # See https://blog.phusion.nl/2017/10/13/why-ruby-app-servers-break-on-macos-high-sierra-and-what-can-be-done-about-it/ export no_proxy='*' -exec "${pants_dir}/bin/python" "${pants_dir}/bin/pants" --pants-bin-name="${PANTS_BIN_NAME}" "$@" +# shellcheck disable=SC2086 +exec "${pants_python}" "${pants_binary}" ${pants_extra_args} \ + --pants-bin-name="${PANTS_BIN_NAME}" --pants-version=${pants_version} "$@" From 34a8ac57dc3046c10581b58fa7f689b051a827d6 Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Thu, 24 Sep 2020 16:52:34 -0700 Subject: [PATCH 15/96] Upgrade to 2.0.0b1 (#44) --- pants.toml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/pants.toml b/pants.toml index 289e50c..ec6c728 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.0.0b0" +pants_version = "2.0.0b1" pantsd = true # Enable the Pants daemon for better performance. backend_packages.add = [ @@ -15,17 +15,14 @@ backend_packages.add = [ 'pants.backend.python.lint.isort', ] -# This ensures that the result of `./pants binary` is always unique. +# This ensures that the result of `./pants binary` is always unique. It will become the default in +# Pants 2.1. pants_distdir_legacy_paths = false [source] # The Python source root is the repo root. See https://www.pantsbuild.org/docs/source-roots. root_patterns = ["/"] -[subprocess-environment] -# We pass through these environment variables to subprocesses. -env_vars = ["LANG", "LC_ALL"] - [python-setup] # The default interpreter compatibility for code in this repo. Individual targets can override # this with the `compatibility` field. See From d3995bcfaf5dcb11bc96e260b0107c1f7e814185 Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Mon, 5 Oct 2020 18:43:38 -0700 Subject: [PATCH 16/96] Upgrade to 2.0.0b3 (#45) --- .travis.yml | 6 ++---- README.md | 6 +++--- pants.toml | 4 ++-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8579509..e540388 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,9 +23,7 @@ install: script: - ./pants lint test '**' # Smoke test that our release process will work. - - ./pants binary helloworld/main.py helloworld/main_py2.py + - ./pants package helloworld/main.py helloworld/main_py2.py helloworld:helloworld-awslambda - ./pants run helloworld/main.py - ./pants run helloworld/main_py2.py - # TODO: Fix PEX bug causing these to fail in CI, then reactivate when 2.0.0b1 is released. -# - ./pants setup-py --args="bdist_wheel" helloworld/util:dist -# - ./pants awslambda helloworld:helloworld-awslambda + - ./pants setup-py --args="bdist_wheel" helloworld/util:dist diff --git a/README.md b/README.md index 55446da..9f816d9 100644 --- a/README.md +++ b/README.md @@ -119,10 +119,10 @@ Try these out in this repo! ./pants test helloworld/util/lang_test.py -- -k test_language_translator # Run just this one test. ``` -## Create a runnable binary +## Create a PEX binary ``` -./pants binary helloworld/main.py helloworld/main_py2.py +./pants package helloworld/main.py helloworld/main_py2.py ``` ## Run a binary @@ -149,7 +149,7 @@ Try these out in this repo! (This example only works on Linux because it has an sdist. See https://www.pantsbuild.org/docs/awslambda-python.) ``` -./pants awslambda helloworld:helloworld-awslambda +./pants package helloworld:helloworld-awslambda ``` ## Count lines of code diff --git a/pants.toml b/pants.toml index ec6c728..7737ddc 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.0.0b1" +pants_version = "2.0.0b3" pantsd = true # Enable the Pants daemon for better performance. backend_packages.add = [ @@ -15,7 +15,7 @@ backend_packages.add = [ 'pants.backend.python.lint.isort', ] -# This ensures that the result of `./pants binary` is always unique. It will become the default in +# This ensures that the result of `./pants package` is always unique. It will become the default in # Pants 2.1. pants_distdir_legacy_paths = false From 87a6541614e9fc626007451da904acf7ca70a6ee Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Mon, 12 Oct 2020 13:00:45 -0700 Subject: [PATCH 17/96] Upgrade to 2.0.0rc0 (#46) --- .travis.yml | 6 ++---- README.md | 21 +++++++++++++++++++-- helloworld/BUILD | 4 ++-- helloworld/util/BUILD | 1 + pants.toml | 7 ++++--- 5 files changed, 28 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index e540388..038c4ed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,9 +21,7 @@ install: - ./pants --version # This will bootstrap Pants script: - - ./pants lint test '**' - # Smoke test that our release process will work. - - ./pants package helloworld/main.py helloworld/main_py2.py helloworld:helloworld-awslambda + # We also smoke test that our release process will work by running `package`. + - ./pants lint test package '::' - ./pants run helloworld/main.py - ./pants run helloworld/main_py2.py - - ./pants setup-py --args="bdist_wheel" helloworld/util:dist diff --git a/README.md b/README.md index 9f816d9..cc03add 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,18 @@ If you want Pants itself to expand the globs (which is sometimes necessary), you ./pants lint 'helloworld/util/*.py' ``` +You can run on all changed files: + +``` +./pants --changed-since=HEAD lint +``` + +You can run on all changed files, and any of their "dependees": + +``` +./pants --changed-since=HEAD --changed-dependees=transitive test +``` + ## Target specifications Targets are referenced on the command line using their address, of the form `path/to/dir:name`, e.g., @@ -138,12 +150,17 @@ Try these out in this repo! ./pants repl --shell=ipython helloworld/greet ``` -## Run `setup.py` commands +## Build a wheel / generate `setup.py` + +This will build both a `.whl` bdist and a `.tar.gz` sdist. ``` -./pants setup-py --args="bdist_wheel" helloworld/util:dist # Build a wheel. +./pants package helloworld/util:dist ``` +We can also remove the `setup_py_commands` field from `helloworld/util/BUILD` to have Pants instead generate a +`setup.py` file, with all the relevant code in a chroot. + ## Build an AWS Lambda (This example only works on Linux because it has an sdist. See https://www.pantsbuild.org/docs/awslambda-python.) diff --git a/helloworld/BUILD b/helloworld/BUILD index 791bec5..a01a1b4 100644 --- a/helloworld/BUILD +++ b/helloworld/BUILD @@ -1,7 +1,7 @@ # Copyright 2020 Pants project contributors. # Licensed under the Apache License, Version 2.0 (see LICENSE). -python_binary( +pex_binary( # name defaults to the name of this directory, i.e., `helloworld`. sources=["main.py"], entry_point="helloworld.main", @@ -15,7 +15,7 @@ python_awslambda( runtime="python3.7", ) -python_binary( +pex_binary( name="helloworld_py2", sources=["main_py2.py"], entry_point="helloworld.main_py2", diff --git a/helloworld/util/BUILD b/helloworld/util/BUILD index caaa0c2..12d83e0 100644 --- a/helloworld/util/BUILD +++ b/helloworld/util/BUILD @@ -6,6 +6,7 @@ python_distribution( name="dist", # Because this has no source code, Pants cannot infer dependencies. dependencies=[":util"], + setup_py_commands=["bdist_wheel", "sdist"], provides=setup_py( name='helloworld.util', version='0.0.1', diff --git a/pants.toml b/pants.toml index 7737ddc..0464aec 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.0.0b3" +pants_version = "2.0.0rc0" pantsd = true # Enable the Pants daemon for better performance. backend_packages.add = [ @@ -31,8 +31,9 @@ interpreter_constraints = [">=3.7"] # Use a lockfile. See https://www.pantsbuild.org/docs/python-third-party-dependencies. requirement_constraints = "constraints.txt" -[protoc] -runtime_targets = ["//:protobuf"] +[python-protobuf] +# See https://www.pantsbuild.org/docs/protobuf. +runtime_dependencies = ["//:protobuf"] [flake8] config = ".flake8" From aa33babb4790cbfe544115b6505eaaf673e67770 Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Mon, 12 Oct 2020 15:10:19 -0700 Subject: [PATCH 18/96] Enable MyPy (#47) This shows off the MyPy Protobuf plugin and partitioning based on interpreter constraints. --- .travis.yml | 2 +- README.md | 10 +++++++-- .flake8 => build-support/.flake8 | 0 build-support/mypy.ini | 34 +++++++++++++++++++++++++++++++ helloworld/greet/__init__.py | 0 helloworld/main.py | 4 +++- helloworld/util/__init__.py | 0 helloworld/util/lang.py | 4 ++-- helloworld/util/proto/BUILD | 12 ++++++++++- helloworld/util/proto/__init__.py | 0 pants.toml | 7 ++++++- 11 files changed, 65 insertions(+), 8 deletions(-) rename .flake8 => build-support/.flake8 (100%) create mode 100644 build-support/mypy.ini create mode 100644 helloworld/greet/__init__.py create mode 100644 helloworld/util/__init__.py create mode 100644 helloworld/util/proto/__init__.py diff --git a/.travis.yml b/.travis.yml index 038c4ed..55bccf3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,6 +22,6 @@ install: script: # We also smoke test that our release process will work by running `package`. - - ./pants lint test package '::' + - ./pants lint typecheck test package '::' - ./pants run helloworld/main.py - ./pants run helloworld/main_py2.py diff --git a/README.md b/README.md index cc03add..59e2d8f 100644 --- a/README.md +++ b/README.md @@ -111,17 +111,23 @@ Try these out in this repo! ## List targets ``` -./pants list helloworld:: # All targets. +./pants list :: # All targets. ./pants list 'helloworld/**/*.py' # Just targets containing Python code. ``` ## Run linters and formatters ``` -./pants lint helloworld:: +./pants lint :: ./pants fmt 'helloworld/**/*.py' ``` +## Run MyPy + +``` +./pants typecheck :: +``` + ## Run tests ``` diff --git a/.flake8 b/build-support/.flake8 similarity index 100% rename from .flake8 rename to build-support/.flake8 diff --git a/build-support/mypy.ini b/build-support/mypy.ini new file mode 100644 index 0000000..1ffad0c --- /dev/null +++ b/build-support/mypy.ini @@ -0,0 +1,34 @@ +[mypy] +# Optionals +no_implicit_optional = True + +# Strictness +allow_untyped_globals = False +allow_redefinition = False +implicit_reexport = False +strict_equality = True + +# Warnings +warn_unused_ignores = True +warn_no_return = True +warn_return_any = True +warn_redundant_casts = True +warn_unreachable = True + +# Error output +show_column_numbers = True +show_error_context = True +show_error_codes = True +show_traceback = True +pretty = True +color_output = True +error_summary = True + +[mypy-colors] +ignore_missing_imports = True + +[mypy-translate] +ignore_missing_imports = True + +[mypy-pytest] +ignore_missing_imports = True diff --git a/helloworld/greet/__init__.py b/helloworld/greet/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/helloworld/main.py b/helloworld/main.py index 42164cc..8353e58 100644 --- a/helloworld/main.py +++ b/helloworld/main.py @@ -9,7 +9,9 @@ def say_hello() -> None: config = load_config() - greeter = Greeter(languages=config.languages, greetings=config.greetings) + greeter = Greeter( + languages=list(config.languages), greetings=list(config.greetings) + ) sentence = greeter.greet("world") print(green(sentence)) diff --git a/helloworld/util/__init__.py b/helloworld/util/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/helloworld/util/lang.py b/helloworld/util/lang.py index 3a75cab..9fc49fe 100644 --- a/helloworld/util/lang.py +++ b/helloworld/util/lang.py @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). import random -from typing import List +from typing import List, cast from translate import Translator @@ -18,7 +18,7 @@ def translate(self, lang: str, phrase: str) -> str: if lang not in self._langs: raise self.UnknownLanguage(lang) translator = Translator(lang) - return translator.translate(phrase) + return cast(str, translator.translate(phrase)) def translate_to_random_language(self, phrase: str) -> str: return self.translate(self._pick_random_language(), phrase) diff --git a/helloworld/util/proto/BUILD b/helloworld/util/proto/BUILD index 3ddf1d9..804b18d 100644 --- a/helloworld/util/proto/BUILD +++ b/helloworld/util/proto/BUILD @@ -3,4 +3,14 @@ # `name` defaults to the name of this directory, i.e., `proto`. # `sources` defaults to ["*.proto"]. -protobuf_library() +protobuf_library(dependencies=[":init"]) + + +# Note that we need an `__init__.py` file for MyPy to recognize our generated code as a valid +# module. We include this in the dependencies for the `protobuf_library` to ensure the +# `__init__.py` is always used. +# +# Often, you won't want to put `__init__.py` files in your Protobuf directories; see +# https://www.pantsbuild.org/docs/protobuf#protobuf-and-source-roots for how to change where the +# protobuf code is generated. +python_library(name="init") diff --git a/helloworld/util/proto/__init__.py b/helloworld/util/proto/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pants.toml b/pants.toml index 0464aec..56b8205 100644 --- a/pants.toml +++ b/pants.toml @@ -13,6 +13,7 @@ backend_packages.add = [ 'pants.backend.python.lint.black', 'pants.backend.python.lint.flake8', 'pants.backend.python.lint.isort', + 'pants.backend.python.typecheck.mypy', ] # This ensures that the result of `./pants package` is always unique. It will become the default in @@ -34,9 +35,13 @@ requirement_constraints = "constraints.txt" [python-protobuf] # See https://www.pantsbuild.org/docs/protobuf. runtime_dependencies = ["//:protobuf"] +mypy_plugin = true [flake8] -config = ".flake8" +config = "build-support/.flake8" [isort] config = [".isort.cfg"] + +[mypy] +config = "build-support/mypy.ini" From 2c70da334dee6176f0c24dbdf6e84aa5cc0e3c18 Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Fri, 16 Oct 2020 09:59:00 -0700 Subject: [PATCH 19/96] Upgrade to 2.0.0rc1 (#48) This corresponds to an updated entry for https://www.pantsbuild.org/docs/python-interpreter-compatibility#changing-the-interpreter-search-path. --- pants.toml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pants.toml b/pants.toml index 56b8205..b1a0baa 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.0.0rc0" +pants_version = "2.0.0rc1" pantsd = true # Enable the Pants daemon for better performance. backend_packages.add = [ @@ -31,6 +31,11 @@ root_patterns = ["/"] interpreter_constraints = [">=3.7"] # Use a lockfile. See https://www.pantsbuild.org/docs/python-third-party-dependencies. requirement_constraints = "constraints.txt" +# We search for interpreters on both on the $PATH and in the `$(pyenv root)/versions` folder. +# If you're using macOS, you may want to leave off the entry to avoid using the +# problematic system Pythons. See +# https://www.pantsbuild.org/docs/python-interpreter-compatibility#changing-the-interpreter-search-path. +interpreter_search_paths = ["", ""] [python-protobuf] # See https://www.pantsbuild.org/docs/protobuf. From f74707e2e2cd3356fa4004c652fdd848c40b9bf3 Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Thu, 22 Oct 2020 20:18:01 -0700 Subject: [PATCH 20/96] Upgrade to 2.0.0rc2 (#49) --- README.md | 2 +- pants.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 59e2d8f..a65c1a8 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ in `pants.toml`). Pants commands are called _goals_. You can get a list of goals with ``` -./pants goals +./pants help goals ``` # Targets diff --git a/pants.toml b/pants.toml index b1a0baa..093a184 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.0.0rc1" +pants_version = "2.0.0rc2" pantsd = true # Enable the Pants daemon for better performance. backend_packages.add = [ From ef09756c187c1e629ed29a41c3d2e1bed6e66e03 Mon Sep 17 00:00:00 2001 From: Stu Hood Date: Mon, 26 Oct 2020 14:47:00 -0700 Subject: [PATCH 21/96] Bump to 2.0.0rc3. (#50) --- pants.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pants.toml b/pants.toml index 093a184..31d53da 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.0.0rc2" +pants_version = "2.0.0rc3" pantsd = true # Enable the Pants daemon for better performance. backend_packages.add = [ From 72890abf9426c9744d9e2537f898fb6c2bb17216 Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Tue, 27 Oct 2020 14:37:53 -0700 Subject: [PATCH 22/96] Upgrade to 2.0.0 (#51) --- pants.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pants.toml b/pants.toml index 31d53da..728949f 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.0.0rc3" +pants_version = "2.0.0" pantsd = true # Enable the Pants daemon for better performance. backend_packages.add = [ From 4d3caad35d6a0592069c86f6832c1e5f81c343cc Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Wed, 11 Nov 2020 11:42:48 -0700 Subject: [PATCH 23/96] Upgrade to 2.1.0rc0 (#52) --- helloworld/BUILD | 2 +- helloworld/greet_py2/BUILD | 2 +- pants.toml | 29 ++++++++++++++--------------- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/helloworld/BUILD b/helloworld/BUILD index a01a1b4..074f433 100644 --- a/helloworld/BUILD +++ b/helloworld/BUILD @@ -19,7 +19,7 @@ pex_binary( name="helloworld_py2", sources=["main_py2.py"], entry_point="helloworld.main_py2", - compatibility=">=2.7,<3", + interpreter_constraints=["==2.7.*"], ) python_library( diff --git a/helloworld/greet_py2/BUILD b/helloworld/greet_py2/BUILD index de883c7..46e5d91 100644 --- a/helloworld/greet_py2/BUILD +++ b/helloworld/greet_py2/BUILD @@ -5,5 +5,5 @@ python_library( # name defaults to the name of this directory, i.e., `greet_py2`. # sources defaults to ['*.py', '!*_test.py', '!test_*.py', '!conftest.py']. - compatibility = ">=2.7,<3" + interpreter_constraints=["==2.7.*"], ) diff --git a/pants.toml b/pants.toml index 728949f..5e164d4 100644 --- a/pants.toml +++ b/pants.toml @@ -2,34 +2,33 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.0.0" +pants_version = "2.1.0rc0" pantsd = true # Enable the Pants daemon for better performance. backend_packages.add = [ - 'pants.backend.awslambda.python', - 'pants.backend.codegen.protobuf.python', - 'pants.backend.python', - 'pants.backend.python.lint.docformatter', - 'pants.backend.python.lint.black', - 'pants.backend.python.lint.flake8', - 'pants.backend.python.lint.isort', - 'pants.backend.python.typecheck.mypy', + "pants.backend.awslambda.python", + "pants.backend.codegen.protobuf.python", + "pants.backend.python", + "pants.backend.python.lint.docformatter", + "pants.backend.python.lint.black", + "pants.backend.python.lint.flake8", + "pants.backend.python.lint.isort", + "pants.backend.python.typecheck.mypy", + # Adds the `py-constraints` goal, as this example repository has + # both Python 2 and Python 3 code. + "pants.backend.python.mixed_interpreter_constraints", ] -# This ensures that the result of `./pants package` is always unique. It will become the default in -# Pants 2.1. -pants_distdir_legacy_paths = false - [source] # The Python source root is the repo root. See https://www.pantsbuild.org/docs/source-roots. root_patterns = ["/"] [python-setup] # The default interpreter compatibility for code in this repo. Individual targets can override -# this with the `compatibility` field. See +# this with the `interpreter_constraints` field. See # https://www.pantsbuild.org/docs/python-interpreter-compatibility. interpreter_constraints = [">=3.7"] -# Use a lockfile. See https://www.pantsbuild.org/docs/python-third-party-dependencies. +# Use a constraints file. See https://www.pantsbuild.org/docs/python-third-party-dependencies. requirement_constraints = "constraints.txt" # We search for interpreters on both on the $PATH and in the `$(pyenv root)/versions` folder. # If you're using macOS, you may want to leave off the entry to avoid using the From c8360d2e16a49f07714534d26f58ca3095ef8f00 Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Thu, 12 Nov 2020 17:37:14 -0700 Subject: [PATCH 24/96] Update to the latest `./pants` script (#53) This prepares us for 2.2 removing support for running with Py36. --- pants | 139 +++++++++++++++++++++++++++++++++------------------------- 1 file changed, 80 insertions(+), 59 deletions(-) diff --git a/pants b/pants index 00c0843..7f7ad8e 100755 --- a/pants +++ b/pants @@ -6,35 +6,33 @@ # This ./pants bootstrap script comes from the pantsbuild/setup # project. It is intended to be checked into your code repository so # that other developers have the same setup. - # # Learn more here: https://www.pantsbuild.org/docs/installation # ==================================================================== set -eou pipefail +# NOTE: To use an unreleased version of Pants from the pantsbuild/pants master branch, +# locate the master branch SHA, set PANTS_SHA= in the environment, and run this script as usual. +# +# E.g., PANTS_SHA=725fdaf504237190f6787dda3d72c39010a4c574 ./pants --version + PYTHON_BIN_NAME="${PYTHON:-unspecified}" -# Set one of these to specify a non-standard location for this script to read the pants version from. +# Set this to specify a non-standard location for this script to read the Pants version from. # NB: This will *not* cause Pants itself to use this location as a config file. # You can use PANTS_CONFIG_FILES or --pants-config-files to do so. -PANTS_INI=${PANTS_INI:-pants.ini} PANTS_TOML=${PANTS_TOML:-pants.toml} -# NOTE: To use an unreleased version of Pants from the pantsbuild/pants master branch, -# locate the master branch SHA, set PANTS_SHA= in the environment, and run this script as usual. -# -# E.g., PANTS_SHA=725fdaf504237190f6787dda3d72c39010a4c574 ./pants --version - PANTS_BIN_NAME="${PANTS_BIN_NAME:-$0}" -PANTS_HOME="${PANTS_HOME:-${XDG_CACHE_HOME:-$HOME/.cache}/pants/setup}" +PANTS_SETUP_CACHE="${PANTS_SETUP_CACHE:-${XDG_CACHE_HOME:-$HOME/.cache}/pants/setup}" # If given a relative path, we fix it to be absolute. -if [[ "$PANTS_HOME" != /* ]]; then - PANTS_HOME="${PWD}/${PANTS_HOME}" +if [[ "$PANTS_SETUP_CACHE" != /* ]]; then + PANTS_SETUP_CACHE="${PWD}/${PANTS_SETUP_CACHE}" fi -PANTS_BOOTSTRAP="${PANTS_HOME}/bootstrap-$(uname -s)-$(uname -m)" +PANTS_BOOTSTRAP="${PANTS_SETUP_CACHE}/bootstrap-$(uname -s)-$(uname -m)" VENV_VERSION=${VENV_VERSION:-16.4.3} @@ -63,38 +61,24 @@ function tempdir { } function get_exe_path_or_die { - exe="$1" + local exe="$1" if ! command -v "${exe}"; then die "Could not find ${exe}. Please ensure ${exe} is on your PATH." fi } -pants_config_file="" -if [[ -f "${PANTS_INI}" ]]; then - pants_config_file="${PANTS_INI}" -fi -if [[ -f "${PANTS_TOML}" ]]; then - pants_config_file="${PANTS_TOML}" -fi - function get_pants_config_value { - config_key="$1" - optional_space="[[:space:]]*" - if [[ "${pants_config_file}" == *.ini ]]; then - valid_delimiters="[:=]" - prefix="^${config_key}${optional_space}${valid_delimiters}${optional_space}" - sed -ne "/${prefix}/ s#${prefix}##p" "${PANTS_INI}" && return 0 - fi - if [[ "${pants_config_file}" == *.toml ]]; then - prefix="^${config_key}${optional_space}=${optional_space}" - raw_value="$(sed -ne "/${prefix}/ s#${prefix}##p" "${PANTS_TOML}")" - echo "${raw_value}" | tr -d \"\' && return 0 - fi + local config_key="$1" + local optional_space="[[:space:]]*" + local prefix="^${config_key}${optional_space}=${optional_space}" + local raw_value + raw_value="$(sed -ne "/${prefix}/ s#${prefix}##p" "${PANTS_TOML}")" + echo "${raw_value}" | tr -d \"\' && return 0 return 0 } function get_python_major_minor_version { - python_exe="$1" + local python_exe="$1" "$python_exe" < Date: Thu, 12 Nov 2020 20:33:00 -0700 Subject: [PATCH 25/96] Stop using `sources` field for `python_awslambda` (#54) --- helloworld/BUILD | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/helloworld/BUILD b/helloworld/BUILD index 074f433..4329962 100644 --- a/helloworld/BUILD +++ b/helloworld/BUILD @@ -7,14 +7,6 @@ pex_binary( entry_point="helloworld.main", ) -# Note: Has sdist dependencies, so must be built on Linux. -python_awslambda( - name="helloworld-awslambda", - sources=["awslambda.py"], - handler="helloworld.awslambda:handler", - runtime="python3.7", -) - pex_binary( name="helloworld_py2", sources=["main_py2.py"], @@ -22,6 +14,19 @@ pex_binary( interpreter_constraints=["==2.7.*"], ) +python_library( + name="awslambda_lib", + sources=["awslambda.py"], +) + +# Note: This has sdist dependencies, so it must be built on Linux. +python_awslambda( + name="helloworld-awslambda", + dependencies=[":awslambda_lib"], + handler="helloworld.awslambda:handler", + runtime="python3.7", +) + python_library( name="config", sources=["config.py"], From 5bcef28475cc6e9d3784e8c8c15cc91c00b697a1 Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Tue, 17 Nov 2020 16:16:50 -0700 Subject: [PATCH 26/96] Upgrade to 2.1.0 (#55) --- README.md | 6 +++++- pants.toml | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a65c1a8..6074d0f 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,10 @@ An example repository to demonstrate Python support in Pants. See [pantsbuild.org](https://www.pantsbuild.org/docs) for much more detailed documentation. +This is only one possible way of laying out your project with Pants. See +[pantsbuild.org/docs/source-roots#examples](https://www.pantsbuild.org/docs/source-roots#examples) for some other +example layouts. + # Running Pants You run Pants goals using the `./pants` wrapper script, which will bootstrap the @@ -23,7 +27,7 @@ Pants commands are called _goals_. You can get a list of goals with Targets are sets of source files with some attached metadata. Targets are provided in `BUILD` files. Targets have types, such as `python_library`, `resources`, `python_binary`. Examples of metadata include -dependencies on other targets, Python version compatibility, entry points for binaries, and so on. +timeouts for tests, Python interpreter constraints, entry points for binaries, and so on. Pants goals can be invoked on targets or directly on source files/directories (which is often more intuitive and convenient). In the latter case, Pants locates target metadata for the source files as needed. diff --git a/pants.toml b/pants.toml index 5e164d4..2ab2cc0 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.1.0rc0" +pants_version = "2.1.0" pantsd = true # Enable the Pants daemon for better performance. backend_packages.add = [ From 2a6f66ce8a4557d4867b39accfca171d7262bb76 Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Tue, 24 Nov 2020 15:01:22 -0700 Subject: [PATCH 27/96] Remove Python 2 (#56) Demonstrating Python 2 is no longer pulling its weight. Python 2 interpreters are becoming harder to come by, and there are some issues with it like PyYAML failing to be built on macOS Big Sur when using a Python 2 interpreter. Instead, we might want a dedicated example repo for Python 2 -> 3 repos. It can be more focused, such as not showing off Protobuf. --- .travis.yml | 1 - BUILD | 14 ++++----- README.md | 2 +- build-support/generate_constraints.sh | 7 ----- constraints.txt | 20 +++++------- helloworld/BUILD | 17 ++--------- helloworld/greet_py2/BUILD | 9 ------ helloworld/greet_py2/__init__.py | 0 helloworld/greet_py2/greeting_py2.py | 7 ----- helloworld/main_py2.py | 14 --------- helloworld/util/BUILD | 44 ++++++++++++--------------- helloworld/util/proto/BUILD | 15 +++------ pants.toml | 3 -- 13 files changed, 44 insertions(+), 109 deletions(-) delete mode 100644 helloworld/greet_py2/BUILD delete mode 100644 helloworld/greet_py2/__init__.py delete mode 100644 helloworld/greet_py2/greeting_py2.py delete mode 100644 helloworld/main_py2.py diff --git a/.travis.yml b/.travis.yml index 55bccf3..1ad9a9e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,4 +24,3 @@ script: # We also smoke test that our release process will work by running `package`. - ./pants lint typecheck test package '::' - ./pants run helloworld/main.py - - ./pants run helloworld/main_py2.py diff --git a/BUILD b/BUILD index 932d9e4..9c0a8bc 100644 --- a/BUILD +++ b/BUILD @@ -6,19 +6,19 @@ # with the name of the corresponding dist. # # For example, `translate>=3.2.1` expands to: +# # python_requirement_library( # name='translate', -# requirements=[ -# python_requirement('translate>=3.2.1') -# ] +# requirements=['translate>=3.2.1'] # ) # -# Refer to https://www.pantsbuild.org/v2.0/docs/python-third-party-dependencies. - +# We set `module_mapping` for any requirements whose module names differ from the project's name so that dependency +# inference works. +# +# Refer to https://www.pantsbuild.org/docs/python-third-party-dependencies. python_requirements( - # `setuptools` exposes a module different than the project name. We teach this to Pants so that - # it can correctly infer dependencies. module_mapping={ + "ansicolors": ["colors"], "setuptools": ["pkg_resources"], }, ) diff --git a/README.md b/README.md index 6074d0f..ff235f6 100644 --- a/README.md +++ b/README.md @@ -144,7 +144,7 @@ Try these out in this repo! ## Create a PEX binary ``` -./pants package helloworld/main.py helloworld/main_py2.py +./pants package helloworld/main.py ``` ## Run a binary diff --git a/build-support/generate_constraints.sh b/build-support/generate_constraints.sh index d4d352c..dbaf0d8 100755 --- a/build-support/generate_constraints.sh +++ b/build-support/generate_constraints.sh @@ -16,10 +16,3 @@ CONSTRAINTS_FILE=constraints.txt "${PIP}" install -r <(./pants dependencies --type=3rdparty ::) echo "# Generated by build-support/generate_constraints.sh on $(date)" > "${CONSTRAINTS_FILE}" "${PIP}" freeze --all >> "${CONSTRAINTS_FILE}" - -# This example repo includes some Python 2-only code for demonstration. Because we generated -# the constraints using Python 3.7, we must manually ensure things still work with Python 2.7. So, -# we warn to the user that they should check the diff. You can delete this if you don't use Python 2. -echo "Check the diff for ${CONSTRAINTS_FILE} and restore any entries that were specific to" \ - "Python 2, i.e. entries ending in \`python_version == '2.7'\`. Those are needed for Python 2 to" \ - "work properly, and this script will overwrite it." 1>&2 diff --git a/constraints.txt b/constraints.txt index 2e7e886..2226fae 100644 --- a/constraints.txt +++ b/constraints.txt @@ -1,36 +1,32 @@ -# Generated by build-support/generate_constraints.sh on Wed Sep 16 11:30:54 MST 2020 +# Generated by build-support/generate_constraints.sh on Tue Nov 24 13:57:41 MST 2020 ansicolors==1.1.8 appdirs==1.4.4 certifi==2020.6.20 -cfgv==2.0.1 ; python_version == '2.7' -cfgv==3.1.0 ; python_version > '2.7' +cfgv==3.2.0 chardet==3.0.4 click==7.1.2 distlib==0.3.1 filelock==3.0.12 -identify==1.5.2 +identify==1.5.5 idna==2.10 importlib-metadata==1.7.0 importlib-resources==3.0.0 lxml==4.5.2 nodeenv==1.5.0 packaging==20.4 -pip==20.2.3 +pip==20.2.4 pluggy==0.13.1 -pre-commit==1.21.0 ; python_version == '2.7' -pre-commit==2.7.1 ; python_version > '2.7' +pre-commit==2.7.1 protobuf==3.13.0 py==1.9.0 pyparsing==2.4.7 PyYAML==5.3.1 requests==2.24.0 -setuptools==44.1.1 ; python_version == '2.7' -setuptools==50.3.0 ; python_version > '2.7' +setuptools==50.3.0 six==1.15.0 toml==0.10.1 tox==3.20.0 translate==3.5.0 urllib3==1.25.10 -virtualenv==20.0.31 -zipp==1.2.0 ; python_version == '2.7' -zipp==3.1.0 ; python_version > '2.7' +virtualenv==20.0.33 +zipp==3.3.0 diff --git a/helloworld/BUILD b/helloworld/BUILD index 4329962..357f004 100644 --- a/helloworld/BUILD +++ b/helloworld/BUILD @@ -1,19 +1,12 @@ # Copyright 2020 Pants project contributors. # Licensed under the Apache License, Version 2.0 (see LICENSE). +# `name` defaults to the name of this directory, i.e., `helloworld`. pex_binary( - # name defaults to the name of this directory, i.e., `helloworld`. sources=["main.py"], entry_point="helloworld.main", ) -pex_binary( - name="helloworld_py2", - sources=["main_py2.py"], - entry_point="helloworld.main_py2", - interpreter_constraints=["==2.7.*"], -) - python_library( name="awslambda_lib", sources=["awslambda.py"], @@ -27,15 +20,11 @@ python_awslambda( runtime="python3.7", ) +# Pants cannot infer dependencies on resources targets and Protobuf, so we explicitly add them. python_library( name="config", sources=["config.py"], - dependencies=[ - # Pants cannot infer dependencies on resources targets and Protobuf, so we explicitly - # add them. - ":config_file", - "helloworld/util/proto", - ], + dependencies=[":config_file", "helloworld/util/proto"], ) resources( diff --git a/helloworld/greet_py2/BUILD b/helloworld/greet_py2/BUILD deleted file mode 100644 index 46e5d91..0000000 --- a/helloworld/greet_py2/BUILD +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright 2020 Pants project contributors. -# Licensed under the Apache License, Version 2.0 (see LICENSE). - - -python_library( - # name defaults to the name of this directory, i.e., `greet_py2`. - # sources defaults to ['*.py', '!*_test.py', '!test_*.py', '!conftest.py']. - interpreter_constraints=["==2.7.*"], -) diff --git a/helloworld/greet_py2/__init__.py b/helloworld/greet_py2/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/helloworld/greet_py2/greeting_py2.py b/helloworld/greet_py2/greeting_py2.py deleted file mode 100644 index f030eb4..0000000 --- a/helloworld/greet_py2/greeting_py2.py +++ /dev/null @@ -1,7 +0,0 @@ -# Copyright 2020 Pants project contributors. -# Licensed under the Apache License, Version 2.0 (see LICENSE). - - -def greet_py2(name): - exec "x = 'hello, {}'.format(name)" - return x # noqa diff --git a/helloworld/main_py2.py b/helloworld/main_py2.py deleted file mode 100644 index 588a2b4..0000000 --- a/helloworld/main_py2.py +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright 2020 Pants project contributors. -# Licensed under the Apache License, Version 2.0 (see LICENSE). - -from colors import green - -from helloworld.greet_py2.greeting_py2 import greet_py2 - - -def say_hello_py2(): - print green(greet_py2("Python 2")) - - -if __name__ == "__main__": - say_hello_py2() diff --git a/helloworld/util/BUILD b/helloworld/util/BUILD index 12d83e0..86761cb 100644 --- a/helloworld/util/BUILD +++ b/helloworld/util/BUILD @@ -1,38 +1,34 @@ # Copyright 2020 Pants project contributors. # Licensed under the Apache License, Version 2.0 (see LICENSE). -# See https://www.pantsbuild.org/docs/python-setup-py-goal. -python_distribution( - name="dist", - # Because this has no source code, Pants cannot infer dependencies. - dependencies=[":util"], - setup_py_commands=["bdist_wheel", "sdist"], - provides=setup_py( - name='helloworld.util', - version='0.0.1', - description='Greeting library utilities.', - ), -) - # `name` defaults to the name of this directory, i.e., `util`. # `sources` defaults to ['*.py', '!*_test.py', '!test_*.py', '!conftest.py']. +# `dependencies` is set because only Pants 2.2+ can infer dependencies on Protobuf. python_library( - # Pants cannot infer dependencies on Protobuf, so we explicitly add it. - dependencies=[ - "helloworld/util/proto", - ], + dependencies=["helloworld/util/proto"], ) +# `sources` defaults to ['*_test.py', 'test_*.py', 'conftest.py']. +# Pants cannot infer dependencies on `resources` targets, so we explicitly add the dep. python_tests( name='tests', - # `sources` defaults to ['*_test.py', 'test_*.py', 'conftest.py']. - # Pants cannot infer dependencies on `resources` targets, so we explicitly add it. - dependencies=[ - ":config_loader_test_data", - ], + dependencies=[":test_data"], ) resources( - name='config_loader_test_data', - sources=['config_loader_test_data.json'], + name='test_data', + sources=['*_test_data.json'], +) + +# See https://www.pantsbuild.org/docs/python-distributions. +# Because this target has no source code, Pants cannot infer dependencies. +python_distribution( + name="dist", + dependencies=[":util"], + setup_py_commands=["bdist_wheel", "sdist"], + provides=setup_py( + name='helloworld.util', + version='0.0.1', + description='Greeting library utilities.', + ), ) diff --git a/helloworld/util/proto/BUILD b/helloworld/util/proto/BUILD index 804b18d..bb4d6dc 100644 --- a/helloworld/util/proto/BUILD +++ b/helloworld/util/proto/BUILD @@ -3,14 +3,9 @@ # `name` defaults to the name of this directory, i.e., `proto`. # `sources` defaults to ["*.proto"]. -protobuf_library(dependencies=[":init"]) +protobuf_library() - -# Note that we need an `__init__.py` file for MyPy to recognize our generated code as a valid -# module. We include this in the dependencies for the `protobuf_library` to ensure the -# `__init__.py` is always used. -# -# Often, you won't want to put `__init__.py` files in your Protobuf directories; see -# https://www.pantsbuild.org/docs/protobuf#protobuf-and-source-roots for how to change where the -# protobuf code is generated. -python_library(name="init") +# Note that we have an empty `__init__.py` file in this folder. Pants will generate +# `helloworld/util/proto/config_pb2.py`, and we need an `__init__.py` file in the folder for that file to be properly +# recognized. Pants will automatically use this `__init__.py` file if it exists, even though we don't have a +# `python_library` target here. diff --git a/pants.toml b/pants.toml index 2ab2cc0..5e89e39 100644 --- a/pants.toml +++ b/pants.toml @@ -14,9 +14,6 @@ backend_packages.add = [ "pants.backend.python.lint.flake8", "pants.backend.python.lint.isort", "pants.backend.python.typecheck.mypy", - # Adds the `py-constraints` goal, as this example repository has - # both Python 2 and Python 3 code. - "pants.backend.python.mixed_interpreter_constraints", ] [source] From 55a48bbd530207ddf2691cefc8bb89bf078183ca Mon Sep 17 00:00:00 2001 From: Stu Hood Date: Fri, 18 Dec 2020 13:42:49 -0800 Subject: [PATCH 28/96] Bump to 2.1.1. (#58) --- pants.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pants.toml b/pants.toml index 5e89e39..d3fe2ab 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.1.0" +pants_version = "2.1.1" pantsd = true # Enable the Pants daemon for better performance. backend_packages.add = [ From 5e76f94ccabddac74b622dbb9087fc7fd2d8ba17 Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Mon, 1 Feb 2021 13:41:49 -0700 Subject: [PATCH 29/96] Upgrade to 2.2 and improve explanation of targets (#61) Thanks to 2.2, we can now use the simplified design for `pex_binary` and `python_awslambda`. They no longer have `sources` fields, but have fields that act like it. We can also simplify thanks to dep inference for Protobuf. In the process, we do a better job explaining what each target is precisely doing. This is easier to do now that we have cleared up the responsibility of each target type. --- README.md | 10 ++++---- helloworld/BUILD | 47 ++++++++++++++++++++----------------- helloworld/greet/BUILD | 16 ++++++++----- helloworld/util/BUILD | 27 +++++++++++++-------- helloworld/util/proto/BUILD | 7 ++++-- pants.toml | 2 +- 6 files changed, 63 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index ff235f6..fe086bf 100644 --- a/README.md +++ b/README.md @@ -25,11 +25,11 @@ Pants commands are called _goals_. You can get a list of goals with # Targets -Targets are sets of source files with some attached metadata. Targets are provided in `BUILD` files. -Targets have types, such as `python_library`, `resources`, `python_binary`. Examples of metadata include -timeouts for tests, Python interpreter constraints, entry points for binaries, and so on. +Targets are a way of setting metadata for some part of your code, such as timeouts for tests and +entry points for binaries. Targets have types like `python_binary`, `resources`, and +`pex_binary`. They are defined in `BUILD` files. -Pants goals can be invoked on targets or directly on source files/directories (which is often more intuitive and convenient). +Pants goals can be invoked on targets or directly on source files (which is often more intuitive and convenient). In the latter case, Pants locates target metadata for the source files as needed. ## File specifications @@ -176,7 +176,7 @@ We can also remove the `setup_py_commands` field from `helloworld/util/BUILD` to (This example only works on Linux because it has an sdist. See https://www.pantsbuild.org/docs/awslambda-python.) ``` -./pants package helloworld:helloworld-awslambda +./pants package helloworld/awslambda.py ``` ## Count lines of code diff --git a/helloworld/BUILD b/helloworld/BUILD index 357f004..47cfc3d 100644 --- a/helloworld/BUILD +++ b/helloworld/BUILD @@ -1,33 +1,36 @@ # Copyright 2020 Pants project contributors. # Licensed under the Apache License, Version 2.0 (see LICENSE). -# `name` defaults to the name of this directory, i.e., `helloworld`. -pex_binary( - sources=["main.py"], - entry_point="helloworld.main", -) - +# This target sets the metadata for all the Python non-test files in this directory. +# +# * `name` defaults to the name of this directory, i.e., `helloworld`. +# * `sources` defaults to ['*.py', '!*_test.py', '!test_*.py', '!conftest.py']. +# * Pants cannot infer dependencies on resources targets, so we explicitly add it. python_library( - name="awslambda_lib", - sources=["awslambda.py"], + dependencies=[":config_file"], ) -# Note: This has sdist dependencies, so it must be built on Linux. -python_awslambda( - name="helloworld-awslambda", - dependencies=[":awslambda_lib"], - handler="helloworld.awslambda:handler", - runtime="python3.7", +# This target teaches Pants about our JSON file, which allows for other targets to depend on it. +resources( + name="config_file", + sources=["config.json"], ) -# Pants cannot infer dependencies on resources targets and Protobuf, so we explicitly add them. -python_library( - name="config", - sources=["config.py"], - dependencies=[":config_file", "helloworld/util/proto"], +# This target allows us to bundle our app into a PEX binary file via +# `./pants package`. We can also run it with `./pants run`. See +# https://www.pantsbuild.org/docs/python-package-goal and +# https://www.pantsbuild.org/docs/python-run-goal. +pex_binary( + name="pex_binary", + entry_point="main.py", ) -resources( - name="config_file", - sources=["config.json"], +# This target allows us to create an AWS Lambda binary via `./pants package`. +# See https://www.pantsbuild.org/docs/awslambda-python. +# +# Note: This has sdist dependencies, so it must be built on Linux. +python_awslambda( + name="awslambda", + handler="awslambda.py:handler", + runtime="python3.7", ) diff --git a/helloworld/greet/BUILD b/helloworld/greet/BUILD index 899ae49..2194ccf 100644 --- a/helloworld/greet/BUILD +++ b/helloworld/greet/BUILD @@ -1,11 +1,15 @@ # Copyright 2020 Pants project contributors. # Licensed under the Apache License, Version 2.0 (see LICENSE). -# `name` defaults to the name of this directory, i.e., `greet`. -# `sources` defaults to ['*.py', '!*_test.py', '!test_*.py', '!conftest.py']. -# `dependencies` are inferred. +# This target sets the metadata for all the Python non-test files in this directory. +# +# * `name` defaults to the name of this directory, i.e., `greet`. +# * `sources` defaults to ['*.py', '!*_test.py', '!test_*.py', '!conftest.py']. +# * `dependencies` are inferred. python_library() -# `sources` defaults to ['*_test.py', 'test_*.py', 'conftest.py']. -# `dependencies` are inferred. -python_tests(name = 'tests') +# This target sets the metadata for all the Python test files in this directory. +# +# * `sources` defaults to ['*_test.py', 'test_*.py', 'conftest.py']. +# * `dependencies` are inferred. +python_tests(name='tests') diff --git a/helloworld/util/BUILD b/helloworld/util/BUILD index 86761cb..bcba562 100644 --- a/helloworld/util/BUILD +++ b/helloworld/util/BUILD @@ -1,27 +1,34 @@ # Copyright 2020 Pants project contributors. # Licensed under the Apache License, Version 2.0 (see LICENSE). -# `name` defaults to the name of this directory, i.e., `util`. -# `sources` defaults to ['*.py', '!*_test.py', '!test_*.py', '!conftest.py']. -# `dependencies` is set because only Pants 2.2+ can infer dependencies on Protobuf. -python_library( - dependencies=["helloworld/util/proto"], -) +# This target sets the metadata for all the Python non-test files in this directory. +# +# * `name` defaults to the name of this directory, i.e., `util`. +# * `sources` defaults to ['*.py', '!*_test.py', '!test_*.py', '!conftest.py']. +# * `dependencies` are inferred. +python_library() -# `sources` defaults to ['*_test.py', 'test_*.py', 'conftest.py']. -# Pants cannot infer dependencies on `resources` targets, so we explicitly add the dep. +# This target sets the metadata for all the Python test files in this directory. +# +# * `sources` defaults to ['*_test.py', 'test_*.py', 'conftest.py']. +# * Pants cannot infer dependencies on `resources` targets, so we explicitly add the dep. python_tests( name='tests', dependencies=[":test_data"], ) +# This target teaches Pants about our JSON file, which allows for other targets to depend on it. resources( name='test_data', sources=['*_test_data.json'], ) -# See https://www.pantsbuild.org/docs/python-distributions. -# Because this target has no source code, Pants cannot infer dependencies. +# This target allows us to build a `.whl` bdist and a `.tar.gz` sdist by auto-generating +# `setup.py`. See https://www.pantsbuild.org/docs/python-distributions. +# +# Because this target has no source code, Pants cannot infer dependencies. We depend on `:util`, +# which means we'll include all the non-test Python files in this directory, and any of +# their dependencies. python_distribution( name="dist", dependencies=[":util"], diff --git a/helloworld/util/proto/BUILD b/helloworld/util/proto/BUILD index bb4d6dc..8b0075d 100644 --- a/helloworld/util/proto/BUILD +++ b/helloworld/util/proto/BUILD @@ -1,8 +1,11 @@ # Copyright 2020 Pants project contributors. # Licensed under the Apache License, Version 2.0 (see LICENSE). -# `name` defaults to the name of this directory, i.e., `proto`. -# `sources` defaults to ["*.proto"]. +# This target sets the metadata for all the `.proto` files in this directory. +# See https://www.pantsbuild.org/docs/protobuf. +# +# * `name` defaults to the name of this directory, i.e., `proto`. +# * `sources` defaults to ["*.proto"]. protobuf_library() # Note that we have an empty `__init__.py` file in this folder. Pants will generate diff --git a/pants.toml b/pants.toml index d3fe2ab..b0cebde 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.1.1" +pants_version = "2.2.0" pantsd = true # Enable the Pants daemon for better performance. backend_packages.add = [ From bbf9e3b128e143908573ba6a37cd7d21e02784d8 Mon Sep 17 00:00:00 2001 From: Tom Dyas Date: Tue, 16 Mar 2021 10:32:06 -0700 Subject: [PATCH 30/96] upgrade Pants to v2.3.0rc3 (#64) * upgrade Pants to v2.3.0rc3 * handle deprecation --- pants.toml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pants.toml b/pants.toml index b0cebde..ff3eae8 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.2.0" +pants_version = "2.3.0rc3" pantsd = true # Enable the Pants daemon for better performance. backend_packages.add = [ @@ -21,6 +21,8 @@ backend_packages.add = [ root_patterns = ["/"] [python-setup] +# Use pip 2020 resolver which will become the default in Pants v2.4.x. +resolver_version = "pip-2020-resolver" # The default interpreter compatibility for code in this repo. Individual targets can override # this with the `interpreter_constraints` field. See # https://www.pantsbuild.org/docs/python-interpreter-compatibility. From 37dba26b578a5d8e590680634c6835e46afb382b Mon Sep 17 00:00:00 2001 From: Tom Dyas Date: Tue, 16 Mar 2021 11:15:47 -0700 Subject: [PATCH 31/96] CI: update GitHub Actions workflow to match Travis config (#65) - Update the GitHub Actions workflow to match the build steps in the current Travis config. - Enable caching of Pants cache. --- .github/workflows/pants.yaml | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pants.yaml b/.github/workflows/pants.yaml index 6c8efdd..a6ecba1 100644 --- a/.github/workflows/pants.yaml +++ b/.github/workflows/pants.yaml @@ -1,10 +1,15 @@ +# Copyright 2020 Pants project contributors. +# Licensed under the Apache License, Version 2.0 (see LICENSE). + +# See https://pants.readme.io/docs/using-pants-in-ci for tips on how to set up your CI with Pants. + name: Pants on: push: - branches: [ master ] + branches: [ main ] pull_request: - branches: [ master ] + branches: [ main ] jobs: build: @@ -16,7 +21,14 @@ jobs: python-version: [3.7] steps: - uses: actions/checkout@v2 - - name: Set up Python ${{ matrix.python-version }} + - uses: actions/cache@v2 + id: cache + with: + path: | + ~/.cache/pants/setup + ~/.cache/pants/lmdb_store + key: ${{ runner.os }}- + - name: Setup Python ${{ matrix.python-version }} uses: actions/setup-python@v1 with: python-version: ${{ matrix.python-version }} @@ -25,7 +37,12 @@ jobs: ./pants --version - name: Lint run: | - ./pants lint :: + ./pants lint typecheck :: - name: Test run: | ./pants test :: + - name: Package / Run + run: | + # We also smoke test that our release process will work by running `package`. + ./pants package :: + ./pants run helloworld/main.py From 37d7d99a66d28f05be1e84b41871a3a9f806de0c Mon Sep 17 00:00:00 2001 From: Stu Hood Date: Fri, 19 Mar 2021 10:15:02 -0700 Subject: [PATCH 32/96] Bump to 2.3.0. (#66) --- pants.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pants.toml b/pants.toml index ff3eae8..1053920 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.3.0rc3" +pants_version = "2.3.0" pantsd = true # Enable the Pants daemon for better performance. backend_packages.add = [ From 0bd3ff08bad326ec9df6f911d09b7b3653c06c1d Mon Sep 17 00:00:00 2001 From: John Sirois Date: Sun, 21 Mar 2021 19:32:48 -0700 Subject: [PATCH 33/96] Upgrade to 2.3.1rc0 with remote exec fix. (#67) This will allow us to get green over in the test matrix run by https://gitlab.com/remote-apis-testing/remote-apis-testing --- pants.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pants.toml b/pants.toml index 1053920..9c269f7 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.3.0" +pants_version = "2.3.1rc0" pantsd = true # Enable the Pants daemon for better performance. backend_packages.add = [ From 23d16589485f03081e1ff0650c7d199a77b54fe6 Mon Sep 17 00:00:00 2001 From: Tom Dyas Date: Tue, 4 May 2021 23:24:30 -0700 Subject: [PATCH 34/96] upgrade to Pants v2.4.1rc1 (#69) --- constraints.txt | 39 ++++++++++++++++++--------------------- pants.toml | 9 ++++++--- requirements.txt | 2 +- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/constraints.txt b/constraints.txt index 2226fae..8e58996 100644 --- a/constraints.txt +++ b/constraints.txt @@ -1,32 +1,29 @@ -# Generated by build-support/generate_constraints.sh on Tue Nov 24 13:57:41 MST 2020 +# Generated by build-support/generate_constraints.sh on Tue May 4 12:41:10 PDT 2021 ansicolors==1.1.8 appdirs==1.4.4 -certifi==2020.6.20 +certifi==2020.12.5 cfgv==3.2.0 -chardet==3.0.4 +chardet==4.0.0 click==7.1.2 distlib==0.3.1 filelock==3.0.12 -identify==1.5.5 +identify==2.2.4 idna==2.10 -importlib-metadata==1.7.0 -importlib-resources==3.0.0 -lxml==4.5.2 -nodeenv==1.5.0 -packaging==20.4 -pip==20.2.4 +lxml==4.6.3 +nodeenv==1.6.0 +packaging==20.9 +pip==21.1.1 pluggy==0.13.1 -pre-commit==2.7.1 -protobuf==3.13.0 -py==1.9.0 +pre-commit==2.12.1 +protobuf==3.15.8 +py==1.10.0 pyparsing==2.4.7 -PyYAML==5.3.1 -requests==2.24.0 -setuptools==50.3.0 +PyYAML==5.4.1 +requests==2.25.1 +setuptools==53.1.0 six==1.15.0 -toml==0.10.1 -tox==3.20.0 +toml==0.10.2 +tox==3.23.0 translate==3.5.0 -urllib3==1.25.10 -virtualenv==20.0.33 -zipp==3.3.0 +urllib3==1.26.4 +virtualenv==20.4.4 diff --git a/pants.toml b/pants.toml index 9c269f7..e97452b 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.3.1rc0" +pants_version = "2.4.1rc1" pantsd = true # Enable the Pants daemon for better performance. backend_packages.add = [ @@ -21,8 +21,6 @@ backend_packages.add = [ root_patterns = ["/"] [python-setup] -# Use pip 2020 resolver which will become the default in Pants v2.4.x. -resolver_version = "pip-2020-resolver" # The default interpreter compatibility for code in this repo. Individual targets can override # this with the `interpreter_constraints` field. See # https://www.pantsbuild.org/docs/python-interpreter-compatibility. @@ -48,3 +46,8 @@ config = [".isort.cfg"] [mypy] config = "build-support/mypy.ini" + +[lambdex] +version = "lambdex==0.1.4" +extra_requirements = [] + diff --git a/requirements.txt b/requirements.txt index 2fbc86c..ffab1be 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,6 +2,6 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). ansicolors>=1.0.2 -setuptools>=42.0.0 +setuptools<54.0,>=50.3.0 translate>=3.2.1 protobuf>=3.11.3 From 86b41de1e53658127cdd1b0798ae12aa0e2396c7 Mon Sep 17 00:00:00 2001 From: Benjy Weinberger Date: Thu, 13 May 2021 00:20:50 -0700 Subject: [PATCH 35/96] Upgrade to Pants 2.5.0rc2. (#71) And update constraints and python versions. Confirmed that the obvious things work: `./pants test ::` `./pants lint ::` etc. `./pants binary ::` fails on MacOS because it cannot resolve for Linux, as required by the Lambda target, and the resolve attempt takes a looooong time. So we probably want to fail-fast in this case. But otherwise, things seem stable. --- constraints.txt | 15 +++++++++------ pants | 18 +++++++++--------- pants.toml | 2 +- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/constraints.txt b/constraints.txt index 8e58996..69f24cb 100644 --- a/constraints.txt +++ b/constraints.txt @@ -1,29 +1,32 @@ -# Generated by build-support/generate_constraints.sh on Tue May 4 12:41:10 PDT 2021 +# Generated by build-support/generate_constraints.sh on Wed May 12 23:42:04 PDT 2021 ansicolors==1.1.8 appdirs==1.4.4 certifi==2020.12.5 cfgv==3.2.0 chardet==4.0.0 -click==7.1.2 +click==8.0.0 distlib==0.3.1 filelock==3.0.12 identify==2.2.4 idna==2.10 +importlib-metadata==4.0.1 lxml==4.6.3 nodeenv==1.6.0 packaging==20.9 pip==21.1.1 pluggy==0.13.1 pre-commit==2.12.1 -protobuf==3.15.8 +protobuf==3.17.0 py==1.10.0 pyparsing==2.4.7 PyYAML==5.4.1 requests==2.25.1 setuptools==53.1.0 -six==1.15.0 +six==1.16.0 toml==0.10.2 -tox==3.23.0 +tox==3.23.1 translate==3.5.0 +typing-extensions==3.10.0.0 urllib3==1.26.4 -virtualenv==20.4.4 +virtualenv==20.4.6 +zipp==3.4.1 diff --git a/pants b/pants index 7f7ad8e..124dce0 100755 --- a/pants +++ b/pants @@ -140,10 +140,16 @@ function set_supported_python_versions { supported_python_versions_decimal=('3.7' '3.8' '3.6') supported_python_versions_int=('37' '38' '36') supported_message='3.7, 3.8, or 3.6 (deprecated)' - else - supported_python_versions_decimal=('3.7' '3.8') - supported_python_versions_int=('37' '38') + elif [[ "${pants_major_version}" -eq 2 && "${pants_minor_version}" -lt 5 ]]; then + supported_python_versions_decimal=('3.8' '3.7') + supported_python_versions_int=('38' '37') supported_message='3.7 or 3.8' + else + # We put 3.9 first because Apple Silicon only works properly with Python 3.9, even though it's possible to have + # older Pythons installed. This makes it more likely that Pants will work out-of-the-box. + supported_python_versions_decimal=('3.9' '3.8' '3.7') + supported_python_versions_int=('39' '38' '37') + supported_message='3.7, 3.8, or 3.9' fi } @@ -272,12 +278,6 @@ if [[ -n "${PANTS_SHA:-}" ]]; then pants_extra_args="${pants_extra_args} --python-repos-repos=$(find_links_url "$pants_version" "$PANTS_SHA")" fi -# We set the env var no_proxy to '*', to work around an issue with urllib using non -# async-signal-safe syscalls after we fork a process that has already spawned threads. -# -# See https://blog.phusion.nl/2017/10/13/why-ruby-app-servers-break-on-macos-high-sierra-and-what-can-be-done-about-it/ -export no_proxy='*' - # shellcheck disable=SC2086 exec "${pants_python}" "${pants_binary}" ${pants_extra_args} \ --pants-bin-name="${PANTS_BIN_NAME}" --pants-version=${pants_version} "$@" diff --git a/pants.toml b/pants.toml index e97452b..b3ae612 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.4.1rc1" +pants_version = "2.5.0rc2" pantsd = true # Enable the Pants daemon for better performance. backend_packages.add = [ From c1a1683ad284c0e206d00baf96921e9e51dfddfe Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Thu, 27 May 2021 14:44:57 -0700 Subject: [PATCH 36/96] Upgrade to Pants 2.5 and modernize CI setup and tool config file locations (#73) Config files are now autodiscovered, so we use their default locations. --- build-support/.flake8 => .flake8 | 0 .github/workflows/pants.yaml | 11 +++++++++-- .travis.yml | 3 ++- build-support/mypy.ini => mypy.ini | 0 pants.ci.toml | 14 +++----------- pants.toml | 17 +---------------- 6 files changed, 15 insertions(+), 30 deletions(-) rename build-support/.flake8 => .flake8 (100%) rename build-support/mypy.ini => mypy.ini (100%) diff --git a/build-support/.flake8 b/.flake8 similarity index 100% rename from build-support/.flake8 rename to .flake8 diff --git a/.github/workflows/pants.yaml b/.github/workflows/pants.yaml index a6ecba1..21a86e1 100644 --- a/.github/workflows/pants.yaml +++ b/.github/workflows/pants.yaml @@ -27,15 +27,16 @@ jobs: path: | ~/.cache/pants/setup ~/.cache/pants/lmdb_store + ~/.cache/pants/named_caches key: ${{ runner.os }}- - name: Setup Python ${{ matrix.python-version }} uses: actions/setup-python@v1 with: python-version: ${{ matrix.python-version }} - - name: bootstrap + - name: Bootstrap Pants run: | ./pants --version - - name: Lint + - name: Lint and typechck run: | ./pants lint typecheck :: - name: Test @@ -46,3 +47,9 @@ jobs: # We also smoke test that our release process will work by running `package`. ./pants package :: ./pants run helloworld/main.py + - name: Upload pants log + uses: actions/upload-artifact@v2 + with: + name: pants-log + path: .pants.d/pants.log + if: always() # We want the log even on failures. diff --git a/.travis.yml b/.travis.yml index 1ad9a9e..546f249 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,9 +16,10 @@ cache: directories: - $HOME/.cache/pants/setup - $HOME/.cache/pants/lmdb_store + - $HOME/.cache/pants/named_caches install: - - ./pants --version # This will bootstrap Pants + - ./pants --version # Bootstrap Pants. script: # We also smoke test that our release process will work by running `package`. diff --git a/build-support/mypy.ini b/mypy.ini similarity index 100% rename from build-support/mypy.ini rename to mypy.ini diff --git a/pants.ci.toml b/pants.ci.toml index ea1e6b1..1174e22 100644 --- a/pants.ci.toml +++ b/pants.ci.toml @@ -4,15 +4,7 @@ # See https://www.pantsbuild.org/docs/using-pants-in-ci. [GLOBAL] -pantsd = false +colors = true -# Limit the maximum number of concurrent processes. Change this -# to a number that makes sense for your CI setup, based on -# the number of cores/threads. -process_execution_local_parallelism = 2 - -[python-setup] -# Limit the maximum number of concurrent jobs used to resolve third -# party dependencies. The total level of parallelism will be -# `process_execution_local_parallelism x resolver_jobs`. -resolver_jobs = 1 +[pytest] +args = ["-vv", "--no-header"] diff --git a/pants.toml b/pants.toml index b3ae612..b5ee007 100644 --- a/pants.toml +++ b/pants.toml @@ -2,8 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.5.0rc2" -pantsd = true # Enable the Pants daemon for better performance. +pants_version = "2.5.0" backend_packages.add = [ "pants.backend.awslambda.python", @@ -37,17 +36,3 @@ interpreter_search_paths = ["", ""] # See https://www.pantsbuild.org/docs/protobuf. runtime_dependencies = ["//:protobuf"] mypy_plugin = true - -[flake8] -config = "build-support/.flake8" - -[isort] -config = [".isort.cfg"] - -[mypy] -config = "build-support/mypy.ini" - -[lambdex] -version = "lambdex==0.1.4" -extra_requirements = [] - From 752e0007a006d2377b7c2f9b3c56f1964ea47c31 Mon Sep 17 00:00:00 2001 From: Benjy Weinberger Date: Thu, 27 May 2021 18:16:48 -0700 Subject: [PATCH 37/96] New runner script. (#72) Fixes virtualenv issues on Python3.9. --- pants | 81 +++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 54 insertions(+), 27 deletions(-) diff --git a/pants b/pants index 124dce0..580460b 100755 --- a/pants +++ b/pants @@ -34,10 +34,10 @@ fi PANTS_BOOTSTRAP="${PANTS_SETUP_CACHE}/bootstrap-$(uname -s)-$(uname -m)" -VENV_VERSION=${VENV_VERSION:-16.4.3} - -VENV_PACKAGE=virtualenv-${VENV_VERSION} -VENV_TARBALL=${VENV_PACKAGE}.tar.gz +VIRTUALENV_ZIPAPP=virtualenv.pyz +VIRTUALENV_VERSION=20.4.7 +VIRTUALENV_ZIPAPP_URL="https://raw.githubusercontent.com/pypa/get-virtualenv/${VIRTUALENV_VERSION}/public/${VIRTUALENV_ZIPAPP}" +VIRTUALENV_ZIPAPP_EXPECTED_SHA256="9d5c8b09cdeaf44414f07902d2ae45c4bb8a2085717d66f82ae389a9c6f94425" COLOR_RED="\x1b[31m" COLOR_GREEN="\x1b[32m" @@ -57,6 +57,7 @@ function green() { } function tempdir { + mkdir -p "$1" mktemp -d "$1"/pants.XXXXXX } @@ -107,9 +108,9 @@ function determine_pants_version { pants_version="$(get_pants_config_value 'pants_version')" if [[ -z "${pants_version}" ]]; then - die "Please explicitly specify the \`pants_version\` in your \`pants.toml\` under the -\`[GLOBAL]\` scope. See https://pypi.org/project/pantsbuild.pants/#history for all released -versions and https://www.pantsbuild.org/docs/installation for more instructions." + die "Please explicitly specify the \`pants_version\` in your \`pants.toml\` under the \`[GLOBAL]\` scope. +See https://pypi.org/project/pantsbuild.pants/#history for all released versions +and https://www.pantsbuild.org/docs/installation for more instructions." fi pants_major_version="$(echo "${pants_version}" | cut -d '.' -f1)" pants_minor_version="$(echo "${pants_version}" | cut -d '.' -f2)" @@ -183,7 +184,7 @@ function determine_python_exe { fi fi local python_exe - python_exe="$(get_exe_path_or_die "${python_bin_name}")" + python_exe="$(get_exe_path_or_die "${python_bin_name}")" || exit 1 local major_minor_version major_minor_version="$(get_python_major_minor_version "${python_exe}")" for valid_version in "${supported_python_versions_int[@]}"; do @@ -194,23 +195,46 @@ function determine_python_exe { die "Invalid Python interpreter version for ${python_exe}. ${requirement_str}" } +function compute_sha256 { + local python="$1" + local path="$2" + + "$python" <&2 + curl -LO "${VIRTUALENV_ZIPAPP_URL}" + fingerprint="$(compute_sha256 "${python}" "${VIRTUALENV_ZIPAPP}")" + if [[ "${VIRTUALENV_ZIPAPP_EXPECTED_SHA256}" != "${fingerprint}" ]]; then + die "SHA256 of ${VIRTUALENV_ZIPAPP_URL} is not as expected. Aborting." + fi + green "SHA256 fingerprint of ${VIRTUALENV_ZIPAPP_URL} verified." + mkdir -p "$(dirname "${bootstrapped}")" + mv -f "${staging_dir}/${VIRTUALENV_ZIPAPP}" "${bootstrapped}" + rmdir "${staging_dir}" + ) 1>&2 || exit 1 fi - echo "${PANTS_BOOTSTRAP}/${VENV_PACKAGE}" + echo "${bootstrapped}" } function find_links_url { @@ -245,32 +269,35 @@ function bootstrap_pants { fi local python_major_minor_version python_major_minor_version="$(get_python_major_minor_version "${python}")" - local target_folder_name - target_folder_name="${pants_version}_py${python_major_minor_version}" + local target_folder_name="${pants_version}_py${python_major_minor_version}" + local bootstrapped="${PANTS_BOOTSTRAP}/${target_folder_name}" - if [[ ! -d "${PANTS_BOOTSTRAP}/${target_folder_name}" ]]; then + if [[ ! -d "${bootstrapped}" ]]; then ( - local venv_path - venv_path="$(bootstrap_venv)" + green "Bootstrapping Pants using ${python}" local staging_dir staging_dir=$(tempdir "${PANTS_BOOTSTRAP}") + local virtualenv_path + virtualenv_path="$(bootstrap_virtualenv "${python}")" || exit 1 + green "Installing ${pants_requirement} into a virtual environment at ${bootstrapped}" # shellcheck disable=SC2086 - "${python}" "${venv_path}/virtualenv.py" --no-download "${staging_dir}/install" && \ + "${python}" "${virtualenv_path}" --no-download "${staging_dir}/install" && \ "${staging_dir}/install/bin/pip" install -U pip && \ "${staging_dir}/install/bin/pip" install ${maybe_find_links} --progress-bar off "${pants_requirement}" && \ ln -s "${staging_dir}/install" "${staging_dir}/${target_folder_name}" && \ - mv "${staging_dir}/${target_folder_name}" "${PANTS_BOOTSTRAP}/${target_folder_name}" && \ - green "New virtual environment successfully created at ${PANTS_BOOTSTRAP}/${target_folder_name}." - ) 1>&2 + mv "${staging_dir}/${target_folder_name}" "${bootstrapped}" && \ + green "New virtual environment successfully created at ${bootstrapped}." + ) 1>&2 || exit 1 fi - echo "${PANTS_BOOTSTRAP}/${target_folder_name}" + echo "${bootstrapped}" } # Ensure we operate from the context of the ./pants buildroot. cd "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" pants_version="$(determine_pants_version)" python="$(determine_python_exe "${pants_version}")" -pants_dir="$(bootstrap_pants "${pants_version}" "${python}" "${PANTS_SHA:-}")" +pants_dir="$(bootstrap_pants "${pants_version}" "${python}" "${PANTS_SHA:-}")" || exit 1 + pants_python="${pants_dir}/bin/python" pants_binary="${pants_dir}/bin/pants" pants_extra_args="" From 810b3b22792ce940ee77082841ef0298133de5ec Mon Sep 17 00:00:00 2001 From: John Sirois Date: Sat, 3 Jul 2021 10:38:07 -0700 Subject: [PATCH 38/96] Limit GH action execution to pantsbuild. (#74) --- .github/workflows/pants.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/pants.yaml b/.github/workflows/pants.yaml index 21a86e1..0b91c6e 100644 --- a/.github/workflows/pants.yaml +++ b/.github/workflows/pants.yaml @@ -12,7 +12,16 @@ on: branches: [ main ] jobs: + org-check: + name: Check GitHub Organization + if: ${{ github.repository_owner == 'pantsbuild' }} + runs-on: ubuntu-20.04 + steps: + - name: Noop + run: "true" build: + name: Perform CI Checks + needs: org-check env: PANTS_CONFIG_FILES: pants.ci.toml runs-on: ubuntu-latest From 7403c4bbf9637daaaf8528f252dabfba67522a58 Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Wed, 14 Jul 2021 11:05:08 -0700 Subject: [PATCH 39/96] Upgrade ./pants script (#77) --- pants | 59 +++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 12 deletions(-) diff --git a/pants b/pants index 580460b..930cf4c 100755 --- a/pants +++ b/pants @@ -34,10 +34,24 @@ fi PANTS_BOOTSTRAP="${PANTS_SETUP_CACHE}/bootstrap-$(uname -s)-$(uname -m)" -VIRTUALENV_ZIPAPP=virtualenv.pyz +PEX_VERSION=2.1.42 +PEX_URL="https://github.com/pantsbuild/pex/releases/download/v${PEX_VERSION}/pex" +PEX_EXPECTED_SHA256="69d6b1b1009b00dd14a3a9f19b72cff818a713ca44b3186c9b12074b2a31e51f" + VIRTUALENV_VERSION=20.4.7 -VIRTUALENV_ZIPAPP_URL="https://raw.githubusercontent.com/pypa/get-virtualenv/${VIRTUALENV_VERSION}/public/${VIRTUALENV_ZIPAPP}" -VIRTUALENV_ZIPAPP_EXPECTED_SHA256="9d5c8b09cdeaf44414f07902d2ae45c4bb8a2085717d66f82ae389a9c6f94425" +VIRTUALENV_REQUIREMENTS=$( +cat << EOF +virtualenv==${VIRTUALENV_VERSION} --hash sha256:2b0126166ea7c9c3661f5b8e06773d28f83322de7a3ff7d06f0aed18c9de6a76 +filelock==3.0.12 --hash sha256:929b7d63ec5b7d6b71b0fa5ac14e030b3f70b75747cef1b10da9b879fef15836 +six==1.16.0 --hash sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254 +distlib==0.3.2 --hash sha256:23e223426b28491b1ced97dc3bbe183027419dfc7982b4fa2f05d5f3ff10711c +appdirs==1.4.4 --hash sha256:a841dacd6b99318a741b166adb07e19ee71a274450e68237b4650ca1055ab128 +importlib-resources==5.1.4; python_version < "3.7" --hash sha256:e962bff7440364183203d179d7ae9ad90cb1f2b74dcb84300e88ecc42dca3351 +importlib-metadata==4.5.0; python_version < "3.8" --hash sha256:833b26fb89d5de469b24a390e9df088d4e52e4ba33b01dc5e0e4f41b81a16c00 +zipp==3.4.1; python_version < "3.10" --hash sha256:51cb66cc54621609dd593d1787f286ee42a5c0adbb4b29abea5a63edc3e03098 +typing-extensions==3.10.0.0; python_version < "3.8" --hash sha256:779383f6086d90c99ae41cf0ff39aac8a7937a9283ce0a414e5dd782f4c94a84 +EOF +) COLOR_RED="\x1b[31m" COLOR_GREEN="\x1b[32m" @@ -213,30 +227,51 @@ EOF # TODO(John Sirois): GC race loser tmp dirs leftover from bootstrap_XXX # functions. Any tmp dir w/o a symlink pointing to it can go. -function bootstrap_virtualenv { +function bootstrap_pex { local python="$1" - local bootstrapped="${PANTS_BOOTSTRAP}/virtualenv-${VIRTUALENV_VERSION}/${VIRTUALENV_ZIPAPP}" + local bootstrapped="${PANTS_BOOTSTRAP}/pex-${PEX_VERSION}/pex" if [[ ! -f "${bootstrapped}" ]]; then ( - green "Downloading the virtualenv zipapp" + green "Downloading the Pex PEX." mkdir -p "${PANTS_BOOTSTRAP}" local staging_dir staging_dir=$(tempdir "${PANTS_BOOTSTRAP}") cd "${staging_dir}" - curl -LO "${VIRTUALENV_ZIPAPP_URL}" - fingerprint="$(compute_sha256 "${python}" "${VIRTUALENV_ZIPAPP}")" - if [[ "${VIRTUALENV_ZIPAPP_EXPECTED_SHA256}" != "${fingerprint}" ]]; then - die "SHA256 of ${VIRTUALENV_ZIPAPP_URL} is not as expected. Aborting." + curl -LO "${PEX_URL}" + fingerprint="$(compute_sha256 "${python}" "pex")" + if [[ "${PEX_EXPECTED_SHA256}" != "${fingerprint}" ]]; then + die "SHA256 of ${PEX_URL} is not as expected. Aborting." fi - green "SHA256 fingerprint of ${VIRTUALENV_ZIPAPP_URL} verified." + green "SHA256 fingerprint of ${PEX_URL} verified." mkdir -p "$(dirname "${bootstrapped}")" - mv -f "${staging_dir}/${VIRTUALENV_ZIPAPP}" "${bootstrapped}" + mv -f "${staging_dir}/pex" "${bootstrapped}" rmdir "${staging_dir}" ) 1>&2 || exit 1 fi echo "${bootstrapped}" } +function bootstrap_virtualenv { + local python="$1" + local bootstrapped="${PANTS_BOOTSTRAP}/virtualenv-${VIRTUALENV_VERSION}/virtualenv.pex" + if [[ ! -f "${bootstrapped}" ]]; then + ( + green "Creating the virtualenv PEX." + pex_path="$(bootstrap_pex "${python}")" || exit 1 + mkdir -p "${PANTS_BOOTSTRAP}" + local staging_dir + staging_dir=$(tempdir "${PANTS_BOOTSTRAP}") + cd "${staging_dir}" + echo "${VIRTUALENV_REQUIREMENTS}" > requirements.txt + "${python}" "${pex_path}" -r requirements.txt -c virtualenv -o virtualenv.pex + mkdir -p "$(dirname "${bootstrapped}")" + mv -f "${staging_dir}/virtualenv.pex" "${bootstrapped}" + rm -rf "${staging_dir}" + ) 1>&2 || exit 1 + fi + echo "${bootstrapped}" +} + function find_links_url { local pants_version="$1" local pants_sha="$2" From 085dd533e0e72c4753ba9aade8ab9997301df463 Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Wed, 14 Jul 2021 15:25:15 -0700 Subject: [PATCH 40/96] Force disabling dynamic UI in CI (#76) --- pants.ci.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pants.ci.toml b/pants.ci.toml index 1174e22..f8aafcb 100644 --- a/pants.ci.toml +++ b/pants.ci.toml @@ -4,6 +4,7 @@ # See https://www.pantsbuild.org/docs/using-pants-in-ci. [GLOBAL] +dynamic_ui = false colors = true [pytest] From ad8c9f0f8b3f76fb3fb4beae983e013599613fb6 Mon Sep 17 00:00:00 2001 From: Benjy Weinberger Date: Thu, 15 Jul 2021 19:01:44 -0700 Subject: [PATCH 41/96] Enable anonymous telemetry. (#75) --- pants.toml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pants.toml b/pants.toml index b5ee007..f876049 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.5.0" +pants_version = "2.5.1" backend_packages.add = [ "pants.backend.awslambda.python", @@ -15,6 +15,10 @@ backend_packages.add = [ "pants.backend.python.typecheck.mypy", ] +[anonymous-telemetry] +enabled = true +repo_id = "3B1D361B-E9F1-49A8-B761-03DCC41FD58E" + [source] # The Python source root is the repo root. See https://www.pantsbuild.org/docs/source-roots. root_patterns = ["/"] From a54cd309e5b78dc861ec5e270550faa1bfb08ac0 Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Mon, 2 Aug 2021 15:12:50 -0700 Subject: [PATCH 42/96] Upgrade to 2.6.0 (#79) This requires adding types-setuptools and types-protobuf to work properly with MyPy 0.9*. This also bumps some requirements. --- constraints.txt | 45 +++++++++++++++++---------------------------- pants.toml | 3 +-- requirements.txt | 10 ++++++---- 3 files changed, 24 insertions(+), 34 deletions(-) diff --git a/constraints.txt b/constraints.txt index 69f24cb..bc35d2c 100644 --- a/constraints.txt +++ b/constraints.txt @@ -1,32 +1,21 @@ -# Generated by build-support/generate_constraints.sh on Wed May 12 23:42:04 PDT 2021 +# Generated by build-support/generate_constraints.sh on Mon Aug 2 21:58:13 UTC 2021 ansicolors==1.1.8 -appdirs==1.4.4 -certifi==2020.12.5 -cfgv==3.2.0 -chardet==4.0.0 -click==8.0.0 -distlib==0.3.1 -filelock==3.0.12 -identify==2.2.4 -idna==2.10 -importlib-metadata==4.0.1 +certifi==2021.5.30 +charset-normalizer==2.0.4 +click==8.0.1 +idna==3.2 +importlib-metadata==4.6.3 +libretranslatepy==2.1.1 lxml==4.6.3 -nodeenv==1.6.0 -packaging==20.9 -pip==21.1.1 -pluggy==0.13.1 -pre-commit==2.12.1 -protobuf==3.17.0 -py==1.10.0 -pyparsing==2.4.7 -PyYAML==5.4.1 -requests==2.25.1 -setuptools==53.1.0 +pip==21.2.2 +protobuf==3.17.3 +requests==2.26.0 +setuptools==56.2.0 six==1.16.0 -toml==0.10.2 -tox==3.23.1 -translate==3.5.0 +translate==3.6.1 +types-futures==0.1.6 +types-protobuf==3.17.4 +types-setuptools==57.0.0 typing-extensions==3.10.0.0 -urllib3==1.26.4 -virtualenv==20.4.6 -zipp==3.4.1 +urllib3==1.26.6 +zipp==3.5.0 diff --git a/pants.toml b/pants.toml index f876049..12ba222 100644 --- a/pants.toml +++ b/pants.toml @@ -2,8 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.5.1" - +pants_version = "2.6.0" backend_packages.add = [ "pants.backend.awslambda.python", "pants.backend.codegen.protobuf.python", diff --git a/requirements.txt b/requirements.txt index ffab1be..1f8d03a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,9 @@ # Copyright 2020 Pants project contributors. # Licensed under the Apache License, Version 2.0 (see LICENSE). -ansicolors>=1.0.2 -setuptools<54.0,>=50.3.0 -translate>=3.2.1 -protobuf>=3.11.3 +ansicolors==1.1.8 +setuptools>=56.2.0,<57 +types-setuptools>=56.2.0,<58 +translate>=3.6.1,<3.7 +protobuf>=3.17.3,<3.18 +types-protobuf>=3.17.4,<3.18 From 2ca03a60d1c0719403817e573ec978ad0ccdbabd Mon Sep 17 00:00:00 2001 From: Asher Foa Date: Wed, 15 Sep 2021 22:17:26 -0700 Subject: [PATCH 43/96] Update `./pants` script (#80) latest script from https://static.pantsbuild.org/setup/pants --- pants | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/pants b/pants index 930cf4c..2e9a10c 100755 --- a/pants +++ b/pants @@ -168,8 +168,19 @@ function set_supported_python_versions { fi } +function check_python_exe_compatible_version { + local python_exe="$1" + local major_minor_version + major_minor_version="$(get_python_major_minor_version "${python_exe}")" + for valid_version in "${supported_python_versions_int[@]}"; do + if [[ "${major_minor_version}" == "${valid_version}" ]]; then + echo "${python_exe}" && return 0 + fi + done +} + function determine_default_python_exe { - for version in "${supported_python_versions_decimal[@]}"; do + for version in "${supported_python_versions_decimal[@]}" "3" ""; do local interpreter_path interpreter_path="$(command -v "python${version}")" if [[ -z "${interpreter_path}" ]]; then @@ -179,7 +190,9 @@ function determine_default_python_exe { if [[ "$("${interpreter_path}" --version 2>&1 > /dev/null)" == "pyenv: python${version}"* ]]; then continue fi - echo "${interpreter_path}" && return 0 + if [[ -n "$(check_python_exe_compatible_version "${interpreter_path}")" ]]; then + echo "${interpreter_path}" && return 0 + fi done } @@ -188,25 +201,19 @@ function determine_python_exe { set_supported_python_versions "${pants_version}" local requirement_str="For \`pants_version = \"${pants_version}\"\`, Pants requires Python ${supported_message} to run." - local python_bin_name + local python_exe if [[ "${PYTHON_BIN_NAME}" != 'unspecified' ]]; then - python_bin_name="${PYTHON_BIN_NAME}" + python_exe="$(get_exe_path_or_die "${PYTHON_BIN_NAME}")" || exit 1 + if [[ -z "$(check_python_exe_compatible_version "${python_exe}")" ]]; then + die "Invalid Python interpreter version for ${python_exe}. ${requirement_str}" + fi else - python_bin_name="$(determine_default_python_exe)" - if [[ -z "${python_bin_name}" ]]; then + python_exe="$(determine_default_python_exe)" + if [[ -z "${python_exe}" ]]; then die "No valid Python interpreter found. ${requirement_str} Please check that a valid interpreter is installed and on your \$PATH." fi fi - local python_exe - python_exe="$(get_exe_path_or_die "${python_bin_name}")" || exit 1 - local major_minor_version - major_minor_version="$(get_python_major_minor_version "${python_exe}")" - for valid_version in "${supported_python_versions_int[@]}"; do - if [[ "${major_minor_version}" == "${valid_version}" ]]; then - echo "${python_exe}" && return 0 - fi - done - die "Invalid Python interpreter version for ${python_exe}. ${requirement_str}" + echo "${python_exe}" } function compute_sha256 { From 243e4c9fd91dd20a03ba7e4b0b7cf0ef0da09737 Mon Sep 17 00:00:00 2001 From: Stu Hood Date: Fri, 24 Sep 2021 11:22:36 -0700 Subject: [PATCH 44/96] Upgrade to 2.7.0. (#81) --- pants.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pants.toml b/pants.toml index 12ba222..b40fe7f 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.6.0" +pants_version = "2.7.0" backend_packages.add = [ "pants.backend.awslambda.python", "pants.backend.codegen.protobuf.python", From 5205674ce765643d7b62e999090b5ab776e9eeac Mon Sep 17 00:00:00 2001 From: Benjy Weinberger Date: Thu, 28 Oct 2021 14:50:24 -0700 Subject: [PATCH 45/96] Don't run CI on Travis. (#83) We already have an equivalent GHA CI. --- .travis.yml | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 546f249..0000000 --- a/.travis.yml +++ /dev/null @@ -1,27 +0,0 @@ -# Copyright 2020 Pants project contributors. -# Licensed under the Apache License, Version 2.0 (see LICENSE). - -# See https://pants.readme.io/docs/using-pants-in-ci for tips on how to set up your CI with Pants. - -env: - global: - - PANTS_CONFIG_FILES=pants.ci.toml - -os: linux -dist: bionic -language: python -python: 3.7 - -cache: - directories: - - $HOME/.cache/pants/setup - - $HOME/.cache/pants/lmdb_store - - $HOME/.cache/pants/named_caches - -install: - - ./pants --version # Bootstrap Pants. - -script: - # We also smoke test that our release process will work by running `package`. - - ./pants lint typecheck test package '::' - - ./pants run helloworld/main.py From 48256bd0ead3c810b90f5a2fb8bde25e327e3334 Mon Sep 17 00:00:00 2001 From: Stu Hood Date: Thu, 28 Oct 2021 14:54:36 -0700 Subject: [PATCH 46/96] Upgrade to 2.7.1. (#82) --- pants.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pants.toml b/pants.toml index b40fe7f..80ed391 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.7.0" +pants_version = "2.7.1" backend_packages.add = [ "pants.backend.awslambda.python", "pants.backend.codegen.protobuf.python", From 2b4c66b704c3ff7d4495cd5c846be626c6b2a1b7 Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Fri, 12 Nov 2021 13:34:18 -0700 Subject: [PATCH 47/96] Remove Protobuf and AWS Lambda from example (#84) We got feedback in Slack that these two backends were making the example too complex. > I could not use that repo as a template because of the aws and protobuf stuff. ie do you want the repo to be a reusable template? or a fully baked example? We would rather have the example repo be very easy to get started than to show every bell and whistle of Pants. Our docs are for the niche features like AWS Lambdas. Our example repo is to allow you to very easily try out Pants to get a feel for it before committing to prototyping in your own repo. --- BUILD | 25 +++---------------- README.md | 8 ------ constraints.txt | 2 -- helloworld/BUILD | 10 -------- helloworld/awslambda.py | 11 -------- helloworld/config.py | 9 ------- helloworld/main.py | 8 +++--- helloworld/util/config.py | 21 ++++++++++++++++ helloworld/util/config_loader.py | 12 --------- .../{config_loader_test.py => config_test.py} | 4 +-- ...r_test_data.json => config_test_data.json} | 0 helloworld/util/proto/BUILD | 14 ----------- helloworld/util/proto/__init__.py | 0 helloworld/util/proto/config.proto | 11 -------- pants.toml | 7 ------ requirements.txt | 2 -- 16 files changed, 30 insertions(+), 114 deletions(-) delete mode 100644 helloworld/awslambda.py delete mode 100644 helloworld/config.py create mode 100644 helloworld/util/config.py delete mode 100644 helloworld/util/config_loader.py rename helloworld/util/{config_loader_test.py => config_test.py} (63%) rename helloworld/util/{config_loader_test_data.json => config_test_data.json} (100%) delete mode 100644 helloworld/util/proto/BUILD delete mode 100644 helloworld/util/proto/__init__.py delete mode 100644 helloworld/util/proto/config.proto diff --git a/BUILD b/BUILD index 9c0a8bc..fe5c7bb 100644 --- a/BUILD +++ b/BUILD @@ -1,24 +1,7 @@ # Copyright 2020 Pants project contributors. # Licensed under the Apache License, Version 2.0 (see LICENSE). - -# A macro that turns every entry in this directory's requirements.txt into a target -# with the name of the corresponding dist. -# -# For example, `translate>=3.2.1` expands to: -# -# python_requirement_library( -# name='translate', -# requirements=['translate>=3.2.1'] -# ) -# -# We set `module_mapping` for any requirements whose module names differ from the project's name so that dependency -# inference works. -# -# Refer to https://www.pantsbuild.org/docs/python-third-party-dependencies. -python_requirements( - module_mapping={ - "ansicolors": ["colors"], - "setuptools": ["pkg_resources"], - }, -) +# A macro that turns every entry in this directory's requirements.txt into a +# `python_requirement_library` target. Refer to +# https://www.pantsbuild.org/docs/python-third-party-dependencies. +python_requirements() diff --git a/README.md b/README.md index fe086bf..d4f1dae 100644 --- a/README.md +++ b/README.md @@ -171,14 +171,6 @@ This will build both a `.whl` bdist and a `.tar.gz` sdist. We can also remove the `setup_py_commands` field from `helloworld/util/BUILD` to have Pants instead generate a `setup.py` file, with all the relevant code in a chroot. -## Build an AWS Lambda - -(This example only works on Linux because it has an sdist. See https://www.pantsbuild.org/docs/awslambda-python.) - -``` -./pants package helloworld/awslambda.py -``` - ## Count lines of code ``` diff --git a/constraints.txt b/constraints.txt index bc35d2c..7fdc0f3 100644 --- a/constraints.txt +++ b/constraints.txt @@ -8,13 +8,11 @@ importlib-metadata==4.6.3 libretranslatepy==2.1.1 lxml==4.6.3 pip==21.2.2 -protobuf==3.17.3 requests==2.26.0 setuptools==56.2.0 six==1.16.0 translate==3.6.1 types-futures==0.1.6 -types-protobuf==3.17.4 types-setuptools==57.0.0 typing-extensions==3.10.0.0 urllib3==1.26.6 diff --git a/helloworld/BUILD b/helloworld/BUILD index 47cfc3d..9dfa86c 100644 --- a/helloworld/BUILD +++ b/helloworld/BUILD @@ -24,13 +24,3 @@ pex_binary( name="pex_binary", entry_point="main.py", ) - -# This target allows us to create an AWS Lambda binary via `./pants package`. -# See https://www.pantsbuild.org/docs/awslambda-python. -# -# Note: This has sdist dependencies, so it must be built on Linux. -python_awslambda( - name="awslambda", - handler="awslambda.py:handler", - runtime="python3.7", -) diff --git a/helloworld/awslambda.py b/helloworld/awslambda.py deleted file mode 100644 index 161db44..0000000 --- a/helloworld/awslambda.py +++ /dev/null @@ -1,11 +0,0 @@ -# Copyright 2020 Pants project contributors. -# Licensed under the Apache License, Version 2.0 (see LICENSE). - -from helloworld.config import load_config -from helloworld.greet.greeting import Greeter - - -def handler(event, context): - config = load_config() - greeter = Greeter(languages=config.languages, greetings=config.greetings) - print(greeter.greet("world")) diff --git a/helloworld/config.py b/helloworld/config.py deleted file mode 100644 index 7d56799..0000000 --- a/helloworld/config.py +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright 2020 Pants project contributors. -# Licensed under the Apache License, Version 2.0 (see LICENSE). - -from helloworld.util.config_loader import load_config_from_json -from helloworld.util.proto.config_pb2 import Config - - -def load_config() -> Config: - return load_config_from_json(__name__, "config.json") diff --git a/helloworld/main.py b/helloworld/main.py index 8353e58..52ca6f1 100644 --- a/helloworld/main.py +++ b/helloworld/main.py @@ -3,15 +3,13 @@ from colors import green -from helloworld.config import load_config from helloworld.greet.greeting import Greeter +from helloworld.util.config import Config def say_hello() -> None: - config = load_config() - greeter = Greeter( - languages=list(config.languages), greetings=list(config.greetings) - ) + config = Config.load_from_json_resource(__name__, "config.json") + greeter = Greeter(languages=config.languages, greetings=config.greetings) sentence = greeter.greet("world") print(green(sentence)) diff --git a/helloworld/util/config.py b/helloworld/util/config.py new file mode 100644 index 0000000..965e15e --- /dev/null +++ b/helloworld/util/config.py @@ -0,0 +1,21 @@ +# Copyright 2020 Pants project contributors. +# Licensed under the Apache License, Version 2.0 (see LICENSE). + +from __future__ import annotations + +import json +from dataclasses import dataclass + +import pkg_resources + + +@dataclass +class Config: + languages: list[str] + greetings: list[str] + + @classmethod + def load_from_json_resource(cls, pkg_name: str, resource_name: str) -> Config: + resource_content = pkg_resources.resource_string(pkg_name, resource_name) + parsed = json.loads(resource_content) + return cls(languages=parsed["languages"], greetings=parsed["greetings"]) diff --git a/helloworld/util/config_loader.py b/helloworld/util/config_loader.py deleted file mode 100644 index 74ac450..0000000 --- a/helloworld/util/config_loader.py +++ /dev/null @@ -1,12 +0,0 @@ -# Copyright 2020 Pants project contributors. -# Licensed under the Apache License, Version 2.0 (see LICENSE). - -import pkg_resources -from google.protobuf.json_format import Parse as parse_json - -from helloworld.util.proto.config_pb2 import Config - - -def load_config_from_json(pkg_name: str, resource_name: str) -> Config: - resource_content = pkg_resources.resource_string(pkg_name, resource_name).decode() - return parse_json(resource_content, Config()) diff --git a/helloworld/util/config_loader_test.py b/helloworld/util/config_test.py similarity index 63% rename from helloworld/util/config_loader_test.py rename to helloworld/util/config_test.py index 2059a06..95237d0 100644 --- a/helloworld/util/config_loader_test.py +++ b/helloworld/util/config_test.py @@ -1,10 +1,10 @@ # Copyright 2020 Pants project contributors. # Licensed under the Apache License, Version 2.0 (see LICENSE). -from helloworld.util.config_loader import load_config_from_json +from helloworld.util.config import Config def test_load_config_from_json() -> None: - config = load_config_from_json(__name__, "config_loader_test_data.json") + config = Config.load_from_json_resource(__name__, "config_test_data.json") assert config.languages == ["af", "zh"] assert config.greetings == ["hi", "hey"] diff --git a/helloworld/util/config_loader_test_data.json b/helloworld/util/config_test_data.json similarity index 100% rename from helloworld/util/config_loader_test_data.json rename to helloworld/util/config_test_data.json diff --git a/helloworld/util/proto/BUILD b/helloworld/util/proto/BUILD deleted file mode 100644 index 8b0075d..0000000 --- a/helloworld/util/proto/BUILD +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright 2020 Pants project contributors. -# Licensed under the Apache License, Version 2.0 (see LICENSE). - -# This target sets the metadata for all the `.proto` files in this directory. -# See https://www.pantsbuild.org/docs/protobuf. -# -# * `name` defaults to the name of this directory, i.e., `proto`. -# * `sources` defaults to ["*.proto"]. -protobuf_library() - -# Note that we have an empty `__init__.py` file in this folder. Pants will generate -# `helloworld/util/proto/config_pb2.py`, and we need an `__init__.py` file in the folder for that file to be properly -# recognized. Pants will automatically use this `__init__.py` file if it exists, even though we don't have a -# `python_library` target here. diff --git a/helloworld/util/proto/__init__.py b/helloworld/util/proto/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/helloworld/util/proto/config.proto b/helloworld/util/proto/config.proto deleted file mode 100644 index 9db68bd..0000000 --- a/helloworld/util/proto/config.proto +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2020 Pants project contributors. -// Licensed under the Apache License, Version 2.0 (see LICENSE). - -syntax = "proto3"; - -package helloworld.util.proto; - -message Config { - repeated string languages = 1; - repeated string greetings = 2; -} diff --git a/pants.toml b/pants.toml index 80ed391..990837c 100644 --- a/pants.toml +++ b/pants.toml @@ -4,8 +4,6 @@ [GLOBAL] pants_version = "2.7.1" backend_packages.add = [ - "pants.backend.awslambda.python", - "pants.backend.codegen.protobuf.python", "pants.backend.python", "pants.backend.python.lint.docformatter", "pants.backend.python.lint.black", @@ -34,8 +32,3 @@ requirement_constraints = "constraints.txt" # problematic system Pythons. See # https://www.pantsbuild.org/docs/python-interpreter-compatibility#changing-the-interpreter-search-path. interpreter_search_paths = ["", ""] - -[python-protobuf] -# See https://www.pantsbuild.org/docs/protobuf. -runtime_dependencies = ["//:protobuf"] -mypy_plugin = true diff --git a/requirements.txt b/requirements.txt index 1f8d03a..5316866 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,5 +5,3 @@ ansicolors==1.1.8 setuptools>=56.2.0,<57 types-setuptools>=56.2.0,<58 translate>=3.6.1,<3.7 -protobuf>=3.17.3,<3.18 -types-protobuf>=3.17.4,<3.18 From aa17fef9d61178c3c18fe711d07feff8e0355701 Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Fri, 12 Nov 2021 14:34:00 -0700 Subject: [PATCH 48/96] Simplify example to not use `translate` requirement (#85) As explained in https://github.com/pantsbuild/example-python/pull/84, we think it's valuable for this example repository to be simple. In particular, we are demoing Pants itself, not the underlying code. This simplifies the project to use our own hardcoded `translate.json`, rather than the much more robust `translate` requirement. We still demonstrate the same things `translate` was showing for us: * third-party management * loading resource files There's an added benefit that the repository is now much faster to build, especially on Apple Silicon where `lxml` must be compiled from source. Likewise, I no longer have to force Pants to use Py39+ for this to build on my M1! The default of 3.7+ now works. --- constraints.txt | 20 ++------- helloworld/BUILD | 12 +----- helloworld/config.json | 15 ------- helloworld/greet/BUILD | 22 ++++++---- helloworld/greet/greeting.py | 29 ++++++++----- helloworld/greet/greeting_test.py | 4 +- helloworld/greet/translations.json | 18 ++++++++ helloworld/main.py | 7 +--- helloworld/{util => translator}/BUILD | 24 +++-------- helloworld/{util => translator}/__init__.py | 0 helloworld/translator/translator.py | 46 +++++++++++++++++++++ helloworld/translator/translator_test.py | 34 +++++++++++++++ helloworld/util/config.py | 21 ---------- helloworld/util/config_test.py | 10 ----- helloworld/util/config_test_data.json | 10 ----- helloworld/util/lang.py | 27 ------------ helloworld/util/lang_test.py | 17 -------- mypy.ini | 3 -- requirements.txt | 1 - 19 files changed, 145 insertions(+), 175 deletions(-) delete mode 100644 helloworld/config.json create mode 100644 helloworld/greet/translations.json rename helloworld/{util => translator}/BUILD (57%) rename helloworld/{util => translator}/__init__.py (100%) create mode 100644 helloworld/translator/translator.py create mode 100644 helloworld/translator/translator_test.py delete mode 100644 helloworld/util/config.py delete mode 100644 helloworld/util/config_test.py delete mode 100644 helloworld/util/config_test_data.json delete mode 100644 helloworld/util/lang.py delete mode 100644 helloworld/util/lang_test.py diff --git a/constraints.txt b/constraints.txt index 7fdc0f3..b7d46f1 100644 --- a/constraints.txt +++ b/constraints.txt @@ -1,19 +1,5 @@ -# Generated by build-support/generate_constraints.sh on Mon Aug 2 21:58:13 UTC 2021 +# Generated by build-support/generate_constraints.sh on Fri Nov 12 13:02:01 MST 2021 ansicolors==1.1.8 -certifi==2021.5.30 -charset-normalizer==2.0.4 -click==8.0.1 -idna==3.2 -importlib-metadata==4.6.3 -libretranslatepy==2.1.1 -lxml==4.6.3 -pip==21.2.2 -requests==2.26.0 +pip==21.3.1 setuptools==56.2.0 -six==1.16.0 -translate==3.6.1 -types-futures==0.1.6 -types-setuptools==57.0.0 -typing-extensions==3.10.0.0 -urllib3==1.26.6 -zipp==3.5.0 +types-setuptools==57.4.2 diff --git a/helloworld/BUILD b/helloworld/BUILD index 9dfa86c..9d83d5f 100644 --- a/helloworld/BUILD +++ b/helloworld/BUILD @@ -2,18 +2,8 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). # This target sets the metadata for all the Python non-test files in this directory. -# -# * `name` defaults to the name of this directory, i.e., `helloworld`. -# * `sources` defaults to ['*.py', '!*_test.py', '!test_*.py', '!conftest.py']. -# * Pants cannot infer dependencies on resources targets, so we explicitly add it. python_library( - dependencies=[":config_file"], -) - -# This target teaches Pants about our JSON file, which allows for other targets to depend on it. -resources( - name="config_file", - sources=["config.json"], + name="lib", ) # This target allows us to bundle our app into a PEX binary file via diff --git a/helloworld/config.json b/helloworld/config.json deleted file mode 100644 index 6069fa0..0000000 --- a/helloworld/config.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "languages": [ - "en", - "de", - "fr", - "es" - ], - "greetings": [ - "hello", - "good morning", - "good afternoon", - "good evening", - "salutations" - ] -} diff --git a/helloworld/greet/BUILD b/helloworld/greet/BUILD index 2194ccf..807efb0 100644 --- a/helloworld/greet/BUILD +++ b/helloworld/greet/BUILD @@ -3,13 +3,19 @@ # This target sets the metadata for all the Python non-test files in this directory. # -# * `name` defaults to the name of this directory, i.e., `greet`. -# * `sources` defaults to ['*.py', '!*_test.py', '!test_*.py', '!conftest.py']. -# * `dependencies` are inferred. -python_library() +# * Pants cannot infer dependencies on `resources` targets, so we explicitly add the dep. +python_library( + name="lib", + dependencies=[":translations"], +) # This target sets the metadata for all the Python test files in this directory. -# -# * `sources` defaults to ['*_test.py', 'test_*.py', 'conftest.py']. -# * `dependencies` are inferred. -python_tests(name='tests') +python_tests( + name="tests", +) + +# This target teaches Pants about our JSON file, which allows other targets to depend on it. +resources( + name="translations", + sources=["translations.json"], +) diff --git a/helloworld/greet/greeting.py b/helloworld/greet/greeting.py index 3338652..6a5eb1a 100644 --- a/helloworld/greet/greeting.py +++ b/helloworld/greet/greeting.py @@ -1,21 +1,30 @@ # Copyright 2020 Pants project contributors. # Licensed under the Apache License, Version 2.0 (see LICENSE). +from __future__ import annotations + +import json import random -from typing import List -from helloworld.util.lang import LanguageTranslator +import pkg_resources +from helloworld.translator.translator import LanguageTranslator -class Greeter: - def __init__(self, greetings: List[str], languages: List[str]) -> None: - self._greetings = greetings - self._language_translator = LanguageTranslator(languages=languages) - def translated_greeting(self) -> str: - random_greeting = random.choice(self._greetings) - return self._language_translator.translate_to_random_language(random_greeting) +class Greeter: + def __init__( + self, *, translations: dict[str, dict[str, str]] | None = None + ) -> None: + self._translations = ( + translations + if translations is not None + else json.loads( + pkg_resources.resource_string(__name__, "translations.json") + ) + ) + self._translator = LanguageTranslator(self._translations) def greet(self, name: str) -> str: - greeting = self.translated_greeting() + random_greeting = random.choice(list(self._translations.keys())) + greeting = self._translator.translate_to_random_language(random_greeting) return f"{greeting}, {name}!".capitalize() diff --git a/helloworld/greet/greeting_test.py b/helloworld/greet/greeting_test.py index 4faa9e8..8d43373 100644 --- a/helloworld/greet/greeting_test.py +++ b/helloworld/greet/greeting_test.py @@ -5,5 +5,5 @@ def test_greeter() -> None: - greeter = Greeter(languages=["es"], greetings=["good morning"]) - assert greeter.greet("world") == "Buenos días, world!" + greeter = Greeter(translations={"hello": {"es": "hola"}}) + assert greeter.greet("test") == "Hola, test!" diff --git a/helloworld/greet/translations.json b/helloworld/greet/translations.json new file mode 100644 index 0000000..a9eddda --- /dev/null +++ b/helloworld/greet/translations.json @@ -0,0 +1,18 @@ +{ + "hello": { + "es": "hola", + "fr": "bonjour", + "af": "hallo", + "ch": "你好", + "ru": "Привет", + "cs": "ahoj" + }, + "good night": { + "es": "buenas noches", + "fr": "bonne nuit", + "af": "Goeie nag", + "ch": "晚安", + "ru": "спокойной ночи", + "cs": "dobrou noc" + } +} diff --git a/helloworld/main.py b/helloworld/main.py index 52ca6f1..125d189 100644 --- a/helloworld/main.py +++ b/helloworld/main.py @@ -4,14 +4,11 @@ from colors import green from helloworld.greet.greeting import Greeter -from helloworld.util.config import Config def say_hello() -> None: - config = Config.load_from_json_resource(__name__, "config.json") - greeter = Greeter(languages=config.languages, greetings=config.greetings) - sentence = greeter.greet("world") - print(green(sentence)) + greeting = Greeter().greet("Pantsbuild") + print(green(greeting)) if __name__ == "__main__": diff --git a/helloworld/util/BUILD b/helloworld/translator/BUILD similarity index 57% rename from helloworld/util/BUILD rename to helloworld/translator/BUILD index bcba562..90fa7b6 100644 --- a/helloworld/util/BUILD +++ b/helloworld/translator/BUILD @@ -2,36 +2,24 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). # This target sets the metadata for all the Python non-test files in this directory. -# -# * `name` defaults to the name of this directory, i.e., `util`. -# * `sources` defaults to ['*.py', '!*_test.py', '!test_*.py', '!conftest.py']. -# * `dependencies` are inferred. -python_library() +python_library( + name="lib", +) # This target sets the metadata for all the Python test files in this directory. -# -# * `sources` defaults to ['*_test.py', 'test_*.py', 'conftest.py']. -# * Pants cannot infer dependencies on `resources` targets, so we explicitly add the dep. python_tests( - name='tests', - dependencies=[":test_data"], -) - -# This target teaches Pants about our JSON file, which allows for other targets to depend on it. -resources( - name='test_data', - sources=['*_test_data.json'], + name="tests", ) # This target allows us to build a `.whl` bdist and a `.tar.gz` sdist by auto-generating # `setup.py`. See https://www.pantsbuild.org/docs/python-distributions. # -# Because this target has no source code, Pants cannot infer dependencies. We depend on `:util`, +# Because this target has no source code, Pants cannot infer dependencies. We depend on `:lib`, # which means we'll include all the non-test Python files in this directory, and any of # their dependencies. python_distribution( name="dist", - dependencies=[":util"], + dependencies=[":lib"], setup_py_commands=["bdist_wheel", "sdist"], provides=setup_py( name='helloworld.util', diff --git a/helloworld/util/__init__.py b/helloworld/translator/__init__.py similarity index 100% rename from helloworld/util/__init__.py rename to helloworld/translator/__init__.py diff --git a/helloworld/translator/translator.py b/helloworld/translator/translator.py new file mode 100644 index 0000000..d9fb1b3 --- /dev/null +++ b/helloworld/translator/translator.py @@ -0,0 +1,46 @@ +# Copyright 2020 Pants project contributors. +# Licensed under the Apache License, Version 2.0 (see LICENSE). + +from __future__ import annotations + +import random +from dataclasses import dataclass + + +class UnknownLanguage(Exception): + pass + + +class UnknownPhrase(Exception): + pass + + +@dataclass +class LanguageTranslator: + """A mapping of phrases (in English) to ISO 639 language codes (like `es`, + `fr`) and their translation. + + Assumes that every phrase is translated into the same languages. + """ + + phrases_to_translations: dict[str, dict[str, str]] + + @property + def all_languages(self) -> set[str]: + return { + lang + for translations in self.phrases_to_translations.values() + for lang in translations.keys() + } + + def translate(self, lang: str, phrase: str) -> str: + if phrase not in self.phrases_to_translations: + raise UnknownPhrase(phrase) + translations = self.phrases_to_translations[phrase] + if lang not in translations: + raise UnknownLanguage(lang) + return translations[lang] + + def translate_to_random_language(self, phrase: str) -> str: + lang = random.choice(sorted(self.all_languages)) + return self.translate(lang, phrase) diff --git a/helloworld/translator/translator_test.py b/helloworld/translator/translator_test.py new file mode 100644 index 0000000..1f838ff --- /dev/null +++ b/helloworld/translator/translator_test.py @@ -0,0 +1,34 @@ +# Copyright 2020 Pants project contributors. +# Licensed under the Apache License, Version 2.0 (see LICENSE). + +import pytest + +from helloworld.translator.translator import ( + LanguageTranslator, + UnknownLanguage, + UnknownPhrase, +) + + +def test_language_translator() -> None: + translator = LanguageTranslator( + { + "hello": {"es": "hola", "ar": "مرحبًا"}, + "computer": {"es": "computadora", "ar": "حاسوب"}, + } + ) + assert translator.translate("es", "hello") == "hola" + assert translator.translate("ar", "hello") == "مرحبًا" + assert translator.translate("es", "computer") == "computadora" + + +def test_unknown_phrase() -> None: + translator = LanguageTranslator({"hello": {"es": "hola"}}) + with pytest.raises(UnknownPhrase): + translator.translate("es", "good morning") + + +def test_unknown_language() -> None: + translator = LanguageTranslator({"hello": {"es": "hola"}}) + with pytest.raises(UnknownLanguage): + translator.translate("ch", "hello") diff --git a/helloworld/util/config.py b/helloworld/util/config.py deleted file mode 100644 index 965e15e..0000000 --- a/helloworld/util/config.py +++ /dev/null @@ -1,21 +0,0 @@ -# Copyright 2020 Pants project contributors. -# Licensed under the Apache License, Version 2.0 (see LICENSE). - -from __future__ import annotations - -import json -from dataclasses import dataclass - -import pkg_resources - - -@dataclass -class Config: - languages: list[str] - greetings: list[str] - - @classmethod - def load_from_json_resource(cls, pkg_name: str, resource_name: str) -> Config: - resource_content = pkg_resources.resource_string(pkg_name, resource_name) - parsed = json.loads(resource_content) - return cls(languages=parsed["languages"], greetings=parsed["greetings"]) diff --git a/helloworld/util/config_test.py b/helloworld/util/config_test.py deleted file mode 100644 index 95237d0..0000000 --- a/helloworld/util/config_test.py +++ /dev/null @@ -1,10 +0,0 @@ -# Copyright 2020 Pants project contributors. -# Licensed under the Apache License, Version 2.0 (see LICENSE). - -from helloworld.util.config import Config - - -def test_load_config_from_json() -> None: - config = Config.load_from_json_resource(__name__, "config_test_data.json") - assert config.languages == ["af", "zh"] - assert config.greetings == ["hi", "hey"] diff --git a/helloworld/util/config_test_data.json b/helloworld/util/config_test_data.json deleted file mode 100644 index deeb560..0000000 --- a/helloworld/util/config_test_data.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "languages": [ - "af", - "zh" - ], - "greetings": [ - "hi", - "hey" - ] -} diff --git a/helloworld/util/lang.py b/helloworld/util/lang.py deleted file mode 100644 index 9fc49fe..0000000 --- a/helloworld/util/lang.py +++ /dev/null @@ -1,27 +0,0 @@ -# Copyright 2020 Pants project contributors. -# Licensed under the Apache License, Version 2.0 (see LICENSE). - -import random -from typing import List, cast - -from translate import Translator - - -class LanguageTranslator: - class UnknownLanguage(Exception): - pass - - def __init__(self, languages: List[str]) -> None: - self._langs = languages - - def translate(self, lang: str, phrase: str) -> str: - if lang not in self._langs: - raise self.UnknownLanguage(lang) - translator = Translator(lang) - return cast(str, translator.translate(phrase)) - - def translate_to_random_language(self, phrase: str) -> str: - return self.translate(self._pick_random_language(), phrase) - - def _pick_random_language(self) -> str: - return random.choice(self._langs) diff --git a/helloworld/util/lang_test.py b/helloworld/util/lang_test.py deleted file mode 100644 index 190a96a..0000000 --- a/helloworld/util/lang_test.py +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright 2020 Pants project contributors. -# Licensed under the Apache License, Version 2.0 (see LICENSE). - -import pytest - -from helloworld.util.lang import LanguageTranslator - - -def test_language_translator() -> None: - language_translator = LanguageTranslator(languages=["es"]) - assert "hola" == language_translator.translate("es", "hello") - - -def test_unknown_language() -> None: - language_translator = LanguageTranslator(languages=[]) - with pytest.raises(LanguageTranslator.UnknownLanguage): - language_translator.translate("xx", "hello") diff --git a/mypy.ini b/mypy.ini index 1ffad0c..77ca553 100644 --- a/mypy.ini +++ b/mypy.ini @@ -27,8 +27,5 @@ error_summary = True [mypy-colors] ignore_missing_imports = True -[mypy-translate] -ignore_missing_imports = True - [mypy-pytest] ignore_missing_imports = True diff --git a/requirements.txt b/requirements.txt index 5316866..ec244b4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,3 @@ ansicolors==1.1.8 setuptools>=56.2.0,<57 types-setuptools>=56.2.0,<58 -translate>=3.6.1,<3.7 From 280c28a8f231469793242c7b39047abed2a5271d Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Fri, 12 Nov 2021 15:51:12 -0700 Subject: [PATCH 49/96] Upgrade to Pants 2.8 (#86) --- .github/workflows/pants.yaml | 2 ++ helloworld/BUILD | 2 +- helloworld/greet/BUILD | 9 +++++---- helloworld/translator/BUILD | 11 ++++++----- pants.toml | 4 ++-- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/.github/workflows/pants.yaml b/.github/workflows/pants.yaml index 0b91c6e..b49705b 100644 --- a/.github/workflows/pants.yaml +++ b/.github/workflows/pants.yaml @@ -45,6 +45,8 @@ jobs: - name: Bootstrap Pants run: | ./pants --version + - name: Check BUILD files + run: ./pants tailor --check update-build-files --check - name: Lint and typechck run: | ./pants lint typecheck :: diff --git a/helloworld/BUILD b/helloworld/BUILD index 9d83d5f..7a3c568 100644 --- a/helloworld/BUILD +++ b/helloworld/BUILD @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). # This target sets the metadata for all the Python non-test files in this directory. -python_library( +python_sources( name="lib", ) diff --git a/helloworld/greet/BUILD b/helloworld/greet/BUILD index 807efb0..66ae252 100644 --- a/helloworld/greet/BUILD +++ b/helloworld/greet/BUILD @@ -3,8 +3,9 @@ # This target sets the metadata for all the Python non-test files in this directory. # -# * Pants cannot infer dependencies on `resources` targets, so we explicitly add the dep. -python_library( +# * Pants cannot infer dependencies on `resource` / `resources` targets, so we explicitly add the +# dep. +python_sources( name="lib", dependencies=[":translations"], ) @@ -15,7 +16,7 @@ python_tests( ) # This target teaches Pants about our JSON file, which allows other targets to depend on it. -resources( +resource( name="translations", - sources=["translations.json"], + source="translations.json", ) diff --git a/helloworld/translator/BUILD b/helloworld/translator/BUILD index 90fa7b6..7086f94 100644 --- a/helloworld/translator/BUILD +++ b/helloworld/translator/BUILD @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). # This target sets the metadata for all the Python non-test files in this directory. -python_library( +python_sources( name="lib", ) @@ -20,10 +20,11 @@ python_tests( python_distribution( name="dist", dependencies=[":lib"], - setup_py_commands=["bdist_wheel", "sdist"], + wheel=True, + sdist=True, provides=setup_py( - name='helloworld.util', - version='0.0.1', - description='Greeting library utilities.', + name="helloworld.translator", + version="0.0.1", + description="A language translator.", ), ) diff --git a/pants.toml b/pants.toml index 990837c..5a4798a 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.7.1" +pants_version = "2.8.0rc5" backend_packages.add = [ "pants.backend.python", "pants.backend.python.lint.docformatter", @@ -20,7 +20,7 @@ repo_id = "3B1D361B-E9F1-49A8-B761-03DCC41FD58E" # The Python source root is the repo root. See https://www.pantsbuild.org/docs/source-roots. root_patterns = ["/"] -[python-setup] +[python] # The default interpreter compatibility for code in this repo. Individual targets can override # this with the `interpreter_constraints` field. See # https://www.pantsbuild.org/docs/python-interpreter-compatibility. From d98ea4bb74c04a930c11527b948ba68a1f123c32 Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Wed, 17 Nov 2021 15:52:46 -0700 Subject: [PATCH 50/96] Upgrade to 2.8.0 (#87) --- pants.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pants.toml b/pants.toml index 5a4798a..c62c9d4 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.8.0rc5" +pants_version = "2.8.0" backend_packages.add = [ "pants.backend.python", "pants.backend.python.lint.docformatter", From cdd93532d21fb3d4c1ce373bc5c7f9515f400ee2 Mon Sep 17 00:00:00 2001 From: Marcelo Trylesinski Date: Sun, 28 Nov 2021 14:33:12 +0100 Subject: [PATCH 51/96] Update pants.yaml (#88) --- .github/workflows/pants.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pants.yaml b/.github/workflows/pants.yaml index b49705b..9445699 100644 --- a/.github/workflows/pants.yaml +++ b/.github/workflows/pants.yaml @@ -47,7 +47,7 @@ jobs: ./pants --version - name: Check BUILD files run: ./pants tailor --check update-build-files --check - - name: Lint and typechck + - name: Lint and typecheck run: | ./pants lint typecheck :: - name: Test From 49e386820a95ed8ec943fd0e4667ac98fc0ac2c0 Mon Sep 17 00:00:00 2001 From: Benjy Weinberger Date: Mon, 24 Jan 2022 14:28:33 -0500 Subject: [PATCH 52/96] Upgrade to Pants 2.9.0. (#89) --- pants.toml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pants.toml b/pants.toml index c62c9d4..8368d4f 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.8.0" +pants_version = "2.9.0" backend_packages.add = [ "pants.backend.python", "pants.backend.python.lint.docformatter", @@ -27,8 +27,10 @@ root_patterns = ["/"] interpreter_constraints = [">=3.7"] # Use a constraints file. See https://www.pantsbuild.org/docs/python-third-party-dependencies. requirement_constraints = "constraints.txt" + +[python-bootstrap] # We search for interpreters on both on the $PATH and in the `$(pyenv root)/versions` folder. # If you're using macOS, you may want to leave off the entry to avoid using the # problematic system Pythons. See # https://www.pantsbuild.org/docs/python-interpreter-compatibility#changing-the-interpreter-search-path. -interpreter_search_paths = ["", ""] +search_path = ["", ""] From 1b38d08821865e3756024950bc000bdbd0161b95 Mon Sep 17 00:00:00 2001 From: Stu Hood Date: Thu, 3 Feb 2022 10:43:51 -0800 Subject: [PATCH 53/96] Remove plugin/path/backend variables from `pants_from_sources` script. (#90) If someone wanted to override any of these, they could do so via environment variables. But I've never seen it be necessary to actually commit an edit, because when testing with a wildly different version of Pants, it's usually a temporary measure. --- pants_from_sources | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/pants_from_sources b/pants_from_sources index 733aae1..4d26a76 100755 --- a/pants_from_sources +++ b/pants_from_sources @@ -16,29 +16,7 @@ PANTS_SOURCE="${PANTS_SOURCE:-../pants}" # you won't want pantsd running. You can override this by setting ENABLE_PANTSD=true. ENABLE_PANTSD="${ENABLE_PANTSD:-false}" -backend_packages=( -) - -pythonpath=( -) - -plugins=( -) - -function string_list() { - eval local -r list_variable="\${$1[@]}" - - echo -n "[" - for item in ${list_variable}; do - echo -n "\"${item}\"," - done - echo -n "]" -} - export PANTS_VERSION="$(cat "${PANTS_SOURCE}/src/python/pants/VERSION")" -export PANTS_PLUGINS="$(string_list plugins)" -export PANTS_PYTHONPATH="+$(string_list pythonpath)" -export PANTS_BACKEND_PACKAGES="+$(string_list backend_packages)" export PANTS_PANTSD="${ENABLE_PANTSD}" export no_proxy="*" From 5c9912ec454e660d65085b9f6d5dfaf19610b580 Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Tue, 8 Feb 2022 10:38:06 -0700 Subject: [PATCH 54/96] Upgrade to Pants 2.10 (#91) --- .github/workflows/pants.yaml | 2 +- BUILD | 2 +- README.md | 27 +++++++++------------------ build-support/generate_constraints.sh | 18 ------------------ constraints.txt | 5 ----- helloworld/greet/BUILD | 4 ++-- lockfile.txt | 27 +++++++++++++++++++++++++++ pants.toml | 16 +++++++++++++--- 8 files changed, 53 insertions(+), 48 deletions(-) delete mode 100755 build-support/generate_constraints.sh delete mode 100644 constraints.txt create mode 100644 lockfile.txt diff --git a/.github/workflows/pants.yaml b/.github/workflows/pants.yaml index 9445699..ffd18d4 100644 --- a/.github/workflows/pants.yaml +++ b/.github/workflows/pants.yaml @@ -49,7 +49,7 @@ jobs: run: ./pants tailor --check update-build-files --check - name: Lint and typecheck run: | - ./pants lint typecheck :: + ./pants lint check :: - name: Test run: | ./pants test :: diff --git a/BUILD b/BUILD index fe5c7bb..fca77e4 100644 --- a/BUILD +++ b/BUILD @@ -4,4 +4,4 @@ # A macro that turns every entry in this directory's requirements.txt into a # `python_requirement_library` target. Refer to # https://www.pantsbuild.org/docs/python-third-party-dependencies. -python_requirements() +python_requirements(name="reqs") diff --git a/README.md b/README.md index d4f1dae..0eb2d34 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Pants commands are called _goals_. You can get a list of goals with # Targets Targets are a way of setting metadata for some part of your code, such as timeouts for tests and -entry points for binaries. Targets have types like `python_binary`, `resources`, and +entry points for binaries. Targets have types like `python_source`, `resources`, and `pex_binary`. They are defined in `BUILD` files. Pants goals can be invoked on targets or directly on source files (which is often more intuitive and convenient). @@ -78,12 +78,6 @@ Targets are referenced on the command line using their address, of the form `pat ./pants lint helloworld/util:util ``` -You can omit the target name if it is the same as the immediately enclosing directory name, e.g., - -``` -./pants lint helloworld/util -``` - You can glob over all targets in a directory with a single trailing `:`, or over all targets in a directory and all its subdirectories with a double trailing `::`, e.g., @@ -103,11 +97,6 @@ those, rather than error. So you can safely do things like To run all tests. -In some cases trying to run a goal on multiple files or targets will fail due to conflicts. For example, you cannot -`./pants repl helloworld::` because that globs over both Python 2 and Python 3 code, so there is -no way to select an interpreter compatible with both both to run the REPL on. - - # Example Goals Try these out in this repo! @@ -123,13 +112,13 @@ Try these out in this repo! ``` ./pants lint :: -./pants fmt 'helloworld/**/*.py' +./pants fmt helloworld/greet:: ``` ## Run MyPy ``` -./pants typecheck :: +./pants check :: ``` ## Run tests @@ -157,7 +146,7 @@ Try these out in this repo! ``` ./pants repl helloworld/greet # The REPL will have all relevant code and dependencies on its sys.path. -./pants repl --shell=ipython helloworld/greet +./pants repl --shell=ipython helloworld/greet --no-pantsd # To use IPython, you must disable Pantsd for now. ``` ## Build a wheel / generate `setup.py` @@ -168,11 +157,13 @@ This will build both a `.whl` bdist and a `.tar.gz` sdist. ./pants package helloworld/util:dist ``` -We can also remove the `setup_py_commands` field from `helloworld/util/BUILD` to have Pants instead generate a -`setup.py` file, with all the relevant code in a chroot. - ## Count lines of code ``` ./pants count-loc '**/*' ``` +## Create virtualenv for IDE integration + +``` +./pants export :: +``` diff --git a/build-support/generate_constraints.sh b/build-support/generate_constraints.sh deleted file mode 100755 index dbaf0d8..0000000 --- a/build-support/generate_constraints.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2020 Pants project contributors (see CONTRIBUTORS.md). -# Licensed under the Apache License, Version 2.0 (see LICENSE). - -# See https://www.pantsbuild.org/v2.0/docs/python-third-party-dependencies. - -set -euo pipefail - -PYTHON_BIN=python3 -VIRTUALENV=build-support/.venv -PIP="${VIRTUALENV}/bin/pip" -CONSTRAINTS_FILE=constraints.txt - -"${PYTHON_BIN}" -m venv "${VIRTUALENV}" -"${PIP}" install pip --upgrade -"${PIP}" install -r <(./pants dependencies --type=3rdparty ::) -echo "# Generated by build-support/generate_constraints.sh on $(date)" > "${CONSTRAINTS_FILE}" -"${PIP}" freeze --all >> "${CONSTRAINTS_FILE}" diff --git a/constraints.txt b/constraints.txt deleted file mode 100644 index b7d46f1..0000000 --- a/constraints.txt +++ /dev/null @@ -1,5 +0,0 @@ -# Generated by build-support/generate_constraints.sh on Fri Nov 12 13:02:01 MST 2021 -ansicolors==1.1.8 -pip==21.3.1 -setuptools==56.2.0 -types-setuptools==57.4.2 diff --git a/helloworld/greet/BUILD b/helloworld/greet/BUILD index 66ae252..6dcc65e 100644 --- a/helloworld/greet/BUILD +++ b/helloworld/greet/BUILD @@ -3,8 +3,8 @@ # This target sets the metadata for all the Python non-test files in this directory. # -# * Pants cannot infer dependencies on `resource` / `resources` targets, so we explicitly add the -# dep. +# * Pants cannot yet infer dependencies on `resource` / `resources` targets, so we explicitly add +# the dep. python_sources( name="lib", dependencies=[":translations"], diff --git a/lockfile.txt b/lockfile.txt new file mode 100644 index 0000000..859d917 --- /dev/null +++ b/lockfile.txt @@ -0,0 +1,27 @@ +# This lockfile was autogenerated by Pants. To regenerate, run: +# +# ./pants generate-lockfiles --resolve=python-default +# +# --- BEGIN PANTS LOCKFILE METADATA: DO NOT EDIT OR REMOVE --- +# { +# "version": 2, +# "valid_for_interpreter_constraints": [ +# "CPython>=3.7" +# ], +# "generated_with_requirements": [ +# "ansicolors==1.1.8", +# "setuptools<57,>=56.2.0", +# "types-setuptools<58,>=56.2.0" +# ] +# } +# --- END PANTS LOCKFILE METADATA --- + +ansicolors==1.1.8 \ + --hash=sha256:00d2dde5a675579325902536738dd27e4fac1fd68f773fe36c21044eb559e187 \ + --hash=sha256:99f94f5e3348a0bcd43c82e5fc4414013ccc19d70bd939ad71e0133ce9c372e0 +setuptools==56.2.0; python_version >= "3.6" \ + --hash=sha256:bc30153eec47d82f20c6f5e1a13d4ee725c6deb7013a67557f89bfe5d25235c4 \ + --hash=sha256:7bb5652625e94e73b9358b7ed8c6431b732e80cf31f4e0972294c64f0e5b849e +types-setuptools==57.4.9 \ + --hash=sha256:536ef74744f8e1e4be4fc719887f886e74e4cf3c792b4a06984320be4df450b5 \ + --hash=sha256:948dc6863373750e2cd0b223a84f1fb608414cde5e55cf38ea657b93aeb411d2 diff --git a/pants.toml b/pants.toml index 8368d4f..b9c6cec 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.9.0" +pants_version = "2.10.0rc0" backend_packages.add = [ "pants.backend.python", "pants.backend.python.lint.docformatter", @@ -12,6 +12,11 @@ backend_packages.add = [ "pants.backend.python.typecheck.mypy", ] +# This will become the default in 2.11, and is only explicitly set to not break +# backwards-compatibility for existing users. If you are setting up Pants for +# the first time, set this to false. +use_deprecated_python_macros = false + [anonymous-telemetry] enabled = true repo_id = "3B1D361B-E9F1-49A8-B761-03DCC41FD58E" @@ -24,9 +29,14 @@ root_patterns = ["/"] # The default interpreter compatibility for code in this repo. Individual targets can override # this with the `interpreter_constraints` field. See # https://www.pantsbuild.org/docs/python-interpreter-compatibility. +# +# If you use Apple Silicon, set to a value like `>=3.9`. interpreter_constraints = [">=3.7"] -# Use a constraints file. See https://www.pantsbuild.org/docs/python-third-party-dependencies. -requirement_constraints = "constraints.txt" + +# Enable the "resolves" mechanism, which allows you to have multiple lockfiles and for Pants to +# generate the lockfiles for you. See https://www.pantsbuild.org/docs/python-third-party-dependencies. +enable_resolves = true +resolves = { python-default = "lockfile.txt"} [python-bootstrap] # We search for interpreters on both on the $PATH and in the `$(pyenv root)/versions` folder. From 1ba1247b824c8756780477ffd44692a21d702d65 Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Mon, 14 Feb 2022 11:57:57 -0700 Subject: [PATCH 55/96] Revert using Python resolves feature (#93) We decided to not widely publicize resolves in Pants 2.10. Pants's mechanism works great, but using Poetry for lockfile generation is causing several issues: * `[python-repos]` does not work * VCS/local requirements don't work * some transitive deps end up with environment markers that are nonsensical and cause the resolve to fail. There is a workaround, but it's not obvious. This didn't hit example-python, but did hit a user of Pants. We'll switch to resolves once we can use Pex for lockfile generation: https://github.com/pantsbuild/pants/issues/13964 --- build-support/generate_constraints.sh | 18 ++++++++++++++++++ constraints.txt | 5 +++++ lockfile.txt | 27 --------------------------- pants.toml | 11 ++++++----- 4 files changed, 29 insertions(+), 32 deletions(-) create mode 100644 build-support/generate_constraints.sh create mode 100644 constraints.txt delete mode 100644 lockfile.txt diff --git a/build-support/generate_constraints.sh b/build-support/generate_constraints.sh new file mode 100644 index 0000000..dbaf0d8 --- /dev/null +++ b/build-support/generate_constraints.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +# Copyright 2020 Pants project contributors (see CONTRIBUTORS.md). +# Licensed under the Apache License, Version 2.0 (see LICENSE). + +# See https://www.pantsbuild.org/v2.0/docs/python-third-party-dependencies. + +set -euo pipefail + +PYTHON_BIN=python3 +VIRTUALENV=build-support/.venv +PIP="${VIRTUALENV}/bin/pip" +CONSTRAINTS_FILE=constraints.txt + +"${PYTHON_BIN}" -m venv "${VIRTUALENV}" +"${PIP}" install pip --upgrade +"${PIP}" install -r <(./pants dependencies --type=3rdparty ::) +echo "# Generated by build-support/generate_constraints.sh on $(date)" > "${CONSTRAINTS_FILE}" +"${PIP}" freeze --all >> "${CONSTRAINTS_FILE}" diff --git a/constraints.txt b/constraints.txt new file mode 100644 index 0000000..b7d46f1 --- /dev/null +++ b/constraints.txt @@ -0,0 +1,5 @@ +# Generated by build-support/generate_constraints.sh on Fri Nov 12 13:02:01 MST 2021 +ansicolors==1.1.8 +pip==21.3.1 +setuptools==56.2.0 +types-setuptools==57.4.2 diff --git a/lockfile.txt b/lockfile.txt deleted file mode 100644 index 859d917..0000000 --- a/lockfile.txt +++ /dev/null @@ -1,27 +0,0 @@ -# This lockfile was autogenerated by Pants. To regenerate, run: -# -# ./pants generate-lockfiles --resolve=python-default -# -# --- BEGIN PANTS LOCKFILE METADATA: DO NOT EDIT OR REMOVE --- -# { -# "version": 2, -# "valid_for_interpreter_constraints": [ -# "CPython>=3.7" -# ], -# "generated_with_requirements": [ -# "ansicolors==1.1.8", -# "setuptools<57,>=56.2.0", -# "types-setuptools<58,>=56.2.0" -# ] -# } -# --- END PANTS LOCKFILE METADATA --- - -ansicolors==1.1.8 \ - --hash=sha256:00d2dde5a675579325902536738dd27e4fac1fd68f773fe36c21044eb559e187 \ - --hash=sha256:99f94f5e3348a0bcd43c82e5fc4414013ccc19d70bd939ad71e0133ce9c372e0 -setuptools==56.2.0; python_version >= "3.6" \ - --hash=sha256:bc30153eec47d82f20c6f5e1a13d4ee725c6deb7013a67557f89bfe5d25235c4 \ - --hash=sha256:7bb5652625e94e73b9358b7ed8c6431b732e80cf31f4e0972294c64f0e5b849e -types-setuptools==57.4.9 \ - --hash=sha256:536ef74744f8e1e4be4fc719887f886e74e4cf3c792b4a06984320be4df450b5 \ - --hash=sha256:948dc6863373750e2cd0b223a84f1fb608414cde5e55cf38ea657b93aeb411d2 diff --git a/pants.toml b/pants.toml index b9c6cec..d98deaf 100644 --- a/pants.toml +++ b/pants.toml @@ -26,17 +26,18 @@ repo_id = "3B1D361B-E9F1-49A8-B761-03DCC41FD58E" root_patterns = ["/"] [python] -# The default interpreter compatibility for code in this repo. Individual targets can override +# The default interpreter constraints for code in this repo. Individual targets can override # this with the `interpreter_constraints` field. See # https://www.pantsbuild.org/docs/python-interpreter-compatibility. # +# It's usually a good idea to pin this to a particular version, e.g. `==3.9.*`. We only use a range +# so that this example works on many different machines. +# # If you use Apple Silicon, set to a value like `>=3.9`. interpreter_constraints = [">=3.7"] -# Enable the "resolves" mechanism, which allows you to have multiple lockfiles and for Pants to -# generate the lockfiles for you. See https://www.pantsbuild.org/docs/python-third-party-dependencies. -enable_resolves = true -resolves = { python-default = "lockfile.txt"} +# Use a constraints file. See https://www.pantsbuild.org/docs/python-third-party-dependencies. +requirement_constraints = "constraints.txt" [python-bootstrap] # We search for interpreters on both on the $PATH and in the `$(pyenv root)/versions` folder. From 30ace119272a9273d32cfce1c4478609faccb103 Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Fri, 11 Mar 2022 10:52:40 -0700 Subject: [PATCH 56/96] Go back to using resolves, but hedge about lockfile generation (#94) Reverts https://github.com/pantsbuild/example-python/pull/93. As discussed in https://pantsbuild.slack.com/archives/C0D7TNJHL/p1646948835870139, we believe that multiple resolves even with manual generation is still an improvement over `[python].requirement_constraints`. The hope is that most users can use `generate-lockfiles` directly, but if not, our new docs continue to give some techniques for manual lockfile generation. Our 2.10 docs no longer discuss `requirement_constraints`, in favor of resolves. --- build-support/generate_constraints.sh | 18 ------------------ constraints.txt | 5 ----- lockfile.txt | 27 +++++++++++++++++++++++++++ pants.toml | 12 ++++++++---- 4 files changed, 35 insertions(+), 27 deletions(-) delete mode 100644 build-support/generate_constraints.sh delete mode 100644 constraints.txt create mode 100644 lockfile.txt diff --git a/build-support/generate_constraints.sh b/build-support/generate_constraints.sh deleted file mode 100644 index dbaf0d8..0000000 --- a/build-support/generate_constraints.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2020 Pants project contributors (see CONTRIBUTORS.md). -# Licensed under the Apache License, Version 2.0 (see LICENSE). - -# See https://www.pantsbuild.org/v2.0/docs/python-third-party-dependencies. - -set -euo pipefail - -PYTHON_BIN=python3 -VIRTUALENV=build-support/.venv -PIP="${VIRTUALENV}/bin/pip" -CONSTRAINTS_FILE=constraints.txt - -"${PYTHON_BIN}" -m venv "${VIRTUALENV}" -"${PIP}" install pip --upgrade -"${PIP}" install -r <(./pants dependencies --type=3rdparty ::) -echo "# Generated by build-support/generate_constraints.sh on $(date)" > "${CONSTRAINTS_FILE}" -"${PIP}" freeze --all >> "${CONSTRAINTS_FILE}" diff --git a/constraints.txt b/constraints.txt deleted file mode 100644 index b7d46f1..0000000 --- a/constraints.txt +++ /dev/null @@ -1,5 +0,0 @@ -# Generated by build-support/generate_constraints.sh on Fri Nov 12 13:02:01 MST 2021 -ansicolors==1.1.8 -pip==21.3.1 -setuptools==56.2.0 -types-setuptools==57.4.2 diff --git a/lockfile.txt b/lockfile.txt new file mode 100644 index 0000000..859d917 --- /dev/null +++ b/lockfile.txt @@ -0,0 +1,27 @@ +# This lockfile was autogenerated by Pants. To regenerate, run: +# +# ./pants generate-lockfiles --resolve=python-default +# +# --- BEGIN PANTS LOCKFILE METADATA: DO NOT EDIT OR REMOVE --- +# { +# "version": 2, +# "valid_for_interpreter_constraints": [ +# "CPython>=3.7" +# ], +# "generated_with_requirements": [ +# "ansicolors==1.1.8", +# "setuptools<57,>=56.2.0", +# "types-setuptools<58,>=56.2.0" +# ] +# } +# --- END PANTS LOCKFILE METADATA --- + +ansicolors==1.1.8 \ + --hash=sha256:00d2dde5a675579325902536738dd27e4fac1fd68f773fe36c21044eb559e187 \ + --hash=sha256:99f94f5e3348a0bcd43c82e5fc4414013ccc19d70bd939ad71e0133ce9c372e0 +setuptools==56.2.0; python_version >= "3.6" \ + --hash=sha256:bc30153eec47d82f20c6f5e1a13d4ee725c6deb7013a67557f89bfe5d25235c4 \ + --hash=sha256:7bb5652625e94e73b9358b7ed8c6431b732e80cf31f4e0972294c64f0e5b849e +types-setuptools==57.4.9 \ + --hash=sha256:536ef74744f8e1e4be4fc719887f886e74e4cf3c792b4a06984320be4df450b5 \ + --hash=sha256:948dc6863373750e2cd0b223a84f1fb608414cde5e55cf38ea657b93aeb411d2 diff --git a/pants.toml b/pants.toml index d98deaf..6b89b95 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.10.0rc0" +pants_version = "2.10.0rc3" backend_packages.add = [ "pants.backend.python", "pants.backend.python.lint.docformatter", @@ -36,11 +36,15 @@ root_patterns = ["/"] # If you use Apple Silicon, set to a value like `>=3.9`. interpreter_constraints = [">=3.7"] -# Use a constraints file. See https://www.pantsbuild.org/docs/python-third-party-dependencies. -requirement_constraints = "constraints.txt" +# Enable the "resolves" mechanism, which turns on lockfiles for user code. See +# https://www.pantsbuild.org/docs/python-third-party-dependencies. This also adds the +# `generate-lockfiles` goal for Pants to generate the lockfile for you, although in some +# situations you may need to manually generate it, as explained in the docs. +enable_resolves = true +resolves = { python-default = "lockfile.txt"} [python-bootstrap] -# We search for interpreters on both on the $PATH and in the `$(pyenv root)/versions` folder. +# We search for interpreters both on the $PATH and in the `$(pyenv root)/versions` folder. # If you're using macOS, you may want to leave off the entry to avoid using the # problematic system Pythons. See # https://www.pantsbuild.org/docs/python-interpreter-compatibility#changing-the-interpreter-search-path. From d06a275bb89a0e353a494127fd8e4d9f1ead9e8e Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Tue, 15 Mar 2022 15:01:48 -0700 Subject: [PATCH 57/96] Run CI on branches too (#95) --- .github/workflows/pants.yaml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/pants.yaml b/.github/workflows/pants.yaml index ffd18d4..3d1f997 100644 --- a/.github/workflows/pants.yaml +++ b/.github/workflows/pants.yaml @@ -5,11 +5,7 @@ name: Pants -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] +on: [push, pull_request] jobs: org-check: From 2062fd92eaf779143625a5e90c3689c306466a94 Mon Sep 17 00:00:00 2001 From: Benjy Weinberger Date: Tue, 22 Mar 2022 10:28:02 -0700 Subject: [PATCH 58/96] Fix the README examples, and upgrade to a non-busted Pants. (#97) --- README.md | 25 +++++++++++++------------ pants.toml | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 0eb2d34..b2c00c5 100644 --- a/README.md +++ b/README.md @@ -37,25 +37,25 @@ In the latter case, Pants locates target metadata for the source files as needed Invoking goals on files is straightforward, e.g., ``` -./pants test helloworld/util/lang_test.py +./pants test helloworld/greet/greeting_test.py ``` You can use globs: ``` -./pants lint helloworld/util/*.py +./pants lint helloworld/greet/*.py ``` But note that these will be expanded by your shell, so this is equivalent to having used ``` -./pants lint helloworld/util/lang.py helloworld/util/lang_test.py helloworld/util/resources.py helloworld/util/resources_test.py +./pants lint helloworld/greet/__init__.py helloworld/greet/greeting.py helloworld/greet/greeting_test.py ``` If you want Pants itself to expand the globs (which is sometimes necessary), you must quote them in the shell: ``` -./pants lint 'helloworld/util/*.py' +./pants lint 'helloworld/greet/*.py' ``` You can run on all changed files: @@ -75,7 +75,7 @@ You can run on all changed files, and any of their "dependees": Targets are referenced on the command line using their address, of the form `path/to/dir:name`, e.g., ``` -./pants lint helloworld/util:util +./pants lint helloworld/greet:lib ``` You can glob over all targets in a directory with a single trailing `:`, or over all targets in a directory @@ -125,9 +125,10 @@ Try these out in this repo! ``` ./pants test :: # Run all tests in the repo. -./pants test helloworld/util:test # Run all the tests in this target. -./pants test helloworld/util/lang_test.py # Run just the tests in this file. -./pants test helloworld/util/lang_test.py -- -k test_language_translator # Run just this one test. +./pants test --output=all :: # Run all tests in the repo and view pytest output even for tests that passed (you can set this permanently in pants.toml). +./pants test helloworld/translator:tests # Run all the tests in this target. +./pants test helloworld/translator/translator_test.py # Run just the tests in this file. +./pants test helloworld/translator/translator_test.py -- -k test_unknown_phrase # Run just this one test by passing through pytest args. ``` ## Create a PEX binary @@ -136,7 +137,7 @@ Try these out in this repo! ./pants package helloworld/main.py ``` -## Run a binary +## Run a binary directly ``` ./pants run helloworld/main.py @@ -145,8 +146,8 @@ Try these out in this repo! ## Open a REPL ``` -./pants repl helloworld/greet # The REPL will have all relevant code and dependencies on its sys.path. -./pants repl --shell=ipython helloworld/greet --no-pantsd # To use IPython, you must disable Pantsd for now. +./pants repl helloworld/greet:lib # The REPL will have all relevant code and dependencies on its sys.path. +./pants repl --shell=ipython helloworld/greet:lib --no-pantsd # To use IPython, you must disable Pantsd for now. ``` ## Build a wheel / generate `setup.py` @@ -154,7 +155,7 @@ Try these out in this repo! This will build both a `.whl` bdist and a `.tar.gz` sdist. ``` -./pants package helloworld/util:dist +./pants package helloworld/translator:dist ``` ## Count lines of code diff --git a/pants.toml b/pants.toml index 6b89b95..453a9b1 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.10.0rc3" +pants_version = "2.10.0rc5" backend_packages.add = [ "pants.backend.python", "pants.backend.python.lint.docformatter", From 42a7c04a71fdc4b1c5e7d97e51793bc24580e021 Mon Sep 17 00:00:00 2001 From: James Webster Date: Thu, 24 Mar 2022 08:56:21 +1000 Subject: [PATCH 59/96] Add MacOS/Apple Silicon guidance for changes to pants.toml (#98) It looks me a couple of attempts to successfully follow along from the README.md on a MacBook Pro with Apple Silicon., ultimately coming down to needing to properly configure pants.toml to use pyenv and update the Python interpreter dependency. I believe the statement added to the README.md by this commit will help others in the same situation. --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index b2c00c5..49f48cc 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,10 @@ example layouts. You run Pants goals using the `./pants` wrapper script, which will bootstrap the configured version of Pants if necessary. +> :question: Running with Apple Silicon and/or MacOS? You will want to make changes to the `search_path` and +`interpreter_constraints` values in `pants.toml` before running `./pants` - there is guidance in `pants.toml` +for those settings. + Use `./pants --version` to see the version of Pants configured for the repo (which you can also find in `pants.toml`). From 93a76bce6fbbc7d027fc2bbfa7b682d1e94f1d2a Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Wed, 23 Mar 2022 19:34:39 -0700 Subject: [PATCH 60/96] Upgrade to 2.10.0 (#99) --- pants.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pants.toml b/pants.toml index 453a9b1..ab3b3b7 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.10.0rc5" +pants_version = "2.10.0" backend_packages.add = [ "pants.backend.python", "pants.backend.python.lint.docformatter", From 68387a9f5f1a1cb288820f8ebb5d6f66d95c888a Mon Sep 17 00:00:00 2001 From: Stu Hood Date: Wed, 27 Apr 2022 14:53:06 -0700 Subject: [PATCH 61/96] Upgrade to `2.11.0rc5` (#100) * Upgrade to `2.11.0rc5`. * Switch to `[python].lockfile_generator=pex`. --- lockfile.txt | 156 ++++++++++++++++++++++++++++++++++++++++++--------- pants.toml | 11 ++-- 2 files changed, 135 insertions(+), 32 deletions(-) diff --git a/lockfile.txt b/lockfile.txt index 859d917..bc43916 100644 --- a/lockfile.txt +++ b/lockfile.txt @@ -1,27 +1,131 @@ -# This lockfile was autogenerated by Pants. To regenerate, run: -# -# ./pants generate-lockfiles --resolve=python-default -# -# --- BEGIN PANTS LOCKFILE METADATA: DO NOT EDIT OR REMOVE --- -# { -# "version": 2, -# "valid_for_interpreter_constraints": [ -# "CPython>=3.7" -# ], -# "generated_with_requirements": [ -# "ansicolors==1.1.8", -# "setuptools<57,>=56.2.0", -# "types-setuptools<58,>=56.2.0" -# ] -# } -# --- END PANTS LOCKFILE METADATA --- +// This lockfile was autogenerated by Pants. To regenerate, run: +// +// ./pants generate-lockfiles --resolve=python-default +// +// --- BEGIN PANTS LOCKFILE METADATA: DO NOT EDIT OR REMOVE --- +// { +// "version": 2, +// "valid_for_interpreter_constraints": [ +// "CPython>=3.7" +// ], +// "generated_with_requirements": [ +// "ansicolors==1.1.8", +// "setuptools<57,>=56.2.0", +// "types-setuptools<58,>=56.2.0" +// ] +// } +// --- END PANTS LOCKFILE METADATA --- -ansicolors==1.1.8 \ - --hash=sha256:00d2dde5a675579325902536738dd27e4fac1fd68f773fe36c21044eb559e187 \ - --hash=sha256:99f94f5e3348a0bcd43c82e5fc4414013ccc19d70bd939ad71e0133ce9c372e0 -setuptools==56.2.0; python_version >= "3.6" \ - --hash=sha256:bc30153eec47d82f20c6f5e1a13d4ee725c6deb7013a67557f89bfe5d25235c4 \ - --hash=sha256:7bb5652625e94e73b9358b7ed8c6431b732e80cf31f4e0972294c64f0e5b849e -types-setuptools==57.4.9 \ - --hash=sha256:536ef74744f8e1e4be4fc719887f886e74e4cf3c792b4a06984320be4df450b5 \ - --hash=sha256:948dc6863373750e2cd0b223a84f1fb608414cde5e55cf38ea657b93aeb411d2 +{ + "allow_builds": true, + "allow_prereleases": false, + "allow_wheels": true, + "build_isolation": true, + "constraints": [], + "locked_resolves": [ + { + "locked_requirements": [ + { + "artifacts": [ + { + "algorithm": "sha256", + "hash": "00d2dde5a675579325902536738dd27e4fac1fd68f773fe36c21044eb559e187", + "url": "https://files.pythonhosted.org/packages/53/18/a56e2fe47b259bb52201093a3a9d4a32014f9d85071ad07e9d60600890ca/ansicolors-1.1.8-py2.py3-none-any.whl" + }, + { + "algorithm": "sha256", + "hash": "99f94f5e3348a0bcd43c82e5fc4414013ccc19d70bd939ad71e0133ce9c372e0", + "url": "https://files.pythonhosted.org/packages/76/31/7faed52088732704523c259e24c26ce6f2f33fbeff2ff59274560c27628e/ansicolors-1.1.8.zip" + } + ], + "project_name": "ansicolors", + "requires_dists": [], + "requires_python": null, + "version": "1.1.8" + }, + { + "artifacts": [ + { + "algorithm": "sha256", + "hash": "bc30153eec47d82f20c6f5e1a13d4ee725c6deb7013a67557f89bfe5d25235c4", + "url": "https://files.pythonhosted.org/packages/d0/15/5041473f5d142ee93bf1593deb8f932e27a078f6f04e2020cf44044f72c5/setuptools-56.2.0-py3-none-any.whl" + }, + { + "algorithm": "sha256", + "hash": "7bb5652625e94e73b9358b7ed8c6431b732e80cf31f4e0972294c64f0e5b849e", + "url": "https://files.pythonhosted.org/packages/fc/0a/b486efab52f8ad03c3eca0c998dd3deafba0c39b29e0c49c68a7152c8b2d/setuptools-56.2.0.tar.gz" + } + ], + "project_name": "setuptools", + "requires_dists": [ + "certifi==2016.9.26; extra == \"certs\"", + "flake8-2020; extra == \"testing\"", + "jaraco.envs; extra == \"testing\"", + "jaraco.packaging>=8.2; extra == \"docs\"", + "jaraco.path>=3.2.0; extra == \"testing\"", + "mock; extra == \"testing\"", + "paver; extra == \"testing\"", + "pip>=19.1; extra == \"testing\"", + "pygments-github-lexers==0.0.5; extra == \"docs\"", + "pytest-black>=0.3.7; (platform_python_implementation != \"PyPy\" and python_version < \"3.10\") and extra == \"testing\"", + "pytest-checkdocs>=2.4; extra == \"testing\"", + "pytest-cov; extra == \"testing\"", + "pytest-enabler>=1.0.1; extra == \"testing\"", + "pytest-flake8; extra == \"testing\"", + "pytest-mypy; (platform_python_implementation != \"PyPy\" and python_version < \"3.10\") and extra == \"testing\"", + "pytest-virtualenv>=1.2.7; extra == \"testing\"", + "pytest-xdist; extra == \"testing\"", + "pytest>=4.6; extra == \"testing\"", + "rst.linker>=1.9; extra == \"docs\"", + "sphinx-inline-tabs; extra == \"docs\"", + "sphinx; extra == \"docs\"", + "sphinx; extra == \"testing\"", + "virtualenv>=13.0.0; extra == \"testing\"", + "wheel; extra == \"testing\"", + "wincertstore==0.2; sys_platform == \"win32\" and extra == \"ssl\"" + ], + "requires_python": ">=3.6", + "version": "56.2" + }, + { + "artifacts": [ + { + "algorithm": "sha256", + "hash": "828f7e7e51e157876f47c80518b23ba0c3c36aa8081efd39d5d39f393938aec9", + "url": "https://files.pythonhosted.org/packages/c8/0d/6c9eb15fd4f6f45973ff1c70c170f2c30803415874e2e47c92eeae509085/types_setuptools-57.4.14-py3-none-any.whl" + }, + { + "algorithm": "sha256", + "hash": "df02fe1dd244f58cf4e67cfc3d0a97930a2d61a72dd89f21d81c71017cd83f9a", + "url": "https://files.pythonhosted.org/packages/42/2e/d21d995feca499eac401958fee97879926249e60b8e5608f0361f0ee2ae1/types-setuptools-57.4.14.tar.gz" + } + ], + "project_name": "types-setuptools", + "requires_dists": [], + "requires_python": null, + "version": "57.4.14" + } + ], + "platform_tag": [ + "cp36", + "cp36m", + "macosx_10_16_x86_64" + ] + } + ], + "path_mappings": {}, + "pex_version": "2.1.80", + "prefer_older_binary": false, + "requirements": [ + "ansicolors==1.1.8", + "setuptools<57,>=56.2.0", + "types-setuptools<58,>=56.2.0" + ], + "requires_python": [ + ">=3.7" + ], + "resolver_version": "pip-2020-resolver", + "style": "universal", + "transitive": true, + "use_pep517": null +} \ No newline at end of file diff --git a/pants.toml b/pants.toml index ab3b3b7..7ace217 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.10.0" +pants_version = "2.11.0rc5" backend_packages.add = [ "pants.backend.python", "pants.backend.python.lint.docformatter", @@ -12,11 +12,6 @@ backend_packages.add = [ "pants.backend.python.typecheck.mypy", ] -# This will become the default in 2.11, and is only explicitly set to not break -# backwards-compatibility for existing users. If you are setting up Pants for -# the first time, set this to false. -use_deprecated_python_macros = false - [anonymous-telemetry] enabled = true repo_id = "3B1D361B-E9F1-49A8-B761-03DCC41FD58E" @@ -43,6 +38,10 @@ interpreter_constraints = [">=3.7"] enable_resolves = true resolves = { python-default = "lockfile.txt"} +# Enable using the PEX lockfile format, which provides support for custom indexes, and +# improves performance for large repositories. +lockfile_generator = "pex" + [python-bootstrap] # We search for interpreters both on the $PATH and in the `$(pyenv root)/versions` folder. # If you're using macOS, you may want to leave off the entry to avoid using the From 7dcd166057bdd71d4e29dad2a81b0af9e444847d Mon Sep 17 00:00:00 2001 From: Asher Foa Date: Wed, 29 Jun 2022 17:17:12 -0400 Subject: [PATCH 62/96] Upgrade to pants 2.12.0 (#101) --- pants.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pants.toml b/pants.toml index 7ace217..6511998 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.11.0rc5" +pants_version = "2.12.0" backend_packages.add = [ "pants.backend.python", "pants.backend.python.lint.docformatter", From 7110abba9b397bcb6441e21246b25f060d658d1d Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer <_@chrisjrn.com> Date: Tue, 26 Jul 2022 09:12:01 -0700 Subject: [PATCH 63/96] Adds sample (inactive) Toolchain config to `pants(.ci).toml` (#103) --- pants.ci.toml | 9 +++++++++ pants.toml | 26 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/pants.ci.toml b/pants.ci.toml index f8aafcb..446bd0d 100644 --- a/pants.ci.toml +++ b/pants.ci.toml @@ -7,5 +7,14 @@ dynamic_ui = false colors = true +# Set to `true` if you have a Pants remote cache provider available for CI builds +remote_cache_read = false +remote_cache_write = false + [pytest] args = ["-vv", "--no-header"] + +# Toolchain plugin auth configuration +[auth] +from_env_var = "TOOLCHAIN_AUTH_TOKEN" +org = "pantsbuild" diff --git a/pants.toml b/pants.toml index 6511998..8ebde2d 100644 --- a/pants.toml +++ b/pants.toml @@ -12,6 +12,21 @@ backend_packages.add = [ "pants.backend.python.typecheck.mypy", ] +# Pants' sponsor, Toolchain, offers remote caching, which can improve your CI performance +# with minimal configuration. For more details, visit https://toolchain.com + +plugins.add = [ + "toolchain.pants.plugin==0.20.0", +] + +remote_cache_read = false +remote_cache_write = false +remote_store_address = "grpcs://cache.toolchain.com:443" +remote_auth_plugin = "toolchain.pants.auth.plugin:toolchain_auth_plugin" + +# End Toolchain-specific configuration + + [anonymous-telemetry] enabled = true repo_id = "3B1D361B-E9F1-49A8-B761-03DCC41FD58E" @@ -48,3 +63,14 @@ lockfile_generator = "pex" # problematic system Pythons. See # https://www.pantsbuild.org/docs/python-interpreter-compatibility#changing-the-interpreter-search-path. search_path = ["", ""] + + +# Configuration for Toolchain instrumentation and remote caching +# Visit https://toolchain.com to enable and try it on your repository + +[toolchain-setup] +repo = "pants" +org = "example-python" + +[buildsense] +enable = false From 9052b6881dc29119bc791789dc92bae1889f5cd4 Mon Sep 17 00:00:00 2001 From: Benjy Weinberger Date: Sat, 13 Aug 2022 10:31:44 -0400 Subject: [PATCH 64/96] Better guidance on how to set up CI with Pants. (#104) --- .github/workflows/pants.yaml | 38 +++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pants.yaml b/.github/workflows/pants.yaml index 3d1f997..8249954 100644 --- a/.github/workflows/pants.yaml +++ b/.github/workflows/pants.yaml @@ -26,14 +26,46 @@ jobs: python-version: [3.7] steps: - uses: actions/checkout@v2 + - name: Get Pants version + id: pants_version + run: | + # Capture the "pants_version = " line from config. + PANTS_VERSION=$(grep -E '^pants_version\s*=' pants.toml) + echo "::set-output name=pants_version::$PANTS_VERSION" - uses: actions/cache@v2 - id: cache + id: cache_pants_setup with: path: | ~/.cache/pants/setup - ~/.cache/pants/lmdb_store + key: pants-setup-${{ steps.pants_version.outputs.pants_version }} + - uses: actions/cache@v2 + id: cached_named_caches + with: + path: | ~/.cache/pants/named_caches - key: ${{ runner.os }}- + # The Python backend uses named_caches for Pip/PEX state, + # so it is appropriate to invalidate on requirements.txt changes. + key: named-caches-${{ runner.os }}-${{ hashFiles('pants.toml') }}-${{ hashFiles('requirements.txt') }} + # Note that falling back to a restore key may give a useful partial result that will save time + # over completely clean state, but will cause the cache entry to grow without bound over time. + # See https://pants.readme.io/docs/using-pants-in-ci for tips on how to periodically clean it up. + # Alternatively you may want to avoid using restore keys. + restore-keys: | + pants-setup-${{ runner.os }}-${{ hashFiles('pants.toml') }}-${{ hashFiles('requirements.txt') }} + pants-setup-${{ runner.os }}-${{ hashFiles('pants.toml') }}- + pants-setup-${{ runner.os }}- + # If you're not using a fine-grained remote caching service (see https://www.pantsbuild.org/docs/remote-caching), + # then you may also want to preserve the local Pants cache (lmdb_store). However this must invalidate for + # changes to any file that can affect the build, so may not be practical in larger repos. + # A remote cache service integrates with Pants's fine-grained invalidation and avoids these problems. + - uses: actions/cache@v2 + id: cache_lmdb_store + with: + path: | + ~/.cache/pants/lmdb_store + key: pants-setup-${{ runner.os }}-${{ hashFiles('**/*') }} + # Same caveat as above regarding the issues with restore keys. + restore-keys: pants-setup-${{ runner.os }}- - name: Setup Python ${{ matrix.python-version }} uses: actions/setup-python@v1 with: From e6cfdb47935c134c55e902ad401201289a211325 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Mon, 15 Aug 2022 13:16:06 +1000 Subject: [PATCH 65/96] Adjust CI cache key names to be consistent (#105) This adjusts the cache keys used in the CI setup based on the improved version from #104. I think there were some typos (e.g. using `pants-setup-...` for the `named_caches` restore key), and it seems that scoping everything under `pants-{name}-...` is nifty. --- .github/workflows/pants.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pants.yaml b/.github/workflows/pants.yaml index 8249954..efb53e9 100644 --- a/.github/workflows/pants.yaml +++ b/.github/workflows/pants.yaml @@ -45,15 +45,15 @@ jobs: ~/.cache/pants/named_caches # The Python backend uses named_caches for Pip/PEX state, # so it is appropriate to invalidate on requirements.txt changes. - key: named-caches-${{ runner.os }}-${{ hashFiles('pants.toml') }}-${{ hashFiles('requirements.txt') }} + key: pants-named-caches-${{ runner.os }}-${{ hashFiles('pants.toml') }}-${{ hashFiles('requirements.txt') }} # Note that falling back to a restore key may give a useful partial result that will save time # over completely clean state, but will cause the cache entry to grow without bound over time. # See https://pants.readme.io/docs/using-pants-in-ci for tips on how to periodically clean it up. # Alternatively you may want to avoid using restore keys. restore-keys: | - pants-setup-${{ runner.os }}-${{ hashFiles('pants.toml') }}-${{ hashFiles('requirements.txt') }} - pants-setup-${{ runner.os }}-${{ hashFiles('pants.toml') }}- - pants-setup-${{ runner.os }}- + pants-named-caches-${{ runner.os }}-${{ hashFiles('pants.toml') }}-${{ hashFiles('requirements.txt') }} + pants-named-caches-${{ runner.os }}-${{ hashFiles('pants.toml') }}- + pants-named-caches-${{ runner.os }}- # If you're not using a fine-grained remote caching service (see https://www.pantsbuild.org/docs/remote-caching), # then you may also want to preserve the local Pants cache (lmdb_store). However this must invalidate for # changes to any file that can affect the build, so may not be practical in larger repos. @@ -63,9 +63,9 @@ jobs: with: path: | ~/.cache/pants/lmdb_store - key: pants-setup-${{ runner.os }}-${{ hashFiles('**/*') }} + key: pants-lmdb-store-${{ runner.os }}-${{ hashFiles('**/*') }} # Same caveat as above regarding the issues with restore keys. - restore-keys: pants-setup-${{ runner.os }}- + restore-keys: pants-lmdb-store-${{ runner.os }}- - name: Setup Python ${{ matrix.python-version }} uses: actions/setup-python@v1 with: From eb31af6492f830cad769efc7a603f1795aeee5b1 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Tue, 13 Sep 2022 22:22:10 -0500 Subject: [PATCH 66/96] Use init-pants-action in gha workflow (#106) This shows the new init-pants-action in GHA. --- .github/workflows/pants.yaml | 61 +++++++++++------------------------- 1 file changed, 19 insertions(+), 42 deletions(-) diff --git a/.github/workflows/pants.yaml b/.github/workflows/pants.yaml index efb53e9..52dd452 100644 --- a/.github/workflows/pants.yaml +++ b/.github/workflows/pants.yaml @@ -18,61 +18,38 @@ jobs: build: name: Perform CI Checks needs: org-check - env: - PANTS_CONFIG_FILES: pants.ci.toml runs-on: ubuntu-latest strategy: matrix: python-version: [3.7] steps: - uses: actions/checkout@v2 - - name: Get Pants version - id: pants_version - run: | - # Capture the "pants_version = " line from config. - PANTS_VERSION=$(grep -E '^pants_version\s*=' pants.toml) - echo "::set-output name=pants_version::$PANTS_VERSION" - - uses: actions/cache@v2 - id: cache_pants_setup - with: - path: | - ~/.cache/pants/setup - key: pants-setup-${{ steps.pants_version.outputs.pants_version }} - - uses: actions/cache@v2 - id: cached_named_caches + - uses: pantsbuild/actions/init-pants@c0ce05ee4ba288bb2a729a2b77294e9cb6ab66f7 + # This action bootstraps pants and manages 2-3 GHA caches. + # See: github.com/pantsbuild/actions/tree/init-pants/ + # We use an action SHA because there are no tags yet. with: - path: | - ~/.cache/pants/named_caches + # cache0 makes it easy to bust the cache if needed + # just increase the integer to start with a fresh cache + gha-cache-key: cache0-py${{ matrix.python-version }} # The Python backend uses named_caches for Pip/PEX state, - # so it is appropriate to invalidate on requirements.txt changes. - key: pants-named-caches-${{ runner.os }}-${{ hashFiles('pants.toml') }}-${{ hashFiles('requirements.txt') }} - # Note that falling back to a restore key may give a useful partial result that will save time - # over completely clean state, but will cause the cache entry to grow without bound over time. + # so it is appropriate to invalidate on lockfile changes. + named-caches-hash: ${{ hashFiles('lockfile.txt') }} + # If you're not using a fine-grained remote caching service (see https://www.pantsbuild.org/docs/remote-caching), + # then you may also want to preserve the local Pants cache (lmdb_store). However this must invalidate for + # changes to any file that can affect the build, so may not be practical in larger repos. + # A remote cache service integrates with Pants's fine-grained invalidation and avoids these problems. + cache-lmdb-store: 'true' # defaults to 'false' + # Note that named_caches and lmdb_store falls back to partial restore keys which + # may give a useful partial result that will save time over completely clean state, + # but will cause the cache entry to grow without bound over time. # See https://pants.readme.io/docs/using-pants-in-ci for tips on how to periodically clean it up. - # Alternatively you may want to avoid using restore keys. - restore-keys: | - pants-named-caches-${{ runner.os }}-${{ hashFiles('pants.toml') }}-${{ hashFiles('requirements.txt') }} - pants-named-caches-${{ runner.os }}-${{ hashFiles('pants.toml') }}- - pants-named-caches-${{ runner.os }}- - # If you're not using a fine-grained remote caching service (see https://www.pantsbuild.org/docs/remote-caching), - # then you may also want to preserve the local Pants cache (lmdb_store). However this must invalidate for - # changes to any file that can affect the build, so may not be practical in larger repos. - # A remote cache service integrates with Pants's fine-grained invalidation and avoids these problems. - - uses: actions/cache@v2 - id: cache_lmdb_store - with: - path: | - ~/.cache/pants/lmdb_store - key: pants-lmdb-store-${{ runner.os }}-${{ hashFiles('**/*') }} - # Same caveat as above regarding the issues with restore keys. - restore-keys: pants-lmdb-store-${{ runner.os }}- + # Alternatively you change gha-cache-key to ignore old caches. + - name: Setup Python ${{ matrix.python-version }} uses: actions/setup-python@v1 with: python-version: ${{ matrix.python-version }} - - name: Bootstrap Pants - run: | - ./pants --version - name: Check BUILD files run: ./pants tailor --check update-build-files --check - name: Lint and typecheck From f0f6454cf804f144ffbd1c9ee7acc76d41045c9e Mon Sep 17 00:00:00 2001 From: Benjy Weinberger Date: Thu, 27 Oct 2022 16:00:27 -0700 Subject: [PATCH 67/96] Upgrade to pants 2.14.0. (#111) - Change lockfile name to match emerging conventions - Pin to a more recent Python minor version - Update to latest pants script - Use tagged version of pants setup action --- .github/workflows/pants.yaml | 12 +- lockfile.txt | 131 -------------- pants | 175 +++++++++++++++--- pants.toml | 21 +-- python-default.lock | 342 +++++++++++++++++++++++++++++++++++ requirements.txt | 1 + 6 files changed, 509 insertions(+), 173 deletions(-) delete mode 100644 lockfile.txt create mode 100644 python-default.lock diff --git a/.github/workflows/pants.yaml b/.github/workflows/pants.yaml index 52dd452..831c052 100644 --- a/.github/workflows/pants.yaml +++ b/.github/workflows/pants.yaml @@ -21,10 +21,10 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.7] + python-version: [3.9] steps: - - uses: actions/checkout@v2 - - uses: pantsbuild/actions/init-pants@c0ce05ee4ba288bb2a729a2b77294e9cb6ab66f7 + - uses: actions/checkout@v3 + - uses: pantsbuild/actions/init-pants@v1 # This action bootstraps pants and manages 2-3 GHA caches. # See: github.com/pantsbuild/actions/tree/init-pants/ # We use an action SHA because there are no tags yet. @@ -34,7 +34,7 @@ jobs: gha-cache-key: cache0-py${{ matrix.python-version }} # The Python backend uses named_caches for Pip/PEX state, # so it is appropriate to invalidate on lockfile changes. - named-caches-hash: ${{ hashFiles('lockfile.txt') }} + named-caches-hash: ${{ hashFiles('python-default.lock') }} # If you're not using a fine-grained remote caching service (see https://www.pantsbuild.org/docs/remote-caching), # then you may also want to preserve the local Pants cache (lmdb_store). However this must invalidate for # changes to any file that can affect the build, so may not be practical in larger repos. @@ -47,7 +47,7 @@ jobs: # Alternatively you change gha-cache-key to ignore old caches. - name: Setup Python ${{ matrix.python-version }} - uses: actions/setup-python@v1 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - name: Check BUILD files @@ -64,7 +64,7 @@ jobs: ./pants package :: ./pants run helloworld/main.py - name: Upload pants log - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: pants-log path: .pants.d/pants.log diff --git a/lockfile.txt b/lockfile.txt deleted file mode 100644 index bc43916..0000000 --- a/lockfile.txt +++ /dev/null @@ -1,131 +0,0 @@ -// This lockfile was autogenerated by Pants. To regenerate, run: -// -// ./pants generate-lockfiles --resolve=python-default -// -// --- BEGIN PANTS LOCKFILE METADATA: DO NOT EDIT OR REMOVE --- -// { -// "version": 2, -// "valid_for_interpreter_constraints": [ -// "CPython>=3.7" -// ], -// "generated_with_requirements": [ -// "ansicolors==1.1.8", -// "setuptools<57,>=56.2.0", -// "types-setuptools<58,>=56.2.0" -// ] -// } -// --- END PANTS LOCKFILE METADATA --- - -{ - "allow_builds": true, - "allow_prereleases": false, - "allow_wheels": true, - "build_isolation": true, - "constraints": [], - "locked_resolves": [ - { - "locked_requirements": [ - { - "artifacts": [ - { - "algorithm": "sha256", - "hash": "00d2dde5a675579325902536738dd27e4fac1fd68f773fe36c21044eb559e187", - "url": "https://files.pythonhosted.org/packages/53/18/a56e2fe47b259bb52201093a3a9d4a32014f9d85071ad07e9d60600890ca/ansicolors-1.1.8-py2.py3-none-any.whl" - }, - { - "algorithm": "sha256", - "hash": "99f94f5e3348a0bcd43c82e5fc4414013ccc19d70bd939ad71e0133ce9c372e0", - "url": "https://files.pythonhosted.org/packages/76/31/7faed52088732704523c259e24c26ce6f2f33fbeff2ff59274560c27628e/ansicolors-1.1.8.zip" - } - ], - "project_name": "ansicolors", - "requires_dists": [], - "requires_python": null, - "version": "1.1.8" - }, - { - "artifacts": [ - { - "algorithm": "sha256", - "hash": "bc30153eec47d82f20c6f5e1a13d4ee725c6deb7013a67557f89bfe5d25235c4", - "url": "https://files.pythonhosted.org/packages/d0/15/5041473f5d142ee93bf1593deb8f932e27a078f6f04e2020cf44044f72c5/setuptools-56.2.0-py3-none-any.whl" - }, - { - "algorithm": "sha256", - "hash": "7bb5652625e94e73b9358b7ed8c6431b732e80cf31f4e0972294c64f0e5b849e", - "url": "https://files.pythonhosted.org/packages/fc/0a/b486efab52f8ad03c3eca0c998dd3deafba0c39b29e0c49c68a7152c8b2d/setuptools-56.2.0.tar.gz" - } - ], - "project_name": "setuptools", - "requires_dists": [ - "certifi==2016.9.26; extra == \"certs\"", - "flake8-2020; extra == \"testing\"", - "jaraco.envs; extra == \"testing\"", - "jaraco.packaging>=8.2; extra == \"docs\"", - "jaraco.path>=3.2.0; extra == \"testing\"", - "mock; extra == \"testing\"", - "paver; extra == \"testing\"", - "pip>=19.1; extra == \"testing\"", - "pygments-github-lexers==0.0.5; extra == \"docs\"", - "pytest-black>=0.3.7; (platform_python_implementation != \"PyPy\" and python_version < \"3.10\") and extra == \"testing\"", - "pytest-checkdocs>=2.4; extra == \"testing\"", - "pytest-cov; extra == \"testing\"", - "pytest-enabler>=1.0.1; extra == \"testing\"", - "pytest-flake8; extra == \"testing\"", - "pytest-mypy; (platform_python_implementation != \"PyPy\" and python_version < \"3.10\") and extra == \"testing\"", - "pytest-virtualenv>=1.2.7; extra == \"testing\"", - "pytest-xdist; extra == \"testing\"", - "pytest>=4.6; extra == \"testing\"", - "rst.linker>=1.9; extra == \"docs\"", - "sphinx-inline-tabs; extra == \"docs\"", - "sphinx; extra == \"docs\"", - "sphinx; extra == \"testing\"", - "virtualenv>=13.0.0; extra == \"testing\"", - "wheel; extra == \"testing\"", - "wincertstore==0.2; sys_platform == \"win32\" and extra == \"ssl\"" - ], - "requires_python": ">=3.6", - "version": "56.2" - }, - { - "artifacts": [ - { - "algorithm": "sha256", - "hash": "828f7e7e51e157876f47c80518b23ba0c3c36aa8081efd39d5d39f393938aec9", - "url": "https://files.pythonhosted.org/packages/c8/0d/6c9eb15fd4f6f45973ff1c70c170f2c30803415874e2e47c92eeae509085/types_setuptools-57.4.14-py3-none-any.whl" - }, - { - "algorithm": "sha256", - "hash": "df02fe1dd244f58cf4e67cfc3d0a97930a2d61a72dd89f21d81c71017cd83f9a", - "url": "https://files.pythonhosted.org/packages/42/2e/d21d995feca499eac401958fee97879926249e60b8e5608f0361f0ee2ae1/types-setuptools-57.4.14.tar.gz" - } - ], - "project_name": "types-setuptools", - "requires_dists": [], - "requires_python": null, - "version": "57.4.14" - } - ], - "platform_tag": [ - "cp36", - "cp36m", - "macosx_10_16_x86_64" - ] - } - ], - "path_mappings": {}, - "pex_version": "2.1.80", - "prefer_older_binary": false, - "requirements": [ - "ansicolors==1.1.8", - "setuptools<57,>=56.2.0", - "types-setuptools<58,>=56.2.0" - ], - "requires_python": [ - ">=3.7" - ], - "resolver_version": "pip-2020-resolver", - "style": "universal", - "transitive": true, - "use_pep517": null -} \ No newline at end of file diff --git a/pants b/pants index 2e9a10c..367830f 100755 --- a/pants +++ b/pants @@ -12,8 +12,18 @@ set -eou pipefail -# NOTE: To use an unreleased version of Pants from the pantsbuild/pants master branch, -# locate the master branch SHA, set PANTS_SHA= in the environment, and run this script as usual. +# an arbitrary number: bump when there's a change that someone might want to query for +# (e.g. checking $(PANTS_BOOTSTRAP_TOOLS=1 ./pants version) >= ...) +SCRIPT_VERSION=1 + +# Source any custom bootstrap settings for Pants from PANTS_BOOTSTRAP if it exists. +: ${PANTS_BOOTSTRAP:=".pants.bootstrap"} +if [[ -f "${PANTS_BOOTSTRAP}" ]]; then + source "${PANTS_BOOTSTRAP}" +fi + +# NOTE: To use an unreleased version of Pants from the pantsbuild/pants main branch, +# locate the main branch SHA, set PANTS_SHA= in the environment, and run this script as usual. # # E.g., PANTS_SHA=725fdaf504237190f6787dda3d72c39010a4c574 ./pants --version @@ -34,9 +44,9 @@ fi PANTS_BOOTSTRAP="${PANTS_SETUP_CACHE}/bootstrap-$(uname -s)-$(uname -m)" -PEX_VERSION=2.1.42 -PEX_URL="https://github.com/pantsbuild/pex/releases/download/v${PEX_VERSION}/pex" -PEX_EXPECTED_SHA256="69d6b1b1009b00dd14a3a9f19b72cff818a713ca44b3186c9b12074b2a31e51f" +_PEX_VERSION=2.1.103 +_PEX_URL="https://github.com/pantsbuild/pex/releases/download/v${_PEX_VERSION}/pex" +_PEX_EXPECTED_SHA256="4d45336511484100ae4e2bab24542a8b86b12c8cb89230463593c60d08c4b8d3" VIRTUALENV_VERSION=20.4.7 VIRTUALENV_REQUIREMENTS=$( @@ -55,8 +65,11 @@ EOF COLOR_RED="\x1b[31m" COLOR_GREEN="\x1b[32m" +COLOR_YELLOW="\x1b[33m" COLOR_RESET="\x1b[0m" +INSTALL_URL="https://www.pantsbuild.org/docs/installation" + function log() { echo -e "$@" 1>&2 } @@ -70,6 +83,10 @@ function green() { (($# > 0)) && log "${COLOR_GREEN}$*${COLOR_RESET}" } +function warn() { + (($# > 0)) && log "${COLOR_YELLOW}$*${COLOR_RESET}" +} + function tempdir { mkdir -p "$1" mktemp -d "$1"/pants.XXXXXX @@ -82,13 +99,18 @@ function get_exe_path_or_die { fi } -function get_pants_config_value { +function get_pants_config_string_value { local config_key="$1" local optional_space="[[:space:]]*" local prefix="^${config_key}${optional_space}=${optional_space}" local raw_value - raw_value="$(sed -ne "/${prefix}/ s#${prefix}##p" "${PANTS_TOML}")" - echo "${raw_value}" | tr -d \"\' && return 0 + raw_value="$(sed -ne "/${prefix}/ s|${prefix}||p" "${PANTS_TOML}")" + local optional_suffix="${optional_space}(#.*)?$" + echo "${raw_value}" \ + | sed -E \ + -e "s|^'([^']*)'${optional_suffix}|\1|" \ + -e 's|^"([^"]*)"'"${optional_suffix}"'$|\1|' \ + && return 0 return 0 } @@ -120,11 +142,11 @@ function determine_pants_version { return fi - pants_version="$(get_pants_config_value 'pants_version')" + pants_version="$(get_pants_config_string_value 'pants_version')" if [[ -z "${pants_version}" ]]; then die "Please explicitly specify the \`pants_version\` in your \`pants.toml\` under the \`[GLOBAL]\` scope. See https://pypi.org/project/pantsbuild.pants/#history for all released versions -and https://www.pantsbuild.org/docs/installation for more instructions." +and ${INSTALL_URL} for more instructions." fi pants_major_version="$(echo "${pants_version}" | cut -d '.' -f1)" pants_minor_version="$(echo "${pants_version}" | cut -d '.' -f2)" @@ -186,8 +208,8 @@ function determine_default_python_exe { if [[ -z "${interpreter_path}" ]]; then continue fi - # Check if the Python version is installed via Pyenv but not activated. - if [[ "$("${interpreter_path}" --version 2>&1 > /dev/null)" == "pyenv: python${version}"* ]]; then + # Check if a version is shimmed by pyenv or asdf but not configured. + if ! "${interpreter_path}" --version >/dev/null 2>&1; then continue fi if [[ -n "$(check_python_exe_compatible_version "${interpreter_path}")" ]]; then @@ -236,7 +258,7 @@ EOF function bootstrap_pex { local python="$1" - local bootstrapped="${PANTS_BOOTSTRAP}/pex-${PEX_VERSION}/pex" + local bootstrapped="${PANTS_BOOTSTRAP}/pex-${_PEX_VERSION}/pex" if [[ ! -f "${bootstrapped}" ]]; then ( green "Downloading the Pex PEX." @@ -244,12 +266,17 @@ function bootstrap_pex { local staging_dir staging_dir=$(tempdir "${PANTS_BOOTSTRAP}") cd "${staging_dir}" - curl -LO "${PEX_URL}" + curl --proto "=https" \ + --tlsv1.2 \ + --silent \ + --location \ + --remote-name \ + "${_PEX_URL}" fingerprint="$(compute_sha256 "${python}" "pex")" - if [[ "${PEX_EXPECTED_SHA256}" != "${fingerprint}" ]]; then - die "SHA256 of ${PEX_URL} is not as expected. Aborting." + if [[ "${_PEX_EXPECTED_SHA256}" != "${fingerprint}" ]]; then + die "SHA256 of ${_PEX_URL} is not as expected. Aborting." fi - green "SHA256 fingerprint of ${PEX_URL} verified." + green "SHA256 fingerprint of ${_PEX_URL} verified." mkdir -p "$(dirname "${bootstrapped}")" mv -f "${staging_dir}/pex" "${bootstrapped}" rmdir "${staging_dir}" @@ -258,6 +285,25 @@ function bootstrap_pex { echo "${bootstrapped}" } +function scrub_env_vars { + # Ensure the virtualenv PEX runs as shrink-wrapped. + # See: https://github.com/pantsbuild/setup/issues/105 + local -r pex_env_vars=(${!PEX_@}) + if [[ ! ${#pex_env_vars[@]} -eq 0 ]]; then + local -r pex_env_vars_to_scrub="${pex_env_vars[@]/PEX_ROOT}" + if [[ -n "${pex_env_vars_to_scrub[@]}" ]]; then + warn "Scrubbing ${pex_env_vars_to_scrub[@]}" + unset ${pex_env_vars_to_scrub[@]} + fi + fi + # Also ensure pip doesn't think packages on PYTHONPATH + # are already installed. + if [ -n "${PYTHONPATH:-}" ]; then + warn "Scrubbing PYTHONPATH" + unset PYTHONPATH + fi +} + function bootstrap_virtualenv { local python="$1" local bootstrapped="${PANTS_BOOTSTRAP}/virtualenv-${VIRTUALENV_VERSION}/virtualenv.pex" @@ -270,7 +316,10 @@ function bootstrap_virtualenv { staging_dir=$(tempdir "${PANTS_BOOTSTRAP}") cd "${staging_dir}" echo "${VIRTUALENV_REQUIREMENTS}" > requirements.txt - "${python}" "${pex_path}" -r requirements.txt -c virtualenv -o virtualenv.pex + ( + scrub_env_vars + "${python}" "${pex_path}" -r requirements.txt -c virtualenv -o virtualenv.pex + ) mkdir -p "$(dirname "${bootstrapped}")" mv -f "${staging_dir}/virtualenv.pex" "${bootstrapped}" rm -rf "${staging_dir}" @@ -290,7 +339,12 @@ function get_version_for_sha { # Retrieve the Pants version associated with this commit. local pants_version - pants_version="$(curl --fail -sL "https://raw.githubusercontent.com/pantsbuild/pants/${sha}/src/python/pants/VERSION")" + pants_version="$(curl --proto "=https" \ + --tlsv1.2 \ + --fail \ + --silent \ + --location \ + "https://raw.githubusercontent.com/pantsbuild/pants/${sha}/src/python/pants/VERSION")" # Construct the version as the release version from src/python/pants/VERSION, plus the string `+gitXXXXXXXX`, # where the XXXXXXXX is the first 8 characters of the SHA. @@ -322,10 +376,15 @@ function bootstrap_pants { local virtualenv_path virtualenv_path="$(bootstrap_virtualenv "${python}")" || exit 1 green "Installing ${pants_requirement} into a virtual environment at ${bootstrapped}" - # shellcheck disable=SC2086 - "${python}" "${virtualenv_path}" --no-download "${staging_dir}/install" && \ - "${staging_dir}/install/bin/pip" install -U pip && \ - "${staging_dir}/install/bin/pip" install ${maybe_find_links} --progress-bar off "${pants_requirement}" && \ + ( + scrub_env_vars + # shellcheck disable=SC2086 + "${python}" "${virtualenv_path}" --quiet --no-download "${staging_dir}/install" && \ + # Grab the latest pip, but don't advance setuptools past 58 which drops support for the + # `setup` kwarg `use_2to3` which Pants 1.x sdist dependencies (pystache) use. + "${staging_dir}/install/bin/pip" install --quiet -U pip "setuptools<58" && \ + "${staging_dir}/install/bin/pip" install ${maybe_find_links} --quiet --progress-bar off "${pants_requirement}" + ) && \ ln -s "${staging_dir}/install" "${staging_dir}/${target_folder_name}" && \ mv "${staging_dir}/${target_folder_name}" "${bootstrapped}" && \ green "New virtual environment successfully created at ${bootstrapped}." @@ -334,6 +393,76 @@ function bootstrap_pants { echo "${bootstrapped}" } +function run_bootstrap_tools { + # functionality for introspecting the bootstrapping process, without actually doing it + if [[ "${PANTS_BOOTSTRAP_TOOLS}" -gt "${SCRIPT_VERSION}" ]]; then + die "$0 script (bootstrap version ${SCRIPT_VERSION}) is too old for this invocation (with PANTS_BOOTSTRAP_TOOLS=${PANTS_BOOTSTRAP_TOOLS}). +Please update it by following ${INSTALL_URL}" + fi + + case "${1:-}" in + bootstrap-cache-key) + local pants_version=$(determine_pants_version) + local python="$(determine_python_exe "${pants_version}")" + # the python above may be a shim (e.g. pyenv or homebrew), so let's get an estimate of the + # actual path, as will be symlinked in the virtualenv. (NB. virtualenv does more complicated + # things, but we at least emulate the symlink-resolution that it does.) + local python_executable_path="$("${python}" -c 'import os, sys; print(os.path.realpath(sys.executable))')" + + local requirements_file="$(mktemp)" + echo "${VIRTUALENV_REQUIREMENTS}" > "${requirements_file}" + local virtualenv_requirements_sha256="$(compute_sha256 "${python}" "${requirements_file}")" + rm "${requirements_file}" + + local parts=( + "os_name=$(uname -s)" + "arch=$(uname -m)" + "python_path=${python}" + "python_executable_path=${python_executable_path}" + # the full interpreter information, for maximum compatibility + "python_version=$("$python" --version)" + "pex_version=${_PEX_VERSION}" + "virtualenv_requirements_sha256=${virtualenv_requirements_sha256}" + "pants_version=${pants_version}" + ) + echo "${parts[*]}" + ;; + bootstrap-version) + echo "${SCRIPT_VERSION}" + ;; + help|"") + cat <=3.9`. -interpreter_constraints = [">=3.7"] + +# Modify this if you don't have Python 3.9 on your machine. +# This can be a range, such as [">=3.8,<3.11"], but it's usually recommended to restrict +# to a single minor version. +interpreter_constraints = ["==3.9.*"] # Enable the "resolves" mechanism, which turns on lockfiles for user code. See # https://www.pantsbuild.org/docs/python-third-party-dependencies. This also adds the -# `generate-lockfiles` goal for Pants to generate the lockfile for you, although in some -# situations you may need to manually generate it, as explained in the docs. +# `generate-lockfiles` goal for Pants to generate the lockfile for you. enable_resolves = true -resolves = { python-default = "lockfile.txt"} -# Enable using the PEX lockfile format, which provides support for custom indexes, and -# improves performance for large repositories. -lockfile_generator = "pex" +resolves = { python-default = "python-default.lock"} [python-bootstrap] # We search for interpreters both on the $PATH and in the `$(pyenv root)/versions` folder. diff --git a/python-default.lock b/python-default.lock new file mode 100644 index 0000000..498b4eb --- /dev/null +++ b/python-default.lock @@ -0,0 +1,342 @@ +// This lockfile was autogenerated by Pants. To regenerate, run: +// +// ./pants generate-lockfiles --resolve=python-default +// +// --- BEGIN PANTS LOCKFILE METADATA: DO NOT EDIT OR REMOVE --- +// { +// "version": 3, +// "valid_for_interpreter_constraints": [ +// "CPython==3.9.*" +// ], +// "generated_with_requirements": [ +// "ansicolors==1.1.8", +// "pytest==7.0.1", +// "setuptools<57,>=56.2.0", +// "types-setuptools<58,>=56.2.0" +// ], +// "manylinux": "manylinux2014", +// "requirement_constraints": [], +// "only_binary": [], +// "no_binary": [] +// } +// --- END PANTS LOCKFILE METADATA --- + +{ + "allow_builds": true, + "allow_prereleases": false, + "allow_wheels": true, + "build_isolation": true, + "constraints": [], + "locked_resolves": [ + { + "locked_requirements": [ + { + "artifacts": [ + { + "algorithm": "sha256", + "hash": "00d2dde5a675579325902536738dd27e4fac1fd68f773fe36c21044eb559e187", + "url": "https://files.pythonhosted.org/packages/53/18/a56e2fe47b259bb52201093a3a9d4a32014f9d85071ad07e9d60600890ca/ansicolors-1.1.8-py2.py3-none-any.whl" + }, + { + "algorithm": "sha256", + "hash": "99f94f5e3348a0bcd43c82e5fc4414013ccc19d70bd939ad71e0133ce9c372e0", + "url": "https://files.pythonhosted.org/packages/76/31/7faed52088732704523c259e24c26ce6f2f33fbeff2ff59274560c27628e/ansicolors-1.1.8.zip" + } + ], + "project_name": "ansicolors", + "requires_dists": [], + "requires_python": null, + "version": "1.1.8" + }, + { + "artifacts": [ + { + "algorithm": "sha256", + "hash": "86efa402f67bf2df34f51a335487cf46b1ec130d02b8d39fd248abfd30da551c", + "url": "https://files.pythonhosted.org/packages/f2/bc/d817287d1aa01878af07c19505fafd1165cd6a119e9d0821ca1d1c20312d/attrs-22.1.0-py2.py3-none-any.whl" + }, + { + "algorithm": "sha256", + "hash": "29adc2665447e5191d0e7c568fde78b21f9672d344281d0c6e1ab085429b22b6", + "url": "https://files.pythonhosted.org/packages/1a/cb/c4ffeb41e7137b23755a45e1bfec9cbb76ecf51874c6f1d113984ecaa32c/attrs-22.1.0.tar.gz" + } + ], + "project_name": "attrs", + "requires_dists": [ + "cloudpickle; platform_python_implementation == \"CPython\" and extra == \"dev\"", + "cloudpickle; platform_python_implementation == \"CPython\" and extra == \"tests\"", + "cloudpickle; platform_python_implementation == \"CPython\" and extra == \"tests_no_zope\"", + "coverage[toml]>=5.0.2; extra == \"dev\"", + "coverage[toml]>=5.0.2; extra == \"tests\"", + "coverage[toml]>=5.0.2; extra == \"tests_no_zope\"", + "furo; extra == \"dev\"", + "furo; extra == \"docs\"", + "hypothesis; extra == \"dev\"", + "hypothesis; extra == \"tests\"", + "hypothesis; extra == \"tests_no_zope\"", + "mypy!=0.940,>=0.900; extra == \"dev\"", + "mypy!=0.940,>=0.900; extra == \"tests\"", + "mypy!=0.940,>=0.900; extra == \"tests_no_zope\"", + "pre-commit; extra == \"dev\"", + "pympler; extra == \"dev\"", + "pympler; extra == \"tests\"", + "pympler; extra == \"tests_no_zope\"", + "pytest-mypy-plugins; extra == \"dev\"", + "pytest-mypy-plugins; extra == \"tests\"", + "pytest-mypy-plugins; extra == \"tests_no_zope\"", + "pytest>=4.3.0; extra == \"dev\"", + "pytest>=4.3.0; extra == \"tests\"", + "pytest>=4.3.0; extra == \"tests_no_zope\"", + "sphinx-notfound-page; extra == \"dev\"", + "sphinx-notfound-page; extra == \"docs\"", + "sphinx; extra == \"dev\"", + "sphinx; extra == \"docs\"", + "zope.interface; extra == \"dev\"", + "zope.interface; extra == \"docs\"", + "zope.interface; extra == \"tests\"" + ], + "requires_python": ">=3.5", + "version": "22.1" + }, + { + "artifacts": [ + { + "algorithm": "sha256", + "hash": "011e24c64b7f47f6ebd835bb12a743f2fbe9a26d4cecaa7f53bc4f35ee9da8b3", + "url": "https://files.pythonhosted.org/packages/9b/dd/b3c12c6d707058fa947864b67f0c4e0c39ef8610988d7baea9578f3c48f3/iniconfig-1.1.1-py2.py3-none-any.whl" + }, + { + "algorithm": "sha256", + "hash": "bc3af051d7d14b2ee5ef9969666def0cd1a000e121eaea580d4a313df4b37f32", + "url": "https://files.pythonhosted.org/packages/23/a2/97899f6bd0e873fed3a7e67ae8d3a08b21799430fb4da15cfedf10d6e2c2/iniconfig-1.1.1.tar.gz" + } + ], + "project_name": "iniconfig", + "requires_dists": [], + "requires_python": null, + "version": "1.1.1" + }, + { + "artifacts": [ + { + "algorithm": "sha256", + "hash": "ef103e05f519cdc783ae24ea4e2e0f508a9c99b2d4969652eed6a2e1ea5bd522", + "url": "https://files.pythonhosted.org/packages/05/8e/8de486cbd03baba4deef4142bd643a3e7bbe954a784dc1bb17142572d127/packaging-21.3-py3-none-any.whl" + }, + { + "algorithm": "sha256", + "hash": "dd47c42927d89ab911e606518907cc2d3a1f38bbd026385970643f9c5b8ecfeb", + "url": "https://files.pythonhosted.org/packages/df/9e/d1a7217f69310c1db8fdf8ab396229f55a699ce34a203691794c5d1cad0c/packaging-21.3.tar.gz" + } + ], + "project_name": "packaging", + "requires_dists": [ + "pyparsing!=3.0.5,>=2.0.2" + ], + "requires_python": ">=3.6", + "version": "21.3" + }, + { + "artifacts": [ + { + "algorithm": "sha256", + "hash": "74134bbf457f031a36d68416e1509f34bd5ccc019f0bcc952c7b909d06b37bd3", + "url": "https://files.pythonhosted.org/packages/9e/01/f38e2ff29715251cf25532b9082a1589ab7e4f571ced434f98d0139336dc/pluggy-1.0.0-py2.py3-none-any.whl" + }, + { + "algorithm": "sha256", + "hash": "4224373bacce55f955a878bf9cfa763c1e360858e330072059e10bad68531159", + "url": "https://files.pythonhosted.org/packages/a1/16/db2d7de3474b6e37cbb9c008965ee63835bba517e22cdb8c35b5116b5ce1/pluggy-1.0.0.tar.gz" + } + ], + "project_name": "pluggy", + "requires_dists": [ + "importlib-metadata>=0.12; python_version < \"3.8\"", + "pre-commit; extra == \"dev\"", + "pytest-benchmark; extra == \"testing\"", + "pytest; extra == \"testing\"", + "tox; extra == \"dev\"" + ], + "requires_python": ">=3.6", + "version": "1" + }, + { + "artifacts": [ + { + "algorithm": "sha256", + "hash": "607c53218732647dff4acdfcd50cb62615cedf612e72d1724fb1a0cc6405b378", + "url": "https://files.pythonhosted.org/packages/f6/f0/10642828a8dfb741e5f3fbaac830550a518a775c7fff6f04a007259b0548/py-1.11.0-py2.py3-none-any.whl" + }, + { + "algorithm": "sha256", + "hash": "51c75c4126074b472f746a24399ad32f6053d1b34b68d2fa41e558e6f4a98719", + "url": "https://files.pythonhosted.org/packages/98/ff/fec109ceb715d2a6b4c4a85a61af3b40c723a961e8828319fbcb15b868dc/py-1.11.0.tar.gz" + } + ], + "project_name": "py", + "requires_dists": [], + "requires_python": "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7", + "version": "1.11" + }, + { + "artifacts": [ + { + "algorithm": "sha256", + "hash": "5026bae9a10eeaefb61dab2f09052b9f4307d44aee4eda64b309723d8d206bbc", + "url": "https://files.pythonhosted.org/packages/6c/10/a7d0fa5baea8fe7b50f448ab742f26f52b80bfca85ac2be9d35cdd9a3246/pyparsing-3.0.9-py3-none-any.whl" + }, + { + "algorithm": "sha256", + "hash": "2b020ecf7d21b687f219b71ecad3631f644a47f01403fa1d1036b0c6416d70fb", + "url": "https://files.pythonhosted.org/packages/71/22/207523d16464c40a0310d2d4d8926daffa00ac1f5b1576170a32db749636/pyparsing-3.0.9.tar.gz" + } + ], + "project_name": "pyparsing", + "requires_dists": [ + "jinja2; extra == \"diagrams\"", + "railroad-diagrams; extra == \"diagrams\"" + ], + "requires_python": ">=3.6.8", + "version": "3.0.9" + }, + { + "artifacts": [ + { + "algorithm": "sha256", + "hash": "9ce3ff477af913ecf6321fe337b93a2c0dcf2a0a1439c43f5452112c1e4280db", + "url": "https://files.pythonhosted.org/packages/38/93/c7c0bd1e932b287fb948eb9ce5a3d6307c9fc619db1e199f8c8bc5dad95f/pytest-7.0.1-py3-none-any.whl" + }, + { + "algorithm": "sha256", + "hash": "e30905a0c131d3d94b89624a1cc5afec3e0ba2fbdb151867d8e0ebd49850f171", + "url": "https://files.pythonhosted.org/packages/3e/2c/a67ad48759051c7abf82ce182a4e6d766de371b183182d2dde03089e8dfb/pytest-7.0.1.tar.gz" + } + ], + "project_name": "pytest", + "requires_dists": [ + "argcomplete; extra == \"testing\"", + "atomicwrites>=1.0; sys_platform == \"win32\"", + "attrs>=19.2.0", + "colorama; sys_platform == \"win32\"", + "hypothesis>=3.56; extra == \"testing\"", + "importlib-metadata>=0.12; python_version < \"3.8\"", + "iniconfig", + "mock; extra == \"testing\"", + "nose; extra == \"testing\"", + "packaging", + "pluggy<2.0,>=0.12", + "py>=1.8.2", + "pygments>=2.7.2; extra == \"testing\"", + "requests; extra == \"testing\"", + "tomli>=1.0.0", + "xmlschema; extra == \"testing\"" + ], + "requires_python": ">=3.6", + "version": "7.0.1" + }, + { + "artifacts": [ + { + "algorithm": "sha256", + "hash": "bc30153eec47d82f20c6f5e1a13d4ee725c6deb7013a67557f89bfe5d25235c4", + "url": "https://files.pythonhosted.org/packages/d0/15/5041473f5d142ee93bf1593deb8f932e27a078f6f04e2020cf44044f72c5/setuptools-56.2.0-py3-none-any.whl" + }, + { + "algorithm": "sha256", + "hash": "7bb5652625e94e73b9358b7ed8c6431b732e80cf31f4e0972294c64f0e5b849e", + "url": "https://files.pythonhosted.org/packages/fc/0a/b486efab52f8ad03c3eca0c998dd3deafba0c39b29e0c49c68a7152c8b2d/setuptools-56.2.0.tar.gz" + } + ], + "project_name": "setuptools", + "requires_dists": [ + "certifi==2016.9.26; extra == \"certs\"", + "flake8-2020; extra == \"testing\"", + "jaraco.envs; extra == \"testing\"", + "jaraco.packaging>=8.2; extra == \"docs\"", + "jaraco.path>=3.2.0; extra == \"testing\"", + "mock; extra == \"testing\"", + "paver; extra == \"testing\"", + "pip>=19.1; extra == \"testing\"", + "pygments-github-lexers==0.0.5; extra == \"docs\"", + "pytest-black>=0.3.7; (platform_python_implementation != \"PyPy\" and python_version < \"3.10\") and extra == \"testing\"", + "pytest-checkdocs>=2.4; extra == \"testing\"", + "pytest-cov; extra == \"testing\"", + "pytest-enabler>=1.0.1; extra == \"testing\"", + "pytest-flake8; extra == \"testing\"", + "pytest-mypy; (platform_python_implementation != \"PyPy\" and python_version < \"3.10\") and extra == \"testing\"", + "pytest-virtualenv>=1.2.7; extra == \"testing\"", + "pytest-xdist; extra == \"testing\"", + "pytest>=4.6; extra == \"testing\"", + "rst.linker>=1.9; extra == \"docs\"", + "sphinx-inline-tabs; extra == \"docs\"", + "sphinx; extra == \"docs\"", + "sphinx; extra == \"testing\"", + "virtualenv>=13.0.0; extra == \"testing\"", + "wheel; extra == \"testing\"", + "wincertstore==0.2; sys_platform == \"win32\" and extra == \"ssl\"" + ], + "requires_python": ">=3.6", + "version": "56.2" + }, + { + "artifacts": [ + { + "algorithm": "sha256", + "hash": "939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc", + "url": "https://files.pythonhosted.org/packages/97/75/10a9ebee3fd790d20926a90a2547f0bf78f371b2f13aa822c759680ca7b9/tomli-2.0.1-py3-none-any.whl" + }, + { + "algorithm": "sha256", + "hash": "de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f", + "url": "https://files.pythonhosted.org/packages/c0/3f/d7af728f075fb08564c5949a9c95e44352e23dee646869fa104a3b2060a3/tomli-2.0.1.tar.gz" + } + ], + "project_name": "tomli", + "requires_dists": [], + "requires_python": ">=3.7", + "version": "2.0.1" + }, + { + "artifacts": [ + { + "algorithm": "sha256", + "hash": "9660b8774b12cd61b448e2fd87a667c02e7ec13ce9f15171f1d49a4654c4df6a", + "url": "https://files.pythonhosted.org/packages/14/45/b8368a8c2d1dc4fa47eb4db980966e23edecbda16fab7a38186b076bbd4d/types_setuptools-57.4.18-py3-none-any.whl" + }, + { + "algorithm": "sha256", + "hash": "8ee03d823fe7fda0bd35faeae33d35cb5c25b497263e6a58b34c4cfd05f40bcf", + "url": "https://files.pythonhosted.org/packages/13/5e/3d46cd143913bd51dde973cd23b1d412de9662b08a3b8c213f26b265e6f1/types-setuptools-57.4.18.tar.gz" + } + ], + "project_name": "types-setuptools", + "requires_dists": [], + "requires_python": null, + "version": "57.4.18" + } + ], + "platform_tag": null + } + ], + "path_mappings": {}, + "pex_version": "2.1.108", + "pip_version": "20.3.4-patched", + "prefer_older_binary": false, + "requirements": [ + "ansicolors==1.1.8", + "pytest==7.0.1", + "setuptools<57,>=56.2.0", + "types-setuptools<58,>=56.2.0" + ], + "requires_python": [ + "==3.9.*" + ], + "resolver_version": "pip-2020-resolver", + "style": "universal", + "target_systems": [ + "linux", + "mac" + ], + "transitive": true, + "use_pep517": null +} diff --git a/requirements.txt b/requirements.txt index ec244b4..73985bc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ ansicolors==1.1.8 setuptools>=56.2.0,<57 types-setuptools>=56.2.0,<58 +pytest==7.0.1 From f94931d69baea0616216b88674428d0a8bce6003 Mon Sep 17 00:00:00 2001 From: Marcelo Trylesinski Date: Mon, 14 Nov 2022 01:24:01 +0100 Subject: [PATCH 68/96] Remove outdated comment from pants.yaml (#114) --- .github/workflows/pants.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/pants.yaml b/.github/workflows/pants.yaml index 831c052..3df4153 100644 --- a/.github/workflows/pants.yaml +++ b/.github/workflows/pants.yaml @@ -27,7 +27,6 @@ jobs: - uses: pantsbuild/actions/init-pants@v1 # This action bootstraps pants and manages 2-3 GHA caches. # See: github.com/pantsbuild/actions/tree/init-pants/ - # We use an action SHA because there are no tags yet. with: # cache0 makes it easy to bust the cache if needed # just increase the integer to start with a fresh cache From e5cd4ce34cf523cc4ebe46d1014ac2aeaa063dd7 Mon Sep 17 00:00:00 2001 From: Marcelo Trylesinski Date: Mon, 14 Nov 2022 17:26:11 +0100 Subject: [PATCH 69/96] Set the pants python version correctly in CI (#113) --- .github/workflows/pants.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pants.yaml b/.github/workflows/pants.yaml index 3df4153..b80909b 100644 --- a/.github/workflows/pants.yaml +++ b/.github/workflows/pants.yaml @@ -28,6 +28,7 @@ jobs: # This action bootstraps pants and manages 2-3 GHA caches. # See: github.com/pantsbuild/actions/tree/init-pants/ with: + pants-python-version: ${{ matrix.python-version }} # cache0 makes it easy to bust the cache if needed # just increase the integer to start with a fresh cache gha-cache-key: cache0-py${{ matrix.python-version }} From 2511ec3f10a973c3330de44804bd56219f2be62f Mon Sep 17 00:00:00 2001 From: Benjy Weinberger Date: Fri, 2 Dec 2022 15:10:53 -0800 Subject: [PATCH 70/96] Update CI config. (#116) --- .github/workflows/pants.yaml | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pants.yaml b/.github/workflows/pants.yaml index b80909b..b502253 100644 --- a/.github/workflows/pants.yaml +++ b/.github/workflows/pants.yaml @@ -18,15 +18,15 @@ jobs: build: name: Perform CI Checks needs: org-check - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 strategy: matrix: python-version: [3.9] steps: - uses: actions/checkout@v3 - - uses: pantsbuild/actions/init-pants@v1 + - uses: pantsbuild/actions/init-pants@v2 # This action bootstraps pants and manages 2-3 GHA caches. - # See: github.com/pantsbuild/actions/tree/init-pants/ + # See: github.com/pantsbuild/actions/tree/main/init-pants/ with: pants-python-version: ${{ matrix.python-version }} # cache0 makes it easy to bust the cache if needed @@ -45,11 +45,6 @@ jobs: # but will cause the cache entry to grow without bound over time. # See https://pants.readme.io/docs/using-pants-in-ci for tips on how to periodically clean it up. # Alternatively you change gha-cache-key to ignore old caches. - - - name: Setup Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - name: Check BUILD files run: ./pants tailor --check update-build-files --check - name: Lint and typecheck From afa8d823cd9f1b655ce060b29b8da315e3b167ff Mon Sep 17 00:00:00 2001 From: Asher Foa Date: Fri, 6 Jan 2023 16:42:44 -0500 Subject: [PATCH 71/96] Upgrade toolchain plugin and config for toolchain (#117) --- pants.toml | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/pants.toml b/pants.toml index 69e8306..8f72070 100644 --- a/pants.toml +++ b/pants.toml @@ -12,20 +12,23 @@ backend_packages.add = [ "pants.backend.python.typecheck.mypy", ] -# Pants' sponsor, Toolchain, offers remote caching, which can improve your CI performance -# with minimal configuration. For more details, visit https://toolchain.com +# Pants' sponsor, Toolchain, offers remote caching, which can improve your CI performance with minimal configuration. +# Visit https://toolchain.com to enable and try it on your repository +# docs: https://docs.toolchain.com/docs plugins.add = [ - "toolchain.pants.plugin==0.20.0", + "toolchain.pants.plugin==0.25.0", ] - remote_cache_read = false remote_cache_write = false -remote_store_address = "grpcs://cache.toolchain.com:443" -remote_auth_plugin = "toolchain.pants.auth.plugin:toolchain_auth_plugin" -# End Toolchain-specific configuration +[toolchain-setup] +repo = "example-python" +org = "pantsbuild" +[buildsense] +enable = false +# End Toolchain-specific configuration [anonymous-telemetry] enabled = true @@ -58,14 +61,3 @@ resolves = { python-default = "python-default.lock"} # problematic system Pythons. See # https://www.pantsbuild.org/docs/python-interpreter-compatibility#changing-the-interpreter-search-path. search_path = ["", ""] - - -# Configuration for Toolchain instrumentation and remote caching -# Visit https://toolchain.com to enable and try it on your repository - -[toolchain-setup] -repo = "pants" -org = "example-python" - -[buildsense] -enable = false From 7cf8c0fefe27be4444a165e1229ea0ce31c91baf Mon Sep 17 00:00:00 2001 From: Asher Foa Date: Fri, 20 Jan 2023 11:33:10 -0500 Subject: [PATCH 72/96] Update pytest & running tailor in CI (#119) see: https://github.com/pantsbuild/example-python/pull/109#issuecomment-1282640689 --- .github/workflows/pants.yaml | 3 +- python-default.lock | 118 +++++++++++++---------------------- requirements.txt | 2 +- 3 files changed, 48 insertions(+), 75 deletions(-) diff --git a/.github/workflows/pants.yaml b/.github/workflows/pants.yaml index b502253..e3aa38e 100644 --- a/.github/workflows/pants.yaml +++ b/.github/workflows/pants.yaml @@ -46,7 +46,8 @@ jobs: # See https://pants.readme.io/docs/using-pants-in-ci for tips on how to periodically clean it up. # Alternatively you change gha-cache-key to ignore old caches. - name: Check BUILD files - run: ./pants tailor --check update-build-files --check + run: | + ./pants tailor --check update-build-files --check :: - name: Lint and typecheck run: | ./pants lint check :: diff --git a/python-default.lock b/python-default.lock index 498b4eb..0bfb6b1 100644 --- a/python-default.lock +++ b/python-default.lock @@ -10,7 +10,7 @@ // ], // "generated_with_requirements": [ // "ansicolors==1.1.8", -// "pytest==7.0.1", +// "pytest==7.1.3", // "setuptools<57,>=56.2.0", // "types-setuptools<58,>=56.2.0" // ], @@ -52,89 +52,83 @@ "artifacts": [ { "algorithm": "sha256", - "hash": "86efa402f67bf2df34f51a335487cf46b1ec130d02b8d39fd248abfd30da551c", - "url": "https://files.pythonhosted.org/packages/f2/bc/d817287d1aa01878af07c19505fafd1165cd6a119e9d0821ca1d1c20312d/attrs-22.1.0-py2.py3-none-any.whl" + "hash": "29e95c7f6778868dbd49170f98f8818f78f3dc5e0e37c0b1f474e3561b240836", + "url": "https://files.pythonhosted.org/packages/fb/6e/6f83bf616d2becdf333a1640f1d463fef3150e2e926b7010cb0f81c95e88/attrs-22.2.0-py3-none-any.whl" }, { "algorithm": "sha256", - "hash": "29adc2665447e5191d0e7c568fde78b21f9672d344281d0c6e1ab085429b22b6", - "url": "https://files.pythonhosted.org/packages/1a/cb/c4ffeb41e7137b23755a45e1bfec9cbb76ecf51874c6f1d113984ecaa32c/attrs-22.1.0.tar.gz" + "hash": "c9227bfc2f01993c03f68db37d1d15c9690188323c067c641f1a35ca58185f99", + "url": "https://files.pythonhosted.org/packages/21/31/3f468da74c7de4fcf9b25591e682856389b3400b4b62f201e65f15ea3e07/attrs-22.2.0.tar.gz" } ], "project_name": "attrs", "requires_dists": [ - "cloudpickle; platform_python_implementation == \"CPython\" and extra == \"dev\"", - "cloudpickle; platform_python_implementation == \"CPython\" and extra == \"tests\"", + "attrs[docs,tests]; extra == \"dev\"", + "attrs[tests-no-zope]; extra == \"tests\"", + "attrs[tests]; extra == \"cov\"", + "cloudpickle; platform_python_implementation == \"CPython\" and extra == \"tests-no-zope\"", "cloudpickle; platform_python_implementation == \"CPython\" and extra == \"tests_no_zope\"", - "coverage[toml]>=5.0.2; extra == \"dev\"", - "coverage[toml]>=5.0.2; extra == \"tests\"", - "coverage[toml]>=5.0.2; extra == \"tests_no_zope\"", - "furo; extra == \"dev\"", + "coverage-enable-subprocess; extra == \"cov\"", + "coverage[toml]>=5.3; extra == \"cov\"", "furo; extra == \"docs\"", - "hypothesis; extra == \"dev\"", - "hypothesis; extra == \"tests\"", + "hypothesis; extra == \"tests-no-zope\"", "hypothesis; extra == \"tests_no_zope\"", - "mypy!=0.940,>=0.900; extra == \"dev\"", - "mypy!=0.940,>=0.900; extra == \"tests\"", - "mypy!=0.940,>=0.900; extra == \"tests_no_zope\"", - "pre-commit; extra == \"dev\"", - "pympler; extra == \"dev\"", - "pympler; extra == \"tests\"", + "mypy<0.990,>=0.971; platform_python_implementation == \"CPython\" and extra == \"tests-no-zope\"", + "mypy<0.990,>=0.971; platform_python_implementation == \"CPython\" and extra == \"tests_no_zope\"", + "myst-parser; extra == \"docs\"", + "pympler; extra == \"tests-no-zope\"", "pympler; extra == \"tests_no_zope\"", - "pytest-mypy-plugins; extra == \"dev\"", - "pytest-mypy-plugins; extra == \"tests\"", - "pytest-mypy-plugins; extra == \"tests_no_zope\"", - "pytest>=4.3.0; extra == \"dev\"", - "pytest>=4.3.0; extra == \"tests\"", + "pytest-mypy-plugins; (platform_python_implementation == \"CPython\" and python_version < \"3.11\") and extra == \"tests-no-zope\"", + "pytest-mypy-plugins; (platform_python_implementation == \"CPython\" and python_version < \"3.11\") and extra == \"tests_no_zope\"", + "pytest-xdist[psutil]; extra == \"tests-no-zope\"", + "pytest-xdist[psutil]; extra == \"tests_no_zope\"", + "pytest>=4.3.0; extra == \"tests-no-zope\"", "pytest>=4.3.0; extra == \"tests_no_zope\"", - "sphinx-notfound-page; extra == \"dev\"", "sphinx-notfound-page; extra == \"docs\"", - "sphinx; extra == \"dev\"", "sphinx; extra == \"docs\"", - "zope.interface; extra == \"dev\"", + "sphinxcontrib-towncrier; extra == \"docs\"", + "towncrier; extra == \"docs\"", "zope.interface; extra == \"docs\"", "zope.interface; extra == \"tests\"" ], - "requires_python": ">=3.5", - "version": "22.1" + "requires_python": ">=3.6", + "version": "22.2" }, { "artifacts": [ { "algorithm": "sha256", - "hash": "011e24c64b7f47f6ebd835bb12a743f2fbe9a26d4cecaa7f53bc4f35ee9da8b3", - "url": "https://files.pythonhosted.org/packages/9b/dd/b3c12c6d707058fa947864b67f0c4e0c39ef8610988d7baea9578f3c48f3/iniconfig-1.1.1-py2.py3-none-any.whl" + "hash": "b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374", + "url": "https://files.pythonhosted.org/packages/ef/a6/62565a6e1cf69e10f5727360368e451d4b7f58beeac6173dc9db836a5b46/iniconfig-2.0.0-py3-none-any.whl" }, { "algorithm": "sha256", - "hash": "bc3af051d7d14b2ee5ef9969666def0cd1a000e121eaea580d4a313df4b37f32", - "url": "https://files.pythonhosted.org/packages/23/a2/97899f6bd0e873fed3a7e67ae8d3a08b21799430fb4da15cfedf10d6e2c2/iniconfig-1.1.1.tar.gz" + "hash": "2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3", + "url": "https://files.pythonhosted.org/packages/d7/4b/cbd8e699e64a6f16ca3a8220661b5f83792b3017d0f79807cb8708d33913/iniconfig-2.0.0.tar.gz" } ], "project_name": "iniconfig", "requires_dists": [], - "requires_python": null, - "version": "1.1.1" + "requires_python": ">=3.7", + "version": "2" }, { "artifacts": [ { "algorithm": "sha256", - "hash": "ef103e05f519cdc783ae24ea4e2e0f508a9c99b2d4969652eed6a2e1ea5bd522", - "url": "https://files.pythonhosted.org/packages/05/8e/8de486cbd03baba4deef4142bd643a3e7bbe954a784dc1bb17142572d127/packaging-21.3-py3-none-any.whl" + "hash": "714ac14496c3e68c99c29b00845f7a2b85f3bb6f1078fd9f72fd20f0570002b2", + "url": "https://files.pythonhosted.org/packages/ed/35/a31aed2993e398f6b09a790a181a7927eb14610ee8bbf02dc14d31677f1c/packaging-23.0-py3-none-any.whl" }, { "algorithm": "sha256", - "hash": "dd47c42927d89ab911e606518907cc2d3a1f38bbd026385970643f9c5b8ecfeb", - "url": "https://files.pythonhosted.org/packages/df/9e/d1a7217f69310c1db8fdf8ab396229f55a699ce34a203691794c5d1cad0c/packaging-21.3.tar.gz" + "hash": "b6ad297f8907de0fa2fe1ccbd26fdaf387f5f47c7275fedf8cce89f99446cf97", + "url": "https://files.pythonhosted.org/packages/47/d5/aca8ff6f49aa5565df1c826e7bf5e85a6df852ee063600c1efa5b932968c/packaging-23.0.tar.gz" } ], "project_name": "packaging", - "requires_dists": [ - "pyparsing!=3.0.5,>=2.0.2" - ], - "requires_python": ">=3.6", - "version": "21.3" + "requires_dists": [], + "requires_python": ">=3.7", + "version": "23" }, { "artifacts": [ @@ -182,40 +176,18 @@ "artifacts": [ { "algorithm": "sha256", - "hash": "5026bae9a10eeaefb61dab2f09052b9f4307d44aee4eda64b309723d8d206bbc", - "url": "https://files.pythonhosted.org/packages/6c/10/a7d0fa5baea8fe7b50f448ab742f26f52b80bfca85ac2be9d35cdd9a3246/pyparsing-3.0.9-py3-none-any.whl" + "hash": "1377bda3466d70b55e3f5cecfa55bb7cfcf219c7964629b967c37cf0bda818b7", + "url": "https://files.pythonhosted.org/packages/e3/b9/3541bbcb412a9fd56593005ff32183825634ef795a1c01ceb6dee86e7259/pytest-7.1.3-py3-none-any.whl" }, { "algorithm": "sha256", - "hash": "2b020ecf7d21b687f219b71ecad3631f644a47f01403fa1d1036b0c6416d70fb", - "url": "https://files.pythonhosted.org/packages/71/22/207523d16464c40a0310d2d4d8926daffa00ac1f5b1576170a32db749636/pyparsing-3.0.9.tar.gz" - } - ], - "project_name": "pyparsing", - "requires_dists": [ - "jinja2; extra == \"diagrams\"", - "railroad-diagrams; extra == \"diagrams\"" - ], - "requires_python": ">=3.6.8", - "version": "3.0.9" - }, - { - "artifacts": [ - { - "algorithm": "sha256", - "hash": "9ce3ff477af913ecf6321fe337b93a2c0dcf2a0a1439c43f5452112c1e4280db", - "url": "https://files.pythonhosted.org/packages/38/93/c7c0bd1e932b287fb948eb9ce5a3d6307c9fc619db1e199f8c8bc5dad95f/pytest-7.0.1-py3-none-any.whl" - }, - { - "algorithm": "sha256", - "hash": "e30905a0c131d3d94b89624a1cc5afec3e0ba2fbdb151867d8e0ebd49850f171", - "url": "https://files.pythonhosted.org/packages/3e/2c/a67ad48759051c7abf82ce182a4e6d766de371b183182d2dde03089e8dfb/pytest-7.0.1.tar.gz" + "hash": "4f365fec2dff9c1162f834d9f18af1ba13062db0c708bf7b946f8a5c76180c39", + "url": "https://files.pythonhosted.org/packages/a4/a7/8c63a4966935b0d0b039fd67ebf2e1ae00f1af02ceb912d838814d772a9a/pytest-7.1.3.tar.gz" } ], "project_name": "pytest", "requires_dists": [ "argcomplete; extra == \"testing\"", - "atomicwrites>=1.0; sys_platform == \"win32\"", "attrs>=19.2.0", "colorama; sys_platform == \"win32\"", "hypothesis>=3.56; extra == \"testing\"", @@ -231,8 +203,8 @@ "tomli>=1.0.0", "xmlschema; extra == \"testing\"" ], - "requires_python": ">=3.6", - "version": "7.0.1" + "requires_python": ">=3.7", + "version": "7.1.3" }, { "artifacts": [ @@ -324,7 +296,7 @@ "prefer_older_binary": false, "requirements": [ "ansicolors==1.1.8", - "pytest==7.0.1", + "pytest==7.1.3", "setuptools<57,>=56.2.0", "types-setuptools<58,>=56.2.0" ], diff --git a/requirements.txt b/requirements.txt index 73985bc..979167d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,4 @@ ansicolors==1.1.8 setuptools>=56.2.0,<57 types-setuptools>=56.2.0,<58 -pytest==7.0.1 +pytest==7.1.3 \ No newline at end of file From c5f6f1f18e213504c452f985f645be9aa292d93b Mon Sep 17 00:00:00 2001 From: Asher Foa Date: Fri, 20 Jan 2023 11:33:27 -0500 Subject: [PATCH 73/96] Fmt BUILD files (#118) --- pants.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pants.toml b/pants.toml index 8f72070..fc5bff0 100644 --- a/pants.toml +++ b/pants.toml @@ -4,6 +4,7 @@ [GLOBAL] pants_version = "2.14.0" backend_packages.add = [ + "pants.backend.build_files.fmt.black", "pants.backend.python", "pants.backend.python.lint.docformatter", "pants.backend.python.lint.black", From a792a8b4e137815dc4974010545f1740501802f4 Mon Sep 17 00:00:00 2001 From: Benjy Weinberger Date: Tue, 28 Feb 2023 10:31:47 -0800 Subject: [PATCH 74/96] Upgrade to Pants 2.15.0 and use scie-pants. (#122) --- .github/workflows/pants.yaml | 20 +- README.md | 66 ++--- helloworld/BUILD | 2 +- pants | 481 ----------------------------------- pants.toml | 2 +- pants_from_sources | 23 -- python-default.lock | 2 +- 7 files changed, 48 insertions(+), 548 deletions(-) delete mode 100755 pants delete mode 100755 pants_from_sources diff --git a/.github/workflows/pants.yaml b/.github/workflows/pants.yaml index e3aa38e..b832eef 100644 --- a/.github/workflows/pants.yaml +++ b/.github/workflows/pants.yaml @@ -24,14 +24,16 @@ jobs: python-version: [3.9] steps: - uses: actions/checkout@v3 - - uses: pantsbuild/actions/init-pants@v2 + - uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - uses: pantsbuild/actions/init-pants@v4-scie-pants # This action bootstraps pants and manages 2-3 GHA caches. # See: github.com/pantsbuild/actions/tree/main/init-pants/ with: - pants-python-version: ${{ matrix.python-version }} - # cache0 makes it easy to bust the cache if needed + # v0 makes it easy to bust the cache if needed # just increase the integer to start with a fresh cache - gha-cache-key: cache0-py${{ matrix.python-version }} + gha-cache-key: v0 # The Python backend uses named_caches for Pip/PEX state, # so it is appropriate to invalidate on lockfile changes. named-caches-hash: ${{ hashFiles('python-default.lock') }} @@ -47,18 +49,18 @@ jobs: # Alternatively you change gha-cache-key to ignore old caches. - name: Check BUILD files run: | - ./pants tailor --check update-build-files --check :: + pants tailor --check update-build-files --check :: - name: Lint and typecheck run: | - ./pants lint check :: + pants lint check :: - name: Test run: | - ./pants test :: + pants test :: - name: Package / Run run: | # We also smoke test that our release process will work by running `package`. - ./pants package :: - ./pants run helloworld/main.py + pants package :: + pants run helloworld/main.py - name: Upload pants log uses: actions/upload-artifact@v3 with: diff --git a/README.md b/README.md index 49f48cc..098239f 100644 --- a/README.md +++ b/README.md @@ -9,14 +9,16 @@ example layouts. # Running Pants -You run Pants goals using the `./pants` wrapper script, which will bootstrap the -configured version of Pants if necessary. +You run Pants goals using the `pants` launcher binary, which will bootstrap the +version of Pants configured for this repo if necessary. -> :question: Running with Apple Silicon and/or MacOS? You will want to make changes to the `search_path` and -`interpreter_constraints` values in `pants.toml` before running `./pants` - there is guidance in `pants.toml` +See [here](https://www.pantsbuild.org/docs/installation) for how to install the `pants` binary. + +> :question: Running with Apple Silicon and/or macOS? You will want to make changes to the `search_path` and +`interpreter_constraints` values in `pants.toml` before running `pants` - there is guidance in `pants.toml` for those settings. -Use `./pants --version` to see the version of Pants configured for the repo (which you can also find +Use `pants --version` to see the version of Pants configured for the repo (which you can also find in `pants.toml`). # Goals @@ -24,7 +26,7 @@ in `pants.toml`). Pants commands are called _goals_. You can get a list of goals with ``` -./pants help goals +pants help goals ``` # Targets @@ -41,37 +43,37 @@ In the latter case, Pants locates target metadata for the source files as needed Invoking goals on files is straightforward, e.g., ``` -./pants test helloworld/greet/greeting_test.py +pants test helloworld/greet/greeting_test.py ``` You can use globs: ``` -./pants lint helloworld/greet/*.py +pants lint helloworld/greet/*.py ``` But note that these will be expanded by your shell, so this is equivalent to having used ``` -./pants lint helloworld/greet/__init__.py helloworld/greet/greeting.py helloworld/greet/greeting_test.py +pants lint helloworld/greet/__init__.py helloworld/greet/greeting.py helloworld/greet/greeting_test.py ``` If you want Pants itself to expand the globs (which is sometimes necessary), you must quote them in the shell: ``` -./pants lint 'helloworld/greet/*.py' +pants lint 'helloworld/greet/*.py' ``` You can run on all changed files: ``` -./pants --changed-since=HEAD lint +pants --changed-since=HEAD lint ``` You can run on all changed files, and any of their "dependees": ``` -./pants --changed-since=HEAD --changed-dependees=transitive test +pants --changed-since=HEAD --changed-dependees=transitive test ``` ## Target specifications @@ -79,14 +81,14 @@ You can run on all changed files, and any of their "dependees": Targets are referenced on the command line using their address, of the form `path/to/dir:name`, e.g., ``` -./pants lint helloworld/greet:lib +pants lint helloworld/greet:lib ``` You can glob over all targets in a directory with a single trailing `:`, or over all targets in a directory and all its subdirectories with a double trailing `::`, e.g., ``` -./pants lint helloworld:: +pants lint helloworld:: ``` ## Globbing semantics @@ -96,7 +98,7 @@ For example, if you run the `test` goal over a set of files that includes non-te those, rather than error. So you can safely do things like ``` -./pants test :: +pants test :: ``` To run all tests. @@ -108,50 +110,50 @@ Try these out in this repo! ## List targets ``` -./pants list :: # All targets. -./pants list 'helloworld/**/*.py' # Just targets containing Python code. +pants list :: # All targets. +pants list 'helloworld/**/*.py' # Just targets containing Python code. ``` ## Run linters and formatters ``` -./pants lint :: -./pants fmt helloworld/greet:: +pants lint :: +pants fmt helloworld/greet:: ``` ## Run MyPy ``` -./pants check :: +pants check :: ``` ## Run tests ``` -./pants test :: # Run all tests in the repo. -./pants test --output=all :: # Run all tests in the repo and view pytest output even for tests that passed (you can set this permanently in pants.toml). -./pants test helloworld/translator:tests # Run all the tests in this target. -./pants test helloworld/translator/translator_test.py # Run just the tests in this file. -./pants test helloworld/translator/translator_test.py -- -k test_unknown_phrase # Run just this one test by passing through pytest args. +pants test :: # Run all tests in the repo. +pants test --output=all :: # Run all tests in the repo and view pytest output even for tests that passed (you can set this permanently in pants.toml). +pants test helloworld/translator:tests # Run all the tests in this target. +pants test helloworld/translator/translator_test.py # Run just the tests in this file. +pants test helloworld/translator/translator_test.py -- -k test_unknown_phrase # Run just this one test by passing through pytest args. ``` ## Create a PEX binary ``` -./pants package helloworld/main.py +pants package helloworld/main.py ``` ## Run a binary directly ``` -./pants run helloworld/main.py +pants run helloworld/main.py ``` ## Open a REPL ``` -./pants repl helloworld/greet:lib # The REPL will have all relevant code and dependencies on its sys.path. -./pants repl --shell=ipython helloworld/greet:lib --no-pantsd # To use IPython, you must disable Pantsd for now. +pants repl helloworld/greet:lib # The REPL will have all relevant code and dependencies on its sys.path. +pants repl --shell=ipython helloworld/greet:lib --no-pantsd # To use IPython, you must disable Pantsd for now. ``` ## Build a wheel / generate `setup.py` @@ -159,16 +161,16 @@ Try these out in this repo! This will build both a `.whl` bdist and a `.tar.gz` sdist. ``` -./pants package helloworld/translator:dist +pants package helloworld/translator:dist ``` ## Count lines of code ``` -./pants count-loc '**/*' +pants count-loc '**/*' ``` ## Create virtualenv for IDE integration ``` -./pants export :: +pants export :: ``` diff --git a/helloworld/BUILD b/helloworld/BUILD index 7a3c568..5e55812 100644 --- a/helloworld/BUILD +++ b/helloworld/BUILD @@ -7,7 +7,7 @@ python_sources( ) # This target allows us to bundle our app into a PEX binary file via -# `./pants package`. We can also run it with `./pants run`. See +# `pants package`. We can also run it with `pants run`. See # https://www.pantsbuild.org/docs/python-package-goal and # https://www.pantsbuild.org/docs/python-run-goal. pex_binary( diff --git a/pants b/pants deleted file mode 100755 index 367830f..0000000 --- a/pants +++ /dev/null @@ -1,481 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2020 Pants project contributors (see CONTRIBUTORS.md). -# Licensed under the Apache License, Version 2.0 (see LICENSE). - -# =============================== NOTE =============================== -# This ./pants bootstrap script comes from the pantsbuild/setup -# project. It is intended to be checked into your code repository so -# that other developers have the same setup. -# -# Learn more here: https://www.pantsbuild.org/docs/installation -# ==================================================================== - -set -eou pipefail - -# an arbitrary number: bump when there's a change that someone might want to query for -# (e.g. checking $(PANTS_BOOTSTRAP_TOOLS=1 ./pants version) >= ...) -SCRIPT_VERSION=1 - -# Source any custom bootstrap settings for Pants from PANTS_BOOTSTRAP if it exists. -: ${PANTS_BOOTSTRAP:=".pants.bootstrap"} -if [[ -f "${PANTS_BOOTSTRAP}" ]]; then - source "${PANTS_BOOTSTRAP}" -fi - -# NOTE: To use an unreleased version of Pants from the pantsbuild/pants main branch, -# locate the main branch SHA, set PANTS_SHA= in the environment, and run this script as usual. -# -# E.g., PANTS_SHA=725fdaf504237190f6787dda3d72c39010a4c574 ./pants --version - -PYTHON_BIN_NAME="${PYTHON:-unspecified}" - -# Set this to specify a non-standard location for this script to read the Pants version from. -# NB: This will *not* cause Pants itself to use this location as a config file. -# You can use PANTS_CONFIG_FILES or --pants-config-files to do so. -PANTS_TOML=${PANTS_TOML:-pants.toml} - -PANTS_BIN_NAME="${PANTS_BIN_NAME:-$0}" - -PANTS_SETUP_CACHE="${PANTS_SETUP_CACHE:-${XDG_CACHE_HOME:-$HOME/.cache}/pants/setup}" -# If given a relative path, we fix it to be absolute. -if [[ "$PANTS_SETUP_CACHE" != /* ]]; then - PANTS_SETUP_CACHE="${PWD}/${PANTS_SETUP_CACHE}" -fi - -PANTS_BOOTSTRAP="${PANTS_SETUP_CACHE}/bootstrap-$(uname -s)-$(uname -m)" - -_PEX_VERSION=2.1.103 -_PEX_URL="https://github.com/pantsbuild/pex/releases/download/v${_PEX_VERSION}/pex" -_PEX_EXPECTED_SHA256="4d45336511484100ae4e2bab24542a8b86b12c8cb89230463593c60d08c4b8d3" - -VIRTUALENV_VERSION=20.4.7 -VIRTUALENV_REQUIREMENTS=$( -cat << EOF -virtualenv==${VIRTUALENV_VERSION} --hash sha256:2b0126166ea7c9c3661f5b8e06773d28f83322de7a3ff7d06f0aed18c9de6a76 -filelock==3.0.12 --hash sha256:929b7d63ec5b7d6b71b0fa5ac14e030b3f70b75747cef1b10da9b879fef15836 -six==1.16.0 --hash sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254 -distlib==0.3.2 --hash sha256:23e223426b28491b1ced97dc3bbe183027419dfc7982b4fa2f05d5f3ff10711c -appdirs==1.4.4 --hash sha256:a841dacd6b99318a741b166adb07e19ee71a274450e68237b4650ca1055ab128 -importlib-resources==5.1.4; python_version < "3.7" --hash sha256:e962bff7440364183203d179d7ae9ad90cb1f2b74dcb84300e88ecc42dca3351 -importlib-metadata==4.5.0; python_version < "3.8" --hash sha256:833b26fb89d5de469b24a390e9df088d4e52e4ba33b01dc5e0e4f41b81a16c00 -zipp==3.4.1; python_version < "3.10" --hash sha256:51cb66cc54621609dd593d1787f286ee42a5c0adbb4b29abea5a63edc3e03098 -typing-extensions==3.10.0.0; python_version < "3.8" --hash sha256:779383f6086d90c99ae41cf0ff39aac8a7937a9283ce0a414e5dd782f4c94a84 -EOF -) - -COLOR_RED="\x1b[31m" -COLOR_GREEN="\x1b[32m" -COLOR_YELLOW="\x1b[33m" -COLOR_RESET="\x1b[0m" - -INSTALL_URL="https://www.pantsbuild.org/docs/installation" - -function log() { - echo -e "$@" 1>&2 -} - -function die() { - (($# > 0)) && log "${COLOR_RED}$*${COLOR_RESET}" - exit 1 -} - -function green() { - (($# > 0)) && log "${COLOR_GREEN}$*${COLOR_RESET}" -} - -function warn() { - (($# > 0)) && log "${COLOR_YELLOW}$*${COLOR_RESET}" -} - -function tempdir { - mkdir -p "$1" - mktemp -d "$1"/pants.XXXXXX -} - -function get_exe_path_or_die { - local exe="$1" - if ! command -v "${exe}"; then - die "Could not find ${exe}. Please ensure ${exe} is on your PATH." - fi -} - -function get_pants_config_string_value { - local config_key="$1" - local optional_space="[[:space:]]*" - local prefix="^${config_key}${optional_space}=${optional_space}" - local raw_value - raw_value="$(sed -ne "/${prefix}/ s|${prefix}||p" "${PANTS_TOML}")" - local optional_suffix="${optional_space}(#.*)?$" - echo "${raw_value}" \ - | sed -E \ - -e "s|^'([^']*)'${optional_suffix}|\1|" \ - -e 's|^"([^"]*)"'"${optional_suffix}"'$|\1|' \ - && return 0 - return 0 -} - -function get_python_major_minor_version { - local python_exe="$1" - "$python_exe" </dev/null 2>&1; then - continue - fi - if [[ -n "$(check_python_exe_compatible_version "${interpreter_path}")" ]]; then - echo "${interpreter_path}" && return 0 - fi - done -} - -function determine_python_exe { - local pants_version="$1" - set_supported_python_versions "${pants_version}" - local requirement_str="For \`pants_version = \"${pants_version}\"\`, Pants requires Python ${supported_message} to run." - - local python_exe - if [[ "${PYTHON_BIN_NAME}" != 'unspecified' ]]; then - python_exe="$(get_exe_path_or_die "${PYTHON_BIN_NAME}")" || exit 1 - if [[ -z "$(check_python_exe_compatible_version "${python_exe}")" ]]; then - die "Invalid Python interpreter version for ${python_exe}. ${requirement_str}" - fi - else - python_exe="$(determine_default_python_exe)" - if [[ -z "${python_exe}" ]]; then - die "No valid Python interpreter found. ${requirement_str} Please check that a valid interpreter is installed and on your \$PATH." - fi - fi - echo "${python_exe}" -} - -function compute_sha256 { - local python="$1" - local path="$2" - - "$python" <&2 || exit 1 - fi - echo "${bootstrapped}" -} - -function scrub_env_vars { - # Ensure the virtualenv PEX runs as shrink-wrapped. - # See: https://github.com/pantsbuild/setup/issues/105 - local -r pex_env_vars=(${!PEX_@}) - if [[ ! ${#pex_env_vars[@]} -eq 0 ]]; then - local -r pex_env_vars_to_scrub="${pex_env_vars[@]/PEX_ROOT}" - if [[ -n "${pex_env_vars_to_scrub[@]}" ]]; then - warn "Scrubbing ${pex_env_vars_to_scrub[@]}" - unset ${pex_env_vars_to_scrub[@]} - fi - fi - # Also ensure pip doesn't think packages on PYTHONPATH - # are already installed. - if [ -n "${PYTHONPATH:-}" ]; then - warn "Scrubbing PYTHONPATH" - unset PYTHONPATH - fi -} - -function bootstrap_virtualenv { - local python="$1" - local bootstrapped="${PANTS_BOOTSTRAP}/virtualenv-${VIRTUALENV_VERSION}/virtualenv.pex" - if [[ ! -f "${bootstrapped}" ]]; then - ( - green "Creating the virtualenv PEX." - pex_path="$(bootstrap_pex "${python}")" || exit 1 - mkdir -p "${PANTS_BOOTSTRAP}" - local staging_dir - staging_dir=$(tempdir "${PANTS_BOOTSTRAP}") - cd "${staging_dir}" - echo "${VIRTUALENV_REQUIREMENTS}" > requirements.txt - ( - scrub_env_vars - "${python}" "${pex_path}" -r requirements.txt -c virtualenv -o virtualenv.pex - ) - mkdir -p "$(dirname "${bootstrapped}")" - mv -f "${staging_dir}/virtualenv.pex" "${bootstrapped}" - rm -rf "${staging_dir}" - ) 1>&2 || exit 1 - fi - echo "${bootstrapped}" -} - -function find_links_url { - local pants_version="$1" - local pants_sha="$2" - echo -n "https://binaries.pantsbuild.org/wheels/pantsbuild.pants/${pants_sha}/${pants_version/+/%2B}/index.html" -} - -function get_version_for_sha { - local sha="$1" - - # Retrieve the Pants version associated with this commit. - local pants_version - pants_version="$(curl --proto "=https" \ - --tlsv1.2 \ - --fail \ - --silent \ - --location \ - "https://raw.githubusercontent.com/pantsbuild/pants/${sha}/src/python/pants/VERSION")" - - # Construct the version as the release version from src/python/pants/VERSION, plus the string `+gitXXXXXXXX`, - # where the XXXXXXXX is the first 8 characters of the SHA. - echo "${pants_version}+git${sha:0:8}" -} - -function bootstrap_pants { - local pants_version="$1" - local python="$2" - local pants_sha="${3:-}" - - local pants_requirement="pantsbuild.pants==${pants_version}" - local maybe_find_links - if [[ -z "${pants_sha}" ]]; then - maybe_find_links="" - else - maybe_find_links="--find-links=$(find_links_url "${pants_version}" "${pants_sha}")" - fi - local python_major_minor_version - python_major_minor_version="$(get_python_major_minor_version "${python}")" - local target_folder_name="${pants_version}_py${python_major_minor_version}" - local bootstrapped="${PANTS_BOOTSTRAP}/${target_folder_name}" - - if [[ ! -d "${bootstrapped}" ]]; then - ( - green "Bootstrapping Pants using ${python}" - local staging_dir - staging_dir=$(tempdir "${PANTS_BOOTSTRAP}") - local virtualenv_path - virtualenv_path="$(bootstrap_virtualenv "${python}")" || exit 1 - green "Installing ${pants_requirement} into a virtual environment at ${bootstrapped}" - ( - scrub_env_vars - # shellcheck disable=SC2086 - "${python}" "${virtualenv_path}" --quiet --no-download "${staging_dir}/install" && \ - # Grab the latest pip, but don't advance setuptools past 58 which drops support for the - # `setup` kwarg `use_2to3` which Pants 1.x sdist dependencies (pystache) use. - "${staging_dir}/install/bin/pip" install --quiet -U pip "setuptools<58" && \ - "${staging_dir}/install/bin/pip" install ${maybe_find_links} --quiet --progress-bar off "${pants_requirement}" - ) && \ - ln -s "${staging_dir}/install" "${staging_dir}/${target_folder_name}" && \ - mv "${staging_dir}/${target_folder_name}" "${bootstrapped}" && \ - green "New virtual environment successfully created at ${bootstrapped}." - ) 1>&2 || exit 1 - fi - echo "${bootstrapped}" -} - -function run_bootstrap_tools { - # functionality for introspecting the bootstrapping process, without actually doing it - if [[ "${PANTS_BOOTSTRAP_TOOLS}" -gt "${SCRIPT_VERSION}" ]]; then - die "$0 script (bootstrap version ${SCRIPT_VERSION}) is too old for this invocation (with PANTS_BOOTSTRAP_TOOLS=${PANTS_BOOTSTRAP_TOOLS}). -Please update it by following ${INSTALL_URL}" - fi - - case "${1:-}" in - bootstrap-cache-key) - local pants_version=$(determine_pants_version) - local python="$(determine_python_exe "${pants_version}")" - # the python above may be a shim (e.g. pyenv or homebrew), so let's get an estimate of the - # actual path, as will be symlinked in the virtualenv. (NB. virtualenv does more complicated - # things, but we at least emulate the symlink-resolution that it does.) - local python_executable_path="$("${python}" -c 'import os, sys; print(os.path.realpath(sys.executable))')" - - local requirements_file="$(mktemp)" - echo "${VIRTUALENV_REQUIREMENTS}" > "${requirements_file}" - local virtualenv_requirements_sha256="$(compute_sha256 "${python}" "${requirements_file}")" - rm "${requirements_file}" - - local parts=( - "os_name=$(uname -s)" - "arch=$(uname -m)" - "python_path=${python}" - "python_executable_path=${python_executable_path}" - # the full interpreter information, for maximum compatibility - "python_version=$("$python" --version)" - "pex_version=${_PEX_VERSION}" - "virtualenv_requirements_sha256=${virtualenv_requirements_sha256}" - "pants_version=${pants_version}" - ) - echo "${parts[*]}" - ;; - bootstrap-version) - echo "${SCRIPT_VERSION}" - ;; - help|"") - cat < Date: Fri, 19 May 2023 09:06:45 -0500 Subject: [PATCH 75/96] Remove Toolchain config. (#124) --- pants.ci.toml | 5 ----- pants.toml | 18 ------------------ 2 files changed, 23 deletions(-) diff --git a/pants.ci.toml b/pants.ci.toml index 446bd0d..bcf7a2e 100644 --- a/pants.ci.toml +++ b/pants.ci.toml @@ -13,8 +13,3 @@ remote_cache_write = false [pytest] args = ["-vv", "--no-header"] - -# Toolchain plugin auth configuration -[auth] -from_env_var = "TOOLCHAIN_AUTH_TOKEN" -org = "pantsbuild" diff --git a/pants.toml b/pants.toml index dad9531..4ca8783 100644 --- a/pants.toml +++ b/pants.toml @@ -13,24 +13,6 @@ backend_packages.add = [ "pants.backend.python.typecheck.mypy", ] -# Pants' sponsor, Toolchain, offers remote caching, which can improve your CI performance with minimal configuration. -# Visit https://toolchain.com to enable and try it on your repository -# docs: https://docs.toolchain.com/docs - -plugins.add = [ - "toolchain.pants.plugin==0.25.0", -] -remote_cache_read = false -remote_cache_write = false - -[toolchain-setup] -repo = "example-python" -org = "pantsbuild" - -[buildsense] -enable = false -# End Toolchain-specific configuration - [anonymous-telemetry] enabled = true repo_id = "3B1D361B-E9F1-49A8-B761-03DCC41FD58E" From 27fc9ee7761e61f3c5c9b502d612df5f1f13e29b Mon Sep 17 00:00:00 2001 From: Alexey Tereshenkov <50622389+AlexTereshenkov@users.noreply.github.com> Date: Thu, 15 Jun 2023 15:31:59 +0100 Subject: [PATCH 76/96] Upgrade to pants 2.16.0 (#125) --- pants.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pants.toml b/pants.toml index 4ca8783..d0981a6 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.15.0" +pants_version = "2.16.0" backend_packages.add = [ "pants.backend.build_files.fmt.black", "pants.backend.python", From 751db8be2ed502dba733d8bc1c340064bb9d1995 Mon Sep 17 00:00:00 2001 From: Rhuan Barreto Date: Thu, 20 Jul 2023 17:53:22 +0200 Subject: [PATCH 77/96] ci: upgrade action version (#126) --- .github/workflows/pants.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pants.yaml b/.github/workflows/pants.yaml index b832eef..acea3a2 100644 --- a/.github/workflows/pants.yaml +++ b/.github/workflows/pants.yaml @@ -27,7 +27,7 @@ jobs: - uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - - uses: pantsbuild/actions/init-pants@v4-scie-pants + - uses: pantsbuild/actions/init-pants@v5-scie-pants # This action bootstraps pants and manages 2-3 GHA caches. # See: github.com/pantsbuild/actions/tree/main/init-pants/ with: @@ -48,10 +48,10 @@ jobs: # See https://pants.readme.io/docs/using-pants-in-ci for tips on how to periodically clean it up. # Alternatively you change gha-cache-key to ignore old caches. - name: Check BUILD files - run: | + run: | pants tailor --check update-build-files --check :: - name: Lint and typecheck - run: | + run: | pants lint check :: - name: Test run: | From a930f25c26774316311b6f062eb598b7dd4fa6b8 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Fri, 1 Sep 2023 02:03:23 +1000 Subject: [PATCH 78/96] Upgrade to Pants 2.17.0 (#127) --- pants.toml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pants.toml b/pants.toml index d0981a6..59bdbc4 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.16.0" +pants_version = "2.17.0" backend_packages.add = [ "pants.backend.build_files.fmt.black", "pants.backend.python", @@ -44,3 +44,7 @@ resolves = { python-default = "python-default.lock"} # problematic system Pythons. See # https://www.pantsbuild.org/docs/python-interpreter-compatibility#changing-the-interpreter-search-path. search_path = ["", ""] + +[python-infer] +# 2.17 is transitioning to a new, faster parser for dependency inference: +use_rust_parser = true From 98ffe0cd62e975ff6122106174652db2a2fb74a5 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Fri, 1 Sep 2023 07:50:05 +1000 Subject: [PATCH 79/96] Check in get-pants.sh script, following doc recommendation (#128) * Check in get-pants.sh script, following doc recommendation * Resolve duplicate owner warning --- .github/workflows/pants.yaml | 2 +- get-pants.sh | 221 +++++++++++++++++++++++++++++++++++ 2 files changed, 222 insertions(+), 1 deletion(-) create mode 100755 get-pants.sh diff --git a/.github/workflows/pants.yaml b/.github/workflows/pants.yaml index acea3a2..77515a4 100644 --- a/.github/workflows/pants.yaml +++ b/.github/workflows/pants.yaml @@ -60,7 +60,7 @@ jobs: run: | # We also smoke test that our release process will work by running `package`. pants package :: - pants run helloworld/main.py + pants run helloworld/:pex_binary - name: Upload pants log uses: actions/upload-artifact@v3 with: diff --git a/get-pants.sh b/get-pants.sh new file mode 100755 index 0000000..56ee4f2 --- /dev/null +++ b/get-pants.sh @@ -0,0 +1,221 @@ +#!/usr/bin/env bash +# Copyright 2023 Pants project contributors (see CONTRIBUTORS.md). +# Licensed under the Apache License, Version 2.0 (see LICENSE). + +set -euo pipefail + +COLOR_RED="\x1b[31m" +COLOR_GREEN="\x1b[32m" +COLOR_YELLOW="\x1b[33m" +COLOR_RESET="\x1b[0m" + +function log() { + echo -e "$@" 1>&2 +} + +function die() { + (($# > 0)) && log "${COLOR_RED}$*${COLOR_RESET}" + exit 1 +} + +function green() { + (($# > 0)) && log "${COLOR_GREEN}$*${COLOR_RESET}" +} + +function warn() { + (($# > 0)) && log "${COLOR_YELLOW}$*${COLOR_RESET}" +} + +function check_cmd() { + local cmd="$1" + command -v "$cmd" > /dev/null || die "This script requires the ${cmd} binary to be on the PATH." +} + +help_url="https://www.pantsbuild.org/docs/getting-help" + +_GC=() + +function gc() { + if (($# > 0)); then + check_cmd rm + _GC+=("$@") + else + rm -rf "${_GC[@]}" + fi +} + +trap gc EXIT + +check_cmd uname + +function calculate_os() { + local os + + os="$(uname -s)" + if [[ "${os}" =~ [Ll]inux ]]; then + echo linux + elif [[ "${os}" =~ [Dd]arwin ]]; then + echo macos + elif [[ "${os}" =~ [Ww]in|[Mm][Ii][Nn][Gg] ]]; then + # Powershell reports something like: Windows_NT + # Git bash reports something like: MINGW64_NT-10.0-22621 + echo windows + else + die "Pants is not supported on this operating system (${os}). Please reach out to us at ${help_url} for help." + fi +} + +OS="$(calculate_os)" + +check_cmd basename +if [[ "${OS}" == "windows" ]]; then + check_cmd pwsh +else + check_cmd curl +fi + +function fetch() { + local url="$1" + local dest_dir="$2" + + local dest + dest="${dest_dir}/$(basename "${url}")" + + if [[ "${OS}" == "windows" ]]; then + pwsh -c "Invoke-WebRequest -OutFile $dest -Uri $url" + else + curl --proto '=https' --tlsv1.2 -sSfL -o "${dest}" "${url}" + fi +} + +if [[ "${OS}" == "macos" ]]; then + check_cmd shasum +else + check_cmd sha256sum +fi + +function sha256() { + if [[ "${OS}" == "macos" ]]; then + shasum --algorithm 256 "$@" + else + sha256sum "$@" + fi +} + +check_cmd mktemp + +function install_from_url() { + local url="$1" + local dest="$2" + + local workdir + workdir="$(mktemp -d)" + gc "${workdir}" + + fetch "${url}.sha256" "${workdir}" + fetch "${url}" "${workdir}" + ( + cd "${workdir}" + sha256 -c --status ./*.sha256 || + die "Download from ${url} did not match the fingerprint at ${url}.sha256" + ) + rm "${workdir}/"*.sha256 + if [[ "${OS}" == "macos" ]]; then + mkdir -p "$(dirname "${dest}")" + install -m 755 "${workdir}/"* "${dest}" + else + install -D -m 755 "${workdir}/"* "${dest}" + fi +} + +function calculate_arch() { + local arch + + arch="$(uname -m)" + if [[ "${arch}" =~ x86[_-]64 ]]; then + echo x86_64 + elif [[ "${arch}" =~ arm64|aarch64 ]]; then + echo aarch64 + else + die "Pants is not supported for this chip architecture (${arch}). Please reach out to us at ${help_url} for help." + fi +} + +check_cmd cat + +function usage() { + cat << EOF +Usage: $0 + +Installs the pants launcher binary. + +You only need to run this once on a machine when you do not have "pants" +available to run yet. + +The pants binary takes care of managing and running the underlying +Pants version configured in "pants.toml" in the surrounding Pants-using +project. + +Once installed, if you want to update your "pants" launcher binary, use +"SCIE_BOOT=update pants" to get the latest release or +"SCIE_BOOT=update pants --help" to learn more options. + +-h | --help: Print this help message. + +-d | --bin-dir: + The directory to install the scie-pants binary in, "~/bin" by default. + +-b | --base-name: + The name to use for the scie-pants binary, "pants" by default. + +-V | --version: + The version of the scie-pants binary to install, the latest version by default. + The available versions can be seen at: + https://github.com/pantsbuild/scie-pants/releases + +EOF +} + +bin_dir="${HOME}/bin" +base_name="pants" +version="latest/download" +while (($# > 0)); do + case "$1" in + --help | -h) + usage + exit 0 + ;; + --bin-dir | -d) + bin_dir="$2" + shift + ;; + --base-name | -b) + base_name="$2" + shift + ;; + --version | -V) + version="download/v$2" + shift + ;; + *) + usage + die "Unexpected argument $1\n" + ;; + esac + shift +done + +ARCH="$(calculate_arch)" +URL="https://github.com/pantsbuild/scie-pants/releases/${version}/scie-pants-${OS}-${ARCH}" +dest="${bin_dir}/${base_name}" + +log "Downloading and installing the pants launcher ..." +install_from_url "${URL}" "${dest}" +green "Installed the pants launcher from ${URL} to ${dest}" +if ! command -v "${base_name}" > /dev/null; then + warn "${dest} is not on the PATH." + log "You'll either need to invoke ${dest} explicitly or else add ${bin_dir} to your shell's PATH." +fi + +green "\nRunning \`pants\` in a Pants-enabled repo will use the version of Pants configured for that repo." +green "In a repo not yet Pants-enabled, it will prompt you to set up Pants for that repo." From 26d55f2772b72944d7f092019e263f5a5d8984d2 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Mon, 13 Nov 2023 13:44:06 +1100 Subject: [PATCH 80/96] Upgrade to Pants 2.18.0 (#130) --- pants.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pants.toml b/pants.toml index 59bdbc4..dfb564f 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.17.0" +pants_version = "2.18.0" backend_packages.add = [ "pants.backend.build_files.fmt.black", "pants.backend.python", From a8d4bf9859f69fade4c5b43e5a5adbdd9c8b5750 Mon Sep 17 00:00:00 2001 From: Krishnan Chandra <1229365+krishnan-chandra@users.noreply.github.com> Date: Mon, 26 Feb 2024 17:48:50 -0500 Subject: [PATCH 81/96] Upgrade to Pants 2.19.0 (#133) Closes #131 and #132. Upgrade Pants to 2.19, but also fix the export command as specified in #132 and add documentation for lockfile generation as specified in #131. --- README.md | 16 ++++++++--- pants.toml | 2 +- python-default.lock | 66 +++++++++++++++++++++------------------------ 3 files changed, 43 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 098239f..65507d7 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ An example repository to demonstrate Python support in Pants. See [pantsbuild.org](https://www.pantsbuild.org/docs) for much more detailed documentation. -This is only one possible way of laying out your project with Pants. See +This is only one possible way of laying out your project with Pants. See [pantsbuild.org/docs/source-roots#examples](https://www.pantsbuild.org/docs/source-roots#examples) for some other example layouts. @@ -31,8 +31,8 @@ pants help goals # Targets -Targets are a way of setting metadata for some part of your code, such as timeouts for tests and -entry points for binaries. Targets have types like `python_source`, `resources`, and +Targets are a way of setting metadata for some part of your code, such as timeouts for tests and +entry points for binaries. Targets have types like `python_source`, `resources`, and `pex_binary`. They are defined in `BUILD` files. Pants goals can be invoked on targets or directly on source files (which is often more intuitive and convenient). @@ -169,8 +169,16 @@ pants package helloworld/translator:dist ``` pants count-loc '**/*' ``` + +## Generate or update a lockfile containing the dependencies + +``` +pants generate-lockfiles --resolve=python-default +``` + + ## Create virtualenv for IDE integration ``` -pants export :: +pants export --resolve=python-default ``` diff --git a/pants.toml b/pants.toml index dfb564f..0e74a29 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.18.0" +pants_version = "2.19.0" backend_packages.add = [ "pants.backend.build_files.fmt.black", "pants.backend.python", diff --git a/python-default.lock b/python-default.lock index 10982be..41b799a 100644 --- a/python-default.lock +++ b/python-default.lock @@ -52,47 +52,42 @@ "artifacts": [ { "algorithm": "sha256", - "hash": "29e95c7f6778868dbd49170f98f8818f78f3dc5e0e37c0b1f474e3561b240836", - "url": "https://files.pythonhosted.org/packages/fb/6e/6f83bf616d2becdf333a1640f1d463fef3150e2e926b7010cb0f81c95e88/attrs-22.2.0-py3-none-any.whl" + "hash": "99b87a485a5820b23b879f04c2305b44b951b502fd64be915879d77a7e8fc6f1", + "url": "https://files.pythonhosted.org/packages/e0/44/827b2a91a5816512fcaf3cc4ebc465ccd5d598c45cefa6703fcf4a79018f/attrs-23.2.0-py3-none-any.whl" }, { "algorithm": "sha256", - "hash": "c9227bfc2f01993c03f68db37d1d15c9690188323c067c641f1a35ca58185f99", - "url": "https://files.pythonhosted.org/packages/21/31/3f468da74c7de4fcf9b25591e682856389b3400b4b62f201e65f15ea3e07/attrs-22.2.0.tar.gz" + "hash": "935dc3b529c262f6cf76e50877d35a4bd3c1de194fd41f47a2b7ae8f19971f30", + "url": "https://files.pythonhosted.org/packages/e3/fc/f800d51204003fa8ae392c4e8278f256206e7a919b708eef054f5f4b650d/attrs-23.2.0.tar.gz" } ], "project_name": "attrs", "requires_dists": [ - "attrs[docs,tests]; extra == \"dev\"", + "attrs[tests-mypy]; extra == \"tests-no-zope\"", "attrs[tests-no-zope]; extra == \"tests\"", "attrs[tests]; extra == \"cov\"", + "attrs[tests]; extra == \"dev\"", "cloudpickle; platform_python_implementation == \"CPython\" and extra == \"tests-no-zope\"", - "cloudpickle; platform_python_implementation == \"CPython\" and extra == \"tests_no_zope\"", - "coverage-enable-subprocess; extra == \"cov\"", "coverage[toml]>=5.3; extra == \"cov\"", "furo; extra == \"docs\"", "hypothesis; extra == \"tests-no-zope\"", - "hypothesis; extra == \"tests_no_zope\"", - "mypy<0.990,>=0.971; platform_python_implementation == \"CPython\" and extra == \"tests-no-zope\"", - "mypy<0.990,>=0.971; platform_python_implementation == \"CPython\" and extra == \"tests_no_zope\"", + "importlib-metadata; python_version < \"3.8\"", + "mypy>=1.6; (platform_python_implementation == \"CPython\" and python_version >= \"3.8\") and extra == \"tests-mypy\"", "myst-parser; extra == \"docs\"", + "pre-commit; extra == \"dev\"", "pympler; extra == \"tests-no-zope\"", - "pympler; extra == \"tests_no_zope\"", - "pytest-mypy-plugins; (platform_python_implementation == \"CPython\" and python_version < \"3.11\") and extra == \"tests-no-zope\"", - "pytest-mypy-plugins; (platform_python_implementation == \"CPython\" and python_version < \"3.11\") and extra == \"tests_no_zope\"", + "pytest-mypy-plugins; (platform_python_implementation == \"CPython\" and python_version >= \"3.8\") and extra == \"tests-mypy\"", "pytest-xdist[psutil]; extra == \"tests-no-zope\"", - "pytest-xdist[psutil]; extra == \"tests_no_zope\"", "pytest>=4.3.0; extra == \"tests-no-zope\"", - "pytest>=4.3.0; extra == \"tests_no_zope\"", "sphinx-notfound-page; extra == \"docs\"", "sphinx; extra == \"docs\"", "sphinxcontrib-towncrier; extra == \"docs\"", "towncrier; extra == \"docs\"", - "zope.interface; extra == \"docs\"", - "zope.interface; extra == \"tests\"" + "zope-interface; extra == \"docs\"", + "zope-interface; extra == \"tests\"" ], - "requires_python": ">=3.6", - "version": "22.2" + "requires_python": ">=3.7", + "version": "23.2.0" }, { "artifacts": [ @@ -110,49 +105,48 @@ "project_name": "iniconfig", "requires_dists": [], "requires_python": ">=3.7", - "version": "2" + "version": "2.0.0" }, { "artifacts": [ { "algorithm": "sha256", - "hash": "714ac14496c3e68c99c29b00845f7a2b85f3bb6f1078fd9f72fd20f0570002b2", - "url": "https://files.pythonhosted.org/packages/ed/35/a31aed2993e398f6b09a790a181a7927eb14610ee8bbf02dc14d31677f1c/packaging-23.0-py3-none-any.whl" + "hash": "8c491190033a9af7e1d931d0b5dacc2ef47509b34dd0de67ed209b5203fc88c7", + "url": "https://files.pythonhosted.org/packages/ec/1a/610693ac4ee14fcdf2d9bf3c493370e4f2ef7ae2e19217d7a237ff42367d/packaging-23.2-py3-none-any.whl" }, { "algorithm": "sha256", - "hash": "b6ad297f8907de0fa2fe1ccbd26fdaf387f5f47c7275fedf8cce89f99446cf97", - "url": "https://files.pythonhosted.org/packages/47/d5/aca8ff6f49aa5565df1c826e7bf5e85a6df852ee063600c1efa5b932968c/packaging-23.0.tar.gz" + "hash": "048fb0e9405036518eaaf48a55953c750c11e1a1b68e0dd1a9d62ed0c092cfc5", + "url": "https://files.pythonhosted.org/packages/fb/2b/9b9c33ffed44ee921d0967086d653047286054117d584f1b1a7c22ceaf7b/packaging-23.2.tar.gz" } ], "project_name": "packaging", "requires_dists": [], "requires_python": ">=3.7", - "version": "23" + "version": "23.2" }, { "artifacts": [ { "algorithm": "sha256", - "hash": "74134bbf457f031a36d68416e1509f34bd5ccc019f0bcc952c7b909d06b37bd3", - "url": "https://files.pythonhosted.org/packages/9e/01/f38e2ff29715251cf25532b9082a1589ab7e4f571ced434f98d0139336dc/pluggy-1.0.0-py2.py3-none-any.whl" + "hash": "7db9f7b503d67d1c5b95f59773ebb58a8c1c288129a88665838012cfb07b8981", + "url": "https://files.pythonhosted.org/packages/a5/5b/0cc789b59e8cc1bf288b38111d002d8c5917123194d45b29dcdac64723cc/pluggy-1.4.0-py3-none-any.whl" }, { "algorithm": "sha256", - "hash": "4224373bacce55f955a878bf9cfa763c1e360858e330072059e10bad68531159", - "url": "https://files.pythonhosted.org/packages/a1/16/db2d7de3474b6e37cbb9c008965ee63835bba517e22cdb8c35b5116b5ce1/pluggy-1.0.0.tar.gz" + "hash": "8c85c2876142a764e5b7548e7d9a0e0ddb46f5185161049a79b7e974454223be", + "url": "https://files.pythonhosted.org/packages/54/c6/43f9d44d92aed815e781ca25ba8c174257e27253a94630d21be8725a2b59/pluggy-1.4.0.tar.gz" } ], "project_name": "pluggy", "requires_dists": [ - "importlib-metadata>=0.12; python_version < \"3.8\"", "pre-commit; extra == \"dev\"", "pytest-benchmark; extra == \"testing\"", "pytest; extra == \"testing\"", "tox; extra == \"dev\"" ], - "requires_python": ">=3.6", - "version": "1" + "requires_python": ">=3.8", + "version": "1.4.0" }, { "artifacts": [ @@ -170,7 +164,7 @@ "project_name": "py", "requires_dists": [], "requires_python": "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7", - "version": "1.11" + "version": "1.11.0" }, { "artifacts": [ @@ -248,7 +242,7 @@ "wincertstore==0.2; sys_platform == \"win32\" and extra == \"ssl\"" ], "requires_python": ">=3.6", - "version": "56.2" + "version": "56.2.0" }, { "artifacts": [ @@ -291,8 +285,8 @@ } ], "path_mappings": {}, - "pex_version": "2.1.108", - "pip_version": "20.3.4-patched", + "pex_version": "2.1.148", + "pip_version": "23.1.2", "prefer_older_binary": false, "requirements": [ "ansicolors==1.1.8", From f37c500e4f4e0c67e29aa9434b1b414f333bdd79 Mon Sep 17 00:00:00 2001 From: APL <17802877+andrelegault@users.noreply.github.com> Date: Fri, 15 Mar 2024 00:02:12 -0400 Subject: [PATCH 82/96] fix path to pants.log (#134) The log file is in workdir, according to https://github.com/pantsbuild/pants/blob/44a06c5825e294757fb1dfe5920ea4b81db56023/src/python/pants/init/logging.py#L232 The path referred to in the docs is preceded by workdir: https://github.com/pantsbuild/pants/blob/44a06c5825e294757fb1dfe5920ea4b81db56023/docs/docs/using-pants/using-pants-in-ci.mdx#L240 --- .github/workflows/pants.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pants.yaml b/.github/workflows/pants.yaml index 77515a4..c167e42 100644 --- a/.github/workflows/pants.yaml +++ b/.github/workflows/pants.yaml @@ -65,5 +65,5 @@ jobs: uses: actions/upload-artifact@v3 with: name: pants-log - path: .pants.d/pants.log + path: .pants.d/workdir/pants.log if: always() # We want the log even on failures. From 55cf90bc4a1e4ccc47749aa39d299b5dace79adc Mon Sep 17 00:00:00 2001 From: Kaushik-Iyer <84177184+Kaushik-Iyer@users.noreply.github.com> Date: Thu, 18 Apr 2024 05:51:55 +0530 Subject: [PATCH 83/96] Upgrade to Pants 2.20.0 (#135) --- pants.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pants.toml b/pants.toml index 0e74a29..f5b38ae 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.19.0" +pants_version = "2.20.0" backend_packages.add = [ "pants.backend.build_files.fmt.black", "pants.backend.python", From 5081a3a0a945ea479baf6017055a5177d1577d9d Mon Sep 17 00:00:00 2001 From: Michael Seifert Date: Thu, 16 May 2024 00:31:51 +0200 Subject: [PATCH 84/96] Update GitHub actions to most recent versions (#136) --- .github/workflows/pants.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pants.yaml b/.github/workflows/pants.yaml index c167e42..7638798 100644 --- a/.github/workflows/pants.yaml +++ b/.github/workflows/pants.yaml @@ -23,11 +23,11 @@ jobs: matrix: python-version: [3.9] steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - - uses: pantsbuild/actions/init-pants@v5-scie-pants + - uses: pantsbuild/actions/init-pants@v8 # This action bootstraps pants and manages 2-3 GHA caches. # See: github.com/pantsbuild/actions/tree/main/init-pants/ with: From ccb79d67ed1371890e1b5cde7fc461a143ec5138 Mon Sep 17 00:00:00 2001 From: SJ Date: Wed, 29 May 2024 09:33:32 -0400 Subject: [PATCH 85/96] Upgrade to Pants 2.21.0 (#137) --- pants.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pants.toml b/pants.toml index f5b38ae..2c95ae7 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.20.0" +pants_version = "2.21.0" backend_packages.add = [ "pants.backend.build_files.fmt.black", "pants.backend.python", From 7f64e7737f98a53d51daf6a6def2767997b82742 Mon Sep 17 00:00:00 2001 From: SJ Date: Fri, 7 Jun 2024 08:38:05 -0400 Subject: [PATCH 86/96] Fixed broken/outdated docs links (#138) --- .github/workflows/pants.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pants.yaml b/.github/workflows/pants.yaml index 7638798..9a70ddb 100644 --- a/.github/workflows/pants.yaml +++ b/.github/workflows/pants.yaml @@ -1,7 +1,7 @@ # Copyright 2020 Pants project contributors. # Licensed under the Apache License, Version 2.0 (see LICENSE). -# See https://pants.readme.io/docs/using-pants-in-ci for tips on how to set up your CI with Pants. +# See https://www.pantsbuild.org/2.21/docs/using-pants/using-pants-in-ci for tips on how to set up your CI with Pants. name: Pants @@ -45,7 +45,7 @@ jobs: # Note that named_caches and lmdb_store falls back to partial restore keys which # may give a useful partial result that will save time over completely clean state, # but will cause the cache entry to grow without bound over time. - # See https://pants.readme.io/docs/using-pants-in-ci for tips on how to periodically clean it up. + # See https://www.pantsbuild.org/2.21/docs/using-pants/using-pants-in-ci for tips on how to periodically clean it up. # Alternatively you change gha-cache-key to ignore old caches. - name: Check BUILD files run: | From fb191bbf51249c663ab181dedcbe02155cfaa62c Mon Sep 17 00:00:00 2001 From: Tom Dyas Date: Thu, 31 Oct 2024 08:14:48 +0900 Subject: [PATCH 87/96] upgrade to Pants v2.23.0rc1 + other fixes (#139) * upgrade to Pants v2.23.0rc1 * update get-pants.sh binary * update commands in README.md to those that work --- README.md | 6 +++++- get-pants.sh | 4 ++-- pants.toml | 8 ++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 65507d7..d991362 100644 --- a/README.md +++ b/README.md @@ -139,10 +139,14 @@ pants test helloworld/translator/translator_test.py -- -k test_unknown_phrase # ## Create a PEX binary +The `package` goal requires specifying a target which can be packaged. In this case, the there is a `pex_binary` target with the name `pex_binary` in the `helloworld/BUILD` file. + ``` -pants package helloworld/main.py +pants package helloworld:pex_binary ``` +The pex file is output to `dist/helloworld/pex_binary.pex` and can be executed directly. + ## Run a binary directly ``` diff --git a/get-pants.sh b/get-pants.sh index 56ee4f2..cae178e 100755 --- a/get-pants.sh +++ b/get-pants.sh @@ -163,7 +163,7 @@ Once installed, if you want to update your "pants" launcher binary, use -h | --help: Print this help message. -d | --bin-dir: - The directory to install the scie-pants binary in, "~/bin" by default. + The directory to install the scie-pants binary in, "~/.local/bin" by default. -b | --base-name: The name to use for the scie-pants binary, "pants" by default. @@ -176,7 +176,7 @@ Once installed, if you want to update your "pants" launcher binary, use EOF } -bin_dir="${HOME}/bin" +bin_dir="${HOME}/.local/bin" base_name="pants" version="latest/download" while (($# > 0)); do diff --git a/pants.toml b/pants.toml index 2c95ae7..6e821a5 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.21.0" +pants_version = "2.23.0rc1" backend_packages.add = [ "pants.backend.build_files.fmt.black", "pants.backend.python", @@ -25,7 +25,7 @@ root_patterns = ["/"] # The default interpreter constraints for code in this repo. Individual targets can override # this with the `interpreter_constraints` field. See # https://www.pantsbuild.org/docs/python-interpreter-compatibility. - +# # Modify this if you don't have Python 3.9 on your machine. # This can be a range, such as [">=3.8,<3.11"], but it's usually recommended to restrict # to a single minor version. @@ -44,7 +44,3 @@ resolves = { python-default = "python-default.lock"} # problematic system Pythons. See # https://www.pantsbuild.org/docs/python-interpreter-compatibility#changing-the-interpreter-search-path. search_path = ["", ""] - -[python-infer] -# 2.17 is transitioning to a new, faster parser for dependency inference: -use_rust_parser = true From ec548ae2deef08bd1e0cc1a597cc1b0c7905bc85 Mon Sep 17 00:00:00 2001 From: Benjy Weinberger Date: Tue, 26 Nov 2024 17:56:54 -0800 Subject: [PATCH 88/96] Upgrade Pants to 2.23.0 (#141) --- .github/workflows/pants.yaml | 6 +++--- pants.toml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pants.yaml b/.github/workflows/pants.yaml index 9a70ddb..1a77656 100644 --- a/.github/workflows/pants.yaml +++ b/.github/workflows/pants.yaml @@ -1,7 +1,7 @@ # Copyright 2020 Pants project contributors. # Licensed under the Apache License, Version 2.0 (see LICENSE). -# See https://www.pantsbuild.org/2.21/docs/using-pants/using-pants-in-ci for tips on how to set up your CI with Pants. +# See https://www.pantsbuild.org/stable/docs/using-pants/using-pants-in-ci for tips on how to set up your CI with Pants. name: Pants @@ -45,7 +45,7 @@ jobs: # Note that named_caches and lmdb_store falls back to partial restore keys which # may give a useful partial result that will save time over completely clean state, # but will cause the cache entry to grow without bound over time. - # See https://www.pantsbuild.org/2.21/docs/using-pants/using-pants-in-ci for tips on how to periodically clean it up. + # See https://www.pantsbuild.org/stable/docs/using-pants/using-pants-in-ci for tips on how to periodically clean it up. # Alternatively you change gha-cache-key to ignore old caches. - name: Check BUILD files run: | @@ -62,7 +62,7 @@ jobs: pants package :: pants run helloworld/:pex_binary - name: Upload pants log - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: pants-log path: .pants.d/workdir/pants.log diff --git a/pants.toml b/pants.toml index 6e821a5..fad9bb4 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.23.0rc1" +pants_version = "2.23.0" backend_packages.add = [ "pants.backend.build_files.fmt.black", "pants.backend.python", From 29e160e3c52549e2b4dd39db4e48bd254634174e Mon Sep 17 00:00:00 2001 From: Noam Elfanbaum <4347848+noamelf@users.noreply.github.com> Date: Thu, 12 Dec 2024 04:31:47 +0200 Subject: [PATCH 89/96] Update README.md with newer changed-dependents command (#142) --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d991362..3cc3c1d 100644 --- a/README.md +++ b/README.md @@ -70,10 +70,10 @@ You can run on all changed files: pants --changed-since=HEAD lint ``` -You can run on all changed files, and any of their "dependees": +You can run on all changed files, and any of their "dependents": ``` -pants --changed-since=HEAD --changed-dependees=transitive test +pants --changed-since=HEAD --changed-dependents=transitive test ``` ## Target specifications From 6a64ed3cba18c171b4f624df4bc29e2f32592b07 Mon Sep 17 00:00:00 2001 From: cburroughs Date: Tue, 4 Feb 2025 10:59:54 -0500 Subject: [PATCH 90/96] Upgrade to Pants 2.24.0 (#143) --- pants.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pants.toml b/pants.toml index fad9bb4..27b816b 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.23.0" +pants_version = "2.24.0" backend_packages.add = [ "pants.backend.build_files.fmt.black", "pants.backend.python", From 45b3f7b59f58ddc5d02528c8e3e5f5259b755f25 Mon Sep 17 00:00:00 2001 From: Benjy Weinberger Date: Wed, 12 Feb 2025 11:29:52 -0800 Subject: [PATCH 91/96] Upgrade to Ubuntu 24.04 in CI. (#144) --- .github/workflows/pants.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pants.yaml b/.github/workflows/pants.yaml index 1a77656..9b8cab4 100644 --- a/.github/workflows/pants.yaml +++ b/.github/workflows/pants.yaml @@ -11,14 +11,14 @@ jobs: org-check: name: Check GitHub Organization if: ${{ github.repository_owner == 'pantsbuild' }} - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 steps: - name: Noop run: "true" build: name: Perform CI Checks needs: org-check - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 strategy: matrix: python-version: [3.9] From 603f4a4b30c1cf4d349500776e841beae2d588ca Mon Sep 17 00:00:00 2001 From: Tom Dyas Date: Fri, 7 Mar 2025 00:16:00 -0500 Subject: [PATCH 92/96] upgrade Pants to v2.25.0rc0 (#145) Upgrade to v2.25.0rc0. --- pants.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pants.toml b/pants.toml index 27b816b..937067c 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.24.0" +pants_version = "2.25.0rc0" backend_packages.add = [ "pants.backend.build_files.fmt.black", "pants.backend.python", From 6fd803f4ec49a668264c05ed01a84c3444a71a93 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Tue, 1 Apr 2025 13:43:32 +1100 Subject: [PATCH 93/96] Upgrade to Pants 2.25.0 (#146) --- pants.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pants.toml b/pants.toml index 937067c..44b230f 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.25.0rc0" +pants_version = "2.25.0" backend_packages.add = [ "pants.backend.build_files.fmt.black", "pants.backend.python", From ee9a500a51022119c49a414227c6bfa114c4c7af Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Mon, 5 May 2025 15:25:32 +1000 Subject: [PATCH 94/96] Upgrade to Pants 2.26.0 (#147) --- pants.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pants.toml b/pants.toml index 44b230f..3edccd3 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.25.0" +pants_version = "2.26.0" backend_packages.add = [ "pants.backend.build_files.fmt.black", "pants.backend.python", From fcee05543e252062fcb5b97ec627ba8457173641 Mon Sep 17 00:00:00 2001 From: Benjy Weinberger Date: Thu, 2 Oct 2025 10:40:34 -0700 Subject: [PATCH 95/96] Upgrade to Pants 2.28.0 (#149) --- pants.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pants.toml b/pants.toml index 3edccd3..cbe1e2e 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.26.0" +pants_version = "2.28.0" backend_packages.add = [ "pants.backend.build_files.fmt.black", "pants.backend.python", From bb97aad3d3fb392fda805d32ed7806293da835b8 Mon Sep 17 00:00:00 2001 From: Chris Burroughs Date: Thu, 9 Oct 2025 23:06:40 -0400 Subject: [PATCH 96/96] Upgrade to Pants 2.29.0 (#150) --- .flake8 | 10 +- .github/workflows/pants.yaml | 2 +- helloworld/greet/greeting.py | 5 +- pants.toml | 6 +- python-default.lock | 173 ++++++++++++++++++++++++----------- 5 files changed, 133 insertions(+), 63 deletions(-) diff --git a/.flake8 b/.flake8 index 160c1b8..cf5d05d 100644 --- a/.flake8 +++ b/.flake8 @@ -1,5 +1,9 @@ [flake8] +# E203 -> whitespace before ':' (conflicts with Black) +# E231 -> Bad trailing comma (conflicts with Black) +# E501 -> line too long (conflicts with Black) + extend-ignore: - E203, # whitespace before ':' (conflicts with Black) - E231, # Bad trailing comma (conflicts with Black) - E501, # line too long (conflicts with Black) + E203, + E231, + E501, diff --git a/.github/workflows/pants.yaml b/.github/workflows/pants.yaml index 9b8cab4..ceb31af 100644 --- a/.github/workflows/pants.yaml +++ b/.github/workflows/pants.yaml @@ -21,7 +21,7 @@ jobs: runs-on: ubuntu-24.04 strategy: matrix: - python-version: [3.9] + python-version: [3.12] steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 diff --git a/helloworld/greet/greeting.py b/helloworld/greet/greeting.py index 6a5eb1a..70c7675 100644 --- a/helloworld/greet/greeting.py +++ b/helloworld/greet/greeting.py @@ -3,11 +3,10 @@ from __future__ import annotations +import importlib.resources import json import random -import pkg_resources - from helloworld.translator.translator import LanguageTranslator @@ -19,7 +18,7 @@ def __init__( translations if translations is not None else json.loads( - pkg_resources.resource_string(__name__, "translations.json") + importlib.resources.read_text(__name__, "translations.json") ) ) self._translator = LanguageTranslator(self._translations) diff --git a/pants.toml b/pants.toml index cbe1e2e..9c62618 100644 --- a/pants.toml +++ b/pants.toml @@ -2,7 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). [GLOBAL] -pants_version = "2.28.0" +pants_version = "2.29.0" backend_packages.add = [ "pants.backend.build_files.fmt.black", "pants.backend.python", @@ -26,10 +26,10 @@ root_patterns = ["/"] # this with the `interpreter_constraints` field. See # https://www.pantsbuild.org/docs/python-interpreter-compatibility. # -# Modify this if you don't have Python 3.9 on your machine. +# Modify this if you don't have Python 3.13 on your machine. # This can be a range, such as [">=3.8,<3.11"], but it's usually recommended to restrict # to a single minor version. -interpreter_constraints = ["==3.9.*"] +interpreter_constraints = ["==3.12.*"] # Enable the "resolves" mechanism, which turns on lockfiles for user code. See # https://www.pantsbuild.org/docs/python-third-party-dependencies. This also adds the diff --git a/python-default.lock b/python-default.lock index 41b799a..4f755f2 100644 --- a/python-default.lock +++ b/python-default.lock @@ -4,9 +4,9 @@ // // --- BEGIN PANTS LOCKFILE METADATA: DO NOT EDIT OR REMOVE --- // { -// "version": 3, +// "version": 4, // "valid_for_interpreter_constraints": [ -// "CPython==3.9.*" +// "CPython==3.12.*" // ], // "generated_with_requirements": [ // "ansicolors==1.1.8", @@ -17,7 +17,9 @@ // "manylinux": "manylinux2014", // "requirement_constraints": [], // "only_binary": [], -// "no_binary": [] +// "no_binary": [], +// "excludes": [], +// "overrides": [] // } // --- END PANTS LOCKFILE METADATA --- @@ -27,6 +29,8 @@ "allow_wheels": true, "build_isolation": true, "constraints": [], + "elide_unused_requires_dist": false, + "excluded": [], "locked_resolves": [ { "locked_requirements": [ @@ -52,101 +56,120 @@ "artifacts": [ { "algorithm": "sha256", - "hash": "99b87a485a5820b23b879f04c2305b44b951b502fd64be915879d77a7e8fc6f1", - "url": "https://files.pythonhosted.org/packages/e0/44/827b2a91a5816512fcaf3cc4ebc465ccd5d598c45cefa6703fcf4a79018f/attrs-23.2.0-py3-none-any.whl" + "hash": "427318ce031701fea540783410126f03899a97ffc6f61596ad581ac2e40e3bc3", + "url": "https://files.pythonhosted.org/packages/77/06/bb80f5f86020c4551da315d78b3ab75e8228f89f0162f2c3a819e407941a/attrs-25.3.0-py3-none-any.whl" }, { "algorithm": "sha256", - "hash": "935dc3b529c262f6cf76e50877d35a4bd3c1de194fd41f47a2b7ae8f19971f30", - "url": "https://files.pythonhosted.org/packages/e3/fc/f800d51204003fa8ae392c4e8278f256206e7a919b708eef054f5f4b650d/attrs-23.2.0.tar.gz" + "hash": "75d7cefc7fb576747b2c81b4442d4d4a1ce0900973527c011d1030fd3bf4af1b", + "url": "https://files.pythonhosted.org/packages/5a/b0/1367933a8532ee6ff8d63537de4f1177af4bff9f3e829baf7331f595bb24/attrs-25.3.0.tar.gz" } ], "project_name": "attrs", "requires_dists": [ - "attrs[tests-mypy]; extra == \"tests-no-zope\"", - "attrs[tests-no-zope]; extra == \"tests\"", - "attrs[tests]; extra == \"cov\"", - "attrs[tests]; extra == \"dev\"", - "cloudpickle; platform_python_implementation == \"CPython\" and extra == \"tests-no-zope\"", + "cloudpickle; platform_python_implementation == \"CPython\" and extra == \"benchmark\"", + "cloudpickle; platform_python_implementation == \"CPython\" and extra == \"cov\"", + "cloudpickle; platform_python_implementation == \"CPython\" and extra == \"dev\"", + "cloudpickle; platform_python_implementation == \"CPython\" and extra == \"tests\"", + "cogapp; extra == \"docs\"", "coverage[toml]>=5.3; extra == \"cov\"", "furo; extra == \"docs\"", - "hypothesis; extra == \"tests-no-zope\"", - "importlib-metadata; python_version < \"3.8\"", - "mypy>=1.6; (platform_python_implementation == \"CPython\" and python_version >= \"3.8\") and extra == \"tests-mypy\"", + "hypothesis; extra == \"benchmark\"", + "hypothesis; extra == \"cov\"", + "hypothesis; extra == \"dev\"", + "hypothesis; extra == \"tests\"", + "mypy>=1.11.1; (platform_python_implementation == \"CPython\" and python_version >= \"3.10\") and extra == \"benchmark\"", + "mypy>=1.11.1; (platform_python_implementation == \"CPython\" and python_version >= \"3.10\") and extra == \"cov\"", + "mypy>=1.11.1; (platform_python_implementation == \"CPython\" and python_version >= \"3.10\") and extra == \"dev\"", + "mypy>=1.11.1; (platform_python_implementation == \"CPython\" and python_version >= \"3.10\") and extra == \"tests\"", + "mypy>=1.11.1; (platform_python_implementation == \"CPython\" and python_version >= \"3.10\") and extra == \"tests-mypy\"", "myst-parser; extra == \"docs\"", - "pre-commit; extra == \"dev\"", - "pympler; extra == \"tests-no-zope\"", - "pytest-mypy-plugins; (platform_python_implementation == \"CPython\" and python_version >= \"3.8\") and extra == \"tests-mypy\"", - "pytest-xdist[psutil]; extra == \"tests-no-zope\"", - "pytest>=4.3.0; extra == \"tests-no-zope\"", + "pre-commit-uv; extra == \"dev\"", + "pympler; extra == \"benchmark\"", + "pympler; extra == \"cov\"", + "pympler; extra == \"dev\"", + "pympler; extra == \"tests\"", + "pytest-codspeed; extra == \"benchmark\"", + "pytest-mypy-plugins; (platform_python_implementation == \"CPython\" and python_version >= \"3.10\") and extra == \"benchmark\"", + "pytest-mypy-plugins; (platform_python_implementation == \"CPython\" and python_version >= \"3.10\") and extra == \"cov\"", + "pytest-mypy-plugins; (platform_python_implementation == \"CPython\" and python_version >= \"3.10\") and extra == \"dev\"", + "pytest-mypy-plugins; (platform_python_implementation == \"CPython\" and python_version >= \"3.10\") and extra == \"tests\"", + "pytest-mypy-plugins; (platform_python_implementation == \"CPython\" and python_version >= \"3.10\") and extra == \"tests-mypy\"", + "pytest-xdist[psutil]; extra == \"benchmark\"", + "pytest-xdist[psutil]; extra == \"cov\"", + "pytest-xdist[psutil]; extra == \"dev\"", + "pytest-xdist[psutil]; extra == \"tests\"", + "pytest>=4.3.0; extra == \"benchmark\"", + "pytest>=4.3.0; extra == \"cov\"", + "pytest>=4.3.0; extra == \"dev\"", + "pytest>=4.3.0; extra == \"tests\"", "sphinx-notfound-page; extra == \"docs\"", "sphinx; extra == \"docs\"", "sphinxcontrib-towncrier; extra == \"docs\"", - "towncrier; extra == \"docs\"", - "zope-interface; extra == \"docs\"", - "zope-interface; extra == \"tests\"" + "towncrier; extra == \"docs\"" ], - "requires_python": ">=3.7", - "version": "23.2.0" + "requires_python": ">=3.8", + "version": "25.3.0" }, { "artifacts": [ { "algorithm": "sha256", - "hash": "b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374", - "url": "https://files.pythonhosted.org/packages/ef/a6/62565a6e1cf69e10f5727360368e451d4b7f58beeac6173dc9db836a5b46/iniconfig-2.0.0-py3-none-any.whl" + "hash": "9deba5723312380e77435581c6bf4935c94cbfab9b1ed33ef8d238ea168eb760", + "url": "https://files.pythonhosted.org/packages/2c/e1/e6716421ea10d38022b952c159d5161ca1193197fb744506875fbb87ea7b/iniconfig-2.1.0-py3-none-any.whl" }, { "algorithm": "sha256", - "hash": "2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3", - "url": "https://files.pythonhosted.org/packages/d7/4b/cbd8e699e64a6f16ca3a8220661b5f83792b3017d0f79807cb8708d33913/iniconfig-2.0.0.tar.gz" + "hash": "3abbd2e30b36733fee78f9c7f7308f2d0050e88f0087fd25c2645f63c773e1c7", + "url": "https://files.pythonhosted.org/packages/f2/97/ebf4da567aa6827c909642694d71c9fcf53e5b504f2d96afea02718862f3/iniconfig-2.1.0.tar.gz" } ], "project_name": "iniconfig", "requires_dists": [], - "requires_python": ">=3.7", - "version": "2.0.0" + "requires_python": ">=3.8", + "version": "2.1.0" }, { "artifacts": [ { "algorithm": "sha256", - "hash": "8c491190033a9af7e1d931d0b5dacc2ef47509b34dd0de67ed209b5203fc88c7", - "url": "https://files.pythonhosted.org/packages/ec/1a/610693ac4ee14fcdf2d9bf3c493370e4f2ef7ae2e19217d7a237ff42367d/packaging-23.2-py3-none-any.whl" + "hash": "29572ef2b1f17581046b3a2227d5c611fb25ec70ca1ba8554b24b0e69331a484", + "url": "https://files.pythonhosted.org/packages/20/12/38679034af332785aac8774540895e234f4d07f7545804097de4b666afd8/packaging-25.0-py3-none-any.whl" }, { "algorithm": "sha256", - "hash": "048fb0e9405036518eaaf48a55953c750c11e1a1b68e0dd1a9d62ed0c092cfc5", - "url": "https://files.pythonhosted.org/packages/fb/2b/9b9c33ffed44ee921d0967086d653047286054117d584f1b1a7c22ceaf7b/packaging-23.2.tar.gz" + "hash": "d443872c98d677bf60f6a1f2f8c1cb748e8fe762d2bf9d3148b5599295b0fc4f", + "url": "https://files.pythonhosted.org/packages/a1/d4/1fc4078c65507b51b96ca8f8c3ba19e6a61c8253c72794544580a7b6c24d/packaging-25.0.tar.gz" } ], "project_name": "packaging", "requires_dists": [], - "requires_python": ">=3.7", - "version": "23.2" + "requires_python": ">=3.8", + "version": "25.0" }, { "artifacts": [ { "algorithm": "sha256", - "hash": "7db9f7b503d67d1c5b95f59773ebb58a8c1c288129a88665838012cfb07b8981", - "url": "https://files.pythonhosted.org/packages/a5/5b/0cc789b59e8cc1bf288b38111d002d8c5917123194d45b29dcdac64723cc/pluggy-1.4.0-py3-none-any.whl" + "hash": "e920276dd6813095e9377c0bc5566d94c932c33b27a3e3945d8389c374dd4746", + "url": "https://files.pythonhosted.org/packages/54/20/4d324d65cc6d9205fabedc306948156824eb9f0ee1633355a8f7ec5c66bf/pluggy-1.6.0-py3-none-any.whl" }, { "algorithm": "sha256", - "hash": "8c85c2876142a764e5b7548e7d9a0e0ddb46f5185161049a79b7e974454223be", - "url": "https://files.pythonhosted.org/packages/54/c6/43f9d44d92aed815e781ca25ba8c174257e27253a94630d21be8725a2b59/pluggy-1.4.0.tar.gz" + "hash": "7dcc130b76258d33b90f61b658791dede3486c3e6bfb003ee5c9bfb396dd22f3", + "url": "https://files.pythonhosted.org/packages/f9/e2/3e91f31a7d2b083fe6ef3fa267035b518369d9511ffab804f839851d2779/pluggy-1.6.0.tar.gz" } ], "project_name": "pluggy", "requires_dists": [ + "coverage; extra == \"testing\"", "pre-commit; extra == \"dev\"", "pytest-benchmark; extra == \"testing\"", "pytest; extra == \"testing\"", "tox; extra == \"dev\"" ], - "requires_python": ">=3.8", - "version": "1.4.0" + "requires_python": ">=3.9", + "version": "1.6.0" }, { "artifacts": [ @@ -248,19 +271,59 @@ "artifacts": [ { "algorithm": "sha256", - "hash": "939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc", - "url": "https://files.pythonhosted.org/packages/97/75/10a9ebee3fd790d20926a90a2547f0bf78f371b2f13aa822c759680ca7b9/tomli-2.0.1-py3-none-any.whl" + "hash": "cb55c73c5f4408779d0cf3eef9f762b9c9f147a77de7b258bef0a5628adc85cc", + "url": "https://files.pythonhosted.org/packages/6e/c2/61d3e0f47e2b74ef40a68b9e6ad5984f6241a942f7cd3bbfbdbd03861ea9/tomli-2.2.1-py3-none-any.whl" + }, + { + "algorithm": "sha256", + "hash": "8d57ca8095a641b8237d5b079147646153d22552f1c637fd3ba7f4b0b29167a8", + "url": "https://files.pythonhosted.org/packages/03/b8/152c68bb84fc00396b83e7bbddd5ec0bd3dd409db4195e2a9b3e398ad2e3/tomli-2.2.1-cp312-cp312-macosx_11_0_arm64.whl" + }, + { + "algorithm": "sha256", + "hash": "cd45e1dc79c835ce60f7404ec8119f2eb06d38b1deba146f07ced3bbc44505ff", + "url": "https://files.pythonhosted.org/packages/18/87/302344fed471e44a87289cf4967697d07e532f2421fdaf868a303cbae4ff/tomli-2.2.1.tar.gz" + }, + { + "algorithm": "sha256", + "hash": "4a8f6e44de52d5e6c657c9fe83b562f5f4256d8ebbfe4ff922c495620a7f6cea", + "url": "https://files.pythonhosted.org/packages/52/e1/f8af4c2fcde17500422858155aeb0d7e93477a0d59a98e56cbfe75070fd0/tomli-2.2.1-cp312-cp312-macosx_10_13_x86_64.whl" }, { "algorithm": "sha256", - "hash": "de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f", - "url": "https://files.pythonhosted.org/packages/c0/3f/d7af728f075fb08564c5949a9c95e44352e23dee646869fa104a3b2060a3/tomli-2.0.1.tar.gz" + "hash": "db2b95f9de79181805df90bedc5a5ab4c165e6ec3fe99f970d0e302f384ad222", + "url": "https://files.pythonhosted.org/packages/5c/51/51c3f2884d7bab89af25f678447ea7d297b53b5a3b5730a7cb2ef6069f07/tomli-2.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl" + }, + { + "algorithm": "sha256", + "hash": "b82ebccc8c8a36f2094e969560a1b836758481f3dc360ce9a3277c65f374285e", + "url": "https://files.pythonhosted.org/packages/9c/de/6b432d66e986e501586da298e28ebeefd3edc2c780f3ad73d22566034239/tomli-2.2.1-cp312-cp312-musllinux_1_2_x86_64.whl" + }, + { + "algorithm": "sha256", + "hash": "400e720fe168c0f8521520190686ef8ef033fb19fc493da09779e592861b78c6", + "url": "https://files.pythonhosted.org/packages/9e/6e/fa2b916dced65763a5168c6ccb91066f7639bdc88b48adda990db10c8c0b/tomli-2.2.1-cp312-cp312-musllinux_1_2_aarch64.whl" + }, + { + "algorithm": "sha256", + "hash": "40741994320b232529c802f8bc86da4e1aa9f413db394617b9a256ae0f9a7f77", + "url": "https://files.pythonhosted.org/packages/ab/df/bfa89627d13a5cc22402e441e8a931ef2108403db390ff3345c05253935e/tomli-2.2.1-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl" + }, + { + "algorithm": "sha256", + "hash": "02abe224de6ae62c19f090f68da4e27b10af2b93213d36cf44e6e1c5abd19fdd", + "url": "https://files.pythonhosted.org/packages/b4/04/885d3b1f650e1153cbb93a6a9782c58a972b94ea4483ae4ac5cedd5e4a09/tomli-2.2.1-cp312-cp312-musllinux_1_2_i686.whl" + }, + { + "algorithm": "sha256", + "hash": "4e340144ad7ae1533cb897d406382b4b6fede8890a03738ff1683af800d54192", + "url": "https://files.pythonhosted.org/packages/c8/d6/fc9267af9166f79ac528ff7e8c55c8181ded34eb4b0e93daa767b8841573/tomli-2.2.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl" } ], "project_name": "tomli", "requires_dists": [], - "requires_python": ">=3.7", - "version": "2.0.1" + "requires_python": ">=3.8", + "version": "2.2.1" }, { "artifacts": [ @@ -284,9 +347,12 @@ "platform_tag": null } ], + "only_builds": [], + "only_wheels": [], + "overridden": [], "path_mappings": {}, - "pex_version": "2.1.148", - "pip_version": "23.1.2", + "pex_version": "2.55.2", + "pip_version": "24.2", "prefer_older_binary": false, "requirements": [ "ansicolors==1.1.8", @@ -295,7 +361,7 @@ "types-setuptools<58,>=56.2.0" ], "requires_python": [ - "==3.9.*" + "CPython==3.12.*" ], "resolver_version": "pip-2020-resolver", "style": "universal", @@ -304,5 +370,6 @@ "mac" ], "transitive": true, - "use_pep517": null + "use_pep517": null, + "use_system_time": false }