From 25f83b7e30f82bd59c0482d3cc4f74f6ee9f3ff8 Mon Sep 17 00:00:00 2001 From: Adeel Hassan Date: Fri, 8 Sep 2023 10:59:34 -0400 Subject: [PATCH 1/4] add pypi_build and pypi_publish scripts --- scripts/pypi_build | 27 +++++++++++++++++++++++++++ scripts/pypi_publish | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100755 scripts/pypi_build create mode 100755 scripts/pypi_publish diff --git a/scripts/pypi_build b/scripts/pypi_build new file mode 100755 index 000000000..b310d8e4f --- /dev/null +++ b/scripts/pypi_build @@ -0,0 +1,27 @@ +#!/bin/bash + +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done +SCRIPTS_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" +SRC_DIR="$( cd -P "$( dirname "$SCRIPTS_DIR" )" && pwd )" + +plugins=("rastervision_pipeline" "rastervision_aws_batch" "rastervision_aws_s3" "rastervision_core" "rastervision_pytorch_learner" "rastervision_pytorch_backend" "rastervision_gdal_vsi") + +# Function to build a plugin +build_plugin() { + cd "$SRC_DIR/$1" + echo "Building $1 ... " + python setup.py sdist bdist_wheel + echo "Done." + cd "$SRC_DIR" +} + +# Build each plugin +for plugin in "${plugins[@]}"; do + build_plugin "$plugin" +done + +# Build the top-level package +echo "rastervision ... " +python setup.py sdist bdist_wheel +echo "Done." diff --git a/scripts/pypi_publish b/scripts/pypi_publish new file mode 100755 index 000000000..2e6eb2e6c --- /dev/null +++ b/scripts/pypi_publish @@ -0,0 +1,43 @@ +#!/bin/bash + +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done +SCRIPTS_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" +SRC_DIR="$( cd -P "$( dirname "$SCRIPTS_DIR" )" && pwd )" + +plugins=("rastervision_pipeline" "rastervision_aws_batch" "rastervision_aws_s3" "rastervision_core" "rastervision_pytorch_learner" "rastervision_pytorch_backend" "rastervision_gdal_vsi") + +# Check if the --test flag is passed +publish_to_test=false +if [[ "$1" == "--test" ]]; then + publish_to_test=true + # Remove the --test flag from the arguments + shift +fi + +# Function to publish a plugin +publish_plugin() { + cd "$SRC_DIR/$1" + echo "Publishing $1 ... " + if [ "$publish_to_test" = true ]; then + twine upload --repository testpypi dist/* + else + twine upload dist/* + fi + echo "Done." + cd "$SRC_DIR" +} + +# Publish each plugin +for plugin in "${plugins[@]}"; do + publish_plugin "$plugin" +done + +# Publish the top-level package +echo "Publishing rastervision ... " +if [ "$publish_to_test" = true ]; then + twine upload --repository testpypi dist/* +else + twine upload dist/* +fi +echo "Done." From 490a3a662a2aa0d6d77ca1fda643b7f9b13af985 Mon Sep 17 00:00:00 2001 From: Adeel Hassan Date: Fri, 8 Sep 2023 10:59:44 -0400 Subject: [PATCH 2/4] update release instructions [skip ci] --- docs/release.rst | 55 +++++++++++++----------------------------------- 1 file changed, 15 insertions(+), 40 deletions(-) diff --git a/docs/release.rst b/docs/release.rst index 2322d8ba4..2214011ff 100644 --- a/docs/release.rst +++ b/docs/release.rst @@ -66,69 +66,44 @@ Minor or Major Version Release pip install twine - To store settings for PyPI you can setup a ``~/.pypirc`` file containing: + To store settings for PyPI you can set up a ``~/.pypirc`` file containing: .. code-block:: console [pypi] username = azavea - Once packages are published they cannot be changed so be careful. (It's possible to practice using testpypi.) Navigate to the ``raster-vision`` repo on your local filesystem. With the version branch checked out, run something like the following to publish each plugin, and then the top-level package. - - .. code-block:: console - - export RV="/Users/lfishgold/projects/raster-vision" - - .. code-block:: console + [testpypi] + username = azavea - cd $RV/rastervision_pipeline - python setup.py sdist bdist_wheel - twine upload dist/* + Once packages are published they cannot be changed, so be careful. (It's possible to practice using TestPyPI.) Navigate to the repo's root directory on your local filesystem. With the version branch checked out, run the following scripts to build packages and publish to PyPI. + + Build: .. code-block:: console - cd $RV/rastervision_aws_batch - python setup.py sdist bdist_wheel - twine upload dist/* + scripts/pypi_build - .. code-block:: console - - cd $RV/rastervision_aws_s3 - python setup.py sdist bdist_wheel - twine upload dist/* + Publish to TestPyPI. (You will be prompted for the PyPI password multiple times--once for each package.) .. code-block:: console - cd $RV/rastervision_core - python setup.py sdist bdist_wheel - twine upload dist/* - - .. code-block:: console + scripts/pypi_publish --test - cd $RV/rastervision_pytorch_learner - python setup.py sdist bdist_wheel - twine upload dist/* + You can then test it with ``pip`` like so: .. code-block:: console - cd $RV/rastervision_pytorch_backend - python setup.py sdist bdist_wheel - twine upload dist/* - - .. code-block:: console + pip install --index-url https://test.pypi.org/simple/ rastervision - cd $RV/rastervision_gdal_vsi - python setup.py sdist bdist_wheel - twine upload dist/* + Finally, if everything looks okay, publish to Pypi. (You will be prompted for the PyPI password multiple times--once for each package.) .. code-block:: console - cd $RV - python setup.py sdist bdist_wheel - twine upload dist/* + scripts/pypi_publish -#. Announce new release in our `forum `_, and with blog post if it's a big release. -#. Make a PR to the master branch that updates the version number to the next development version. For example, if the last release was ``0.20.1``, update the version to ``0.20.2-dev``. +#. Announce the new release in our `forum `_, and with a blog post if it's a big release. +#. Make a PR to the master branch that updates the version number to the next development version, ``X.Y.Z-dev``. For example, if the last release was ``0.20.1``, update the version to ``0.20.2-dev``. Bug Fix Release ----------------- From 78cb7bbb5a51bd3c35d3572d9459c82e2dcc1401 Mon Sep 17 00:00:00 2001 From: Adeel Hassan Date: Thu, 14 Sep 2023 15:23:58 -0400 Subject: [PATCH 3/4] ask for confirmation before actually publishing --- scripts/pypi_publish | 95 +++++++++++++++++++++++++++++++++----------- 1 file changed, 72 insertions(+), 23 deletions(-) diff --git a/scripts/pypi_publish b/scripts/pypi_publish index 2e6eb2e6c..46c9839d3 100755 --- a/scripts/pypi_publish +++ b/scripts/pypi_publish @@ -1,43 +1,92 @@ #!/bin/bash +# Determine the script's directory (even if it's a symbolic link) SOURCE="${BASH_SOURCE[0]}" -while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done -SCRIPTS_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" -SRC_DIR="$( cd -P "$( dirname "$SCRIPTS_DIR" )" && pwd )" +while [ -h "$SOURCE" ]; do SOURCE="$(readlink "$SOURCE")"; done +SCRIPTS_DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)" +SRC_DIR="$(cd -P "$(dirname "$SCRIPTS_DIR")" && pwd)" +# List of plugins to publish plugins=("rastervision_pipeline" "rastervision_aws_batch" "rastervision_aws_s3" "rastervision_core" "rastervision_pytorch_learner" "rastervision_pytorch_backend" "rastervision_gdal_vsi") -# Check if the --test flag is passed -publish_to_test=false -if [[ "$1" == "--test" ]]; then - publish_to_test=true - # Remove the --test flag from the arguments - shift -fi +# Usage documentation +function usage() { + echo "Usage: $(basename "$0") [--test]" + echo "" + echo "Publish Raster Vision plugins and top-level package to PyPI or TestPyPI." + echo "" + echo "Options:" + echo " -y Automatically answer 'yes' to prompts." + echo " --test Publish to TestPyPI instead of PyPI." +} -# Function to publish a plugin -publish_plugin() { - cd "$SRC_DIR/$1" - echo "Publishing $1 ... " +# Function to publish a package to the specified repository +function publish_package() { if [ "$publish_to_test" = true ]; then + echo "Publishing to TestPyPI ... " twine upload --repository testpypi dist/* else + echo "Publishing to PyPI ... " twine upload dist/* fi echo "Done." +} + +# publish a plugin +function publish_plugin() { + local plugin_name="$1" + cd "$SRC_DIR/$plugin_name" + echo "Publishing $plugin_name ... " + publish_package cd "$SRC_DIR" } -# Publish each plugin -for plugin in "${plugins[@]}"; do - publish_plugin "$plugin" -done +# publish all plugins and the top-level package +function publish_all() { + # Publish each plugin + for plugin in "${plugins[@]}"; do + publish_plugin "$plugin" + done + + # Publish the top-level package + echo "Publishing rastervision ... " + publish_package +} + +# Check for command-line arguments +if [[ "$1" == "--help" || "$1" == "-h" ]]; then + usage + exit +fi -# Publish the top-level package -echo "Publishing rastervision ... " +# Check if the --test flag is passed +publish_to_test=false +if [[ "$1" == "--test" ]]; then + publish_to_test=true + # Remove the --test flag from the arguments + shift +fi + +# If testing: publish and exit if [ "$publish_to_test" = true ]; then - twine upload --repository testpypi dist/* + publish_all + exit +fi + +# If actually publishing: prompt for confirmation +if [[ "$1" == "-y" ]]; then + response="y" else - twine upload dist/* + read -r -p "Actually publish to PyPi? (y/N): " response fi -echo "Done." + +case "$response" in + [yY][eE][sS]|[yY]) + echo "Publishing to PyPi..." + publish_all + ;; + *) + echo "Aborting." + ;; +esac + From e53b4644e0901883a0e18f4bf993463f41c4ed32 Mon Sep 17 00:00:00 2001 From: Adeel Hassan Date: Thu, 14 Sep 2023 15:20:43 -0400 Subject: [PATCH 4/4] add usage docs [skip ci] --- scripts/pypi_build | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/scripts/pypi_build b/scripts/pypi_build index b310d8e4f..9219d89a6 100755 --- a/scripts/pypi_build +++ b/scripts/pypi_build @@ -1,14 +1,29 @@ #!/bin/bash +# Determine the script's directory (even if it's a symbolic link) SOURCE="${BASH_SOURCE[0]}" while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done SCRIPTS_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" SRC_DIR="$( cd -P "$( dirname "$SCRIPTS_DIR" )" && pwd )" +# List of plugins to build plugins=("rastervision_pipeline" "rastervision_aws_batch" "rastervision_aws_s3" "rastervision_core" "rastervision_pytorch_learner" "rastervision_pytorch_backend" "rastervision_gdal_vsi") +# Usage documentation +function usage() { + echo "Usage: $(basename "$0") [--test]" + echo "" + echo "Build Raster Vision plugins and top-level package." +} + +# Check for command-line arguments +if [[ "$1" == "--help" || "$1" == "-h" ]]; then + usage + exit +fi + # Function to build a plugin -build_plugin() { +function build_plugin() { cd "$SRC_DIR/$1" echo "Building $1 ... " python setup.py sdist bdist_wheel