Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Cookiecutter flask
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Remy Mudingay
Cookiecutter flask
Commits
dbfea314
Commit
dbfea314
authored
5 years ago
by
James Curtin
Committed by
James Curtin
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Update cookiecutter hooks and python versions
parent
524b8ada
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
hooks/post_gen_project.py
+6
-3
6 additions, 3 deletions
hooks/post_gen_project.py
hooks/pre_gen_project.py
+19
-8
19 additions, 8 deletions
hooks/pre_gen_project.py
tasks.py
+11
-22
11 additions, 22 deletions
tasks.py
{{cookiecutter.app_name}}/Dockerfile
+2
-1
2 additions, 1 deletion
{{cookiecutter.app_name}}/Dockerfile
with
38 additions
and
34 deletions
hooks/post_gen_project.py
+
6
−
3
View file @
dbfea314
...
...
@@ -2,10 +2,13 @@
# -*- coding: utf-8 -*-
"""
Post gen hook to ensure that the generated project
has only one package management, either pipenv or pip.
"""
import
logging
import
os
import
shutil
import
sys
LOGGER
=
logging
.
getLogger
()
def
clean_extra_package_management_files
():
"""
Removes either requirements files and folder or the Pipfile.
"""
...
...
@@ -27,10 +30,10 @@ def clean_extra_package_management_files():
os
.
remove
(
file_or_dir
)
else
:
shutil
.
rmtree
(
file_or_dir
)
sys
.
exit
(
0
)
except
OSError
as
e
:
sys
.
stdout
.
write
(
"
While attempting to remove file(s) an error occurred
"
)
sys
.
stdout
.
write
(
"
Error: {}
"
.
format
(
e
))
LOGGER
.
warning
(
"
While attempting to remove file(s) an error occurred
"
)
LOGGER
.
warning
(
f
"
Error:
{
e
}
"
)
sys
.
exit
(
1
)
if
__name__
==
"
__main__
"
:
...
...
This diff is collapsed.
Click to expand it.
hooks/pre_gen_project.py
+
19
−
8
View file @
dbfea314
import
logging
import
re
import
sys
LOGGER
=
logging
.
getLogger
()
MODULE_REGEX
=
r
"
^[_a-zA-Z][_a-zA-Z0-9]+$
"
...
...
@@ -10,17 +12,26 @@ class bcolors:
BOLD
=
"
\033
[1m
"
def
colorize
(
escape_code
,
text
):
code
=
getattr
(
bcolors
,
escape_code
)
return
f
"
{
code
}{
text
}{
bcolors
.
ENDC
}
"
def
log_warning
(
module_name
):
warning
=
(
f
"
\n
{
colorize
(
'
WARNING
'
,
'
WARNING
:
'
)
}
{
colorize
(
'
BOLD
'
,
module_name
)
}
"
"
is not a valid Python module name!
\n
"
"
See https://www.python.org/dev/peps/pep-0008/#package-and-module-names
"
"
for naming standards.
\n
"
)
LOGGER
.
warning
(
warning
)
def
validate_python_module_name
():
module_name
=
"
{{ cookiecutter.app_name }}
"
if
not
re
.
match
(
MODULE_REGEX
,
module_name
):
print
(
(
"
\n
{0}ERROR:{1}
"
+
"
{2}{3}{1} is not a valid Python module name!
\n
"
+
"
See https://www.python.org/dev/peps/pep-0008/#package-and-module-names for naming standards.
\n
"
).
format
(
bcolors
.
WARNING
,
bcolors
.
ENDC
,
bcolors
.
BOLD
,
module_name
)
)
sys
.
exit
(
1
)
log_warning
(
module_name
)
raise
ValueError
if
__name__
==
"
__main__
"
:
...
...
This diff is collapsed.
Click to expand it.
tasks.py
+
11
−
22
View file @
dbfea314
...
...
@@ -19,16 +19,23 @@ REQUIREMENTS = os.path.join(COOKIE, "requirements", "dev.txt")
def
_run_npm_command
(
ctx
,
command
):
os
.
chdir
(
COOKIE
)
ctx
.
run
(
"
npm {
0}
"
.
format
(
command
)
,
echo
=
True
)
ctx
.
run
(
f
"
npm
{
command
}
"
,
echo
=
True
)
os
.
chdir
(
HERE
)
def
_run_flask_command
(
ctx
,
command
,
*
args
):
os
.
chdir
(
COOKIE
)
flask_command
=
f
"
flask
{
command
}
"
if
args
:
flask_command
+=
f
"
{
'
'
.
join
(
args
)
}
"
ctx
.
run
(
flask_command
,
echo
=
True
)
@task
def
build
(
ctx
):
"""
Build the cookiecutter.
"""
ctx
.
run
(
"
cookiecutter {
0
} --no-input
"
.
format
(
HERE
)
)
ctx
.
run
(
f
"
cookiecutter
{
HERE
}
--no-input
"
)
_run_npm_command
(
ctx
,
"
install
"
)
_run_npm_command
(
ctx
,
"
run build
"
)
@task
...
...
@@ -36,23 +43,12 @@ def clean(ctx):
"""
Clean out generated cookiecutter.
"""
if
os
.
path
.
exists
(
COOKIE
):
shutil
.
rmtree
(
COOKIE
)
print
(
"
Removed {0}
"
.
format
(
COOKIE
))
else
:
print
(
"
App directory does not exist. Skipping.
"
)
def
_run_flask_command
(
ctx
,
command
,
*
args
):
os
.
chdir
(
COOKIE
)
flask_command
=
"
flask {0}
"
.
format
(
command
)
if
args
:
flask_command
=
"
{0} {1}
"
.
format
(
flask_command
,
"
"
.
join
(
args
))
ctx
.
run
(
flask_command
,
echo
=
True
)
@task
(
pre
=
[
clean
,
build
])
def
test
(
ctx
):
"""
Run lint commands and tests.
"""
ctx
.
run
(
"
pip install -r {
0
} --ignore-installed
"
.
format
(
REQUIREMENTS
)
,
echo
=
True
)
ctx
.
run
(
f
"
pip install -r
{
REQUIREMENTS
}
--ignore-installed
"
,
echo
=
True
)
_run_npm_command
(
ctx
,
"
run lint
"
)
os
.
chdir
(
COOKIE
)
shutil
.
copyfile
(
os
.
path
.
join
(
COOKIE
,
"
.env.example
"
),
os
.
path
.
join
(
COOKIE
,
"
.env
"
))
...
...
@@ -60,10 +56,3 @@ def test(ctx):
os
.
environ
[
"
FLASK_DEBUG
"
]
=
"
0
"
_run_flask_command
(
ctx
,
"
lint
"
,
"
--check
"
)
_run_flask_command
(
ctx
,
"
test
"
)
@task
def
readme
(
ctx
,
browse
=
False
):
ctx
.
run
(
"
rst2html.py README.rst > README.html
"
)
if
browse
:
webbrowser
.
open_new_tab
(
"
README.html
"
)
This diff is collapsed.
Click to expand it.
{{cookiecutter.app_name}}/Dockerfile
+
2
−
1
View file @
dbfea314
...
...
@@ -4,7 +4,8 @@ FROM python:${INSTALL_PYTHON_VERSION}-slim-buster AS base
RUN
apt-get update
RUN
apt-get
install
-y
\
curl
curl
\
gcc
ARG
INSTALL_NODE_VERSION=${INSTALL_NODE_VERSION:-12}
RUN
curl
-sL
https://deb.nodesource.com/setup_
${
INSTALL_NODE_VERSION
}
.x | bash -
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment