Skip to content

Commit 746b7c1

Browse files
authored
Quiet in command line (#58)
* ✨ non-verbose mode. #38 * 📚update shell instructions * 🔨 refactor yehua's own template * :sparkles; update coding style * 💚 yehua.yml is now able to have default values and jinja2 template too. #49 * 📚 update text info * This is an auto-commit Co-authored-by: chfw <[email protected]>
1 parent 84816dc commit 746b7c1

11 files changed

+68
-31
lines changed

CHANGELOG.rst

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Change log
1616
**Added**
1717

1818
#. `#37 <https://github.com/moremoban/yehua/issues/37>`_: cookiecutter support
19+
#. `#38 <https://github.com/moremoban/yehua/issues/38>`_: non-verbose mode
1920
#. added moban update work flow
2021
#. python filesystem 2 support. yehua templates and cookiecutter templates can
2122
be in git, zip, s3, etc.

changelog.yml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ releases:
1111
- action: Added
1212
details:
1313
- "`#37`: cookiecutter support"
14+
- "`#38`: non-verbose mode"
1415
- "added moban update work flow"
1516
- "python filesystem 2 support. yehua templates and cookiecutter templates can be in git, zip, s3, etc."
1617
date: 2020

test.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
pip freeze
22
pip install -e .
3-
pytest --cov=yehua --cov=tests tests/
3+
pytest --cov=yehua --cov=tests tests/ --ignore=tests/fixtures/project_s

tests/test_cookie_cutter.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ def test_local_cookie_cutter_package(fake_inputs):
3535
shutil.rmtree(project_name)
3636

3737

38-
@patch("yehua.project._git_add")
3938
@patch("yehua.cookiecutter.get_user_inputs")
40-
def test_github_package(fake_inputs, fake_system):
39+
def test_github_package(fake_inputs):
4140
project_name = "git_package_test"
4241
file_name = "yehua_test"
4342
fake_inputs.return_value = {

tests/test_main.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
from nose.tools import eq_, raises
99

1010

11-
@patch("os.system")
11+
@patch("yehua.project.os.chdir")
12+
@patch("yehua.project._run_command")
1213
@patch("yehua.project.get_user_inputs")
1314
@patch("yehua.utils.mkdir")
1415
@patch("yehua.utils.save_file")
1516
@patch("yehua.utils.copy_file")
16-
def test_main(copy, save, mkdir, inputs, os_system):
17+
def test_main(copy, save, mkdir, inputs, *_):
1718
copy.return_value = 0
1819
save.return_value = 0
1920
mkdir.return_value = 0

tests/test_project.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def test_template():
144144

145145
questions_with_template = [
146146
{"hello": "hello?"},
147-
{"foo": "foo [{{yehua.hello}}]"},
147+
{"foo": "foo [{{hello}}]"}, # note yehua does not require a prefix
148148
{"bar": "bar [{{cookiecutter.hello}}]"},
149149
]
150150

yehua/cookiecutter.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ def templating(self):
8585
project_yaml = deepcopy(self.answers)
8686
project_yaml.pop("now") # is not required
8787
dump_yaml(project_yaml, f)
88+
utils.color_print(
89+
f"\u2713 Your answers are saved in [info]{path}[/info]!"
90+
)
8891

8992
moban_file = utils.load_yaml(MOBAN_FILE_FOR_COOKIE_CUTTER)
9093
moban_file["configuration"]["configuration"] = (
@@ -102,7 +105,12 @@ def templating(self):
102105
+ "/"
103106
+ self.cookie_cutter_dir
104107
)
105-
with open(
106-
os.path.join(self.answers["project_name"], ".moban.yml"), "w"
107-
) as f:
108+
moban_file_path = os.path.join(
109+
self.answers["project_name"], ".moban.yml"
110+
)
111+
with open(moban_file_path, "w") as f:
108112
dump_yaml(moban_file, f)
113+
utils.color_print(
114+
f"\u2713 [info]{moban_file_path}[/info]! l"
115+
+ "inks your project with the template."
116+
)

yehua/cookiecutter_to_yehua.py

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
INTRODUCTION = """
1010
[info]Yehua /'jɛhwa/[/info] will walk you through cookiecutter template wizard
1111
Press ^C to quit at any time.
12+
1213
"""
1314

1415

yehua/project.py

+34-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import subprocess
23
from datetime import datetime
34

45
import yehua.utils as utils
@@ -50,8 +51,15 @@ def copy_static_files(self):
5051
utils.copy_file(source, dest)
5152

5253
def inflate_all_by_moban(self):
53-
cmd = "cd %s && moban" % self.answers["project_name"]
54-
os.system(cmd)
54+
current = os.getcwd()
55+
project_name = self.answers["project_name"]
56+
os.chdir(project_name)
57+
cmd = "moban"
58+
_run_command(cmd)
59+
os.chdir(current)
60+
utils.color_print(
61+
f"\u2713 Files are generated under [info]{project_name}[/info]"
62+
)
5563

5664
def post_moban(self):
5765
if "post-moban" not in self.directives:
@@ -62,14 +70,27 @@ def post_moban(self):
6270

6371
def initialize_git_and_add_all(self, project_files):
6472
project_name = self.answers["project_name"]
65-
cmd = "cd %s && git init" % project_name
66-
os.system(cmd)
73+
current = os.getcwd()
74+
os.chdir(project_name)
75+
cmd = "git init"
76+
_run_command(cmd)
6777
for file_name in project_files:
68-
_git_add(project_name, file_name)
69-
print("Please review changes before commit!")
78+
_run_command(f"git add {file_name}")
79+
os.chdir(current)
80+
utils.color_print(
81+
f"\u2713 Git repo initialized under [info]{project_name}[/info]"
82+
+ " and is ready to commit"
83+
)
7084

7185
def end(self):
72-
print("All done!! project %s is created" % self.project_name)
86+
utils.color_print(
87+
"All done!! project [info]%s[/info] is created."
88+
% self.project_name
89+
)
90+
utils.color_print(
91+
"In the future, "
92+
+ "run [info]moban[/info] to synchronize with the project template"
93+
)
7394

7495
def _ask_questions(self):
7596
content = read_unicode(self.project_file)
@@ -119,6 +140,9 @@ def _create_jj2_environment(self, path):
119140
return environment
120141

121142

122-
def _git_add(project_name, file_name):
123-
cmd = "cd %s && git add %s" % (project_name, file_name)
124-
os.system(cmd)
143+
def _run_command(command):
144+
subprocess.check_call(
145+
command.split(" "),
146+
stdout=subprocess.DEVNULL,
147+
stderr=subprocess.DEVNULL,
148+
)

yehua/resources/yehua.yml

+13-10
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
introduction: |
2-
Yehua will walk you through creating a blank python package.
2+
[info]Yehua[/info] will walk you through creating a blank python package.
33
Press ^C to quit at any time.
44
configuration:
55
template_path: ./templates
66
static_path: ./static
77
questions:
8-
- project_name: "project name:"
9-
- description: "description:"
10-
- license: "license:(mit or newbsd)"
11-
- author: "author:"
12-
- contact: "contact email:"
13-
- organisation: "github profile/organisation:"
14-
- company: "copyright owner:"
8+
- project_name: "project name [yehua boilerplate]: "
9+
- description: "description [Moremoban organisation's best template]: "
10+
- license:
11+
- question: "license: "
12+
"1. mit": "N/A"
13+
"2. newbsd": "N/A"
14+
- author: "author: "
15+
- contact: "contact email: "
16+
- organisation: "github profile/organisation: "
17+
- company: "copyright owner [{{author}}]: "
1518
- project_type:
16-
- question: "project type?"
19+
- question: "project type: "
1720
"1. library": "N/A"
1821
"2. command line interface":
19-
- cli: "cli executable name?"
22+
- cli: "cli executable name: "
2023
"3. C extension":
2124
- sources: "source files?(Comma separated list is expected. For example: pymodule.c,file.c)"
2225
layout:

yehua/utils.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def get_user_inputs(questions): # refactor this later
109109
# {"bar": "bar [{{cookiecutter.hello}}]"}
110110
template = env.from_string(question)
111111
question = template.render(
112-
cookiecutter=answers, yehua=answers
112+
cookiecutter=answers, **answers
113113
)
114114

115115
match = re.match(r"(.*)\[(.*)\].*", question)
@@ -181,4 +181,3 @@ def color_print(rich_text):
181181
theme = Theme(THEME)
182182
console = Console(theme=theme)
183183
console.print(rich_text)
184-
print("\n")

0 commit comments

Comments
 (0)