Skip to content

Commit

Permalink
Merge pull request #60 from oleoneto/v0.19.1rc
Browse files Browse the repository at this point in the history
0.19.1
  • Loading branch information
oleoneto authored Apr 21, 2024
2 parents 58e6024 + 3ef6321 commit 392dd40
Show file tree
Hide file tree
Showing 153 changed files with 680 additions and 620 deletions.
2 changes: 1 addition & 1 deletion .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx --no-install commitlint --edit "$1"
#npx --no-install commitlint --edit "$1"
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Base image
FROM python:3.13.0a1-alpine
FROM python:3.13.0a4-alpine

LABEL MAINTAINER="Leo Neto"

Expand All @@ -17,4 +17,4 @@ COPY . .
# Install dependencies
RUN apk add gcc musl-dev linux-headers && pip install -e .

ENTRYPOINT ["django-clite"]
CMD ["django-clite"]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ prepending or appending any number of underscores (`_`). Any code contained with
The flag `--templates-dir` can be used to configure an additional path wherein the CLI can look for resource templates.
Alternatively, you can use the environment variable `DJANGO_CLITE_TEMPLATES_DIR` for the same purpose.

Take a look at the [template files directory](src/cli/template_files) for a reference of what files can be overriden. The
Take a look at the [template files directory](django_clite/cli/template_files) for a reference of what files can be overriden. The
paths of the templates you wish to override need to match the provided template. For example, if you wish to override the
model template, which is defined under [`src/cli/template_files/models/model.tpl`](src/cli/template_files/models/model.tpl),
model template, which is defined under [`src/cli/template_files/models/model.tpl`](django_clite/cli/template_files/models/model.tpl),
you should define your own model template under your desired directory, i.e `/path/to/templates/models/model.tpl`.

## Development
Expand Down
6 changes: 2 additions & 4 deletions src/cli/__init__.py → django_clite/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
django-clite: a cli tool that handles creating and managing Django projects
"""
import os
from .constants import PLUGINS_ENV_VAR

__version__ = "0.19.0"
__license__ = "BSD 3-Clause"
__author__ = "Leo Neto"
__copyright__ = "Copyright 2019-2023 Leo Neto"

COMMANDS_FOLDER = os.path.join(os.path.dirname(__file__), "commands")

PLUGINS_FOLDER = os.environ.get("DJANGO_CLITE_PLUGINS", None)

VERSION = __version__
PLUGINS_FOLDER = os.environ.get(PLUGINS_ENV_VAR, None)
1 change: 1 addition & 0 deletions django_clite/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# django_clite:cli
14 changes: 7 additions & 7 deletions src/cli/app.py → django_clite/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
import logging
from pathlib import Path

from cli.extensions.combined import AliasedAndDiscoverableGroup
from django_clite.extensions.combined import AliasedAndDiscoverableGroup
from geny.core.filesystem.finder import core_project_files, project_and_app_names
from geny.core.templates.template import TemplateParser

from cli import VERSION
from cli.constants import (
from django_clite.constants import (
DJANGO_FILES_KEY,
ENABLE_DRY_RUN_KEY,
ENABLE_DEBUG_KEY,
ENABLE_FORCE_KEY,
ENABLE_VERBOSITY_KEY,
PROJECT_NAME_KEY,
APPLICATION_NAME_KEY,
TEMPLATES_DIRECTORY_ENV_VAR,
)


Expand All @@ -23,18 +23,18 @@
)
@click.option("--debug", is_flag=True, help="Enable debug logs.")
@click.option("--dry", is_flag=True, help="Do not modify the file system.")
@click.option("-f", "--force", is_flag=True, help="Override any conflicting files.")
@click.option("-f", "--force", is_flag=True, envvar=ENABLE_FORCE_KEY, help="Override any conflicting files.")
@click.option("--verbose", is_flag=True, help="Enable verbosity.")
@click.option("--project", help="Project name.")
@click.option("--app", help="Application name.")
@click.option(
"--templates-dir",
"-t",
envvar="DJANGO_CLITE_TEMPLATES_DIR",
envvar=TEMPLATES_DIRECTORY_ENV_VAR,
help="Template directory.",
type=click.Path(),
)
@click.version_option(version=VERSION)
@click.version_option(package_name="django-clite")
@click.pass_context
def cli(ctx, debug, dry, force, verbose, project, app, templates_dir):
"""
Expand Down Expand Up @@ -86,7 +86,7 @@ def cli(ctx, debug, dry, force, verbose, project, app, templates_dir):
django_files = core_project_files()
project_name, app_name = project_and_app_names(django_files)

