Skip to content

Commit

Permalink
Bump version to 1.9.2; update dependencies and enhance documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
krishvsoni committed Dec 10, 2024
1 parent 3e79d92 commit 26a69cc
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 25 deletions.
97 changes: 73 additions & 24 deletions build/lib/flask_wiz/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
import click
from flask import Flask

db_options = {'1':'mongodb', '2':'sqlite', '3':'mysql', '4':'postgresql'}
value_key = {v: k for k,v in db_options.items()} #created reverse mapping of values to keys

#to display options
def display_options():
options = "\n".join([f"{key}: {value}" for key, value in db_options.items()])
return f"Select database system:\n{options}\n(Enter either key or value)"

def create_app():
app = Flask(__name__)

Expand All @@ -19,14 +27,46 @@ def cli():
def new():
name = click.prompt('Enter project name')

db_options = ['mongodb', 'sqlite', 'mysql', 'postgresql']
db = click.prompt('Select database system', type=click.Choice(db_options))
click.echo(display_options())
db_input = click.prompt('Enter key / Value for db selection')

if db_input in db_options:
db = db_options[db_input]
elif db_input in value_key:
db = value_key[db_input]
else:
click.echo('Invalid input')
return

os.makedirs(name)
os.chdir(name)

os.makedirs('templates')
os.chdir('templates')

with open('home.html', 'w') as home_file:
home_file.write("""<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flask-app</title>
</head>
<body>
<h1>flask app generated with flask-wiz</h1>
<p>{{ message }}</p>
</body>
</html>""")

os.chdir('..')

os.makedirs('static')
os.chdir('static')

os.makedirs('css')
os.makedirs('js')
os.makedirs('img')
os.chdir('..')

with open('.gitignore', 'w') as gitignore_file:
gitignore_file.write("# Default .gitignore for Flask project\n")
Expand All @@ -40,10 +80,12 @@ def new():
with open('app.py', 'w') as app_file:
db_module = None

if db == 'mongodb':
db_module = 'pymongo'
app_file.write(
"""from flask import Flask

match db_input:
case '1':
db_module = 'pymongo'
app_file.write(
"""from flask import Flask, render_template, redirect
from pymongo import MongoClient
app = Flask(__name__)
Expand All @@ -52,64 +94,71 @@ def new():
@app.route('/')
def index():
return 'Namaste Duniya! This is a Flask app generated by Flask-Wiz for MongoDB.'
return render_template('home.html', message = 'Namaste Duniya! This is a Flask app generated by Flask-Wiz for MongoDB.')
if __name__ == '__main__':
app.run()
""")
elif db == 'sqlite':
db_module = 'sqlite3'
app_file.write(
"""from flask import Flask
case '2':
db_module = 'sqlite3'
app_file.write(
"""from flask import Flask, render_template, redirect
import sqlite3
app = Flask(__name__)
conn = sqlite3.connect('database.db')
@app.route('/')
def index():
return 'Namaste Duniya! This is a Flask app generated by Flask-Wiz for SQLite.'
return render_template('home.html', message = 'Namaste Duniya! This is a Flask app generated by Flask-Wiz for SQLite.')
if __name__ == '__main__':
app.run()
""")
elif db == 'mysql':
db_module = 'pymysql'
app_file.write(
"""from flask import Flask
case '3':
db_module = 'pymysql'
app_file.write(
"""from flask import Flask, render_template, redirect
import pymysql
app = Flask(__name__)
conn = pymysql.connect(host='localhost', user='root', password='', database='my_database')
@app.route('/')
def index():
return 'Namaste Duniya! This is a Flask app generated by Flask-Wiz MySQL.'
return render_template('home.html', message = 'Namaste Duniya! This is a Flask app generated by Flask-Wiz MySQL.')
if __name__ == '__main__':
app.run()
""")
elif db == 'postgresql':
db_module = 'psycopg2'
app_file.write(
"""from flask import Flask
case '4':
db_module = 'psycopg2'
app_file.write(
"""from flask import Flask, render_template, redirect
import psycopg2
app = Flask(__name__)
conn = psycopg2.connect(host='localhost', user='postgres', password='', dbname='my_database')
@app.route('/')
def index():
return 'Namaste Duniya! This is a Flask app generated by Flask-Wiz PostgreSQL.'
return render_template('home.html', message = 'Namaste Duniya! This is a Flask app generated by Flask-Wiz PostgreSQL.')
if __name__ == '__main__':
app.run()
""")
case _:
print('Invalid choice. Please choose a valid database system.')

if db_module:
os.system(f"pip install {db_module}") # Install the required database module

click.echo(f'New Flask project "{name}" created successfully with {db} database!')
if db_module != 'sqlite3':
os.system(f"pip install {db_module}") # Install the required database module

# to create a requirements file
os.system(f"pip freeze > requirements.txt")

click.echo(f'New Flask project "{name}" created successfully with {db_module} database!')

if __name__ == '__main__':
cli()
Binary file added dist/flask_wiz-1.9.2-py3-none-any.whl
Binary file not shown.
Binary file added dist/flask_wiz-1.9.2.tar.gz
Binary file not shown.
19 changes: 18 additions & 1 deletion flask_wiz.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
Metadata-Version: 2.1
Name: flask-wiz
Version: 1.9.1
Version: 1.9.2
Author: Krish Soni
Description-Content-Type: text/markdown
Requires-Dist: flask
Requires-Dist: click
Requires-Dist: Flask

# Flask-Wiz: Simplified Flask Setup

Expand All @@ -29,10 +32,24 @@ pip install flask-wiz

```Terminal
flask-wiz new
Project Name: my_project
Database (MongoDB/SQLite/MySQL/PostgreSQL):
```

```Terminal
<project_name>/
├── templates/
├── static/
├── .gitignore
└── .env
```

3. **Follow the Prompts**: Flask-Wiz will guide you through the setup process, including selecting your desired database and configuring directory structure.

4. **Start Developing**: Once the setup is complete, you're ready to start developing your Flask application!

Flask-Wiz simplifies the setup process for Flask projects, allowing you to focus on building your application without worrying about initial configuration.

## Need More Assistance
- Visit: https://www.blackbox.ai/agent/flask-wizhelpN9qFZun

0 comments on commit 26a69cc

Please sign in to comment.