|
| 1 | +import os |
| 2 | +import sys |
| 3 | +from subprocess import run, PIPE, STDOUT |
| 4 | + |
| 5 | +import click |
| 6 | + |
| 7 | +from hobbit import ROOT_PATH |
| 8 | + |
| 9 | + |
| 10 | +def dev_init(all_, hooks, pipenv): |
| 11 | + run('git init', shell=True) |
| 12 | + |
| 13 | + if all_ or hooks: |
| 14 | + HOOKS_PATH = os.path.join(ROOT_PATH, 'static', 'hooks') |
| 15 | + run(f'cp -r {HOOKS_PATH}/* .git/hooks', shell=True) |
| 16 | + |
| 17 | + if all_ or pipenv: |
| 18 | + sub = run('which pipenv', shell=True, stdout=PIPE, stderr=STDOUT) |
| 19 | + if sub.returncode != 0: |
| 20 | + click.echo(click.style('cmd pipenv not exist.', fg='red')) |
| 21 | + sys.exit(sub.returncode) |
| 22 | + pipenv_path = sub.stdout.strip().decode('utf8') |
| 23 | + |
| 24 | + pipenv_cmds = [ |
| 25 | + f'{pipenv_path} install --dev pytest pytest-cov pytest-env flake8', |
| 26 | + ] |
| 27 | + if 'requirements.txt' in os.listdir(): |
| 28 | + pipenv_cmds.insert( |
| 29 | + 0, f'{pipenv_path} install -r requirements.txt --pre') |
| 30 | + |
| 31 | + cmd = ' && '.join(pipenv_cmds) |
| 32 | + click.echo(click.style(cmd, fg='green')) |
| 33 | + # force pipenv to ignore that environment and create its own instead |
| 34 | + env = os.environ.copy() |
| 35 | + env.update({'PIPENV_IGNORE_VIRTUALENVS': '1'}) |
| 36 | + run(cmd, shell=True, env=env) |
0 commit comments