Skip to main content

Work library for Plain

Project description

plain-dev

A single command to run everything you need for local Plain development.

Plain work command example

The plain dev command runs a combination of local commands + a Docker container for your database.

The following processes will run simultaneously (some will only run if they are detected as available):

Installation

pip install plain-dev

If you have plain-models installed (i.e. you're using a database), then add DATABASE_URL to your .env file.

DATABASE_URL=postgres://postgres:postgres@localhost:54321/postgres
# pyproject.toml
[tool.plain.dev.services]
postgres = {cmd = "docker run --name app-postgres --rm -p 54321:5432 -v $(pwd)/.plain/dev/pgdata:/var/lib/postgresql/data -e POSTGRES_PASSWORD=postgres postgres:15 postgres"}
plain dev

plain dev

Default processes

  • plain preflight
  • gunicorn
  • migrations
  • tailwind

Custom processes

  • package.json "dev" script
  • pyproject.toml tool.plain.dev.run = {command = "..."}

GitHub Codespaces

The BASE_URL setting is automatically set to the Codespace URL.

TODO

plain dev db

Only supports Postgres currently.

  • snapshot
  • import
  • export

Development processes

Gunicorn

The key process here is still manage.py runserver. But, before that runs, it will also wait for the database to be available and run manage.py migrate.

plain-models

If plain-models is installed, it will automatically start and show the logs of the running database container.

plain-tailwind

If plain-tailwind is installed, it will automatically run the Tailwind compile --watch process.

Debugging

View on YouTube →

Since plain work runs multiple processes at once, the regular pdb debuggers can be hard to use. Instead, we include microsoft/debugpy and an attach function to make it even easier to use VS Code's debugger.

First, import and run the debug.attach() function:

class HomeView(TemplateView):
    template_name = "home.html"

    def get_context(self, **kwargs):
        context = super().get_context(**kwargs)

        # Make sure the debugger is attached (will need to be if runserver reloads)
        from plain.work import debug; debug.attach()

        # Add a breakpoint (or use the gutter in VSCode to add one)
        breakpoint()

        return context

When you load the page, you'll see "Waiting for debugger to attach...".

Add a new VS Code debug configuration (using localhost and port 5768) by saving this to .vscode/launch.json or using the GUI:

// .vscode/launch.json
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Plain: Attach to Django",
            "type": "python",
            "request": "attach",
            "connect": {
                "host": "localhost",
                "port": 5678
            },
            "pathMappings": [
                {
                    "localRoot": "${workspaceFolder}",
                    "remoteRoot": "."
                }
            ],
            "justMyCode": true,
            "django": true
        }
    ]
}

Then in the "Run and Debug" tab, you can click the green arrow next to "Plain: Attach to Django" to start the debugger.

In your terminal is should tell you it was attached, and when you hit a breakpoint you'll see the debugger information in VS Code. If Django's runserver reloads, you'll be prompted to reattach by clicking the green arrow again.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

plain_dev-0.0.0.tar.gz (16.8 kB view hashes)

Uploaded Source

Built Distribution

plain_dev-0.0.0-py3-none-any.whl (22.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page