Skip to content

Instantly share code, notes, and snippets.

@batisteo
Created February 12, 2018 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save batisteo/44a2c7d44a3362b4c5899d00c27655aa to your computer and use it in GitHub Desktop.
Save batisteo/44a2c7d44a3362b4c5899d00c27655aa to your computer and use it in GitHub Desktop.

The state of Pipenv

Python Development Workflow for Humans™

Pipenv is meant to replace:

  • requirements.txt
  • virtualenv / virtualenvwrapper
  • pip-tools / pip-compile
  1. Pipfile
  2. TOML
  3. Pipfile.lock
  4. Workflow
  5. In production

Pipfile

Same philosophy as requirements.in, with the TOML syntax.

[[source]]
url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"

[requires]
python_version = "3.4"

[packages]
Django = ">=1.11,<2"
psycopg2 = ">=2.7.3"
django-solo = "*"
[packages.django-yubin]
url = "https://github.com/APSL/django-yubin.git"
ref = "abcd567"

[dev-packages]
bpython = "*"
django-debug-toolbar = ">=1.9.1"

TOML

Tom's Obvious, Minimal Language

By Tom Preston-Werner (GitHub, Gravatar, semver)

Rust as an early adopter with Cargo.toml and Cargo.lock

Pipfile.lock

Quite easy to read. Shouldn’t write!

    "_meta": {
        "hash": {
            "sha256": "21fb10662530619307c989ac2fdb4f02ab96d11079930db48eb7e4e9fd0375c9"
        },
        "pipfile-spec": 6,
        "requires": {
            "python_version": "3.4"
        },
        "sources": [
            {
                "name": "pypi",
                "url": "https://pypi.python.org/simple",
                "verify_ssl": true
            }
        ]
    },
    "default": {
        "django": {
            "hashes": [
                "sha256:ac4c797a328a5ac8777ad61bcd00da279773455cc78b4058de2a9842a0eb6ee8",
            ],
            "version": "==1.11.10"
        },
    },
}

Workflow

In production

Cron

/etc/cron.d/life-of-brian

PATH=$PATH:/usr/local/bin 

42 4 * * * brian cd /srv/life-of-brian && pipenv run ./src/manage.py clearsessions

SystemD

/etc/systemd/system/life-of-brian.daphne.service

[Unit]
Description=Django daphne
After=syslog.target

[Service]
WorkingDirectory=/srv/life-of-brian
ExecStart=/usr/local/bin/pipenv run daphne -u /tmp/life-of-brian.sock life-of-brian.asgi:channel_layer -v2
RuntimeDirectory=life-of-brian
Restart=always
KillSignal=SIGQUIT
Type=notify
StandardError=syslog
NotifyAccess=all

[Install]
WantedBy=multi-user.target

uWSGI vassal

$ pipenv --venv
/home/brian/.local/share/virtualenvs/life-of-brian-zVxdobNk

/etc/uwsgi-emperor/vassals/life-of-brian.ini

[uwsgi]
username = brian
project = life-of-brian
venv-name= life-of-brian-zVxdobNk

chdir = /srv/%(project)/src
home = /home/%(username)/.local/share/virtualenvs/%(venv-name)
module = %(project).wsgi:application
env = DJANGO_SETTINGS_MODULE=life_of_brian.settings
log = /var/log/uwsgi
daemonize = /var/log/uwsgi/%(project).log

master = true
processes = 1
threads = 1

uid = %(username)
gid = nginx
socket = /var/uwsgi/%(project).sock
chmod-socket = 660
vacuum = true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment