Skip to content

Commit

Permalink
merge to 0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
italomaia committed Nov 10, 2018
2 parents 8ccc6f7 + 99d5e56 commit e4d9051
Show file tree
Hide file tree
Showing 15 changed files with 417 additions and 486 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vscode
.idea
*.pyc
*~
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Changelog
=========

Version 0.5

- Updated commands to use click (flask-script is no more)
- Empty package is now used
- Added docs to newly created projects
- Random fixes here and there =3

Version 0.3.2

- Changed cookiecutter input to ask wether the app will be rest or _plain_ http.
- New default dependencies.

Version 0.3.1

- Still quite unsure

Version 0.3

- I'm quite unsure
91 changes: 33 additions & 58 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use cookiecutter and create a new project in no time.

```shell
# if cookiecutter is not installed
sudo pip install cookiecutter
sudo pip install cookiecutter # or pip install --user cookiecutter

# using cookiecutter // linux/Mac
cookiecutter https://github.com/italomaia/flask-empty
Expand All @@ -19,16 +19,17 @@ cookiecutter https://github.com/italomaia/flask-empty
Setup
=====

You're advised to use virtualenvwrapper from here on. Install it like this:
You're advised to use venv from here on. In your project folder,
create and enable it like this:

```
pip install virtualenvwrapper
```shell
python3 -m venv venv
. venv/bin/activate # [.csh|.fish]
```

Create a virtual environment for you project and install the adequate requirements.
Install the adequate requirements.

