-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmdakitter
executable file
·169 lines (151 loc) · 4.51 KB
/
mdakitter
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/usr/bin/env python
import argparse
from cookiecutter.main import cookiecutter
parser = argparse.ArgumentParser("Cookiecutter for MDAKits")
parser.add_argument(
"--project-name",
type=str,
help="Project name you would write in words",
required=False,
default="MyMDAKit"
)
parser.add_argument(
"--repo-name",
type=str,
help="Repository name used for directory names and URLs",
required=False,
)
parser.add_argument(
"--package-name",
type=str,
help="Package name used to install",
required=False,
)
parser.add_argument(
"--description",
type=str,
help="Description of your new project",
default="",
required=False,
)
parser.add_argument(
"--github-username",
type=str,
help="Your GitHub username",
required=True,
)
parser.add_argument(
"--github-host-account",
type=str,
help="Your GitHub host account; this can be the same or different as your username",
required=False,
)
parser.add_argument(
"--author-name",
type=str,
help="Your name",
required=False,
)
parser.add_argument(
"--author-email",
type=str,
help="Your email address",
required=False,
)
parser.add_argument(
"--dependency-source",
choices=["conda-forge", "anaconda", "pip"],
help=(
"Source to choose for dependencies. "
"'conda-forge' prefers conda-forge over the default anaconda channel with pip fallback. "
"'anaconda' prefers default anaconda channel with pip fallback. "
"'pip' uses dependencies from pip only (no conda)"
),
default="conda-forge",
required=False,
)
parser.add_argument(
"--without-ReadTheDocs",
action="store_true",
help="Do not include ReadTheDocs support",
required=False,
)
parser.add_argument(
"--template_analysis_class",
type=str,
help="Name of the analysis class to use in the template",
required=False,
default=""
)
parser.add_argument(
"--template",
type=str,
help="Template to use. Either a path to a directory, or URL to a cookiecutter template",
default="https://github.com/MDAnalysis/cookiecutter-mdakit")
parser.add_argument(
"--output-directory",
type=str,
help="Directory to create the cookie in",
default=".")
def preprocess_kwargs(**kwargs):
REPLACE_KEYS = {
"dependency_source": "__dependency_source",
"output_directory": "output_dir",
}
processed = {}
for key, value in kwargs.items():
if key == "without_ReadTheDocs":
key = "include_ReadTheDocs"
value = "n" if value else "y"
if key in REPLACE_KEYS:
key = REPLACE_KEYS[key]
processed[key] = value
return processed
def process_package_names(**kwargs):
kwargs = dict(kwargs)
if kwargs.get("project_name") is None:
raise ValueError("Project name must be specified")
if kwargs.get("repo_name") is None:
kwargs["repo_name"] = kwargs["project_name"].replace(" ", "-")
if kwargs.get("package_name") is None:
kwargs["package_name"] = kwargs["repo_name"].replace("-", "_")
if kwargs.get("description") is None:
kwargs["description"] = kwargs["project_name"]
return kwargs
def process_author_details(**kwargs):
kwargs = dict(kwargs)
if kwargs.get("github_username") is None:
raise ValueError("GitHub username must be specified")
if kwargs.get("github_host_account") is None:
kwargs["github_host_account"] = kwargs["github_username"]
if kwargs.get("author_name") is None:
kwargs["author_name"] = kwargs["github_username"]
if kwargs.get("author_email") is None:
kwargs["author_email"] = f"{kwargs['github_username']}@users.noreply.github.com"
return kwargs
def process_missing_kwargs(**kwargs):
kwargs = dict(kwargs)
kwargs = process_package_names(**kwargs)
kwargs = process_author_details(**kwargs)
return kwargs
def run_cookiecutter(**kwargs):
COOKIECUTTER_KWARGS = ["output_dir"]
cookiecutter_kwargs = {}
extra_context = {}
template = kwargs.pop("template")
for key, value in kwargs.items():
if key in COOKIECUTTER_KWARGS:
cookiecutter_kwargs[key] = value
else:
extra_context[key] = value
return cookiecutter(
template,
no_input=True,
extra_context=extra_context,
**cookiecutter_kwargs
)
if __name__ == "__main__":
args = parser.parse_args()
kwargs = preprocess_kwargs(**vars(args))
kwargs = process_missing_kwargs(**kwargs)
run_cookiecutter(**kwargs)