Skip to content

Commit

Permalink
Merge pull request #260 from flask-dashboard/formatter
Browse files Browse the repository at this point in the history
Formatter
  • Loading branch information
mircealungu committed Oct 9, 2019
2 parents 78d2c04 + e8ff6a9 commit 1a075a3
Show file tree
Hide file tree
Showing 80 changed files with 1,109 additions and 464 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,12 @@ If you run into trouble migrating from version 1.X.X to version 2.0.0, this site
![Screenshot 4](/docs/img/ss4.png)
![Screenshot 5](/docs/img/ss5.png)

## Development
If you like our project, and willing to contribute, you can get started by running the following command:

. ./config/install.sh

For more information, check [this page](https://flask-monitoringdashboard.readthedocs.io/en/latest/developing.html).

## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
21 changes: 21 additions & 0 deletions config/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
repos:
- repo: https://github.com/psf/black
rev: 19.3b0
hooks:
- id: black
args: [-S, --line-length=100]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: flake8
args: ['--max-line-length=100', '--ignore=F401, W503']
- repo: local
hooks:
- id: version_increase
name: version_increase
description: Increase version in constants.json
entry: env/bin/python config/increase_version.py
language: python
files: ^$
args: ['patch']
always_run: true
64 changes: 64 additions & 0 deletions config/increase_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env python
"""
Run this script to increase the version defined in flask_monitoringdashboard/constants.py
The script can use the arguments 'major', 'minor', or 'patch' to increase the corresponding
version. If no argument is specified, the 'patch' version is increased
"""
import argparse
import json
import sys
import requests
import os
import subprocess

HERE = os.path.dirname(os.path.realpath(__file__))
FILE = os.path.abspath(os.path.join(HERE, '..', 'flask_monitoringdashboard', 'constants.json'))


def main(argv=None):
parser = argparse.ArgumentParser()
parser.add_argument("type", nargs="?", default="patch")
args = parser.parse_args(argv)

options = ['major', 'minor', 'patch']
if args.type not in options:
print('Incorrect argument type: {}. Options are: {}'.format(args.type, ', '.join(options)))
return 1

branch = (
subprocess.Popen("git rev-parse --abbrev-ref HEAD", shell=True, stdout=subprocess.PIPE)
.stdout.read()
.decode('utf-8')
.replace('\n', '')
)

if branch != 'development':
print('Only increasing version on development, not on branch "{}"'.format(branch))
return 0

index = options.index(args.type)

# read current data
with open(FILE, 'r', encoding='UTF-8') as json_file:
constants = json.load(json_file)

# retrieve latest version
response = requests.get('https://pypi.org/pypi/Flask-MonitoringDashboard/json')
pypi_json = response.json()
version = pypi_json['info']['version'].split('.')

version[index] = int(version[index]) + 1
for i in range(index + 1, len(version)): # set version after updated version to 0
version[i] = 0
constants['version'] = '.'.join(str(v) for v in version)
print('Increased {} version to {}'.format(args.type, constants['version']))

# write new version
with open(FILE, 'w', encoding='UTF-8') as json_file:
json.dump(constants, json_file, indent=4, separators=(',', ': '))

return 0


if __name__ == '__main__':
sys.exit(main())
9 changes: 9 additions & 0 deletions config/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Run from the root directory with ./config/install.sh
# Note that pre-commit is not in the requirements.txt, as we don't want this to ship with the package.

python -m venv env
source env/bin/activate
pip install -r requirements-dev.txt
cd config || exit
pre-commit install
cd ..
39 changes: 26 additions & 13 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# full list see the documentation:
# http://www.sphinx-doc.org/en/stable/config
import datetime

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
Expand All @@ -15,6 +16,7 @@
import os
import sys
import json

sys.path.insert(0, os.path.abspath('..'))
sys.path.insert(0, os.path.abspath('../flask-monitoringdashboard'))

Expand Down Expand Up @@ -88,9 +90,7 @@
# further. For a list of options available for each theme, see the
# documentation.
#
html_theme_options = {
'github_fork': 'flask-dashboard/Flask-MonitoringDashboard'
}
html_theme_options = {'github_fork': 'flask-dashboard/Flask-MonitoringDashboard'}

html_sidebars = {'**': ['globaltoc.html', 'searchbox.html', 'sourcelink.html']}

Expand Down Expand Up @@ -122,15 +122,12 @@
# The paper size ('letterpaper' or 'a4paper').
#
'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
'pointsize': '11pt',

# Additional stuff for the LaTeX preamble.
#
'preamble': '',

# Latex figure (float) alignment
#
'figure_align': 'htbp',
Expand All @@ -140,8 +137,13 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'Flask-MonitoringDashboard.tex', 'Flask-MonitoringDashboard Documentation',
author, 'manual'),
(
master_doc,
'Flask-MonitoringDashboard.tex',
'Flask-MonitoringDashboard Documentation',
author,
'manual',
)
]


