Skip to content

Commit

Permalink
bump to 1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
zackees committed Mar 29, 2023
1 parent 3e92bd9 commit d1cf185
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 13 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ This environment requires you to use `git-bash`.
# Linting

Run `./lint.sh` to find linting errors using `pylint`, `flake8` and `mypy`.

# Versions

* 1.0.1: Adds +x to all shell scripts
* 1.0.0: Initial commit
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies = [
]
# Change this with the version number bump.
# Also make the change in zcmds/version.py
version = "1.0.0"
version = "1.0.1"

[tool.pylint."MESSAGES CONTROL"]
good-names = [
Expand Down
38 changes: 29 additions & 9 deletions src/createfastapiapp/createapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,30 @@


import os
import tempfile
import shutil
import tempfile
from typing import Optional


TEMPLATE_PROJECT_URL = "https://github.com/zackees/template-fastapi-project"
DIR_MATCH = "fastapi_template_project"


def check_name(app_name: str) -> None:
"""Check the name of the application."""
if not app_name.isidentifier():
raise ValueError("The name of the application is not a valid Python identifier.")
raise ValueError(
"The name of the application is not a valid Python identifier."
)


def check_semantic_version(version: str) -> None:
"""Check the version of the application."""
version_list = version.split(".")
for v in version_list:
if not v.isnumeric():
raise ValueError("The version of the application is not a valid semantic version.")
raise ValueError(
"The version of the application is not a valid semantic version."
)


def remove_double_blank_lines(lines: list) -> list:
Expand Down Expand Up @@ -140,23 +143,33 @@ def do_create_fastapi_app(
replace_in_file(file, "fastapi_template_project", app_name_underscore)
# TODO: template_fastapi_project -> fastapi_template_project
replace_in_file(
os.path.join(app_dir, "app.py"), "template_fastapi_project", app_name_underscore
os.path.join(app_dir, "app.py"),
"template_fastapi_project",
app_name_underscore,
)
replace_in_file(
os.path.join(app_dir, "app.py"), "FastAPI Template Project", app_name_underscore
os.path.join(app_dir, "app.py"),
"FastAPI Template Project",
app_name_underscore,
)
########
# Transform run_dev.py with new imports
replace_in_file(
os.path.join(tmpdir, "run_dev.py"), "fastapi_template_project", app_name_underscore
os.path.join(tmpdir, "run_dev.py"),
"fastapi_template_project",
app_name_underscore,
)
########
# Transform run_dev.py with new imports
replace_in_file(
os.path.join(tmpdir, "entry_point.sh"), "fastapi_template_project", app_name_underscore
os.path.join(tmpdir, "entry_point.sh"),
"fastapi_template_project",
app_name_underscore,
)
replace_in_file(
os.path.join(tmpdir, "README.md"), "fastapi_template_project", app_name_underscore
os.path.join(tmpdir, "README.md"),
"fastapi_template_project",
app_name_underscore,
)
replace_in_file(
os.path.join(tmpdir, "README.md"),
Expand All @@ -180,6 +193,13 @@ def do_create_fastapi_app(
shutil.copytree(f, os.path.join(cwd, os.path.basename(f)))
else:
shutil.copy(f, cwd)
# Add +x to all *.sh files
for root, _, files in os.walk(tmpdir):
for f in files:
if f.endswith(".sh"):
path = os.path.join(root, f)
# git +x permission
os.system(f'git update-index --chmod=+x "{path}"')


def create_python_app() -> None:
Expand Down
11 changes: 8 additions & 3 deletions tests/test_createfastapiapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ def test_imports(self) -> None:
self.assertTrue(os.path.exists(outdir))
self.assertTrue(os.path.exists(os.path.join(outdir, "pyproject.toml")))
self.assertTrue(os.path.exists(os.path.join(outdir, "setup.py")))
setup_py_lines: list[str] = read_utf8(os.path.join(outdir, "setup.py")).splitlines()
setup_py_lines: list[str] = read_utf8(
os.path.join(outdir, "setup.py")
).splitlines()
self.assertIn('KEYWORDS = "myapp test"', setup_py_lines)
self.assertTrue(os.path.exists(os.path.join(outdir, "src", "myapp")))
# self.assertTrue(os.path.exists(os.path.join(outdir, "src", "myapp", "cli.py")))
self.assertTrue(os.path.exists(os.path.join(outdir, "src", "myapp", "__init__.py")))
self.assertTrue(
os.path.exists(os.path.join(outdir, "src", "myapp", "__init__.py"))
)
self.assertTrue(os.path.exists(os.path.join(outdir, "tests")))
# self.assertTrue(os.path.exists(os.path.join(outdir, "tests", "test_cli.py")))
self.assertTrue(os.path.exists(os.path.join(outdir, "tox.ini")))
Expand All @@ -56,7 +60,8 @@ def test_imports(self) -> None:
for line in lines:
if "template_fastapi_project" in line:
self.assertTrue( # pylint: disable=redundant-unittest-assert
False, f"Found template_fastapi_project in {file_path}: {line}"
False,
f"Found template_fastapi_project in {file_path}: {line}",
)
os.chdir(outdir)
subprocess.check_call("pip install -e .", shell=True)
Expand Down

0 comments on commit d1cf185

Please sign in to comment.