```
mkvirtualenv my_project
```shell
pip install -r requirements/dev.txt # dev environment if local
pip install -r requirements/prod.txt # prod environment if server
```
Expand All @@ -38,71 +39,44 @@ You're advised to change the requirements files according to your needs.
Important files to be aware of
==============================

### project/config.py

**extensions.py** all extension instances that need initialization should be available
here in order for _Empty_ to see and initialize them for you.
**<project>/extensions.py** all extension instances that need initialization should be available
here in order to have _Empty_ see and initialize them for you.

**config.py** is a pre-set configuration classes for you to meddle with. They're are all self explanatory
**<project>/config.py** is a pre-set configuration classes for you to meddle with. They're are all self explanatory
and commented.

**main.py** the _Empty_ class inherits from the _Flask_ class. Override it if you need to setup
extensions, an index view, context processors, etc. It already has sensitive defaults for most
features. (see **empty.py** to better understand _Empty_)
**<project>/main.py** the _Empty_ class inherits from _empty.Empty_ which inherits from _flask.Flask_. Override it if you need to setup extensions, an index view, context processors, etc. It already has some sensitive defaults for most use cases. See https://github.com/italomaia/empty for all options.

**database.py** setup your database library there. There is some commented code for sqlalchemy support out of the box.

**PROJECT_NAME.ini** is the configuration file used with
**<project>/<project>.ini** is the configuration file used with
[uwsgi](https://github.com/unbit/uwsgi). Use it like this:

```
uwsgi --ini your_project.ini
```

**manage.py** adds few very useful commandline commands (...) to help your development productivity. Check
available commands by running **python manage.py**.
**commands.py** adds few very useful commandline commands (...) to help your development productivity. Check available commands by running **flask**.

## Heroku

Empty comes with a pre-configured _procfile_ and _heroku()_ wrapper for _app_factory_. No setup required.

## Observations

Note that the Flask-Script option "-d (disable debug)" does not work as expected with Flask-Empty. If you want
to start a non-debug internal server instance, use the **config.Config** configuration or write your own. Example:

```python
# loads config.Config configuration, which has DEBUG=False
# -r is the Flask-Script option for internal server no-reload
python manage.py -r -c Config
```

If [environment config named APP_CONFIG is set](http://flask.pocoo.org/docs/config/#configuring-from-files),
it will be used, overwriting any other set configuration.

Other topics
============

## Templates

There are some error templates bundled with flask-empty by default. All empty right now. Just fill them up for
your project.
There are some error templates bundled with flask-empty by default. All empty right now. Just fill them up for your project.

## Macros

You can use the jinja2 macros available in **templates/macros** to easily integrate your jinja2 templates with
flask extensions like wtforms and commons tasks like showing flash messages. Available macros, **formhelpers**
and **flashing** are very useful.
flask extensions like wtforms and commons tasks like showing flash messages. Available macros, **formhelpers** and **flashing** are very useful.

## Blueprints

Add your blueprints using **src/config.Config.BLUEPRINTS** as documented in the file itself. A blueprint can be add
using the path to the Blueprint or a tuple. Make sure your blueprint has a views.py and
it has a **app** Blueprint instance and you're ready to go. If unsure, check out **flask-empty/blueprint/**
for an empty blueprint example. You can also copy **flask-empty/blueprint/** to create blueprints.

With flask-empty, blueprints can live in the project root or in a special folder called **apps** in the project root.

You can create blueprints easily with **flask new-app <name>**. The will live, by default
at **apps** folder. Remember to configure your blueprints in **config.py** so that they
can be properly loaded.

# Supported Extensions

Expand All @@ -129,32 +103,34 @@ supports it! Just say "yes" during project creation and Flask-WTF support will b
Just create an admin.py file in your blueprint, define your admin models inside and change
**LOAD_MODULES_EXTENSIONS** to also pre-load admin, like this:

```
LOAD_MODULES_EXTENSIONS = ['views', 'models', 'admin']
```
## Flask-Marshmallow

## Other Extensions
Gives you, almost for free, model serialization, deserialization and validation. Also
quite handy for fast development of rest applications.

## Flask-Security

Get user session and permissioning out-of-the-box with this great project.

Examples
========
If my explanation above is as crappy as I think it is, you're gonna want/need to take a look at **examples/**. They
are a very nice starting point to learn how to configure your project. Wort-case-scenario, just copy it, rename it,
configure it and be happy!

The blog example in this project is probably outdated by now, so, just create a new project
and mess around to your heart's content for quick learning.

FAQ
===
**Is flask-empty _boilerplate_ compatible with flask 0.x? Cuz' that's what my app uses.**

Right now, flask-empty is a very simple project where many good practices and code examples were glued together.

Until recently I was focused in keeping backward compatibility with flask 0.8. Well, **that goal is no more**.
Flask-empty will be compatible with the latest version of Flask and, by chance, with previous versions.
Things will be easier this way.
Flask-empty will be compatible with the latest version of Flask and, by chance, with previous versions.
Things will be easier (for me!) this way.

**So, which is the oldest version where flask-empty works?**

In my last test, version 0.9, but no guarantees here.
In my last test, version 1.0.

**I think flask-empty should have _this_ and _that_ configured by default. Will you add support?**

Expand All @@ -163,9 +139,8 @@ My current goals are:
* Make flask-empty real easy to start a project with
* Keep things simple and robust

If your suggestion is simple, **VERY** useful and has little overhead, I'll probably consider adding it to the
project. If you make the code and send a pull request, then I'll consider it real hard. Now, if your suggestion is
rejected or advised in a different approach, don't get sad (you're awesome ;).
If your suggestion is simple, **VERY** useful and has little overhead, I'll probably consider adding it to the project.
If you make the code and send a pull request, then I'll consider it real hard. Now, if your suggestion is rejected or advised in a different approach, don't get sad (you're awesome ;).

**I just made a cool example with flask-empty and want to add it to examples.**

Expand Down
8 changes: 6 additions & 2 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
"create_index_view": "yes",
"use_sql": "yes",
"use_nosql": "no",
"use_forms": "yes",
"use_socketio": "no"
"use_admin": "no",
"rest_app": "yes",
"use_security": "{{ cookiecutter.use_admin }}",
"use_socketio": "{{ cookiecutter.rest_app }}",
"use_async_tasks": "{{ cookiecutter.use_socketio }}",
"http_app": "no"
}
2 changes: 2 additions & 0 deletions {{ cookiecutter.repo_name }}/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FLASK_APP=wsgi.py
FLASK_DEBUG=1
58 changes: 58 additions & 0 deletions {{ cookiecutter.repo_name }}/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Getting Started

## main.py

Holds your project class definition and factory. If you want to tweak with it,
be sure to read the docs at https://github.com/italomaia/empty first.

## wsgi.py

This is where your project instance lives.

## config.py

Holds most of your configuration, like which extensions to use, which
blueprints to load, how looging should work, etc.

## commands.py

You can add custom commands to your project here.

## extensions.py

Your extensions are defined and loaded here. If you're adding a new
extension to your project, might be a good idea to create its instance
here (and load it through your configuration).

## mixins.py

Right now it only has a http mixin for some standard http behavior. Useful
for vanilla web projects. Not so much if you're building a web service.

## Some examples below

```
# run your flask application
flask run
# create a new blueprint
flask new-app name
# create your migration files
flask db init
# given your models are defined, this creates your migrations
flask db migrate
# applies migrations to the database (creates tables and so on)
flask db upgrade
# looks up your tests and runs them =D (blueprints and project level)
flask test
# looks up roles (see flask-security docs)
flask roles
# looks up users (see flask-security docs)
flask users
```
Loading

0 comments on commit e4d9051

Please sign in to comment.