Skip to main content

Work library for Forge

Project description

forge-work

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

Forge work command example

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

It also comes with debugging tools to make local debugging easier with VS Code.

Installation

First, install forge-work from PyPI:

pip install forge-work

Now instead of using the basic manage.py runserver (and a bunch of commands before and during that process), you can simply do:

forge work

Development processes

Runserver

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.

forge-db

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

forge-tailwind

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

package.json

If a package.json file is found and contains a watch script, it will automatically run. This is an easy place to run your own custom JavaScript watch process.

Stripe

If a STRIPE_WEBHOOK_PATH env variable is set then this will add a STRIPE_WEBHOOK_SECRET to .env (using stripe listen --print-secret) and it will then run stripe listen --forward-to <runserver:port/stripe-webhook-path>.

Ngrok

If an NGROK_SUBDOMAIN env variable is set then this will run ngrok http <runserver_port> --subdomain <subdomain>. Note that ngrok will need to be installed on your system already (however you prefer to do that).

Celery

If a CELERY_APP env variable is set, then an autoreloading celery worker will be started automatically.

Debugging

View on YouTube →

Since forge 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_data(self, **kwargs):
        context = super().get_context_data(**kwargs)

        # Make sure the debugger is attached (will need to be if runserver reloads)
        from forgework 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": "Forge: 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 "Forge: 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

forge_work-1.1.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

forge_work-1.1.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file forge_work-1.1.0.tar.gz.

File metadata

  • Download URL: forge_work-1.1.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.0 CPython/3.11.2 Linux/5.15.0-1033-azure

File hashes

Hashes for forge_work-1.1.0.tar.gz
Algorithm Hash digest
SHA256 f1cafec3e87cc6609e5b8b09b12fffe3ade8c19a54d1ab6f1ab912c01a0c7a8f
MD5 7ae364fec59a78e72d121ba79938ed13
BLAKE2b-256 769fcf20a2945554ae42089aa7a00e380dcae14fe68822c2e76050345a81a9f1

See more details on using hashes here.

File details

Details for the file forge_work-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: forge_work-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.0 CPython/3.11.2 Linux/5.15.0-1033-azure

File hashes

Hashes for forge_work-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ccef5ffec15d4c10dd2db269fb5b23861b258c59f078325b5d3dc537de2dbafb
MD5 faecee8757d5bdc8bc8fc29774378afc
BLAKE2b-256 b333f2f8b49de1205ab2189d8183c10a172684598843283cdcccdfa4e0b47ed0

See more details on using hashes here.

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