Skip to content

Commit 84d222c

Browse files
committed
refactor & fix: command not found: pipenv
1 parent 3f4fc60 commit 84d222c

File tree

3 files changed

+40
-21
lines changed

3 files changed

+40
-21
lines changed

hobbit/devtools.py

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import os
21
import click
3-
from subprocess import run
42

5-
from .handlers import echo
6-
from . import HobbitGroup, CONTEXT_SETTINGS, ROOT_PATH
3+
from . import HobbitGroup, CONTEXT_SETTINGS
4+
from .handlers.devtools import dev_init
75

86

97
class BootstrapGroup(HobbitGroup):
@@ -30,20 +28,4 @@ def dev():
3028
def init(ctx, all_, hooks, pipenv):
3129
"""Init dev env: git hooks, pyenv install etc.
3230
"""
33-
run('git init', shell=True)
34-
35-
if all_ or hooks:
36-
HOOKS_PATH = os.path.join(ROOT_PATH, 'static', 'hooks')
37-
run(f'cp -r {HOOKS_PATH}/* .git/hooks', shell=True)
38-
39-
pipenv_cmds = [
40-
'pipenv install --dev pytest pytest-cov pytest-env flake8',
41-
]
42-
if 'requirements.txt' in os.listdir():
43-
pipenv_cmds.insert(0, 'pipenv install -r requirements.txt --pre')
44-
45-
cmd = ' && '.join(pipenv_cmds)
46-
# force pipenv to ignore that environment and create its own instead
47-
if all_ or pipenv:
48-
run(cmd, shell=True)
49-
echo('Please run: pipenv shell')
31+
dev_init(all_, hooks, pipenv)

hobbit/handlers/devtools.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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)

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ deps =
3030
pytest-cov
3131
pytest-env
3232
flake8
33+
pipenv
3334
commands =
3435
flake8 .
3536
mypy hobbit hobbit_core tests

0 commit comments

Comments
 (0)