Hacking Docassemble Internals

The Suffolk LIT Lab logo

Bryce Willey

@brycew@publicinterest.town

https://brycewilley.xyz/docacon23-slides

Why hack?

The docassemble logo, a black cat The docassemble cat, with ladybug wings on it's back and an antenna The docassemble cat, on top of a picture of a cat tower, or a cat condo The docassemble cat, with a window opening into its side to reveal that the python logo inside the cat A group of six docassemble cats, facing each other The docassemble cat, under an umbrella on the sandy beach

Here comes the firehose

The docassemble cat with a red fire hose, spraying a forceful blast of water

Don't memorize all of this: it's in the docs

Some starting assumptions:

Don't have time to cover:

Install an editor

I recommend VSCode, but anything works

A screenshot of visual studio code editor

The Terminal

A screenshot of the Windows terminal, with the message 'Hello Docacon!'

Download Docassemble


              # If on WSL2 or Linux (no need on Mac)
              sudo apt install git
              git clone https://github.com/jhpyle/docassemble
            

Install Docker

Docker terminology

  • container
  • image
  • volume
A screenshot of Virtual Box, running Ubuntu Linux on a Windows computer A nested tree of folders An image of a flash drive

Run Docker


              docker pull jhyple/docassemble
              docker run \
                  --env WWWUID=`id -u` \
                  --env WWWGID=`id -g` \
                  --name mydocassemble
                  -p 80:80 \
                  -v ./docassemble:/tmp/docassemble \
                  -d \
                  jhpyle/docassemble
            

Some extra tips


                docker run \
                    --cap-add SYS_PTRACE \
                    --memory="4gb" \
                    ... # same as before
            

Our change: more logs

The Key components to hacking

  • Exploring and Navigating the code
  • reading the code
  • surgical change

Live demo backup

A screen shot of 'Only the last 30 lines' in the VS Code search bar, with results below A screenshot of the `logs.html` file, that contains the words 'Only the last 30 lines' A screenshot of the VS code search bar, this time with 'logs.html' in it The code in `server.py` in the `logs` function The same code as above, but changed to include the last 60 lines instead of the last 30

Open a shell in docassemble


                docker exec -it mydocassemble /bin/bash
            
The prompt will change to "root@a54e5b3:/#"

                su www-data
                source /usr/share/docassemble/local3.10/bin/activate
                cd /tmp/docassemble
                pip install --no-deps --no-index \
                    --force-reinstall --upgrade \
                    ./docassemble_base ./docassemble_webapp ./docassemble_demo ./docassemble
                touch /usr/share/docassemble/webapp/docassemble.wsgi
            

And so much more!

  • going past surface level Flask and git
  • Other systems in docassemble: pikepdf, sqlalchemy, redis, celery
  • You don't have to learn it all at once!

Reach out on Slack; go forth and hack