Skip to content

Commit

Permalink
Merge pull request #21 from seapagan/move-licenses
Browse files Browse the repository at this point in the history
Move licenses out of template folder
  • Loading branch information
seapagan authored Jul 26, 2023
2 parents 3d28f00 + f451734 commit 0b851c8
Show file tree
Hide file tree
Showing 14 changed files with 16 additions and 10 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 4 additions & 1 deletion py_maker/prompt.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"""Subclass the Prompt class from Rich to add a few features.
I have a PR open to add these features to Rich, but until it is merged (if it is
merged) I will use this subclass.
Currently only makes the choices case-insensitive.
"""
from rich.prompt import Confirm as RichConfirm
Expand All @@ -9,7 +12,7 @@


class Confirm(RichConfirm):
"""Just so we can import it from the same place as IPrompt.
"""Just so we can import it from the same place as our Prompt.
Saves importing from the Rich library.
"""
Expand Down
21 changes: 12 additions & 9 deletions py_maker/pymaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,20 @@ def copy_template_files(self) -> None:
'README.md.jinja' is copied as 'README.md' after template substitution.
"""
template_dir = pkg_resources.files(template)
skip_dirs = ["__pycache__", "licenses"]

skip_dirs = ["__pycache__"]
file_list = [
item.relative_to(template_dir)
for item in template_dir.rglob("*") # type: ignore[attr-defined]
if set(item.parts).isdisjoint(skip_dirs)
]

# set up Jinja environment
jinja_env = Environment(
loader=FileSystemLoader(str(template_dir)),
autoescape=True,
)

try:
# ---------------------- copy all the files ---------------------- #
jinja_env = Environment(
loader=FileSystemLoader(str(template_dir)),
autoescape=True,
)
for item in file_list:
with pkg_resources.as_file(template_dir / item) as src:
if src.is_dir():
Expand All @@ -154,8 +153,12 @@ def copy_template_files(self) -> None:
dst.write_text(src.read_text(encoding="UTF-8"))

# ---------------- generate the license file next. ------------- #
license_template = jinja_env.get_template(
f"licenses/{self.choices.license}.jinja"
license_env = Environment(
loader=FileSystemLoader(str(template_dir / "../licenses")),
autoescape=True,
)
license_template = license_env.get_template(
f"{self.choices.license}.jinja"
)
dst = self.choices.project_dir / "LICENSE.txt"
dst.write_text(
Expand Down

0 comments on commit 0b851c8

Please sign in to comment.