Expand All @@ -150,8 +152,13 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'flask-monitoringdashboard', 'Flask-MonitoringDashboard Documentation',
[author], 1)
(
master_doc,
'flask-monitoringdashboard',
'Flask-MonitoringDashboard Documentation',
[author],
1,
)
]


Expand All @@ -161,9 +168,15 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'Flask-MonitoringDashboard', 'Flask-MonitoringDashboard Documentation',
author, 'Flask-MonitoringDashboard', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
'Flask-MonitoringDashboard',
'Flask-MonitoringDashboard Documentation',
author,
'Flask-MonitoringDashboard',
'One line description of project.',
'Miscellaneous',
)
]


Expand Down
20 changes: 19 additions & 1 deletion docs/developing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@ this page shows FMD from the point of view of the developer. We explain the
architecture of the project, take a look at the main components, and then
present some useful tools that we use during development.

Getting started
----------------
In order to get started with the environment of the FMD, run the following script

.. code-block:: bash
. ./config/install.sh
Note the '. ' before the script. This will activate your virtual environment. This script is
responsible for setting up the project, and installing the following pre-commit hooks:

- `Black`_: for automatic formatting the code. Note that we use a width-length of 100 characters.
- `Flake8`_: for checking style error.
- Auto increase the Python version. This can either be a major, minor, or patch version increase. For more info, see
the Versions-section below.

Architecture
--------------

Expand Down Expand Up @@ -161,4 +177,6 @@ The following tools are used for helping the development of the Dashboard:
.. _`Semantic-versioning`: https://semver.org/
.. _`SQLAlchemy`: https://www.sqlalchemy.org/
.. _Sphinx: www.sphinx-doc.org
.. _ReadTheDocs: http://flask-monitoringdashboard.readthedocs.io
.. _ReadTheDocs: http://flask-monitoringdashboard.readthedocs.io
.. _Black: https://github.com/psf/black
.. _Flake8: https://pypi.org/project/flake8
13 changes: 12 additions & 1 deletion flask_monitoringdashboard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,16 @@ def bind(app, schedule=True):
app.secret_key = 'my-secret-key'

# Add all route-functions to the blueprint
from flask_monitoringdashboard.views import deployment, custom, endpoint, outlier, request, profiler, version, auth
from flask_monitoringdashboard.views import (
deployment,
custom,
endpoint,
outlier,
request,
profiler,
version,
auth,
)
import flask_monitoringdashboard.views

# Add wrappers to the endpoints that have to be monitored
Expand All @@ -64,6 +73,7 @@ def bind(app, schedule=True):
# flush cache to db before shutdown
import atexit
from flask_monitoringdashboard.core.cache import flush_cache

atexit.register(flush_cache)


Expand All @@ -75,5 +85,6 @@ def add_graph(title, func, **schedule):
:param func: function reference without arguments
"""
from flask_monitoringdashboard.core import custom_graph

graph_id = custom_graph.register_graph(title)
custom_graph.add_background_job(func, graph_id, **schedule)
3 changes: 2 additions & 1 deletion flask_monitoringdashboard/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ def fmd():
def init_db():
# Importing the database package is enough
import flask_monitoringdashboard.database
print('Flask-MonitoringDashboard database has been created')

print('Flask-MonitoringDashboard database has been created')
8 changes: 4 additions & 4 deletions flask_monitoringdashboard/constants.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "3.0.6",
"author": "Patrick Vogel, Bogdan Petre",
"email": "flask.monitoringdashboard@gmail.com"
}
"version": "3.0.6",
"author": "Patrick Vogel, Bogdan Petre",
"email": "flask.monitoringdashboard@gmail.com"
}

0 comments on commit 1a075a3

Please sign in to comment.