Skip to content

Commit 64077b6

Browse files
edmorleymrkn
authored andcommitted
Update Heroku instructions in README
Since Heroku's Python builds now use `--enable-shared` (for Python 3.10 and newer), so use of custom builds or a custom buildpack is no longer required. See: heroku/heroku-buildpack-python#1320 https://github.com/heroku/heroku-buildpack-python/blob/928d0c593f6b6def16d6ad8451f56a997760eace/builds/build_python_runtime.sh#L117-L133 In addition the Python buildpack now supports the `.python-version` file (and recommends it over `runtime.txt`): https://devcenter.heroku.com/changelog-items/3005
1 parent 39f8834 commit 64077b6

File tree

1 file changed

+11
-40
lines changed

1 file changed

+11
-40
lines changed

README.md

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -163,41 +163,16 @@ translates Ruby's coerce system into Python's swapped operation protocol.
163163

164164
## Deploying on Heroku
165165

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

169-
There are many ways to make our heroku use Python that is compiled with the `--enabled-shared` option:
170-
171-
- use Heroku's official Python buildpacks `post_compile` hooks to recompile the python if the `--enabled-shared` option is not enabled.
172-
example script of `post_compile` in ruby on rails app `bin/post_compile`.
173-
174-
set -e
175-
buildpack_url=https://github.com/heroku/heroku-buildpack-python
176-
buildpack_vsn=v197 # adjust version accordingly https://github.com/heroku/heroku-buildpack-python/tags
177-
178-
# rebuild python if it's missing enable-shared
179-
if ! python3 -msysconfig | grep enable-shared \
180-
> /dev/null; then
181-
PYTHON_VERSION="$(< runtime.txt)"
182-
git clone -b "$buildpack_vsn" "$buildpack_url" _buildpack
183-
export WORKSPACE_DIR="$PWD/_buildpack/builds"
184-
rm -f .heroku/python/bin/python # prevent failing ln after build
185-
sed -i 's!figure --pre!figure --enable-shared --pre!' \
186-
"$WORKSPACE_DIR"/runtimes/python3
187-
"$WORKSPACE_DIR/runtimes/$PYTHON_VERSION" /app/.heroku/python/
188-
rm -fr _buildpack
189-
fi
190-
191-
- 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.
192-
- use 3rd party buildpacks from the [markets](https://elements.heroku.com/buildpacks) that have python with `--enabled-shared` option.
193-
194-
195-
The buildpack will expect to find both a `runtime.txt` and a `requirements.txt`
170+
The Python buildpack will expect to find both a `.python-version` and a `requirements.txt`
196171
file in the root of your project. You will need to add these to specify the
197172
version of Python and any packages to be installed via `pip`, _e.g_ to use
198-
version Python 3.8.1 and version 2.5 of the 'networkx' package:
173+
the latest patch version Python 3.12 and version 2.5 of the 'networkx' package:
199174

200-
$ echo "python-3.8.1" >> runtime.txt
175+
$ echo "3.12" > .python-version
201176
$ echo "networkx==2.5" >> requirements.txt
202177

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

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

223197
$ heroku buildpacks:clear
224-
$ heroku buildpacks:add https://github.com/ReforgeHQ/heroku-buildpack-python -i 1
198+
$ heroku buildpacks:add heroku/python -i 1
225199
$ heroku buildpacks:add heroku/nodejs -i 2
226200
# heroku buildpacks:add heroku/ruby -i 3
227201

@@ -233,15 +207,12 @@ specify the order Heroku will load runtimes and execute bootstrapping code. It's
233207
important for the Python environment to be engaged first, as PyCall will need to
234208
be able to find it when Ruby-based processes start.
235209

236-
Once you have set up your buildpacks, and have commited both `requirements.txt` and
237-
`runtime.txt` files to git, deploy your Heroku application as your normally would.
210+
Once you have set up your buildpacks, and have committed both `requirements.txt` and
211+
`.python-version` files to git, deploy your Heroku application as your normally would.
238212
The Python bootstrapping process will appear in the log first, followed by the Ruby
239213
and so on. PyCall should now be able to successfully call Python functions from
240214
within the Heroku environment.
241215

242-
NB It is also possible to specify buildpacks within Docker images on Heroku.
243-
See Heroku's [documentation on using Docker Images](https://devcenter.heroku.com/articles/build-docker-images-heroku-yml).
244-
245216
## Development
246217

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

0 commit comments

Comments
 (0)