-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from seapagan/improve-cli-metadata
Add improvements to the CLI metadata generation.
- Loading branch information
Showing
8 changed files
with
100 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,20 @@ | ||
"""CLI functionality to customize the template.""" | ||
import os | ||
import sys | ||
from pathlib import Path | ||
|
||
from datetime import date | ||
|
||
import asyncclick as click | ||
import tomli | ||
import tomli_w | ||
from jinja2 import Template | ||
from rich import print | ||
|
||
from config.helpers import LICENCES, template | ||
|
||
|
||
def get_config_path(): | ||
"""Return the full path of the custom config file.""" | ||
script_dir = Path(os.path.dirname(os.path.realpath(sys.argv[0]))) | ||
return script_dir / "config" / "metadata.py" | ||
|
||
|
||
def get_toml_path(): | ||
"""Return the full path of the pyproject.toml.""" | ||
script_dir = Path(os.path.dirname(os.path.realpath(sys.argv[0]))) | ||
return script_dir / "pyproject.toml" | ||
from config.helpers import ( | ||
LICENCES, | ||
get_api_version, | ||
get_config_path, | ||
get_toml_path, | ||
template, | ||
) | ||
|
||
|
||
def init(): | ||
|
@@ -36,6 +29,8 @@ def init(): | |
}, | ||
"author": "Grant Ramsay (seapagan)", | ||
"website": "https://www.gnramsay.com", | ||
"email": "[email protected]", | ||
"this_year": date.today().year, | ||
} | ||
|
||
out = Template(template).render(data) | ||
|
@@ -80,7 +75,7 @@ def choose_license(): | |
|
||
while choice.strip().lower() not in [lic.lower() for lic in license_list]: | ||
choice = click.prompt( | ||
f"\nChoose a license from the following options.\n" | ||
f"\nChoose a license from the following options:\n" | ||
f"{license_strings}\nYour Choice of License?", | ||
type=str, | ||
default=custom_metadata.license_info["name"], | ||
|
@@ -89,6 +84,18 @@ def choose_license(): | |
return get_case_insensitive_dict(choice) | ||
|
||
|
||
def choose_version(current_version): | ||
"""Change the version or reset it.""" | ||
choice = click.prompt( | ||
"Version Number (use * to reset to '0.0.1')", | ||
type=str, | ||
default=current_version, | ||
) | ||
if choice == "*": | ||
return "0.0.1" | ||
return choice | ||
|
||
|
||
@click.group(name="custom") | ||
def customize_group(): | ||
"""Customize the Template Strings and Metadata. | ||
|
@@ -105,6 +112,7 @@ def metadata(): | |
Documentation, Author details, Repository URL and more. | ||
""" | ||
print("\n[green]API-Template : Customize application Metadata\n") | ||
|
||
data = { | ||
"title": click.prompt( | ||
"Enter your API title", type=str, default=custom_metadata.title | ||
|
@@ -114,6 +122,7 @@ def metadata(): | |
type=str, | ||
default=custom_metadata.description, | ||
), | ||
"version": choose_version(get_api_version()), | ||
"repo": click.prompt( | ||
"URL to your Repository", | ||
type=str, | ||
|
@@ -136,14 +145,19 @@ def metadata(): | |
default=custom_metadata.contact["url"], | ||
), | ||
} | ||
|
||
data["this_year"] = date.today().year | ||
|
||
print("\nYou have entered the following data:") | ||
print(f"[green]Title : [/green]{data['title']}") | ||
print(f"[green]Description : [/green]{data['desc']}") | ||
print(f"[green]Version : [/green]{data['version']}") | ||
print(f"[green]Repository : [/green]{data['repo']}") | ||
print(f"[green]License : [/green]{data['license']['name']}") | ||
print(f"[green]Author : [/green]{data['author']}") | ||
print(f"[green]Email : [/green]{data['email']}") | ||
print(f"[green]Website : [/green]{data['website']}") | ||
print(f"[green](C) Year : [/green]{data['this_year']}") | ||
|
||
if click.confirm("\nIs this Correct?", abort=True, default=True): | ||
# write the metadata | ||
|
@@ -161,6 +175,7 @@ def metadata(): | |
with open(get_toml_path(), "rb") as f: | ||
config = tomli.load(f) | ||
config["tool"]["poetry"]["name"] = data["title"] | ||
config["tool"]["poetry"]["version"] = data["version"] | ||
config["tool"]["poetry"]["description"] = data["desc"] | ||
config["tool"]["poetry"]["authors"] = [ | ||
f"{data['author']} <{data['email']}>" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,8 +14,9 @@ | |
"url": "https://opensource.org/licenses/MIT", | ||
}, | ||
contact={ | ||
"name": "Grant Ramsay", | ||
"name": "Grant Ramsay (seapagan)", | ||
"url": "https://www.gnramsay.com", | ||
}, | ||
email="[email protected]", | ||
year="2023" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
[tool.poetry] | ||
name = "API Template" | ||
version = "1.3.0" | ||
version = "1.3.1" | ||
description = "Run 'api-admin custom metadata' to change this information." | ||
authors = ["Grant Ramsay <[email protected]>"] | ||
authors = [ | ||
"Grant Ramsay (seapagan) <[email protected]>", | ||
] | ||
license = "MIT" | ||
readme = "README.md" | ||
|
||
|
@@ -23,20 +25,31 @@ anyio = "^3.6.2" | |
email-validator = "^1.3.1" | ||
tomli = "^2.0.1" | ||
tomli-w = "^1.0.0" | ||
fastapi-mail = { extras = ["httpx"], version = "^1.2.0" } | ||
|
||
[tool.poetry.dependencies.fastapi-mail] | ||
extras = [ | ||
"httpx", | ||
] | ||
version = "^1.2.0" | ||
|
||
[tool.poetry.dependencies.uvicorn] | ||
extras = ["standard"] | ||
extras = [ | ||
"standard", | ||
] | ||
version = "^0.20.0" | ||
|
||
[tool.poetry.dependencies.passlib] | ||
extras = ["bcrypt"] | ||
extras = [ | ||
"bcrypt", | ||
] | ||
version = "^1.7.4" | ||
|
||
[tool.poetry.group.dev.dependencies] | ||
openapi-readme = "^0.2.1" | ||
aiosmtpd = "^1.4.4" | ||
|
||
[build-system] | ||
requires = ["poetry-core"] | ||
requires = [ | ||
"poetry-core", | ||
] | ||
build-backend = "poetry.core.masonry.api" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters