Skip to content

Commit 8c71535

Browse files
committed
rebuilt new version
1 parent f251be4 commit 8c71535

File tree

5 files changed

+142
-22
lines changed

5 files changed

+142
-22
lines changed

build/lib/kickstart_flask_app/core.py

+74-19
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,34 @@
1212
main_bp_init_template,
1313
requirements_template,
1414
config_template,
15-
runtime_template)
15+
runtime_template,
16+
html_index,
17+
style_css)
1618

1719
class KickstartFlaskApp():
1820

1921
def __init__(self):
2022
self.project_name: str = 'Hello-Flask'
2123
self.root_app_name: str = 'server'
2224
self.app_version: float = 1.0
23-
self.description: str = ''
25+
self.description: str = (f'This is a simple Flask app initiated with '
26+
f'kickstart-flask-app Python package')
2427
self.author: str = getuser()
2528
self.main_bp_name: str = 'main_bp'
26-
self.setup_heroku_deployment_files: str = 'yes'
29+
self.setup_heroku_deployment_files_check: str = 'yes'
30+
self.setup_flask_templates_and_static_files_check: str = 'yes'
2731
self.fields_names = [f'Project name. Default ({self.project_name})',
2832
f'Root app name. Default ({self.root_app_name})',
2933
f'App version. Default ({self.app_version})',
3034
f'Description. Default ({self.description})',
3135
f'Author. Default ({self.author})',
3236
f'Main Blueprint name. Default ({self.main_bp_name})',
33-
f'Setup Heroku deployment files. Default ({self.setup_heroku_deployment_files})']
37+
f'Setup Heroku deployment files. Default ({self.setup_heroku_deployment_files_check})']
3438
self.runtime: str = ".".join(map(str, version_info[:3]))
39+
40+
"""
41+
Main files to run the app
42+
"""
3543
self.flask_files = ['wsgi.py',
3644
'__init__.py',
3745
'routes.py',
@@ -40,14 +48,27 @@ def __init__(self):
4048
'tests.py',
4149
'requirement.txt'
4250
]
43-
self.flask_files_paths = []
44-
self.flask_files_templates = []
51+
self.flask_files_paths: dict = []
52+
self.flask_files_templates: dict = []
53+
54+
"""
55+
Flask directories: templates and static
56+
"""
57+
self.flask_dirs: dict = ['templates',
58+
'static'
59+
]
60+
self.flask_dirs_paths: dict = []
61+
self.flask_dirs_files: dict = ['index.html', 'style.css']
62+
self.flask_dirs_templates: dict = []
4563

64+
"""
65+
Required files to deploy the application to Heroku
66+
"""
4667
self.heroku_files = ['runtime.txt', 'Procfile']
4768
self.heroku_files_paths = []
4869
self.heroku_files_templates = []
4970

50-
def get_input(self, input_msg, default=None):
71+
def get_input(self, input_msg, default=None) -> str:
5172
if version_info >= (3, 0):
5273
input_value = input(f'{input_msg}: ')
5374
else:
@@ -59,7 +80,8 @@ def get_input(self, input_msg, default=None):
5980

6081

6182
def write_content(self, file, content, path) -> None:
62-
with open(f'{path}/{file}', 'w') as file:
83+
file_path = os.path.join(path, file)
84+
with open(file_path, 'w') as file:
6385
if version_info >= (3, 0):
6486
file.write(content)
6587
else:
@@ -75,13 +97,22 @@ def populate_project_files(self) -> None:
7597
self.flask_files_templates):
7698
self.write_content(flask_file, flask_file_template, flask_file_path)
7799

