Boot.py is an small set of tools to build simple scripts. Python3 only, and really small: 2Kb!
Project description
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()
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
boot.py-0.8.tar.gz
(4.5 kB
view details)
Built Distribution
File details
Details for the file boot.py-0.8.tar.gz
.
File metadata
- Download URL: boot.py-0.8.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 958539cbd31f4ac4946c42847b1d69c04c567ccba27fc9c0e679011b3865b91b |
|
MD5 | d8b6cd9936b11727d95eb1320d21c8f6 |
|
BLAKE2b-256 | 9bd764fe12f77db55cf5922745ac70659eadfae4856632a5c36db2f4dc868a9b |
File details
Details for the file boot.py-0.8-py2.py3-none-any.whl
.
File metadata
- Download URL: boot.py-0.8-py2.py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 031136faaa3b83091e5b015abc5e8c1ba981cdab3d3663705736a7329b08aa96 |
|
MD5 | 4a618463c9990174da5c2cfa88909111 |
|
BLAKE2b-256 | 70ff39deff1e167c9a08641d735bd306ac16c565ba1a625a7934892cec0ee827 |