Skip to content

Commit

Permalink
v24.11.8
Browse files Browse the repository at this point in the history
  • Loading branch information
GitRon committed Nov 29, 2024
1 parent 4817a69 commit 7f04243
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
6 changes: 5 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

**24.11.7 (2024-11-20)**
**24.11.8 (2024-11-29)**
* Added version variable to template context
* Small code improvements in rendering logic

**24.11.7 (2024-11-29)**
* Added possibility to add script executables
* Added flag for non-django packages
* Fixed a "None" value on empty Readme content template
Expand Down
2 changes: 1 addition & 1 deletion ambient_package_update/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Ambient package update tool for clean and swift maintenance"""

__version__ = "24.11.7"
__version__ = "24.11.8"
10 changes: 7 additions & 3 deletions ambient_package_update/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def get_metadata() -> PackageMetadata:
return m.METADATA


def create_rendered_file(*, template: Path, relative_target_path: Path | str) -> None:
def create_rendered_file(*, template: Path | str, relative_target_path: Path | str) -> None:
"""
Takes a template Path object and renders a template in the target package.
"""
Expand All @@ -54,6 +54,10 @@ def create_rendered_file(*, template: Path, relative_target_path: Path | str) ->
)

j2_template = env.get_template(str(template).replace("\\", "/"))
variable_namespace = {}
with open(Path.cwd() / metadata_dict["module_name"] / "__init__.py") as f:
exec(f.read(), {}, variable_namespace) # Führt den Code in einem isolierten Namespace aus
j2_template.globals["version"] = variable_namespace["__version__"]
j2_template.globals["current_year"] = datetime.now(tz=UTC).date().year
j2_template.globals["license_label"] = (
"GNU General Public License (GPL)" if metadata_dict["license"] == LICENSE_GPL else "MIT License"
Expand All @@ -74,7 +78,7 @@ def create_rendered_file(*, template: Path, relative_target_path: Path | str) ->
print(f'> Successfully rendered template "{abs_path}".')


def get_template_list(*, include_snippets: bool = False) -> list[str]:
def get_template_list(*, include_snippets: bool = False) -> list[str | Path]:
template_list = [
str(Path(Path(path).relative_to(TEMPLATE_PATH), file))
for path, subdirs, files in os.walk(TEMPLATE_PATH)
Expand All @@ -100,7 +104,7 @@ def render_templates():
relative_target_path=template.removesuffix(".tpl"),
)

# License file is conditional so we have to render it separately
# The licence file is conditional, so we have to render it separately
metadata_dict = get_metadata().__dict__
create_rendered_file(
template=f"snippets/licenses/{metadata_dict['license']}.md",
Expand Down

0 comments on commit 7f04243

Please sign in to comment.