Install and Use
Install with pip.
pip install boot.py
Create a file and import boot. For example this will install a virtual environment, install requirements, and create some files.
#!/usr/bin/env python3
import os
import venv
from boot import step, run
from pathlib import Path
root_path = Path(__file__).parent.resolve()
venv_dir = root_path / '.venv'
with step(f'Creating virtualenv in {venv_dir.name}'):
if not venv_dir.exists():
venv.create(venv_dir, with_pip=True)
with step('Installing requirements'):
run(f'{venv_dir / "bin/pip"} install -r requirements.txt')
with step('Creating directories'):
run(f'mkdir -p public/media')
run(f'mkdir -p public/static')
with step('Environment file'):
envfile = root_path / '.env'
if not envfile.exists():
with open(envfile, 'w') as handle:
os.chmod(envfile, 0o600)
handle.write('')
This will output.
$ ./script.py
Creating virtualenv in .venv ... [Ok]
Installing requirements ... [Ok]
Installing project ... [Ok]
Creating directories ... [Ok]
Environment file ... [Ok]
Simple!
You can also compose tasks to decide what to execute and what order.
#!/usr/bin/env python3
import os
import venv
from boot import step, run, task
from pathlib import Path
root_path = Path(__file__).parent.resolve()
venv_dir = root_path / '.venv'
@task
def build(this)
with step(f'Creating virtualenv in {venv_dir.name}'):
if not venv_dir.exists():
venv.create(venv_dir, with_pip=True)
with step('Creating directories'):
run(f'mkdir -p public/media')
run(f'mkdir -p public/static')
with step('Environment file'):
envfile = root_path / '.env'
if not envfile.exists():
with open(envfile, 'w') as handle:
os.chmod(envfile, 0o600)
handle.write('')
@task
def requirements(this)
with step('Installing requirements'):
run(f'{venv_dir / "bin/pip"} install -r requirements.txt')
@task
def backup(this)
with step(f'Backup db'):
run('pg_dump -d database -f output.sql')
if __name__ == '__main__':
tasks = {
'default': build >> requirements,
'build': build,
'requirements': requirements,
}
if len(sys.argv) == 1:
if sys.argv[0] in tasks:
tasks[sys.argv[0]]()
else:
print(f'Unknown task: {sys.argv[0]}')
print(f'Available tasks are: {tasks.keys()}')
else:
default()
There are helpers to build scripts with less code, for example we can replace in the code above the main call with a a simple task argument parser:
from boot.cli import ActionsCommand
if __name__ == '__main__':
ActionsCommand.main(
default=build >> requirements,
build=build,
requirements=requirements,
}
This parse –help
Metadata
Release files for boot.py 0.16
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| boot.py-0.16.tar.gz | 7.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| boot.py-0.16-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 16.3 kB
Release files / boot.py-0.16.tar.gz
| Download URL | boot.py-0.16.tar.gz |
|---|---|
| Size | 7.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
958b8165c67996b0ce80d49e86ce3082146930949ec4ebc4c80f41bcd98287ed
|
|
BLAKE2b-256 checksum How to use checksums |
8f02663478b989d6e52c3fead2cb36bed20aa97d604515e94d314afe594007f5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / boot.py-0.16-py2.py3-none-any.whl
| Download URL | boot.py-0.16-py2.py3-none-any.whl |
|---|---|
| Size | 9.0 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
9317d464e71395adb07d165149438147ed951ce277166d2958c346479ef1262f
|
|
BLAKE2b-256 checksum How to use checksums |
34f4ccb9cc0a692f2300b40db3c13f091047380dee682c94d206287947309fa8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |