Skip to content

Commit 169b475

Browse files
authored
cookiecutter's gh: support (#70)
* ✨ support gh:audreyr/cookiecutter-pypackage. fix #53 * This is an auto-commit, updating project meta data, such as changelog.rst, contributors.rst * update * 💚 update format.sh * 💚 test new syntax and update 📚 * This is an auto-commit, updating project meta data, such as changelog.rst, contributors.rst * Update test_main.py Co-authored-by: chfw <[email protected]>
1 parent 4983665 commit 169b475

27 files changed

+82
-51
lines changed

.isort.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
include_trailing_comma=true
1010
default_section=FIRSTPARTY
1111
no_lines_before=LOCALFOLDER
12-
sections=FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
12+
sections=FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER

.moban.d/yehua.feature.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Europython. Simply there is tons of cookiecutter templates out there.
2323
What you do is to replace 'cookiecutter' with 'yh'::
2424

2525
$ pip install yehua[cookiecutter]
26-
$ yh git://github.com/audreyr/cookiecutter-pypackage.git
26+
$ yh gh:audreyr/cookiecutter-pypackage
2727

2828
And what moremoban promise is, whenever your source template changes, you
2929
can `synchronize` them any time with another moremoban's command 'moban'::

CHANGELOG.rst

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
Change log
22
================================================================================
33

4+
0.1.4 - 14.09.2020
5+
--------------------------------------------------------------------------------
6+
7+
**Updated**
8+
9+
#. `#53 <https://github.com/moremoban/yehua/issues/53>`_: parity with
10+
cookiecutter: support gh:audreyr/cookiecutter-pypackage
11+
412
0.1.3 - 13.09.2020
513
--------------------------------------------------------------------------------
614

README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Europython. Simply there is tons of cookiecutter templates out there.
5555
What you do is to replace 'cookiecutter' with 'yh'::
5656

5757
$ pip install yehua[cookiecutter]
58-
$ yh git://github.com/audreyr/cookiecutter-pypackage.git
58+
$ yh gh:audreyr/cookiecutter-pypackage
5959

6060
And what moremoban promise is, whenever your source template changes, you
6161
can `synchronize` them any time with another moremoban's command 'moban'::

changelog.yml

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
name: yehua
22
organisation: moremoban
33
releases:
4+
- changes:
5+
- action: Updated
6+
details:
7+
- "`#53`: parity with cookiecutter: support gh:audreyr/cookiecutter-pypackage"
8+
date: 14.09.2020
9+
version: 0.1.4
410
- changes:
511
- action: Updated
612
details:

docs/source/conf.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
spelling_word_list_filename = 'spelling_wordlist.txt'
1717
project = u'yehua'
1818
copyright = u'2017-2020 Onni Software Ltd.'
19-
version = '0.1.3'
20-
release = '0.1.3'
19+
version = '0.1.4'
20+
release = '0.1.4'
2121
exclude_patterns = []
2222
pygments_style = 'sphinx'
2323
html_theme = 'default'

docs/source/index.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Europython. Simply there is tons of cookiecutter templates out there.
5757
What you do is to replace 'cookiecutter' with 'yh'::
5858

5959
$ pip install yehua[cookiecutter]
60-
$ yh git://github.com/audreyr/cookiecutter-pypackage.git
60+
$ yh gh:audreyr/cookiecutter-pypackage
6161

6262
And what moremoban promise is, whenever your source template changes, you
6363
can `synchronize` them any time with another moremoban's command 'moban'::

format.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
isort $(find yehua -name "*.py"|xargs echo) $(find tests -name "*.py"|xargs echo)
1+
isort $(find yehua -name "*.py"|xargs echo) $(find tests -name "*.py"|grep -v 'project_'| xargs echo)
22
black -l 79 yehua
3-
black -l 79 tests --exclude=tests/fixtures/project_
3+
black --exclude "/tests\/fixtures\/project_.*/" -l 79 tests

