Skip to content

Commit

Permalink
fix: generate utils with user contrib model
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobi-De committed Sep 5, 2024
1 parent 3ec7181 commit 0af382e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 29 deletions.
2 changes: 1 addition & 1 deletion blueprints/bootstrap
2 changes: 1 addition & 1 deletion blueprints/tailwind
35 changes: 9 additions & 26 deletions src/falco/commands/update_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from cruft._commands.utils.iohelper import AltTemporaryDirectory
from falco import checks
from falco.config import FalcoConfig
from falco.config import read_falco_config
from falco.utils import get_project_name
from falco.utils import RICH_INFO_MARKER
from falco.utils import RICH_SUCCESS_MARKER
Expand All @@ -34,9 +33,7 @@ def cruft_file(cruft_state: dict):
file_path.unlink()


def cruft_state_from(
config: FalcoConfig, project_name: str, author_name: str, author_email: str
) -> dict:
def cruft_state_from(config: FalcoConfig, project_name: str, author_name: str, author_email: str) -> dict:
return {
"template": config["blueprint"],
"commit": config["revision"],
Expand All @@ -59,14 +56,10 @@ def cruft_state_from(
class UpdateProject:
diff: Annotated[
bool,
cappa.Arg(
default=False, short="-d", long="--diff", help="Show diff of changes."
),
cappa.Arg(default=False, short="-d", long="--diff", help="Show diff of changes."),
]

def __call__(
self, project_name: Annotated[str, cappa.Dep(get_project_name)]
) -> None:
def __call__(self, project_name: Annotated[str, cappa.Dep(get_project_name)]) -> None:
# if is_new_falco_cli_available(fail_on_error=True):
# raise cappa.Exit(
# "You need have the latest version of falco-cli to update.", code=1
Expand All @@ -78,9 +71,7 @@ def __call__(
try:
pyproject = tomlkit.parse(pyproject_path.read_text())
except FileNotFoundError as e:
raise cappa.Exit(
"Could not find a pyproject.toml file in the current directory.", code=1
) from e
raise cappa.Exit("Could not find a pyproject.toml file in the current directory.", code=1) from e

cruft_state = cruft_state_from(
config=pyproject["tool"]["falco"],
Expand All @@ -97,22 +88,18 @@ def __call__(
with cruft_file(cruft_state):
last_commit = cruft_update(allow_untracked_files=True)
if last_commit is None:
rich_print(
f"{RICH_INFO_MARKER} Nothing to do, project is already up to date!"
)
rich_print(f"{RICH_INFO_MARKER} Nothing to do, project is already up to date!")
raise cappa.Exit(code=0)
pyproject["tool"]["falco"]["revision"] = last_commit
pyproject_path.write_text(tomlkit.dumps(pyproject))
rich_print(
f"{RICH_SUCCESS_MARKER} Great! Your project has been updated to the latest version!"
)
rich_print(f"{RICH_SUCCESS_MARKER} Great! Your project has been updated to the latest version!")


def cruft_update(
project_dir: Path = Path("."),
cookiecutter_input: bool = False,
refresh_private_variables: bool = False,
skip_apply_ask: bool = True,
skip_apply_ask: bool = False,
skip_update: bool = False,
checkout: Optional[str] = None,
strict: bool = True,
Expand Down Expand Up @@ -169,17 +156,13 @@ def cruft_update(
new_template_dir = tmpdir / "new_template"
deleted_paths: Set[Path] = set()
# Clone the template
with utils.cookiecutter.get_cookiecutter_repo(
cruft_state["template"], repo_dir, checkout
) as repo:
with utils.cookiecutter.get_cookiecutter_repo(cruft_state["template"], repo_dir, checkout) as repo:
last_commit = repo.head.object.hexsha

# Bail early if the repo is already up to date and no inputs are asked
if not (
extra_context or cookiecutter_input or refresh_private_variables
) and utils.cruft.is_project_updated(
repo, cruft_state["commit"], last_commit, strict
):
) and utils.cruft.is_project_updated(repo, cruft_state["commit"], last_commit, strict):
typer.secho(
"Nothing to do, project's cruft is already up to date!",
fg=typer.colors.GREEN,
Expand Down
2 changes: 1 addition & 1 deletion src/falco/crud/utils/types.py.jinja
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# IMPORTS:START
from django.contrib.auth.models import User
from django.http import HttpRequest as HttpRequestBase
from django_htmx.middleware import HtmxDetails
from {{project_name}}.users.models import User
# IMPORTS:END


Expand Down

0 comments on commit 0af382e

Please sign in to comment.