Skip to main content

Run commands with `dj {command_name}`. Uses aliases defined in a simple config file or defaults to Django management commands.

Project description

Why?

It is available everywhere if you install via pip, has cute aliases defined in a JSON file (.dj-config.json) per project, will run as many commands as you want, and defaults to Django management commands if an alias cannot be found.

Commands can be run sequentially by dj (e.g. dj makemigrations migrate). However, calling a long-running process (e.g. dj runserver) will prevent any other commands from being run. For example, dj runserver migrate will never run the migrate command because runserver will block the process.

Example .dj-config.json

{
	"commands": [
		{
			"name": "nice name for the command",
			"help": "help text for the command (optional)",  
			"execute": "shell command to run",
			"long_running": false  // whether the process is expected to execute and exit or run forever (optional, defaults to false)
			"requires_virtualenv": false  // check that a virtual environment is activated before running the command (optional, defaults to false)
		},
		{
			"name": "m",
			"help": "Does the migration dance",
			"execute": "./manage.py makemigrations && ./manage.py migrate",
		},
		{
			"name": "r",
			"help": "Runserver",
			"execute": "./manage.py runserver",
			"long_running": true
		}
	],
	"disable_django_management_command": false  // prevent falling back to a Django management command cannot be found (optional, defaults to false)
}

dj will look in the current directory for .dj-config.json and then in ~/, unless the --config argument is used to specify a particular file location.

Basic arguments and options

  • dj --help to see all of the options
  • dj --list to see all of the available custom commands
  • dj {command_name} to run a custom command or Django management command (e.g. dj migrate)
  • dj {command_name} --dry_run to show what commands would run without actually executing them

How to work on the source

  1. Clone the repo
  2. Run the source locally: poetry run python dj
  3. Test the source: poetry run pytest
  4. Build and install locally: poetry build && pip3 install --user --upgrade --force-reinstall dist/dj_command-0.3.0-py3-none-any.whl
  5. Test with ~/.local/bin/dj migrate
  6. Publish the source to pypi: poetry publish --build --username USERNAME --password PASSWORD

Acknowledgements

  • poetry: please, please, please continue to wrangle the complexity of 1) creating Python projects, and 2) installing dependencies; seriously, it's baffling out there without you
  • click: ridiculously full-featured library to help implement CLI programs in Python; it has all the bells and most of the whistles
  • attrs: would you like easy classes in Python? yes, please
  • delegator.py: dealing with subprocess is a pain, but delegator hides all the ugly cruft behind a nice API

Prior art

This isn't a new idea and there are a few other implementations out there that do similar things. But, uh, I like mine. 😀

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

dj-command-0.4.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

dj_command-0.4.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file dj-command-0.4.0.tar.gz.

File metadata

  • Download URL: dj-command-0.4.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.17 CPython/3.6.6 Darwin/18.7.0

File hashes

Hashes for dj-command-0.4.0.tar.gz
Algorithm Hash digest
SHA256 34a2dbedd01c89f4fa8b5353341a44ca5d7aa1885425c0c8e51d1ae22c7b94dd
MD5 a3e259f5f19b2e672f6d3a76c758682c
BLAKE2b-256 f2434e0071907eb94d2b1f168fcf378c369bde2c17e9c3030149f73e83a61559

See more details on using hashes here.

File details

Details for the file dj_command-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: dj_command-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.17 CPython/3.6.6 Darwin/18.7.0

File hashes

Hashes for dj_command-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ec94c2eb85cbfff623b920477de4762a82d2ed99fda4f80c7dcda45ce2d6f178
MD5 3c37f786afbf9c4e9f1ce6282bd27b1e
BLAKE2b-256 24e4b5ac59f03254d8abd3f1cd893ba7eecce58670e4330c0f72112fa31a17c5

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