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

Commit f0c59d8

Browse files
Added python project content (#3)
2 parents 40b75f3 + 6bd8ce2 commit f0c59d8

34 files changed

+1464
-57
lines changed

.github/workflows/standard.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# ----------------------------------------------------------------------
2-
# SPDX-FileCopyrightText: 2024 Scientific Software Engineering Center <ssec-dev@gatech.edu>
3-
# SPDX-License-Identifier: MIT
2+
#
3+
# Copyright (c) 2024 Scientific Software Engineering Center at Georgia Tech
4+
# Distributed under the MIT License.
5+
#
46
# ----------------------------------------------------------------------
57
name: "Standard"
68

BootstrapEpilog.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# ----------------------------------------------------------------------
2-
# SPDX-FileCopyrightText: 2024 Scientific Software Engineering Center <ssec-dev@gatech.edu>
3-
# SPDX-License-Identifier: MIT
2+
# |
3+
# | Copyright (c) 2024 Scientific Software Engineering Center at Georgia Tech
4+
# | Distributed under the MIT License.
5+
# |
46
# ----------------------------------------------------------------------
57
# pylint: disable=missing-module-docstring
68

Build.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# ----------------------------------------------------------------------
2-
# SPDX-FileCopyrightText: 2024 Scientific Software Engineering Center <ssec-dev@gatech.edu>
3-
# SPDX-License-Identifier: MIT
2+
# |
3+
# | Copyright (c) 2024 Scientific Software Engineering Center at Georgia Tech
4+
# | Distributed under the MIT License.
5+
# |
46
# ----------------------------------------------------------------------
57
"""Build tasks for this python module."""
68

@@ -37,28 +39,33 @@ def list_commands(self, *args, **kwargs): # pylint: disable=unused-argument
3739
# ----------------------------------------------------------------------
3840
this_dir = PathEx.EnsureDir(Path(__file__).parent)
3941
src_dir = PathEx.EnsureDir(this_dir / "src")
42+
package_dir = PathEx.EnsureDir(src_dir / "PythonProjectBootstrapper")
4043
tests_dir = PathEx.EnsureDir(this_dir / "tests")
4144

4245

4346
# ----------------------------------------------------------------------
44-
Black = RepoBuildTools.BlackFuncFactory(this_dir, app)
47+
Black = RepoBuildTools.BlackFuncFactory(
48+
this_dir,
49+
app,
50+
'--force-exclude "{{ cookiecutter.__empty_dir }}"',
51+
)
4552

4653
Pylint = RepoBuildTools.PylintFuncFactory(
47-
src_dir / "PythonProjectBootstrapper",
54+
package_dir,
4855
app,
4956
default_min_score=9.5,
5057
)
5158

5259
Pytest = RepoBuildTools.PytestFuncFactory(
5360
tests_dir,
54-
"PythonProjectBootstrapper",
61+
package_dir.name,
5562
app,
5663
default_min_coverage=70.0,
5764
)
5865

5966
UpdateVersion = RepoBuildTools.UpdateVersionFuncFactory(
6067
src_dir,
61-
PathEx.EnsureFile(src_dir / "PythonProjectBootstrapper" / "__init__.py"),
68+
PathEx.EnsureFile(package_dir / "__init__.py"),
6269
app,
6370
)
6471

@@ -71,6 +78,8 @@ def list_commands(self, *args, **kwargs): # pylint: disable=unused-argument
7178
app,
7279
)
7380

81+
CreateDockerImage = RepoBuildTools.CreateDockerImageFuncFactory(this_dir, app)
82+
7483

7584
# ----------------------------------------------------------------------
7685
# ----------------------------------------------------------------------

src/BuildBinary.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
# ----------------------------------------------------------------------
2-
# SPDX-FileCopyrightText: 2024 Scientific Software Engineering Center <ssec-dev@gatech.edu>
3-
# SPDX-License-Identifier: MIT
2+
# |
3+
# | Copyright (c) 2024 Scientific Software Engineering Center at Georgia Tech
4+
# | Distributed under the MIT License.
5+
# |
46
# ----------------------------------------------------------------------
57
"""Builds the binary for this project."""
68

79
import datetime
810
import importlib
11+
import os
912
import textwrap
1013

1114
from pathlib import Path, PurePath
@@ -75,12 +78,25 @@
7578
# ----------------------------------------------------------------------
7679
_include_files: list[tuple[str, str]] = []
7780

78-
for child in PathEx.EnsureDir(
79-
_this_dir / "PythonProjectBootstrapper" / "python_project" / "hooks"
80-
).iterdir():
81-
relative_path = PurePath(*child.parts[len(_this_dir.parts) :])
81+
_project_root = PathEx.EnsureDir(_this_dir / "PythonProjectBootstrapper" / "python_project")
82+
_lib_path = PurePath("lib")
8283

83-
_include_files.append((relative_path.as_posix(), (PurePath("lib") / relative_path).as_posix()))
84+
for root, _, filenames in os.walk(_project_root):
85+
if not filenames:
86+
continue
87+
88+
root_path = Path(root)
89+
relative_path = PurePath(*root_path.parts[len(_this_dir.parts) :])
90+
91+
for filename in filenames:
92+
fullpath = root_path / filename
93+
94+
_include_files.append(
95+
(
96+
(relative_path / filename).as_posix(),
97+
(_lib_path / relative_path / filename).as_posix(),
98+
)
99+
)
84100

85101

86102
# ----------------------------------------------------------------------

src/PythonProjectBootstrapper/EntryPoint.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ----------------------------------------------------------------------
22
# |
3-
# | Copyright Scientific Software Engineering Center at Georgia Tech 2024
3+
# | Copyright (c) 2024 Scientific Software Engineering Center at Georgia Tech
44
# | Distributed under the MIT License.
55
# |
66
# ----------------------------------------------------------------------
@@ -19,6 +19,11 @@
1919
from dbrownell_Common import PathEx
2020
from PythonProjectBootstrapper import __version__
2121

22+
# The following imports are used in cookiecutter hooks. Import them here to
23+
# ensure that they are frozen when creating binaries,
24+
import shutil # pylint: disable=unused-import, wrong-import-order
25+
import textwrap # pylint: disable=unused-import, wrong-import-order
26+
2227

2328
# ----------------------------------------------------------------------
2429
class NaturalOrderGrouper(TyperGroup):
@@ -47,9 +52,6 @@ def list_commands(self, *args, **kwargs): # pylint: disable=unused-argument
4752
help="Filename that contains template configuration values; see https://cookiecutter.readthedocs.io/en/stable/advanced/user_config.html for more info.",
4853
)
4954

50-
_overwrite_option = typer.Option(
51-
"--overwrite", help="Overwrite the contents of the output directory if it exists."
52-
)
5355
_replay_option = typer.Option(
5456
"--replay", help="Do not prompt for input, instead read from saved json."
5557
)
@@ -79,7 +81,6 @@ def FrozenExecute(
7981
Path, typer.Argument(resolve_path=True, help="Directory to populate.")
8082
],
8183
configuration_filename: Annotated[Optional[Path], _configuration_filename_option] = None,
82-
overwrite: Annotated[bool, _overwrite_option] = False,
8384
replay: Annotated[bool, _replay_option] = False,
8485
version: Annotated[bool, _version_option] = False,
8586
) -> None:
@@ -93,7 +94,6 @@ def FrozenExecute(
9394
_ExecuteOutputDir(
9495
output_dir,
9596
configuration_filename,
96-
overwrite=overwrite,
9797
replay=replay,
9898
version=version,
9999
)
@@ -110,14 +110,12 @@ def StandardExecute(
110110
Path, typer.Argument(file_okay=False, resolve_path=True, help="Directory to populate.")
111111
],
112112
configuration_filename: Annotated[Optional[Path], _configuration_filename_option] = None,
113-
overwrite: Annotated[bool, _overwrite_option] = False,
114113
replay: Annotated[bool, _replay_option] = False,
115114
version: Annotated[bool, _version_option] = False,
116115
) -> None:
117116
_ExecuteOutputDir(
118117
output_dir,
119118
configuration_filename,
120-
overwrite=overwrite,
121119
replay=replay,
122120
version=version,
123121
)
@@ -133,7 +131,6 @@ def _ExecuteOutputDir(
133131
output_dir: Path,
134132
configuration_filename: Optional[Path],
135133
*,
136-
overwrite: bool,
137134
replay: bool,
138135
version: bool,
139136
) -> None:
@@ -146,7 +143,7 @@ def _ExecuteOutputDir(
146143
output_dir=str(output_dir),
147144
config_file=str(configuration_filename) if configuration_filename is not None else None,
148145
replay=replay,
149-
overwrite_if_exists=overwrite,
146+
overwrite_if_exists=True,
150147
accept_hooks=True,
151148
)
152149

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,30 @@
11
{
22
"name": "<your name>",
3-
"__empty_dir": ""
3+
"email": "<your email>",
4+
5+
"project_description": "<your project description>",
6+
7+
"license": [
8+
"MIT",
9+
"Apache-2.0",
10+
"BSD-3-Clause-Clear",
11+
"GPL-3.0-or-later",
12+
"BSL-1.0"
13+
],
14+
15+
"gist_id": "<your gist id>",
16+
17+
"github_url": "https://github.com",
18+
"github_username": "<your github username>",
19+
"github_project_name": "<your github repository>",
20+
"pypi_project_name": "{{ cookiecutter.github_project_name }}",
21+
22+
"create_docker_image": "no",
23+
24+
"__empty_dir": "",
25+
26+
"__prompts__": {
27+
},
28+
29+
"_extensions": ["local_extensions.pypi_string"]
430
}
Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,40 @@
11
# ----------------------------------------------------------------------
2-
# |
3-
# | Copyright Scientific Software Engineering Center at Georgia Tech 2024
4-
# | Distributed under the MIT License.
5-
# |
2+
#
3+
# Copyright (c) 2024 Scientific Software Engineering Center at Georgia Tech
4+
# Distributed under the MIT License.
5+
#
66
# ----------------------------------------------------------------------
7+
import shutil
8+
import sys
9+
import textwrap
10+
11+
from pathlib import Path
12+
from typing import Callable
13+
14+
from dbrownell_Common import PathEx
715
from rich import print
816