setup.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
NAME = "yehua"
3434
AUTHOR = "chfw"
35-
VERSION = "0.1.3"
35+
VERSION = "0.1.4"
3636
3737
LICENSE = "New BSD"
3838
ENTRY_POINTS = {
@@ -44,7 +44,7 @@
4444
"Yet another a project template tool for an organisation."
4545
)
4646
URL = "https://github.com/moremoban/yehua"
47-
DOWNLOAD_URL = "%s/archive/0.1.3.tar.gz" % URL
47+
DOWNLOAD_URL = "%s/archive/0.1.4.tar.gz" % URL
4848
FILES = ["README.rst","CONTRIBUTORS.rst", "CHANGELOG.rst"]
4949
KEYWORDS = [
5050
"python",
@@ -90,8 +90,8 @@
9090
}
9191
# You do not need to read beyond this line
9292
PUBLISH_COMMAND = "{0} setup.py sdist bdist_wheel upload -r pypi".format(sys.executable)
93-
GS_COMMAND = ("gs yehua v0.1.3 " +
94-
"Find 0.1.3 in changelog for more details")
93+
GS_COMMAND = ("gs yehua v0.1.4 " +
94+
"Find 0.1.4 in changelog for more details")
9595
NO_GS_MESSAGE = ("Automatic github release is disabled. " +
9696
"Please install gease to enable it.")
9797
UPLOAD_FAILED_MSG = (

tests/cutie_tests/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from yehua.thirdparty import cutie
2-
31
import readchar
42

3+
from yehua.thirdparty import cutie
4+
55

66
def PrintCall(states):
77
def func(msg=None, state="selectable"):

tests/cutie_tests/test_get_number.py

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from unittest import mock
33

44
from yehua.thirdparty import cutie
5-
65
from . import MockException
76

87

tests/cutie_tests/test_prompt_yes_or_no.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from unittest import mock
33

44
import readchar
5+
56
from . import PrintCall, InputContext, cutie
67

78
print_call = PrintCall(

tests/cutie_tests/test_select.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from unittest import mock
44

55
import readchar
6+
67
from . import PrintCall, InputContext, MockException, cutie
78

89
print_call = PrintCall(

tests/cutie_tests/test_select_multiple.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from unittest import mock
33

44
import readchar
5+
56
from . import PrintCall, InputContext, MockException, cutie
67

78
print_call = PrintCall(

tests/fixtures/project_yehua/docs/source/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@
5959
# Add any paths that contain custom static files (such as style sheets) here,
6060
# relative to this directory. They are copied after the builtin static files,
6161
# so a file named "default.css" will overwrite the builtin "default.css".
62-
html_static_path = ['static']
62+
html_static_path = ['static']
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
# flake8: noqa
2-
from project_yehua._version import __version__
3-
from project_yehua._version import __author__
2+
from project_yehua._version import __author__, __version__

tests/test_cookie_cutter.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
import sys
33
import shutil
44

5-
from yehua.main import main
5+
from mock import patch
6+
from nose.tools import eq_
67
from moban.externals.file_system import is_dir, url_join, read_unicode
78

89
import fs
9-
from mock import patch
10-
from nose.tools import eq_
10+
from yehua.main import main
1111

1212

1313
@patch("yehua.cookiecutter.get_user_inputs")
@@ -79,7 +79,7 @@ def test_reference_pypi_package(fake_inputs):
7979
"create_author_file": "y",
8080
"open_source_license": "MIT license",
8181
}
82-
path = "git://github.com/moremoban/cookiecutter-pypackage.git"
82+
path = "gh:moremoban/cookiecutter-pypackage"
8383
with patch.object(sys, "argv", ["yh", path]):
8484
main()
8585

tests/test_main.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import os
22
import sys
33

4-
from yehua.main import HELP_TEXT, main, control_c_quit, get_yehua_file
5-
6-
from six import StringIO
74
from mock import patch
85
from nose.tools import eq_, raises
96

7+
from six import StringIO
8+
from yehua.main import HELP_TEXT, main, control_c_quit, get_yehua_file
9+
1010

1111
@patch("yehua.project.os.chdir")
1212
@patch("yehua.project._run_command")
@@ -63,6 +63,18 @@ def test_yehua_file_passed_in_command_line():
6363
mocked_project.assert_called()
6464

6565

66+
@patch("yehua.main.Project")
67+
@patch("yehua.main.cookiecutter_json_to_yehua_file")
68+
def test_gh_url(cookie_cutter_handler, mocked_project):
69+
from moban.exceptions import FileNotFound
70+
71+
args = ["yehua", "gh:org/repo"]
72+
cookie_cutter_handler.side_effect = FileNotFound
73+
with patch.object(sys, "argv", args):
74+
main()
75+
mocked_project.assert_called_with("git://github.com/org/repo.git")
76+
77+
6678
@raises(Exception)
6779
def test_a_directory_is_passed_in_command_line():
6880
args = ["yehua", "/"]
@@ -87,7 +99,7 @@ def test_get_yehua_file_2():
8799

88100

89101
def test_get_yehua_file_3():
90-
default_yehua_file = 'pypi://pypi-mobans-pkg/resources/yehua.yml'
102+
default_yehua_file = "pypi://pypi-mobans-pkg/resources/yehua.yml"
91103
yehua_file = get_yehua_file()
92104
eq_(default_yehua_file, yehua_file)
93105

tests/test_project.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
import codecs
44
import unittest
55

6-
from yehua.main import get_yehua_file
7-
from yehua.project import Project
8-
96
from mock import patch
107
from nose.tools import eq_, raises
118

9+
from yehua.main import get_yehua_file
10+
from yehua.project import Project
11+
1212

1313
@patch("yehua.utils.mkdir")
1414
@patch("yehua.project.get_user_inputs")

tests/test_yehua.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import shutil
44
from filecmp import dircmp
55

6-
from yehua.main import main
7-
86
from mock import patch
97

8+
from yehua.main import main
9+
1010

1111
@patch("yehua.project.get_user_inputs")
1212
def test_reference_pypi_package(fake_inputs):

yehua.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ organisation: "moremoban"
44
author: chfw
55
66
company: "Onni Software Ltd."
7-
version: "0.1.3"
8-
current_version: "0.1.3"
9-
release: "0.1.3"
7+
version: "0.1.4"
8+
current_version: "0.1.4"
9+
release: "0.1.4"
1010
copyright_year: 2017-2020
1111
command_line_interface: "yh"
1212
entry_point: "yehua.main:main"

yehua/_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
__version__ = "0.1.3"
1+
__version__ = "0.1.4"
22
__author__ = "chfw"

yehua/cookiecutter.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
import logging
33
from copy import deepcopy
44

5+
from jinja2 import Environment
6+
57
import yehua.utils as utils
68
from yehua.utils import dump_yaml, get_user_inputs
79
from yehua.project import Project
810

9-
from jinja2 import Environment
10-
1111
MOBAN_FILE_FOR_COOKIE_CUTTER = """
1212
configuration:
1313
template_dir:

yehua/cookiecutter_to_yehua.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import json
22
from io import StringIO
33

4-
from yehua.utils import dump_yaml, find_project_name
54
from moban.externals.file_system import is_dir, url_join, read_unicode
65

76
import fs
7+
from yehua.utils import dump_yaml, find_project_name
88

99
INTRODUCTION = """
1010
[info]Yehua /'jɛhwa/[/info] will walk you through cookiecutter template wizard

yehua/main.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
import logging
44
import argparse
55

6+
from moban.exceptions import FileNotFound
7+
68
from yehua.utils import get_yehua_file
79
from yehua.project import Project
810
from yehua._version import __version__
9-
from moban.exceptions import FileNotFound
1011
from yehua.cookiecutter import CookieCutter
1112
from yehua.cookiecutter_to_yehua import cookiecutter_json_to_yehua_file
1213

@@ -50,6 +51,11 @@ def main():
5051
if yehua_file.endswith("git") and yehua_file.startswith("https"):
5152
yehua_file = yehua_file.replace("https://", "git://")
5253

54+
if yehua_file.startswith("gh:"):
55+
yehua_file = yehua_file.replace("gh:", "git://github.com/")
56+
if not yehua_file.endswith(".git"):
57+
yehua_file = yehua_file + ".git"
58+
5359
yehua = cookiecutter_json_to_yehua_file(yehua_file)
5460
project = CookieCutter(yehua, yehua_file)
5561
except FileNotFound:

yehua/project.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
import subprocess
33
from datetime import datetime
44

5-
import yehua.utils as utils
6-
from yehua.utils import get_user_inputs
5+
from jinja2 import Environment
76
from moban.externals.file_system import exists, is_dir, read_unicode
87

98
import fs
10-
from jinja2 import Environment
9+
import yehua.utils as utils
10+
from yehua.utils import get_user_inputs
1111
from jinja2_fsloader import FSLoader
1212

1313

@@ -130,7 +130,7 @@ def _create_jj2_environment(self, path):
130130
loader=template_loader,
131131
keep_trailing_newline=True,
132132
trim_blocks=True,
133-
lstrip_blocks=True
133+
lstrip_blocks=True,
134134
)
135135
return environment
136136

yehua/utils.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
import shutil
55
import logging
66

7-
from yehua.theme import THEME
8-
from yehua.thirdparty import cutie
9-
10-
import fs
117
import colorful
128
from jinja2 import Environment
139
from ruamel.yaml import YAML
1410

11+
import fs
12+
from yehua.theme import THEME
13+
from yehua.thirdparty import cutie
14+
1515
DEFAULT_FILE = "yehua.yml"
16-
DEFAULT_PYPI_YEHUA_FILE = 'pypi://pypi-mobans-pkg/resources/yehua.yml'
16+
DEFAULT_PYPI_YEHUA_FILE = "pypi://pypi-mobans-pkg/resources/yehua.yml"
1717
ENVIRONMENT_KEY = "YEHUA_FILE"
1818
LOG = logging.getLogger(__name__)
1919

@@ -108,9 +108,7 @@ def get_user_inputs(questions): # refactor this later
108108
# {"foo": "foo [{{yehua.hello}}]"},
109109
# {"bar": "bar [{{cookiecutter.hello}}]"}
110110
template = env.from_string(question)
111-
question = template.render(
112-
cookiecutter=answers, **answers
113-
)
111+
question = template.render(cookiecutter=answers, **answers)
114112

115113
match = re.match(r"(.*)\[(.*)\].*", question)
116114
if match:

0 commit comments

Comments
 (0)