Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit bcfd39b

Browse files
Addressed usability issues encountered when generating a project (#13)
2 parents f374fe0 + 0e70cc2 commit bcfd39b

File tree

5 files changed

+47
-36
lines changed

5 files changed

+47
-36
lines changed

src/PopulateCookiecutterPrompts.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ def Replace(
6363
",\n".join(
6464
'"{}": "{}"'.format(
6565
key,
66-
"\n\n{}{}".format(value, "\n\n" if "\n" in value else "")
67-
.replace("\n", "\\n")
68-
.replace('"', '\\"'),
66+
"\n\n{}\n\n".format(value).replace("\n", "\\n").replace('"', '\\"'),
6967
)
7068
for key, value in yaml_content.items()
7169
),

src/PythonProjectBootstrapper/package/cookiecutter.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"gist_id": "<your gist id>",
2121
"gist_username": "{{ cookiecutter.github_username }}",
2222

23-
"create_docker_image": "no",
23+
"create_docker_image": false,
2424

2525
"__empty_dir": "",
2626

@@ -36,7 +36,7 @@
3636
"github_project_name": "\n\nPlease enter your GitHub project name. You should use the URL to your GitHub repository as a guide\nwhen specifying this value.\n\n https://github.com/username/projectname\n ^^^^^^^^^^^\n This is the GitHub project name\n\n",
3737
"pypi_project_name": "\n\nPlease enter the name of your project as it will appear on PyPI (https://pypi.org). This\nname cannot be associated with any other project on PyPI.\n\n",
3838
"gist_id": "\n\nPlease enter the GitHub gist id for use with this project.\n\nGitHub defines a gist as \"a simple way to share snippets and pastes with others.\" The generated\npython project will use a gist to store information dynamically generated during the build (for\nexample code coverage information) that can be retrieved at a later time (for example, to display\na code coverage badge in the project's README.md file).\n\nTo create a gist:\n 1. Go to https://gist.github.com/\n 2. Enter the following values in their respective fields:\n\n Gist description...: Gist used by GitHub Action workflows to store and retrieve dynamic information (oftentimes used to create and display badges).\n Filename including extension...: README.md\n File contents: Gist used by GitHub Action workflows to store and retrieve dynamic information (oftentimes used to create and display badges).\n\n 3. Click the \"Create secret gist\" button\n 4. Copy the gist id (this will be the hex string at the end of the url associated with the gist\n that was just created). It will look something like:\n\n https://gist.github.com/<github username>/4c10281ff1abc26cafcb9a5f9a8a443e\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n This is the gist id\n\n",
39-
"gist_username": "\n\nPlease enter the username associated with your gist_id. In most cases, this will be the same as your GitHub username.",
39+
"gist_username": "\n\nPlease enter the username associated with your gist_id. In most cases, this will be the same as your GitHub username.\n\n",
4040
"create_docker_image": "\n\nWould you like the GitHub Action workflows to create docker images of the development environment?\nThese images can be used to produce exact results across different commits made to the repository\nover time (which is especially valuable when writing scientific software).\n\n"
4141
},
4242

src/PythonProjectBootstrapper/package/cookiecutter_prompts.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ gist_id: |-
8484
https://gist.github.com/<github username>/4c10281ff1abc26cafcb9a5f9a8a443e
8585
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8686
This is the gist id
87+
8788
gist_username: |-
8889
Please enter the username associated with your gist_id. In most cases, this will be the same as your GitHub username.
8990

src/PythonProjectBootstrapper/package/hooks/post_gen_project.py

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@
1818

1919

2020
# ----------------------------------------------------------------------
21-
_prompts: dict[str, str] = {
21+
_prefix_prompts: dict[str, str] = {
2222
"GitHub Personal Access Token for gists": textwrap.dedent(
2323
"""\
24-
In this step, we will create a GitHub Personal Access Token (PAT) that is used to
25-
update the gist that stores dynamic build data.
24+
In this step, we will create a GitHub Personal Access Token (PAT) that is used to update the gist that stores dynamic build data.
2625
2726
1. Visit {{ cookiecutter.github_url }}/settings/tokens?type=beta
2827
2. Click the "Generate new token" button
@@ -54,16 +53,13 @@
5453
),
5554
"Temporary PyPi Token to Publish Packages": textwrap.dedent(
5655
"""\
57-
In this step, we will create a PyPi token that is used to publish python packages. Note
58-
that this token will be scoped to all of your projects on PyPi. Once the package is
59-
published for the first time, we will delete this token and create one that is scoped to
60-
a single project.
56+
In this step, we will create a PyPi token that is used to publish python packages. Note that this token will be scoped to all of your projects on PyPi. Once the package is published for the first time, we will delete this token and create one that is scoped to a single project.
6157
6258
1. Visit https://pypi.org/manage/account/
6359
2. Click the "Add API token" button
6460
3. Enter the values:
65-
Token name: "Temporary GitHub Publish Action ({{ cookiecutter.github_project_name }})"
66-
Scope: "Entire account (all projects)"
61+
Token name: Temporary GitHub Publish Action ({{ cookiecutter.github_project_name }})
62+
Scope: Entire account (all projects)
6763
4. Click the "Create token" button
6864
5. Click the "Copy token" button for use in the next step
6965
""",
@@ -81,38 +77,50 @@
8177
5. Click the "Add secret" button
8278
""",
8379
),
84-
"Commit and Push the Repository": textwrap.dedent(
80+
}
81+
82+
if {{cookiecutter.create_docker_image}}:
83+
_prefix_prompts["Update GitHub Seettings"] = textwrap.dedent(
8584
"""\
86-
In this step, we commit the files generated in git, push the changes in GitHub, and verify
87-
that the GitHub Actions workflow ran successfully.
85+
In this step, we will update GitHub settings to allow pushing the generated docker image to the GitHub Container Registry during the build.
86+
87+
1. Visit {{ cookiecutter.github_url }}/{{ cookiecutter.github_username }}/{{ cookiecutter.github_project_name }}/settings/actions
88+
2. In the "Workflow permissions" section...
89+
3. Select "Read and write permissions"
90+
4. Click the "Save" button
91+
""",
92+
)
8893

89-
Commit and Push the Changes
90-
---------------------------
91-
Note that these steps assume that the GitHub repository has already been created.
94+
_prompts: dict[str, str] = {
95+
"Commit and Push the Repository": textwrap.dedent(
96+
"""\
97+
In this step, we commit the files generated in git and push the changes to GitHub. Note that these steps assume that the GitHub repository has already been created.
9298
9399
From a terminal:
94100
95101
1. Run 'git add -all'
96102
{windows_command}{commit_step_num}. Run 'git commit -m "🎉 Initial commit"'
97103
{push_step_num}. Run 'git push'
98-
99-
Verify the GitHub Actions Workflow
100-
----------------------------------
101-
1. Visit {{ cookiecutter.github_url }}/{{ cookiecutter.github_username }}/{{ cookiecutter.github_project_name }}/actions
102-
2. Click on the most recent workflow
103-
3. Wait for the workflow to complete
104104
""",
105105
).format(
106106
windows_command=(
107-
"2. git update-index --chmod=+x Bootstrap.sh\n" if os.name == "nt" else ""
107+
"2. Run 'git update-index --chmod=+x Bootstrap.sh'\n" if os.name == "nt" else ""
108108
),
109109
commit_step_num="3" if os.name == "nt" else "2",
110110
push_step_num="4" if os.name == "nt" else "3",
111111
),
112+
"Verify GitHub Actions": textwrap.dedent(
113+
"""\
114+
In this step, we will verify that the GitHub Action workflows ran successfully.
115+
116+
1. Visit {{ cookiecutter.github_url }}/{{ cookiecutter.github_username }}/{{ cookiecutter.github_project_name }}/actions
117+
2. Click on the most recent workflow
118+
3. Wait for the workflow to complete
119+
""",
120+
),
112121
"Remove Temporary PyPi Token": textwrap.dedent(
113122
"""\
114-
In this step, we will delete the temporary PyPi token previously created. A new token to replace
115-
it will be created in the steps that follow.
123+
In this step, we will delete the temporary PyPi token previously created. A new token to replace it will be created in the steps that follow.
116124
117125
1. Visit https://pypi.org/manage/account/
118126
2. Find the token named "Temporary GitHub Publish Action ({{ cookiecutter.github_project_name }})"...
@@ -130,8 +138,8 @@
130138
1. Visit https://pypi.org/manage/account/
131139
2. Click the "Add API token" button
132140
3. Enter the values:
133-
Token name: "GitHub Publish Action ({{ cookiecutter.github_project_name }})"
134-
Scope: "Project: {{ cookiecutter.pypi_project_name }}"
141+
Token name: GitHub Publish Action ({{ cookiecutter.github_project_name }})
142+
Scope: Project: {{ cookiecutter.pypi_project_name }}
135143
4. Click the "Create token" button
136144
5. Click the "Copy token" button for use in the next step
137145
""",
@@ -179,16 +187,20 @@ def UpdateLicenseFile():
179187
# ----------------------------------------------------------------------
180188
def DisplayPrompts():
181189
border_colors = itertools.cycle(
182-
["green", "yellow", "blue", "magenta", "cyan"],
190+
["yellow", "blue", "magenta", "cyan", "green"],
183191
)
184192

185-
for prompt_index, (title, prompt) in enumerate(_prompts.items()):
193+
sys.stdout.write("\n\n")
194+
195+
prompts = list(itertools.chain(_prefix_prompts.items(), _prompts.items()))
196+
197+
for prompt_index, (title, prompt) in enumerate(prompts):
186198
print(
187199
Panel(
188-
prompt.strip(),
200+
prompt.rstrip(),
189201
border_style=next(border_colors),
190202
padding=1,
191-
title=f"[{prompt_index + 1}/{len(_prompts)}] {title}",
203+
title=f"[{prompt_index + 1}/{len(prompts)}] {title}",
192204
title_align="left",
193205
),
194206
)

src/PythonProjectBootstrapper/package/hooks/startup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def Execute(
3333
step-by-step instructions on how to set up your project so that it works with 3rd party
3434
solutions (GitHub, PyPi, etc.).
3535
36-
The entire process should take about 10 minutes to complete.
36+
The entire process should take about 20 minutes to complete.
3737
""",
3838
)
3939

0 commit comments

Comments
 (0)