100+
def setup_flask_templates_and_static_files(self) -> None:
101+
for flask_dir, flask_dir_path, flask_dir_file, flask_dir_template in zip(self.flask_dirs,
102+
self.flask_dirs_paths,
103+
self.flask_dirs_files,
104+
self.flask_dirs_templates):
105+
full_dir_path = os.path.join(flask_dir_path, flask_dir)
106+
os.makedirs(full_dir_path, exist_ok=True)
107+
self.write_content(flask_dir_file, flask_dir_template, full_dir_path)
108+
78109
def setup_heroku_files(self) -> None:
79110
for heroku_file, heroku_file_path, heroku_file_template in zip(self.heroku_files,
80111
self.heroku_files_paths,
81112
self.heroku_files_templates):
82113
self.write_content(heroku_file, heroku_file_template, heroku_file_path)
83114

84-
def main(self):
115+
def main(self) -> None:
85116

86117
self.project_name = self.get_input(f'Project name. Default ({self.project_name})',
87118
default=self.project_name)
@@ -95,10 +126,15 @@ def main(self):
95126
default=self.author)
96127
self.main_bp_name = self.get_input(f'Main Blueprint name. Default ({self.main_bp_name})',
97128
default=self.main_bp_name)
98-
self.setup_heroku_deployment_files = self.get_input(f'Setup Heroku deployment files (yes/no). Default ({self.setup_heroku_deployment_files})',
99-
default=self.setup_heroku_deployment_files)
129+
self.setup_heroku_deployment_files_check = self.get_input(
130+
(
131+
f'Setup Heroku deployment files (yes/no). Default'
132+
f'({self.setup_heroku_deployment_files_check})'
133+
),
134+
default=self.setup_heroku_deployment_files_check)
100135