templates = [Path(__file__).resolve().parent / "template_files"]
templates = [Path(__file__).resolve().parent.parent / "template_files"]

if templates_dir is not None:
templates.append(Path(templates_dir))
Expand Down
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions django_clite/commands/callbacks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django_clite.cli.utils import sanitized_string
from django_clite.core.field_parser.factory import AttributeFactory


def sanitized_string_callback(_ctx, _param, value):
return sanitized_string(value)


def fields_callback(ctx, _param, values):
return AttributeFactory().parsed_fields(values)
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import click

from geny.core.filesystem.files import File
from cli.commands.callbacks import sanitized_string_callback
from cli.decorators.scope import scoped, Scope
from cli.commands import command_defaults
from django_clite.decorators.scope import scoped, Scope
from django_clite.commands import command_defaults
from django_clite.commands.callbacks import sanitized_string_callback


@scoped(to=Scope.APP)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import click

from geny.core.filesystem.files import File
from cli.commands.callbacks import sanitized_string_callback
from cli.decorators.scope import scoped, Scope
from django_clite.commands.callbacks import sanitized_string_callback
from django_clite.decorators.scope import scoped, Scope


@scoped(to=Scope.APP)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import click

from geny.core.filesystem.files import File
from cli.commands.callbacks import sanitized_string_callback
from cli.decorators.scope import scoped, Scope
from django_clite.decorators.scope import scoped, Scope
from django_clite.commands.callbacks import sanitized_string_callback


@scoped(to=Scope.APP)
Expand Down
50 changes: 50 additions & 0 deletions django_clite/commands/destroy/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# cli:commands:destroy
import click

from django_clite.commands.destroy.admin import admin, admin_inline as admin_inline
from django_clite.commands.destroy.fixtures import fixture
from django_clite.commands.destroy.forms import form
from django_clite.commands.destroy.management import management
from django_clite.commands.destroy.managers import manager
from django_clite.commands.destroy.models import model, scaffold
from django_clite.commands.destroy.serializers import serializer
from django_clite.commands.destroy.signals import signal
from django_clite.commands.destroy.tags import tag
from django_clite.commands.destroy.template import template
from django_clite.commands.destroy.tests import test
from django_clite.commands.destroy.validators import validator
from django_clite.commands.destroy.views import view
from django_clite.commands.destroy.viewsets import viewset


@click.group()
@click.pass_context
def destroy(ctx):
"""
Destroy application resources.
"""

ctx.ensure_object(dict)


[
destroy.add_command(cmd)
for cmd in [
admin,
admin_inline,
fixture,
form,
management,
manager,
model,
scaffold,
serializer,
signal,
tag,
template,
test,
validator,
view,
viewset,
]
]
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import click

from geny.core.filesystem.files import File
from cli.commands.callbacks import sanitized_string_callback
from cli.decorators.scope import scoped, Scope
from django_clite.decorators.scope import scoped, Scope
from django_clite.commands.callbacks import sanitized_string_callback


@scoped(to=Scope.APP)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import click

from geny.core.filesystem.files import File
from cli.commands.callbacks import sanitized_string_callback
from cli.decorators.scope import scoped, Scope
from django_clite.decorators.scope import scoped, Scope
from django_clite.commands.callbacks import sanitized_string_callback


@scoped(to=Scope.APP)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import click

from geny.core.filesystem.files import File
from cli.commands.callbacks import sanitized_string_callback
from cli.decorators.scope import scoped, Scope
from cli.core.logger import logger
from cli.commands import command_defaults
from django_clite.core.logger import logger
from django_clite.decorators.scope import scoped, Scope
from django_clite.commands import command_defaults
from django_clite.commands.callbacks import sanitized_string_callback


@scoped(to=Scope.APP)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import click

from geny.core.filesystem.files import File
from cli.commands.callbacks import sanitized_string_callback
from cli.decorators.scope import scoped, Scope
from cli.commands import command_defaults
from django_clite.decorators.scope import scoped, Scope
from django_clite.commands import command_defaults
from django_clite.commands.callbacks import sanitized_string_callback


@scoped(to=Scope.APP)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import click

