Skip to content

Commit b2f3ffc

Browse files
committed
CHANGELOG updated
1 parent ee328d9 commit b2f3ffc

File tree

8 files changed

+99
-10
lines changed

8 files changed

+99
-10
lines changed

CHANGELOG

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ makeapp changelog
22
=================
33

44

5+
Unreleased
6+
----------
7+
+ Added virtual environment creation on project rollout.
8+
+ CLI. Added command.
9+
* Fixed package name availability check.
10+
11+
512
v1.9.1 [2023-05-19]
613
-------------------
714
* Added '-i' shortcut for '--increment' option of 'release' command.

makeapp/appmaker.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from .apptemplate import TemplateFile, AppTemplate
1212
from .exceptions import AppMakerException
1313
from .helpers.vcs import VcsHelper
14+
from .helpers.venvs import VenvHelper
1415
from .rendering import Renderer
1516
from .utils import chdir, configure_logging, PYTHON_VERSION
1617

@@ -276,9 +277,11 @@ def _hook_run(self, hook_name: str) -> Dict[AppTemplate, bool]:
276277

277278
def rollout(
278279
self,
279-
dest: str, *,
280+
dest: str,
281+
*,
280282
overwrite: bool = False,
281283
init_repository: bool = False,
284+
init_venv: bool = False,
282285
remote_address: str = None,
283286
remote_push: bool = False
284287
):
@@ -290,6 +293,8 @@ def rollout(
290293
291294
:param init_repository: Whether to initialize a repository.
292295
296+
:param init_venv: Whether to initialize a virtual environment.
297+
293298
:param remote_address: Remote repository address to add to DVCS.
294299
295300
:param remote_push: Whether to push to remote.
@@ -338,12 +343,15 @@ def rollout(
338343
with chdir(dest):
339344
self._hook_run('rollout_post')
340345

341-
if init_repository:
342-
self._vcs_init(
343-
dest,
344-
add_files=bool(files.keys()),
345-
remote_address=remote_address,
346-
remote_push=remote_push)
346+
if init_venv:
347+
VenvHelper(dest).initialize()
348+
349+
if init_repository:
350+
self._vcs_init(
351+
dest,
352+
add_files=bool(files.keys()),
353+
remote_address=remote_address,
354+
remote_push=remote_push)
347355

348356
@staticmethod
349357
def _comment_out(text: Optional[str]) -> Optional[str]:

makeapp/apptools.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from .helpers.dist import DistHelper
1010
from .helpers.files import FileHelper
1111
from .helpers.vcs import VcsHelper
12+
from .helpers.venvs import VenvHelper
1213
from .utils import chdir
1314

1415
LOG = logging.getLogger(__name__)
@@ -337,10 +338,12 @@ def __init__(self, project_path: str = None):
337338
:param project_path: Application root (containing setup.py) path.
338339
339340
"""
340-
self.project_path = project_path or os.getcwd()
341+
project_path = project_path or os.getcwd()
342+
self.project_path = project_path
341343
self.package: Optional[PackageData] = None
342344
self.changelog: Optional[ChangelogData] = None
343345
self.vcs = VcsHelper.get(project_path)
346+
self.venv = VenvHelper(project_path)
344347

345348
with chdir(self.project_path):
346349
self._gather_data()
@@ -472,3 +475,7 @@ def publish(self):
472475
with chdir(self.project_path):
473476
self.vcs.push()
474477
DistHelper.upload()
478+
479+
def venv_init(self, *, reset: bool = False):
480+
LOG.info(f'Initializing virtual environment [{reset=}] ...')
481+
self.venv.initialize(reset=reset)

makeapp/cli.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def process_custom_args(args):
106106
click.secho(app_maker.get_settings_string(), fg='green')
107107

108108
init_repo = True
109+
init_venv = True
109110
remote_address = app_maker.settings['vcs_remote'] or ''
110111
remote_push = False
111112

@@ -129,10 +130,14 @@ def process_custom_args(args):
129130
if remote_address:
130131
remote_push = click.confirm('Do you want to commit and push files to remote?', default=False)
131132

133+
init_venv = click.confirm(
134+
'Do you want to initialize a virtual environment in the application directory?', default=True)
135+
132136
app_maker.rollout(
133137
target_path,
134138
overwrite=overwrite_on_conflict,
135139
init_repository=init_repo,
140+
init_venv=init_venv,
136141
remote_address=remote_address,
137142
remote_push=remote_push,
138143
)
@@ -185,6 +190,17 @@ def change(description):
185190
click.secho('Done', fg='green')
186191

187192

193+
@entry_point.group()
194+
def venv():
195+
"""Virtual environment related commands."""
196+
197+
198+
@venv.command()
199+
def reset():
200+
"""Remove old virtual environment and generate a new one."""
201+
Project().venv_init(reset=True)
202+
203+
188204
def main():
189205
try:
190206
entry_point(obj={})

makeapp/helpers/venvs.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import logging
2+
from pathlib import Path
3+
from shutil import rmtree
4+
5+
from ..utils import run_command
6+
7+
LOG = logging.getLogger(__name__)
8+
9+
10+
class VenvHelper:
11+
"""Encapsulates virtual environment related functions."""
12+
13+
def __init__(self, project_path: str):
14+
self.venv_path = Path(project_path) / 'venv'
15+
16+
def initialize(self, *, reset: bool = False):
17+
path = self.venv_path
18+
19+
if reset:
20+
LOG.debug(f'Remove {path} ...')
21+
rmtree(f'{path}', ignore_errors=True)
22+
23+
run_command('python3 -m venv venv')
24+
run_command(f'{path}/bin/python -m pip install -e .')

tests/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
@pytest.fixture
55
def get_appmaker():
66

7-
def get_appmaker_(app_name='dummy', templates=None, *, rollout=True):
7+
def get_appmaker_(app_name='dummy', templates=None, *, rollout=True, init_venv=False):
88

99
from makeapp.appmaker import AppMaker
1010

@@ -26,6 +26,7 @@ def get_appmaker_(app_name='dummy', templates=None, *, rollout=True):
2626
'.',
2727
overwrite=True,
2828
init_repository=True,
29+
init_venv=init_venv,
2930
remote_address='[email protected]',
3031
remote_push=False,
3132
)

tests/test_appmaker.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def test_default(tmpdir, get_appmaker, assert_content):
66

77
with tmpdir.as_cwd():
88

9-
app_maker = get_appmaker()
9+
app_maker = get_appmaker(init_venv=True)
1010

1111
settings_str = app_maker.get_settings_string()
1212

@@ -41,6 +41,10 @@ def test_default(tmpdir, get_appmaker, assert_content):
4141
'from dummy import VERSION_STR',
4242
])
4343

44+
assert_content(tmpdir / 'venv', 'pyvenv.cfg', [
45+
'executable ='
46+
])
47+
4448

4549
def test_tpl_userdefined(tmpdir, get_appmaker, assert_content):
4650

tests/test_apptools.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,25 @@ def dummy_communicate(self, *args, **kwargs):
4949
'python3 setup.py clean --all sdist bdist_wheel',
5050
'twine upload dist/*'
5151
]
52+
53+
54+
def test_venv(tmpdir, get_appmaker, assert_content):
55+
56+
with tmpdir.as_cwd():
57+
58+
get_appmaker()
59+
60+
vcs = VcsHelper.get()
61+
vcs.commit('initial')
62+
63+
project = Project()
64+
65+
project.venv_init()
66+
assert_content(tmpdir / 'venv', 'pyvenv.cfg', [
67+
'executable ='
68+
])
69+
70+
project.venv_init(reset=True)
71+
assert_content(tmpdir / 'venv', 'pyvenv.cfg', [
72+
'executable ='
73+
])

0 commit comments

Comments
 (0)