Skip to content

Commit fc29e57

Browse files
buncismrkn
authored andcommitted
update deploying on heroku readme
1 parent 6911f21 commit fc29e57

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

README.md

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -160,18 +160,34 @@ translates Ruby's coerce system into Python's swapped operation protocol.
160160
## Deploying on Heroku
161161

162162
Heroku's default version of Python is not compiled with the `--enabled-shared`
163-
option and can't be accessed by PyCall. Alternative [buildpacks](https://devcenter.heroku.com/articles/buildpacks) are available,
164-
including these that have been reported to work with PyCall:
165-
166-
https://github.com/richgong/heroku-buildpack-python
167-
https://github.com/dsounded/heroku-buildpack-python
168-
https://github.com/ReforgeHQ/heroku-buildpack-python
169-
170-
These community-developed buildpacks are not supported by Heroku, so it's
171-
worth examining the source to make sure the buildpack you use suits your
172-
needs. For instance, 'ReforgeHQ' works well with Python 3.8.1, but has not
173-
been configured to work with other versions and may not be as generally
174-
useful as the 'dsounded' or 'richgong' buildpacks.
163+
option and can't be accessed by PyCall.
164+
165+
There are many ways to make our heroku use Python that is compiled with the `--enabled-shared` option.
166+
167+
- use Heroku's official Python buildpacks `post_compile` hooks to recompile the python if the `--enabled-shared` option is not enabled.
168+
here are the example script of `post_compile` in ruby on rails app
169+
`bin/post_compile`
170+
171+
set -e
172+
buildpack_url=https://github.com/heroku/heroku-buildpack-python
173+
buildpack_vsn=v197 # adjust version accordingly https://github.com/heroku/heroku-buildpack-python/tags
174+
175+
# rebuild python if it's missing enable-shared
176+
if ! python3 -msysconfig | grep enable-shared \
177+
> /dev/null; then
178+
PYTHON_VERSION="$(< runtime.txt)"
179+
git clone -b "$buildpack_vsn" "$buildpack_url" _buildpack
180+
export WORKSPACE_DIR="$PWD/_buildpack/builds"
181+
rm -f .heroku/python/bin/python # prevent failing ln after build
182+
sed -i 's!figure --pre!figure --enable-shared --pre!' \
183+
"$WORKSPACE_DIR"/runtimes/python3
184+
"$WORKSPACE_DIR/runtimes/$PYTHON_VERSION" /app/.heroku/python/
185+
rm -fr _buildpack
186+
fi
187+
188+
- 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
189+
- use 3rd party buildpacks from the [markets](https://elements.heroku.com/buildpacks) that have python with `--enabled-shared` option
190+
175191

176192
The buildpack will expect to find both a `runtime.txt` and a `requirements.txt`
177193
file in the root of your project. You will need to add these to specify the

0 commit comments

Comments
 (0)