from geny.core.filesystem.files import File
from cli.commands.callbacks import sanitized_string_callback
from cli.decorators.scope import scoped, Scope
from cli.commands import command_defaults
from django_clite.decorators.scope import scoped, Scope
from django_clite.commands import command_defaults
from django_clite.commands.callbacks import sanitized_string_callback


@scoped(to=Scope.APP)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import click

from geny.core.filesystem.files import File
from cli.commands.callbacks import sanitized_string_callback
from cli.decorators.scope import scoped, Scope
from cli.commands import command_defaults
from django_clite.decorators.scope import scoped, Scope
from django_clite.commands import command_defaults
from django_clite.commands.callbacks import sanitized_string_callback


@scoped(to=Scope.APP)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import click

from geny.core.filesystem.files import File
from cli.commands.callbacks import sanitized_string_callback
from cli.decorators.scope import scoped, Scope
from django_clite.decorators.scope import scoped, Scope
from django_clite.commands.callbacks import sanitized_string_callback


SUPPORTED_CLASSES = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import inflection

from geny.core.filesystem.files import File
from cli.commands.callbacks import sanitized_string, sanitized_string_callback
from cli.decorators.scope import scoped, Scope
from cli.core.logger import logger
from cli.commands import command_defaults
from django_clite.core.logger import logger
from django_clite.decorators.scope import scoped, Scope
from django_clite.commands import command_defaults
from django_clite.commands.callbacks import sanitized_string, sanitized_string_callback


SUPPORTED_SCOPES = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import click

from geny.core.filesystem.files import File
from cli.commands.callbacks import sanitized_string_callback
from cli.decorators.scope import scoped, Scope
from cli.commands import command_defaults
from django_clite.decorators.scope import scoped, Scope
from django_clite.commands import command_defaults
from django_clite.commands.callbacks import sanitized_string_callback


@scoped(to=Scope.APP)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import click

from geny.core.filesystem.files import File
from cli.commands.callbacks import sanitized_string_callback
from cli.decorators.scope import scoped, Scope
from cli.commands import command_defaults
from django_clite.decorators.scope import scoped, Scope
from django_clite.commands import command_defaults
from django_clite.commands.callbacks import sanitized_string_callback
from .template import template


Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import click

from geny.core.filesystem.files import File
from cli.commands.callbacks import sanitized_string_callback
from cli.decorators.scope import scoped, Scope
from cli.commands import command_defaults
from django_clite.decorators.scope import scoped, Scope
from django_clite.commands import command_defaults
from django_clite.commands.callbacks import sanitized_string_callback


@scoped(to=Scope.APP)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import inflection

from geny.core.filesystem.files import File
from cli.commands.callbacks import sanitized_string_callback, fields_callback
from cli.decorators.scope import scoped, Scope
from cli.commands import command_defaults
from django_clite.commands import command_defaults
from django_clite.commands.callbacks import sanitized_string_callback, fields_callback
from django_clite.decorators.scope import scoped, Scope


@scoped(to=Scope.APP)
Expand All @@ -26,8 +26,7 @@ def admin(ctx, name, fields, permissions, skip_import):
Generate an admin model.
"""

admin_fields, _ = fields
admin_fields = [x for x in admin_fields if x.supported_in_admin]
admin_fields = [attr_name for attr_name, v in fields.items() if v.supports_admin]

file = File(
name=f"admin/{name}.py",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import click

from geny.core.filesystem.files import File
from cli.decorators.scope import scoped, Scope
from django_clite.decorators.scope import scoped, Scope


@scoped(to=Scope.PROJECT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import inflection

from geny.core.filesystem.files import File
from cli.commands.callbacks import sanitized_string_callback, fields_callback
from cli.decorators.scope import scoped, Scope
from django_clite.decorators.scope import scoped, Scope
from django_clite.commands.callbacks import sanitized_string_callback, fields_callback


@scoped(to=Scope.APP)
Expand All @@ -17,14 +17,12 @@ def fixture(ctx, model, total, fields):
Generate model fixtures.
"""

fixture_fields, _ = fields

file = File(
name=f"fixtures/{model}.json",
template="fixture.tpl",
context={
"total": total,
"fields": fixture_fields,
"fields": fields,
"classname": inflection.camelize(model),
},
)
Expand Down
Loading

0 comments on commit 392dd40

Please sign in to comment.