Skip to content

Commit

Permalink
Merge pull request #24 from seapagan/tidy-standalone-templates
Browse files Browse the repository at this point in the history
use conditional logic in templates
  • Loading branch information
seapagan authored Jul 28, 2023
2 parents daed0f3 + d673391 commit 62936b6
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
19 changes: 7 additions & 12 deletions py_maker/pymaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from pathlib import Path, PurePath
from typing import Union

import rtoml
from git.config import GitConfigParser
from git.exc import GitError
from git.repo import Repo
Expand Down Expand Up @@ -132,6 +131,9 @@ def copy_template_files(self) -> None:
jinja_env = Environment(
loader=FileSystemLoader(str(template_dir)),
autoescape=True,
trim_blocks=True,
lstrip_blocks=True,
keep_trailing_newline=True,
)
for item in file_list:
with pkg_resources.as_file(template_dir / item) as src:
Expand All @@ -156,6 +158,7 @@ def copy_template_files(self) -> None:
license_env = Environment(
loader=FileSystemLoader(str(template_dir / "../licenses")),
autoescape=True,
keep_trailing_newline=True,
)
license_template = license_env.get_template(
f"{self.choices.license}.jinja"
Expand All @@ -178,17 +181,6 @@ def copy_template_files(self) -> None:
Path(self.choices.project_dir / "main.py")
)
shutil.rmtree(self.choices.project_dir / "app")
# remove script setting from pyproject.toml
toml_file = rtoml.load(
Path(self.choices.project_dir) / "pyproject.toml"
)
for key in ["packages", "urls", "scripts"]:
del toml_file["tool"]["poetry"][key]
rtoml.dump(
toml_file,
Path(self.choices.project_dir) / "pyproject.toml",
pretty=True,
)
except OSError as exc:
print(f"\n[red] -> {exc}")
sys.exit(ExitErrors.OS_ERROR)
Expand Down Expand Up @@ -282,6 +274,9 @@ def run(self) -> None:
default="MIT",
)

if self.choices.package_name == "-":
self.choices.standalone = True

if not self.confirm_values():
# User chose not to continue
print("\n[red]Aborting![/red]")
Expand Down
2 changes: 2 additions & 0 deletions py_maker/schema.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Define some Pydantic schemas for the application."""
from pathlib import Path
from typing import Optional

from pydantic import BaseModel

Expand All @@ -22,3 +23,4 @@ class ProjectValues(ProjectSettings):

project_dir: Path = Path("")
name: str = ""
standalone: Optional[bool] = False
2 changes: 1 addition & 1 deletion py_maker/template/README.md.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ then the script name, for example:
$ poe pre
```

You can define your own, but there are 5 specific ones provided with the script.
You can define your own, but there are 7 specific ones provided with the script.

- `pre` : Run `pre-commit run --all-files`
- `pylint`: Run Pylint on all Python files in the project.
Expand Down
2 changes: 2 additions & 0 deletions py_maker/template/app/main.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

You can customize this file to your liking, or indeed empty it entirely and
start from scratch.
{% if not standalone %}
Note that if you remove the 'App' class entirely, you will need to remove the
`[tool.poetry.scripts]` section from pyproject.toml as well (if it exist).
{% endif %}
"""


Expand Down
9 changes: 5 additions & 4 deletions py_maker/template/pyproject.toml.jinja
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
[tool.poetry]
name = "{{ name }}"
name = "{{ slug }}"
version = "0.1.0"
description = "{{ description }}."
authors = ["{{ author }} <{{ email }}>"]
readme = "README.md"
license = "{{ license }}"

{% if not standalone %}
packages = [{ include = "{{ package_name }}" }]

[tool.poetry.urls]
# customize the below URLs to point to your own GitHub repo. These will be
# shown on [Pypi.org](https://pypi.org/) if you are creating a public package.
#"Pull Requests" = "https://github.com/seapagan/py-maker/pulls"
#"Bug Tracker" = "https://github.com/seapagan/py-maker/issues"

"Pull Requests" = "https://github.com/seapagan/{{ slug }}/pulls"
"Bug Tracker" = "https://github.com/seapagan/{{ slug }}/issues"
[tool.poetry.scripts]
# rename "{{ slug }}" below to change the executable name. You can also
# add more scripts if your package offers multiple commands.
{{ slug }} = "{{ package_name }}.main:app"
{% endif %}

[tool.poetry.dependencies]
python = ">=3.9,<4.0"
Expand Down

0 comments on commit 62936b6

Please sign in to comment.