Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scripts for building packages and publishing them to PyPi #1915

Merged
merged 4 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 15 additions & 40 deletions docs/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/azavea/raster-vision/discussions>`_, 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 <https://github.com/azavea/raster-vision/discussions>`_, 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
-----------------
Expand Down
27 changes: 27 additions & 0 deletions scripts/pypi_build
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see anything that looks obviously wrong to me ... if the test publication works as expected, than it should be good.


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."
43 changes: 43 additions & 0 deletions scripts/pypi_publish
Original file line number Diff line number Diff line change
@@ -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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing that I might suggest -- from a belt-and-suspenders point of view -- is to force a test publication before a real one. If the person says passes --test then it will terminate after the test publication, if they do not then it will publish to testpypi then prompt them to inspect the published artifacts before proceeding with the real publication.

Copy link
Collaborator Author

@AdeelH AdeelH Sep 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep things simple, I've made it so that

  • --test works as before
  • With no --test, you have to go through an Actually publish to PyPi? (y/N) prompt
  • -y bypasses the prompt (for when/if we choose to fully automate things)

# 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."