101-
self.flask_files_paths = [f'{self.project_name}',
136+
self.flask_files_paths = [
137+
f'{self.project_name}',
102138
f'{self.project_name}/{self.root_app_name}',
103139
f'{self.project_name}/{self.root_app_name}/{self.main_bp_name}',
104140
f'{self.project_name}/{self.root_app_name}/{self.main_bp_name}',
@@ -107,25 +143,44 @@ def main(self):
107143
f'{self.project_name}'
108144
]
109145

110-
self.flask_files_templates = [wsgi_template.substitute(app_name=self.root_app_name),
111-
app_init_template.substitute(app_name=self.root_app_name, main_bp_name=self.main_bp_name) ,
112-
main_bp_routes_template.substitute(app_name=self.root_app_name, main_bp_name=self.main_bp_name),
113-
main_bp_init_template.substitute(app_name=self.root_app_name, main_bp_name=self.main_bp_name),
114-
config_template.substitute(app_name=self.root_app_name, project_name=self.project_name, runtime=self.runtime),
146+
self.flask_files_templates = [
147+
wsgi_template.substitute(app_name=self.root_app_name),
148+
app_init_template.substitute(app_name=self.root_app_name,
149+
main_bp_name=self.main_bp_name) ,
150+
main_bp_routes_template.substitute(app_name=self.root_app_name,
151+
main_bp_name=self.main_bp_name),
152+
main_bp_init_template.substitute(app_name=self.root_app_name,
153+
main_bp_name=self.main_bp_name),
154+
config_template.substitute(app_name=self.root_app_name,
155+
project_name=self.project_name, runtime=self.runtime,
156+
description=self.description),
115157
tests_template.substitute(),
116158
requirements_template.substitute()
117159
]
118160

119161
self.create_project_structure()
120162
self.populate_project_files()
121163

122-
if 'y'.lower() in self.setup_heroku_deployment_files:
164+
# setup Heroku files if (y)es
165+
if 'y'.lower() in self.setup_heroku_deployment_files_check:
123166
self.heroku_files_paths = [f'{self.project_name}'] * len(self.heroku_files)
124-
self.heroku_files_templates = [runtime_template.substitute(runtime=self.runtime),
167+
self.heroku_files_templates = [
168+
runtime_template.substitute(runtime=self.runtime),
125169
procfile_template.substitute()
126170
]
127171
self.setup_heroku_files()
128172

173+
# setup Flask templates and static dirs and files if (y)es
174+
if 'y'.lower() in self.setup_flask_templates_and_static_files_check:
175+
self.flask_dirs_paths = [
176+
f'{self.project_name}/{self.root_app_name}'
177+
] * len(self.flask_dirs)
178+
self.flask_dirs_templates = [
179+
html_index.substitute(project_name=self.project_name, description=self.description),
180+
style_css.substitute()
181+
]
182+
self.setup_flask_templates_and_static_files()
183+
129184
def console() -> None:
130185
kickstart_flask_app = KickstartFlaskApp()
131186
kickstart_flask_app.main()

build/lib/kickstart_flask_app/templates.py

+66-2
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,21 @@ def create_app(config_class=config_class()):
7171
"""))
7272

7373
main_bp_routes_template = Template(dedent("""\
74+
from datetime import datetime
7475
from ${app_name}.${main_bp_name} import ${main_bp_name}
76+
from flask import jsonify, render_template
77+
78+
@${main_bp_name}.route('/api')
79+
def api():
80+
data = {
81+
'message': 'Hello world!',
82+
'timestamp': datetime.utcnow()
83+
}
84+
return jsonify(data), 200
7585
7686
@${main_bp_name}.route('/')
77-
def Hello():
78-
return 'Hello world!', 200
87+
def index():
88+
return render_template('index.html')
7989
8090
"""))
8191

@@ -113,6 +123,7 @@ class Config(object):
113123
PROJECT_NAME = '${project_name}'
114124
APP_NAME = '${app_name}'
115125
APP_RUNTIME = '${runtime}'
126+
APP_DESCRIPTION = '${description}'
116127
117128
'''
118129
Environment variabbles
@@ -148,6 +159,59 @@ class Development(Config):
148159
149160
"""))
150161

162+
html_index = Template(dedent("""\
163+
<!DOCTYPE html>
164+
<html>
165+
<head>
166+
<title>${project_name}</title>
167+
<link rel="stylesheet" type="text/css" href="{{url_for('static', filename='style.css', _external=True)}}">
168+
</head>
169+
<body>
170+
<h1>${project_name}</h1>
171+
<p>${description}</p>
172+
<p>
173+
<a href="https://github.com/MurphyAdam/kickstart-flask-app"
174+
alt="Github repository for kickstart-flask-app package">Github repository
175+
</a>
176+
</p>
177+
</body>
178+
</html>
179+
"""))
180+
181+
style_css = Template(dedent("""\
182+
html,
183+
body {
184+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
185+
font-size: 14px;
186+
}
187+
188+
body {
189+
background: #fafafa;
190+
overflow-x: hidden;
191+
}
192+
193+
h1 {
194+
color: #4db6ac;
195+
display: flex;
196+
justify-content: center;
197+
}
198+
199+
p {
200+
margin: 2rem;
201+
padding: 1rem;
202+
display: flex;
203+
justify-content: center;
204+
font-size: xx-large;
205+
}
206+
a {
207+
color: #4db6ac;
208+
text-decoration: none;
209+
display: flex;
210+
justify-content: center;
211+
font-size: 1.5rem;
212+
}
213+
"""))
214+
151215
bashrc_template = Template(dedent("""\
152216
EXPORT FLASK_ENV='development'
153217
EXPORT FLASK_APP='development'
-5.45 KB
Binary file not shown.

kickstart_flask_app.egg-info/PKG-INFO

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 1.2
22
Name: kickstart-flask-app
3-
Version: 1.1.4
3+
Version: 1.1.5
44
Summary: Generate a new Flask app project.
55
Home-page: https://github.com/MurphyAdam/kickstart-flask-app
66
Author: Majdi Mahfoud

kickstart_flask_app.egg-info/SOURCES.txt

+1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ kickstart_flask_app.egg-info/SOURCES.txt
88
kickstart_flask_app.egg-info/dependency_links.txt
99
kickstart_flask_app.egg-info/entry_points.txt
1010
kickstart_flask_app.egg-info/not-zip-safe
11+
kickstart_flask_app.egg-info/requires.txt
1112
kickstart_flask_app.egg-info/top_level.txt

0 commit comments

Comments
 (0)