Skip to content

Commit 24a74b1

Browse files
committed
Add pyenv based dev env and mod_wsgi setup instructions
1 parent 12b6309 commit 24a74b1

File tree

1 file changed

+74
-26
lines changed

1 file changed

+74
-26
lines changed

README.md

Lines changed: 74 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -198,35 +198,83 @@ These instructions are tested on Linux Mint 18 and should also work on close der
198198

199199
#### Install packaged dependencies
200200

201-
$ sudo apt update
202-
$ sudo apt -fy dist-upgrade
203-
$ sudo apt install -y python-setuptools libssl-dev postgresql postgresql-server-dev-all git
201+
sudo bash -c '
202+
apt update
203+
apt -fy dist-upgrade
204+
apt install -y python-setuptools libssl-dev postgresql postgresql-server-dev-all git python3-dev
205+
'
204206

205-
##### Python 3
207+
#### Install pyenv
206208

207-
$ sudo apt install -y python3-dev python3-venv
208-
$ python3 -m venv venv
209+
In general, the system version of Python should not be touched. E.g., avoid installing packages with `sudo pip`.
209210

210-
##### Python 2
211+
pyenv provides a handy way to download and build local versions of Python mostly without sudo and without modifying the system Python environment. The Python environments created and managed by pyenv are stored under `~/.pyenv` by default. pyenv automatically switches between Python environments based on the current directory.
211212

212-
$ sudo apt install -y python-dev python-virtualenv
213+
Install:
213214

214-
##### Python 3 and Python 2
215+
curl https://pyenv.run | bash
216+
217+
* Follow the instructions on how to activate pyenv automatically.
218+
* Open a new shell.
215219

216-
$ . ./venv/bin/activate
220+
#### Set up a virtual environment for d1_python
217221

218-
Download the source from GitHub:
222+
This is the environment all of d1_python's packaged Python dependencies will be installed to. It provides the runtime environment for d1_python tests and utilities.
219223

220-
$ git clone https://github.com/DataONEorg/d1_python.git
224+
The `CONFIGURE_OPTS=--enable-shared` setting in the snippet is required for `mod_wsgi` to be able to run from the environment.
221225

222-
Add the DataONE packages to the Python path, and install their dependencies:
226+
bash -c '
227+
pyver=3.7.3
228+
CONFIGURE_OPTS=--enable-shared pyenv install ${pyver}
229+
pyenv virtualenv ${pyver} d1_python
230+
pyenv activate d1_python
231+
pip install --upgrade pip
232+
'
223233

224-
cd ~/d1_python
225-
sudo ./dev_tools/src/d1_dev/setup-all.py --root . develop
234+
Select a location for the d1_python git repository. Changed this as needed.
226235

227-
#### Postgres
236+
$ export d1path=~/dev/d1_python
228237

229-
:
238+
Download the source from GitHub and install:
239+
240+
bash -c '
241+
git clone https://github.com/DataONEorg/d1_python.git ${d1path}
242+
cd ${d1path}
243+
pyenv activate d1_python
244+
sudo ./dev_tools/src/d1_dev/setup-all.py --root . develop
245+
'
246+
247+
#### Running GMN under Apache
248+
249+
The setup above is sufficient for testing against GMN using HTTP and the Django test client, which is normally all that is required. However, if testing over HTTPS or in an environment that is closer to production is required, Apache can be set up to host GMN directly from its location in d1_python, using the d1_python virtual environment.
250+
251+
In such a setup, the GMN source can be open in an IDE and changes made active with an `service apache2 reload`.
252+
253+
Note that `mod_wsgi` can only run from a Python environment compiled with `--enable-shared`, as done in the venv setup above.
254+
255+
The APT package version of `mod_wsgi` has been compiled to work with the APT package version of Python. The two must be compatible at the ABI level, and Apache can only load a single instance of `mod_wsgi`. So this uninstalls any installed `mod_wsgi` APT package before compiling a new version against the Python environment in which it will be used.
256+
257+
258+
sudo bash -c '
259+
service apache2 stop
260+
apt remove libapache2-mod-wsgi*
261+
apt-get update
262+
apt-get install python libexpat1 apache2 apache2-utils ssl-cert apache2-dev
263+
setfacl -m u:${SUDO_USER}:w /etc/apache2/mods-available/wsgi.load
264+
'
265+
266+
bash -c '
267+
pyenv activate d1_python
268+
pip install mod_wsgi
269+
mod_wsgi-express module-config >> /etc/apache2/mods-available/wsgi.load
270+
'
271+
272+
sudo bash -c '
273+
a2enmod wsgi
274+
service apache2 restart
275+
'
276+
277+
#### Postgres
230278

231279
$ sudo apt install --yes postgresql
232280

@@ -237,21 +285,15 @@ Set the password of the postgres superuser account:
237285

238286
When prompted for the password, enter a new superuser password (and remember it :-).
239287

240-
:
241-
242288
$ sudo -u postgres createdb -E UTF8 gmn2
243289
$ sudo -u postgres createuser --superuser `whoami`
244290

245291
PyCharm (and other IntelliJ based platforms), are not able to connect to database with local (UNIX) sockets. Postgres' convenient "peer" authentication type only works over local sockets. A convenient workaround for this is to set Postgres up to trust local connections made over TCP/IP.
246292

247-
:
248-
249293
$ sudo editor /etc/postgresql/10/main/pg_hba.conf
250294

251295
Add line:
252296

253-
:
254-
255297
host all all 127.0.0.1/32 trust
256298

257299
A similar line for MD5 may already be present and, if so, must be commented out.
@@ -318,14 +360,20 @@ After successful build, clone a fresh copy, which will be used for building the
318360

319361
Building the release packages from a fresh clone is a simple way of ensuring that only tracked files are released. It is a workaround for the way setuptools works, which is basically that it vacuums up everything that looks like a Python script in anything that looks like a package, which makes it easy to publish local files by accident.
320362

321-
Create a Python venv to use for build and deploy
363+
Create a Python venv to use for build and deploy:
322364

365+
* The package `setup.py` scripts will run in this venv.
366+
* The venv can be reused indefinitly.
367+
323368
$ pyenv virtualenv "x.y.z" venv_build
324369

325-
* Where "x.y.z" is one of the versions listed in `pyenv versions`.
326-
* Pick a version that is close or the same as the version of Python used for testing on Travis
370+
* Where "x.y.z" is one of the versions listed in `pyenv versions`.
371+
* Pick a version that is close or the same as the version of Python used for testing on Travis.
372+
327373

328374
Build and publish the packages:
375+
376+
* Download current master from GitHub, create binary wheel packages and push the packages to PyPI.
329377

330378
bash -c '
331379
bdir=~/d1_python_build

0 commit comments

Comments
 (0)