flaskforge-cli 0.1.1__tar.gz → 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/PKG-INFO +7 -1
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/README.md +6 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/pyproject.toml +1 -1
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/__init__.py +1 -1
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/generators.py +3 -1
- flaskforge_cli-0.1.2/src/flaskforge/naming.py +136 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/app/admin.py.tpl +1 -1
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/app/index.html.tpl +2 -2
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge_cli.egg-info/PKG-INFO +7 -1
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge_cli.egg-info/SOURCES.txt +3 -1
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/tests/test_flaskforge.py +38 -0
- flaskforge_cli-0.1.2/tests/test_naming.py +80 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/LICENSE +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/setup.cfg +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/__main__.py +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/cli.py +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/commands.py +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/management.py +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/registry.py +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/scaffold.py +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/app/__init__.py.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/app/forms.py.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/app/models.py.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/app/schemas.py.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/app/test_app.py.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/app/views.py.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/ext/admin/accounts_admin.py.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/ext/admin/admin_views.py.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/ext/admin/test_admin.py.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/ext/login/__init__.py.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/ext/login/_csrf.html.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/ext/login/commands.py.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/ext/login/login.html.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/ext/login/models.py.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/ext/login/profile.html.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/ext/login/register.html.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/ext/login/test_accounts.py.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/ext/login/views.py.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/ext/sqlalchemy/mixins.py.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/project/Dockerfile.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/project/README.md.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/project/apps/__init__.py.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/project/apps/main/__init__.py.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/project/apps/main/templates/main/index.html.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/project/apps/main/views.py.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/project/config/__init__.py.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/project/config/settings.py.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/project/core/__init__.py.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/project/core/errors.py.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/project/core/extensions.py.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/project/dot_env.example.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/project/dot_env.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/project/dot_gitignore.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/project/manage.py.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/project/pytest.ini.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/project/requirements-dev.txt.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/project/requirements.txt.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/project/static/css/style.css.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/project/templates/base.html.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/project/templates/errors/error.html.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/project/tests/__init__.py.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/project/tests/conftest.py.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/project/tests/test_main.py.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/project/wsgi.py.tpl +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge_cli.egg-info/dependency_links.txt +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge_cli.egg-info/entry_points.txt +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge_cli.egg-info/requires.txt +0 -0
- {flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge_cli.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flaskforge-cli
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: Django-like CLI that scaffolds and extends large Flask projects
|
|
5
5
|
Requires-Python: >=3.9
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -79,6 +79,12 @@ Each app in `INSTALLED_APPS` is auto-loaded:
|
|
|
79
79
|
| `views.py` | Must define `bp` (or a `blueprints` list) |
|
|
80
80
|
| `commands.py` | `commands = [...]` are added to the CLI |
|
|
81
81
|
|
|
82
|
+
Apps are named in the plural and classes in the singular: `startapp products` creates
|
|
83
|
+
`apps/products/` (URL `/products/`, templates in `products/`) with `Product`, `ProductForm` and
|
|
84
|
+
`ProductSchema`; only the last word of a snake_case name is singularized (`blog_categories` ->
|
|
85
|
+
`BlogCategory`), and irregular plurals (`people` -> `Person`) and uncountable words (`news` -> `News`)
|
|
86
|
+
are handled.
|
|
87
|
+
|
|
82
88
|
Blueprints mounted under `/api` are exempt from CSRF (token-authenticated JSON APIs).
|
|
83
89
|
|
|
84
90
|
## Supported extensions
|
|
@@ -64,6 +64,12 @@ Each app in `INSTALLED_APPS` is auto-loaded:
|
|
|
64
64
|
| `views.py` | Must define `bp` (or a `blueprints` list) |
|
|
65
65
|
| `commands.py` | `commands = [...]` are added to the CLI |
|
|
66
66
|
|
|
67
|
+
Apps are named in the plural and classes in the singular: `startapp products` creates
|
|
68
|
+
`apps/products/` (URL `/products/`, templates in `products/`) with `Product`, `ProductForm` and
|
|
69
|
+
`ProductSchema`; only the last word of a snake_case name is singularized (`blog_categories` ->
|
|
70
|
+
`BlogCategory`), and irregular plurals (`people` -> `Person`) and uncountable words (`news` -> `News`)
|
|
71
|
+
are handled.
|
|
72
|
+
|
|
67
73
|
Blueprints mounted under `/api` are exempt from CSRF (token-authenticated JSON APIs).
|
|
68
74
|
|
|
69
75
|
## Supported extensions
|
|
@@ -11,6 +11,7 @@ from pathlib import Path
|
|
|
11
11
|
import click
|
|
12
12
|
|
|
13
13
|
from . import __version__
|
|
14
|
+
from .naming import class_name_for, title_for
|
|
14
15
|
from .registry import EXTENSIONS, PRESETS, Extension, resolve_key
|
|
15
16
|
from .scaffold import (
|
|
16
17
|
MANIFEST,
|
|
@@ -140,7 +141,8 @@ def create_app(project: Project, name: str, api: bool = False, force: bool = Fal
|
|
|
140
141
|
ctx = _ctx(
|
|
141
142
|
project,
|
|
142
143
|
app_name=name,
|
|
143
|
-
class_name=
|
|
144
|
+
class_name=class_name_for(name), # singular: products -> Product
|
|
145
|
+
app_title=title_for(name), # plural heading: products -> Products
|
|
144
146
|
api=api,
|
|
145
147
|
)
|
|
146
148
|
click.secho(f"Creating {'API ' if api else ''}app '{name}'", bold=True)
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"""Naming helpers for generated code.
|
|
2
|
+
|
|
3
|
+
Apps are named in the plural (``products``, ``blog_posts``) while Python classes are
|
|
4
|
+
singular (``Product``, ``BlogPost``). The singularizer is a small rule-based English
|
|
5
|
+
implementation with an irregular-word table, so flaskforge needs no extra dependency.
|
|
6
|
+
Only the last ``snake_case`` word is singularized: ``order_items`` -> ``OrderItem``.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
# Plural -> singular, checked first (exact match on the whole word).
|
|
12
|
+
IRREGULAR = {
|
|
13
|
+
"people": "person",
|
|
14
|
+
"men": "man",
|
|
15
|
+
"women": "woman",
|
|
16
|
+
"children": "child",
|
|
17
|
+
"feet": "foot",
|
|
18
|
+
"teeth": "tooth",
|
|
19
|
+
"mice": "mouse",
|
|
20
|
+
"geese": "goose",
|
|
21
|
+
"oxen": "ox",
|
|
22
|
+
"criteria": "criterion",
|
|
23
|
+
"phenomena": "phenomenon",
|
|
24
|
+
"indices": "index",
|
|
25
|
+
"matrices": "matrix",
|
|
26
|
+
"vertices": "vertex",
|
|
27
|
+
"appendices": "appendix",
|
|
28
|
+
"analyses": "analysis",
|
|
29
|
+
"bases": "basis",
|
|
30
|
+
"theses": "thesis",
|
|
31
|
+
"crises": "crisis",
|
|
32
|
+
"diagnoses": "diagnosis",
|
|
33
|
+
"hypotheses": "hypothesis",
|
|
34
|
+
"axes": "axis",
|
|
35
|
+
"leaves": "leaf",
|
|
36
|
+
"wolves": "wolf",
|
|
37
|
+
"knives": "knife",
|
|
38
|
+
"lives": "life",
|
|
39
|
+
"wives": "wife",
|
|
40
|
+
"shelves": "shelf",
|
|
41
|
+
"halves": "half",
|
|
42
|
+
"calves": "calf",
|
|
43
|
+
"thieves": "thief",
|
|
44
|
+
"loaves": "loaf",
|
|
45
|
+
"selves": "self",
|
|
46
|
+
"quizzes": "quiz",
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
# Same form in singular and plural (or not safely singularizable).
|
|
50
|
+
UNCHANGED = {
|
|
51
|
+
"news", "series", "species", "sheep", "fish", "deer", "moose", "aircraft",
|
|
52
|
+
"data", "media", "metadata", "info", "information", "equipment", "software",
|
|
53
|
+
"hardware", "feedback", "money", "analytics", "physics", "mathematics",
|
|
54
|
+
"economics", "politics", "statistics", "ethics", "athletics", "linguistics",
|
|
55
|
+
"means", "lens", "headquarters", "scissors", "pants", "jeans", "chaos",
|
|
56
|
+
"cosmos", "kudos", "bias", "atlas", "canvas", "gas", "plus", "alias",
|
|
57
|
+
"status", "bonus", "campus", "virus", "focus", "census", "corpus", "genus",
|
|
58
|
+
"bus", "lotus", "sinus", "apparatus", "radius", "cactus", "chorus", "iris",
|
|
59
|
+
"nexus", "stimulus", "syllabus", "fungus", "thesaurus", "octopus", "platypus",
|
|
60
|
+
"prospectus", "consensus", "nucleus", "terminus", "mucus", "surplus",
|
|
61
|
+
"tennis", "pelvis", "metropolis", "debris", "chassis",
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
# Singular words that end in "s" and form their plural with "-es" (buses, statuses).
|
|
65
|
+
_S_SINGULARS = {
|
|
66
|
+
"bus", "status", "bonus", "campus", "virus", "focus", "census", "corpus",
|
|
67
|
+
"genus", "lotus", "sinus", "alias", "atlas", "canvas", "gas", "plus", "bias",
|
|
68
|
+
"apparatus", "radius", "cactus", "chorus", "iris", "lens",
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
# "-ches" words whose singular is "-che" (caches -> cache), not "-ch" (batches -> batch).
|
|
72
|
+
_CHE_SINGULARS = {
|
|
73
|
+
"cache", "niche", "headache", "moustache", "mustache", "avalanche", "quiche",
|
|
74
|
+
"psyche", "creche", "brioche", "apache", "attache",
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
# "-ies" words whose singular is "-ie" (movies -> movie), not "-y".
|
|
78
|
+
_IE_SINGULARS = {
|
|
79
|
+
"movie", "cookie", "zombie", "pie", "tie", "selfie", "brownie", "rookie",
|
|
80
|
+
"hoodie", "genie", "lie", "die", "calorie", "smoothie", "birdie", "prairie",
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
# "-oes" words whose singular is "-oe" (shoes -> shoe), not "-o" (heroes -> hero).
|
|
84
|
+
_OE_SINGULARS = {"shoe", "toe", "canoe", "oboe", "foe", "hoe", "doe", "horseshoe"}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def singularize(word: str) -> str:
|
|
88
|
+
"""Return the singular form of a lowercase English noun.
|
|
89
|
+
|
|
90
|
+
Already-singular words are returned unchanged (``product`` -> ``product``).
|
|
91
|
+
"""
|
|
92
|
+
w = word.lower()
|
|
93
|
+
if len(w) < 2 or w in UNCHANGED:
|
|
94
|
+
return w
|
|
95
|
+
if w in IRREGULAR:
|
|
96
|
+
return IRREGULAR[w]
|
|
97
|
+
|
|
98
|
+
if w.endswith("ies") and len(w) > 4:
|
|
99
|
+
stem = w[:-1] # movies -> movie
|
|
100
|
+
return stem if stem in _IE_SINGULARS else w[:-3] + "y" # categories -> category
|
|
101
|
+
if w.endswith("ies"): # "ties", "pies", "lies": too short to be "-y" words
|
|
102
|
+
return w[:-1]
|
|
103
|
+
if w.endswith("sses"): # addresses -> address, classes -> class
|
|
104
|
+
return w[:-2]
|
|
105
|
+
if w.endswith("ses"):
|
|
106
|
+
with_s = w[:-2] # buses -> bus, statuses -> status
|
|
107
|
+
return with_s if with_s in _S_SINGULARS else w[:-1] # cases -> case, databases -> database
|
|
108
|
+
if w.endswith("ches"):
|
|
109
|
+
stem = w[:-1] # caches -> cache
|
|
110
|
+
return stem if stem in _CHE_SINGULARS else w[:-2] # batches -> batch
|
|
111
|
+
if w.endswith(("shes", "xes")): # dishes -> dish, boxes -> box
|
|
112
|
+
return w[:-2]
|
|
113
|
+
if w.endswith("zzes"): # buzzes -> buzz
|
|
114
|
+
return w[:-2]
|
|
115
|
+
if w.endswith("oes"):
|
|
116
|
+
stem = w[:-1] # shoes -> shoe
|
|
117
|
+
return stem if stem in _OE_SINGULARS else w[:-2] # heroes -> hero
|
|
118
|
+
if w.endswith("ves"): # archives -> archive, drives -> drive
|
|
119
|
+
return w[:-1]
|
|
120
|
+
if w.endswith(("ss", "sis")): # already singular: class, analysis, basis
|
|
121
|
+
return w
|
|
122
|
+
if w.endswith("s"):
|
|
123
|
+
return w[:-1]
|
|
124
|
+
return w
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def class_name_for(app_name: str) -> str:
|
|
128
|
+
"""``blog_posts`` -> ``BlogPost``; only the last word is singularized."""
|
|
129
|
+
parts = app_name.split("_")
|
|
130
|
+
parts[-1] = singularize(parts[-1])
|
|
131
|
+
return "".join(p.capitalize() for p in parts if p)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def title_for(app_name: str) -> str:
|
|
135
|
+
"""Human-friendly plural heading: ``blog_posts`` -> ``Blog Posts``."""
|
|
136
|
+
return app_name.replace("_", " ").title()
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{% extends "base.html" %}
|
|
2
|
-
{% block title %}[[
|
|
2
|
+
{% block title %}[[ app_title ]]{% endblock %}
|
|
3
3
|
|
|
4
4
|
{% block content %}
|
|
5
5
|
<section class="card">
|
|
6
|
-
<h1>[[
|
|
6
|
+
<h1>[[ app_title ]]</h1>
|
|
7
7
|
<p>The <code>[[ app_name ]]</code> app works. Edit <code>apps/[[ app_name ]]/templates/[[ app_name ]]/index.html</code>.</p>
|
|
8
8
|
</section>
|
|
9
9
|
{% endblock %}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flaskforge-cli
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: Django-like CLI that scaffolds and extends large Flask projects
|
|
5
5
|
Requires-Python: >=3.9
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -79,6 +79,12 @@ Each app in `INSTALLED_APPS` is auto-loaded:
|
|
|
79
79
|
| `views.py` | Must define `bp` (or a `blueprints` list) |
|
|
80
80
|
| `commands.py` | `commands = [...]` are added to the CLI |
|
|
81
81
|
|
|
82
|
+
Apps are named in the plural and classes in the singular: `startapp products` creates
|
|
83
|
+
`apps/products/` (URL `/products/`, templates in `products/`) with `Product`, `ProductForm` and
|
|
84
|
+
`ProductSchema`; only the last word of a snake_case name is singularized (`blog_categories` ->
|
|
85
|
+
`BlogCategory`), and irregular plurals (`people` -> `Person`) and uncountable words (`news` -> `News`)
|
|
86
|
+
are handled.
|
|
87
|
+
|
|
82
88
|
Blueprints mounted under `/api` are exempt from CSRF (token-authenticated JSON APIs).
|
|
83
89
|
|
|
84
90
|
## Supported extensions
|
|
@@ -7,6 +7,7 @@ src/flaskforge/cli.py
|
|
|
7
7
|
src/flaskforge/commands.py
|
|
8
8
|
src/flaskforge/generators.py
|
|
9
9
|
src/flaskforge/management.py
|
|
10
|
+
src/flaskforge/naming.py
|
|
10
11
|
src/flaskforge/registry.py
|
|
11
12
|
src/flaskforge/scaffold.py
|
|
12
13
|
src/flaskforge/templates/app/__init__.py.tpl
|
|
@@ -61,4 +62,5 @@ src/flaskforge_cli.egg-info/dependency_links.txt
|
|
|
61
62
|
src/flaskforge_cli.egg-info/entry_points.txt
|
|
62
63
|
src/flaskforge_cli.egg-info/requires.txt
|
|
63
64
|
src/flaskforge_cli.egg-info/top_level.txt
|
|
64
|
-
tests/test_flaskforge.py
|
|
65
|
+
tests/test_flaskforge.py
|
|
66
|
+
tests/test_naming.py
|
|
@@ -153,3 +153,41 @@ def test_generated_readme_and_requirements(runner, tmp_path):
|
|
|
153
153
|
assert "flaskforge-cli" in (root / "requirements-dev.txt").read_text()
|
|
154
154
|
readme = (root / "README.md").read_text()
|
|
155
155
|
assert "Getting started" in readme and "cp .env.example" not in readme
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def test_startapp_uses_singular_classes_but_keeps_plural_names(runner, tmp_path, monkeypatch):
|
|
159
|
+
"""Acceptance criteria of issue #1."""
|
|
160
|
+
root = make_project(runner, tmp_path, "--preset", "web", "-e", "marshmallow,admin")
|
|
161
|
+
monkeypatch.chdir(root)
|
|
162
|
+
assert invoke(runner, "startapp", "products").exit_code == 0
|
|
163
|
+
|
|
164
|
+
# plural directory, template directory, URL prefix, blueprint and test file names
|
|
165
|
+
assert (root / "apps/products").is_dir()
|
|
166
|
+
assert not (root / "apps/product").exists()
|
|
167
|
+
assert (root / "apps/products/templates/products/index.html").exists()
|
|
168
|
+
assert (root / "tests/test_products.py").exists()
|
|
169
|
+
views = (root / "apps/products/views.py").read_text()
|
|
170
|
+
assert 'Blueprint("products"' in views and 'url_prefix="/products"' in views
|
|
171
|
+
assert '"apps.products",' in (root / "config/settings.py").read_text()
|
|
172
|
+
|
|
173
|
+
# singular classes
|
|
174
|
+
models = (root / "apps/products/models.py").read_text()
|
|
175
|
+
assert "class Product(TimestampMixin, db.Model):" in models
|
|
176
|
+
assert "class Products" not in models
|
|
177
|
+
assert "class ProductForm(FlaskForm):" in (root / "apps/products/forms.py").read_text()
|
|
178
|
+
assert "from .models import Product\n" in (root / "apps/products/admin.py").read_text()
|
|
179
|
+
|
|
180
|
+
# plural headings in the UI
|
|
181
|
+
index = (root / "apps/products/templates/products/index.html").read_text()
|
|
182
|
+
assert "<h1>Products</h1>" in index
|
|
183
|
+
assert compileall.compile_dir(str(root), quiet=1)
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def test_startapp_api_singular_model_and_schema(runner, tmp_path, monkeypatch):
|
|
187
|
+
root = make_project(runner, tmp_path, "--preset", "api")
|
|
188
|
+
monkeypatch.chdir(root)
|
|
189
|
+
invoke(runner, "startapp", "blog_categories", "--api")
|
|
190
|
+
assert (root / "apps/blog_categories").is_dir()
|
|
191
|
+
assert "class BlogCategory(TimestampMixin" in (root / "apps/blog_categories/models.py").read_text()
|
|
192
|
+
assert "class BlogCategorySchema" in (root / "apps/blog_categories/schemas.py").read_text()
|
|
193
|
+
assert 'url_prefix="/api/blog_categories"' in (root / "apps/blog_categories/views.py").read_text()
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
from flaskforge.naming import class_name_for, singularize, title_for
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@pytest.mark.parametrize(
|
|
7
|
+
"plural, singular",
|
|
8
|
+
[
|
|
9
|
+
# regular
|
|
10
|
+
("products", "product"), ("users", "user"), ("orders", "order"),
|
|
11
|
+
("settings", "setting"), ("photos", "photo"), ("videos", "video"),
|
|
12
|
+
# -ies
|
|
13
|
+
("categories", "category"), ("stories", "story"), ("queries", "query"),
|
|
14
|
+
("movies", "movie"), ("cookies", "cookie"), ("ties", "tie"), ("calories", "calorie"),
|
|
15
|
+
# -es: sibilants
|
|
16
|
+
("addresses", "address"), ("classes", "class"), ("processes", "process"),
|
|
17
|
+
("batches", "batch"), ("dishes", "dish"), ("boxes", "box"), ("taxes", "tax"),
|
|
18
|
+
("indexes", "index"), ("quizzes", "quiz"), ("buzzes", "buzz"),
|
|
19
|
+
# -ches that keep the "e"
|
|
20
|
+
("caches", "cache"), ("headaches", "headache"), ("niches", "niche"),
|
|
21
|
+
# -ses
|
|
22
|
+
("buses", "bus"), ("statuses", "status"), ("bonuses", "bonus"), ("aliases", "alias"),
|
|
23
|
+
("lenses", "lens"), ("cases", "case"), ("databases", "database"),
|
|
24
|
+
("responses", "response"), ("licenses", "license"), ("houses", "house"),
|
|
25
|
+
# -oes
|
|
26
|
+
("heroes", "hero"), ("potatoes", "potato"), ("shoes", "shoe"), ("toes", "toe"),
|
|
27
|
+
# -ves
|
|
28
|
+
("archives", "archive"), ("drives", "drive"), ("leaves", "leaf"), ("knives", "knife"),
|
|
29
|
+
("wolves", "wolf"), ("shelves", "shelf"),
|
|
30
|
+
# words that look like plurals but are not (or end in -us / -is as plurals)
|
|
31
|
+
("menus", "menu"), ("wikis", "wiki"), ("emojis", "emoji"), ("taxis", "taxi"),
|
|
32
|
+
# irregular
|
|
33
|
+
("people", "person"), ("children", "child"), ("men", "man"), ("women", "woman"),
|
|
34
|
+
("feet", "foot"), ("teeth", "tooth"), ("mice", "mouse"), ("criteria", "criterion"),
|
|
35
|
+
("indices", "index"), ("analyses", "analysis"), ("bases", "basis"),
|
|
36
|
+
("crises", "crisis"), ("diagnoses", "diagnosis"),
|
|
37
|
+
],
|
|
38
|
+
)
|
|
39
|
+
def test_singularize_plurals(plural, singular):
|
|
40
|
+
assert singularize(plural) == singular
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@pytest.mark.parametrize(
|
|
44
|
+
"word",
|
|
45
|
+
[
|
|
46
|
+
# already singular
|
|
47
|
+
"product", "user", "category", "address", "class", "status", "bonus", "campus",
|
|
48
|
+
"analysis", "basis", "crisis", "person", "child", "index", "box", "mouse",
|
|
49
|
+
# uncountable / same in both forms
|
|
50
|
+
"news", "series", "species", "sheep", "fish", "data", "media", "metadata",
|
|
51
|
+
"analytics", "statistics", "physics", "economics", "bias", "canvas", "tennis",
|
|
52
|
+
],
|
|
53
|
+
)
|
|
54
|
+
def test_singularize_is_idempotent_on_singular_and_uncountable(word):
|
|
55
|
+
assert singularize(word) == word
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def test_singularize_edge_cases():
|
|
59
|
+
assert singularize("") == ""
|
|
60
|
+
assert singularize("s") == "s"
|
|
61
|
+
assert singularize("Products") == "product" # case-insensitive input, lowercase output
|
|
62
|
+
assert singularize(singularize("categories")) == "category"
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
@pytest.mark.parametrize(
|
|
66
|
+
"app, cls",
|
|
67
|
+
[
|
|
68
|
+
("products", "Product"), ("blog", "Blog"), ("blog_posts", "BlogPost"),
|
|
69
|
+
("order_items", "OrderItem"), ("user_profiles", "UserProfile"),
|
|
70
|
+
("team_people", "TeamPerson"), ("news", "News"), ("categories", "Category"),
|
|
71
|
+
("blog_categories", "BlogCategory"),
|
|
72
|
+
],
|
|
73
|
+
)
|
|
74
|
+
def test_class_name_for_singularizes_only_last_word(app, cls):
|
|
75
|
+
assert class_name_for(app) == cls
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def test_title_stays_plural():
|
|
79
|
+
assert title_for("products") == "Products"
|
|
80
|
+
assert title_for("blog_posts") == "Blog Posts"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/ext/admin/admin_views.py.tpl
RENAMED
|
File without changes
|
{flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/ext/admin/test_admin.py.tpl
RENAMED
|
File without changes
|
{flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/ext/login/__init__.py.tpl
RENAMED
|
File without changes
|
{flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/ext/login/_csrf.html.tpl
RENAMED
|
File without changes
|
{flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/ext/login/commands.py.tpl
RENAMED
|
File without changes
|
{flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/ext/login/login.html.tpl
RENAMED
|
File without changes
|
{flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/ext/login/models.py.tpl
RENAMED
|
File without changes
|
{flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/ext/login/profile.html.tpl
RENAMED
|
File without changes
|
{flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/ext/login/register.html.tpl
RENAMED
|
File without changes
|
|
File without changes
|
{flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/ext/login/views.py.tpl
RENAMED
|
File without changes
|
{flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/ext/sqlalchemy/mixins.py.tpl
RENAMED
|
File without changes
|
{flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/project/Dockerfile.tpl
RENAMED
|
File without changes
|
{flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/project/README.md.tpl
RENAMED
|
File without changes
|
{flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/project/apps/__init__.py.tpl
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/project/core/__init__.py.tpl
RENAMED
|
File without changes
|
{flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/project/core/errors.py.tpl
RENAMED
|
File without changes
|
|
File without changes
|
{flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/project/dot_env.example.tpl
RENAMED
|
File without changes
|
|
File without changes
|
{flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/project/dot_gitignore.tpl
RENAMED
|
File without changes
|
{flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/project/manage.py.tpl
RENAMED
|
File without changes
|
{flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/project/pytest.ini.tpl
RENAMED
|
File without changes
|
|
File without changes
|
{flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/project/requirements.txt.tpl
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/project/tests/__init__.py.tpl
RENAMED
|
File without changes
|
{flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge/templates/project/tests/conftest.py.tpl
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{flaskforge_cli-0.1.1 → flaskforge_cli-0.1.2}/src/flaskforge_cli.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|