917

18+
# ----------------------------------------------------------------------
19+
def UpdateLicenseFile():
20+
this_dir = Path.cwd()
21+
licenses_dir = PathEx.EnsureDir(this_dir / "Licenses")
22+
23+
license_name = "{{ cookiecutter.license }}"
24+
25+
if license_name == "BSL-1.0":
26+
source_file = licenses_dir / "BST-1.0_LICENSE_1_0.txt"
27+
else:
28+
source_file = licenses_dir / "{}_LICENSE.txt".format(license_name)
29+
30+
PathEx.EnsureFile(source_file)
31+
dest_file = this_dir / source_file.name[len(license_name) + 1 :]
32+
33+
shutil.copy(source_file, dest_file)
34+
shutil.rmtree(licenses_dir)
35+
36+
37+
UpdateLicenseFile()
38+
39+
1040
print("Hello, [bold magenta]World[/bold magenta]!", ":vampire:", locals())
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# ----------------------------------------------------------------------
2+
# |
3+
# | Copyright (c) 2024 Scientific Software Engineering Center at Georgia Tech
4+
# | Distributed under the MIT License.
5+
# |
6+
# ----------------------------------------------------------------------
7+
errors: list[str] = []
8+
9+
# fmt: off
10+
if "{{ cookiecutter.name }}".startswith("<") and "{{ cookiecutter.name }}".endswith(">"):
11+
errors.append('name ("{{ cookiecutter.name }}")')
12+
if "{{ cookiecutter.email }}".startswith("<") and "{{ cookiecutter.email }}".endswith(">"):
13+
errors.append('email ("{{ cookiecutter.email }}")')
14+
if "{{ cookiecutter.project_description }}".startswith("<") and "{{ cookiecutter.project_description }}".endswith(">"):
15+
errors.append('project_description ("{{ cookiecutter.project_description }}")')
16+
if "{{ cookiecutter.gist_id }}".startswith("<") and "{{ cookiecutter.gist_id }}".endswith(">"):
17+
errors.append('gist_id ("{{ cookiecutter.gist_id }}")')
18+
if "{{ cookiecutter.github_username }}".startswith("<") and "{{ cookiecutter.github_username }}".endswith(">"):
19+
errors.append('github_username ("{{ cookiecutter.github_username }}")')
20+
# fmt: on
21+
22+
if errors:
23+
raise Exception(
24+
"Required data has not been populated:\n{}".format(
25+
"\n".join(" - {}".format(e) for e in errors)
26+
)
27+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# ----------------------------------------------------------------------
2+
# |
3+
# | Copyright (c) 2024 Scientific Software Engineering Center at Georgia Tech
4+
# | Distributed under the MIT License.
5+
# |
6+
# ----------------------------------------------------------------------
7+
from cookiecutter.utils import simple_filter
8+
9+
10+
# ----------------------------------------------------------------------
11+
@simple_filter
12+
def pypi_string(value):
13+
return value.lower().replace("_", "-")
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# ----------------------------------------------------------------------
2+
# |
3+
# | Copyright (c) {% now 'utc', '%Y' %} {{ cookiecutter.name }}
4+
# | Distributed under the {{ cookiecutter.license }} License.
5+
# |
6+
# ----------------------------------------------------------------------

0 commit comments

Comments
 (0)