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

Update Heroku instructions in README #188

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
45 changes: 8 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,41 +159,16 @@ translates Ruby's coerce system into Python's swapped operation protocol.

## Deploying on Heroku

Heroku's default version of Python is not compiled with the `--enabled-shared`
option and can't be accessed by PyCall.
Heroku's default builds of Python are now compiled with the `--enabled-shared` option
(when using Python 3.10 and newer) and so work out of the box with PyCall without
the need for a custom buildpack.

There are many ways to make our heroku use Python that is compiled with the `--enabled-shared` option:

- use Heroku's official Python buildpacks `post_compile` hooks to recompile the python if the `--enabled-shared` option is not enabled.
example script of `post_compile` in ruby on rails app `bin/post_compile`.

set -e
buildpack_url=https://github.com/heroku/heroku-buildpack-python
buildpack_vsn=v197 # adjust version accordingly https://github.com/heroku/heroku-buildpack-python/tags

# rebuild python if it's missing enable-shared
if ! python3 -msysconfig | grep enable-shared \
> /dev/null; then
PYTHON_VERSION="$(< runtime.txt)"
git clone -b "$buildpack_vsn" "$buildpack_url" _buildpack
export WORKSPACE_DIR="$PWD/_buildpack/builds"
rm -f .heroku/python/bin/python # prevent failing ln after build
sed -i 's!figure --pre!figure --enable-shared --pre!' \
"$WORKSPACE_DIR"/runtimes/python3
"$WORKSPACE_DIR/runtimes/$PYTHON_VERSION" /app/.heroku/python/
rm -fr _buildpack
fi

- use your own precompiled python with `--enabled-shared` options then fork the official heroku [python buildspacks](https://github.com/heroku/heroku-buildpack-python) and change the `BUILDPACK_S3_BASE_URL` with your own uploaded precompiled python in Amazon's S3.
- use 3rd party buildpacks from the [markets](https://elements.heroku.com/buildpacks) that have python with `--enabled-shared` option.


The buildpack will expect to find both a `runtime.txt` and a `requirements.txt`
The Python buildpack will expect to find both a `runtime.txt` and a `requirements.txt`
file in the root of your project. You will need to add these to specify the
version of Python and any packages to be installed via `pip`, _e.g_ to use
version Python 3.8.1 and version 2.5 of the 'networkx' package:

$ echo "python-3.8.1" >> runtime.txt
$ echo "python-3.12.6" >> runtime.txt
$ echo "networkx==2.5" >> requirements.txt

Commit these two files into project's repository. You'll use these to manage
Expand All @@ -212,12 +187,11 @@ For a Ruby/Rails application this will typically report the stock `heroku/ruby`
buildpack, or possibly both `heroku/ruby` and `heroku/nodejs`.

Clear the list and progressively add back your buildpacks, starting with the Python
community-developed buildpack. For example, if `ruby` and `nodejs` buildpacks were
previously installed, and chosing the 'ReforgeHQ' buildback, your setup process will
be similar to this:
buildpack. For example, if `ruby` and `nodejs` buildpacks were previously installed,
your setup process will be similar to this:

$ heroku buildpacks:clear
$ heroku buildpacks:add https://github.com/ReforgeHQ/heroku-buildpack-python -i 1
$ heroku buildpacks:add heroku/python -i 1
$ heroku buildpacks:add heroku/nodejs -i 2
# heroku buildpacks:add heroku/ruby -i 3

Expand All @@ -235,9 +209,6 @@ The Python bootstrapping process will appear in the log first, followed by the R
and so on. PyCall should now be able to successfully call Python functions from
within the Heroku environment.

NB It is also possible to specify buildpacks within Docker images on Heroku.
Copy link
Author

Choose a reason for hiding this comment

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

This removal is since the Heroku container deploy feature now only supports plain Dockerfile deploys, and not the previous experimental heroku.yml + buildpacks feature.

See Heroku's [documentation on using Docker Images](https://devcenter.heroku.com/articles/build-docker-images-heroku-yml).

## Development

After checking out the repo, run `bin/setup` to install dependencies.
Expand Down