Skip to content

Commit

Permalink
Minor refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
toddbirchard committed Dec 8, 2023
1 parent a39eff7 commit 080d9e7
Show file tree
Hide file tree
Showing 15 changed files with 516 additions and 525 deletions.
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[flake8]
max-line-length = 120
select = E9,F63,F7,F82
exclude = .git,.github,__pycache__,.pytest_cache,.venv,logs,creds,.reports
2 changes: 0 additions & 2 deletions .github/workflows/linter.yml

This file was deleted.

47 changes: 22 additions & 25 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,31 @@

name: Python application

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
on: [push]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
pip install -r requirements.txt
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
14 changes: 8 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,6 @@ venv.bak/
# mypy
.mypy_cache/

# System & Cache files
.idea
.DS_Store
.webassets-cache
.vscode

# Secrets
creds
creds/*
Expand All @@ -116,3 +110,11 @@ gcloud.json

# Socket
*.sock

# System & Cache files
.DS_Store
.webassets-cache

# IDES
.idea
.vscode
4 changes: 0 additions & 4 deletions .vscode/settings.json

This file was deleted.

1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ lint: env
$(LOCAL_PYTHON) -m flake8 . --count \
--select=E9,F63,F7,F82 \
--exclude .git,.github,__pycache__,.pytest_cache,.venv,logs,creds,.venv,docs,logs,.reports \
--max-line-length=120 \
--show-source \
--statistics

Expand Down
4 changes: 3 additions & 1 deletion clients/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@


class Database:
"""Database connection object."""

def __init__(self, uri, table, args=None):
self.uri = uri
self.table = table
self.args = args

@property
def engine(self):
# Database connection engine
"""Database connection engine"""
return create_engine(self.uri, connect_args=self.args)

def upload_dataframe(self, df: DataFrame):
Expand Down
845 changes: 407 additions & 438 deletions poetry.lock

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,23 @@ cssmin = "*"
jsmin = "*"
lesscpy = "*"
uwsgi = "*"
flake8 = "*"

[tool.poetry.scripts]
run = "wsgi:app"

[tool.poetry.urls]
issues = "https://github.com/toddbirchard/pythonmyadmin/issues"

[tool.poetry.group.dev.dependencies]
black = { version = "^23.7.0", allow-prereleases = true }

[build-system]
requires = ["poetry>=1.5.1"]
build-backend = "poetry.masonry.api"
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.isort]
profile = "black"
src_paths = ["pythonmyadmin", "table", "clients", "config"]


[tool.pylint.'MESSAGES CONTROL']
disable = "C0103,C0301,W0703,W0621"
Expand Down
5 changes: 2 additions & 3 deletions pythonmyadmin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ def create_app() -> Flask:
db.create_all()

# Import parts of our application
from pythonmyadmin import routes
from pythonmyadmin.assets import compile_js_assets, compile_style_assets
from table import tableview

from . import routes
from .assets import compile_js_assets, compile_style_assets

# Register App Blueprint
app.register_blueprint(routes.main_bp)

Expand Down
2 changes: 1 addition & 1 deletion pythonmyadmin/static/dist/css/style.css

Large diffs are not rendered by default.

25 changes: 13 additions & 12 deletions pythonmyadmin/static/less/table.less
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,12 @@
}

#search,
.Select-control {
.Select {
margin: 0;
padding: 8px;
border: 0;
box-shadow: 0 0 4px #cdd3e2;


.Select-placeholder {
height: fit-content;
margin: auto;
Expand All @@ -219,19 +218,21 @@
.Select-value-label {
padding: 4px 9px;
line-height: 1;
font-size: .8em;
font-size: .7em;
}
}
}

.Select-menu-outer {
border: 0;
box-shadow: 0 0 6px #cdd3e2;
font-size: .8em;

* {
width: 100%;
color: #404552;
.Select-menu-outer {
border: 0;
box-shadow: 0 0 6px #cdd3e2;
font-size: .7em;
height: 500px !important;
min-height: 500px !important;

* {
width: 100%;
color: #404552;
}
}
}

Expand Down
47 changes: 26 additions & 21 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,58 +1,63 @@
ansi2html==1.8.0 ; python_version >= "3.10" and python_version < "4.0"
async-timeout==4.0.3 ; python_version >= "3.10" and python_full_version <= "3.11.2"
black==23.10.0 ; python_version >= "3.10" and python_version < "4.0"
certifi==2023.7.22 ; python_version >= "3.10" and python_version < "4.0"
charset-normalizer==3.3.0 ; python_version >= "3.10" and python_version < "4.0"
black==23.11.0 ; python_version >= "3.10" and python_version < "4.0"
blinker==1.7.0 ; python_version >= "3.10" and python_version < "4.0"
certifi==2023.11.17 ; python_version >= "3.10" and python_version < "4.0"
charset-normalizer==3.3.2 ; python_version >= "3.10" and python_version < "4.0"
click==8.1.7 ; python_version >= "3.10" and python_version < "4.0"
colorama==0.4.6 ; python_version >= "3.10" and python_version < "4.0" and (sys_platform == "win32" or platform_system == "Windows")
cssmin==0.2.0 ; python_version >= "3.10" and python_version < "4.0"
dash-core-components==2.0.0 ; python_version >= "3.10" and python_version < "4.0"
dash-html-components==2.0.0 ; python_version >= "3.10" and python_version < "4.0"
dash-renderer==1.9.1 ; python_version >= "3.10" and python_version < "4.0"
dash-table==5.0.0 ; python_version >= "3.10" and python_version < "4.0"
dash==2.14.0 ; python_version >= "3.10" and python_version < "4.0"
exceptiongroup==1.1.3 ; python_version >= "3.10" and python_version < "3.11"
flask-assets==2.0 ; python_version >= "3.10" and python_version < "4.0"
dash==2.14.2 ; python_version >= "3.10" and python_version < "4.0"
exceptiongroup==1.2.0 ; python_version >= "3.10" and python_version < "3.11"
flake8==6.1.0 ; python_version >= "3.10" and python_version < "4.0"
flask-assets==2.1.0 ; python_version >= "3.10" and python_version < "4.0"
flask-sqlalchemy==3.1.1 ; python_version >= "3.10" and python_version < "4.0"
flask==2.2.5 ; python_version >= "3.10" and python_version < "4.0"
greenlet==3.0.0 ; python_version >= "3.10" and python_version < "4.0" and (platform_machine == "aarch64" or platform_machine == "ppc64le" or platform_machine == "x86_64" or platform_machine == "amd64" or platform_machine == "AMD64" or platform_machine == "win32" or platform_machine == "WIN32")
idna==3.4 ; python_version >= "3.10" and python_version < "4.0"
importlib-metadata==6.8.0 ; python_version >= "3.10" and python_version < "4.0"
flask==3.0.0 ; python_version >= "3.10" and python_version < "4.0"
greenlet==3.0.1 ; python_version >= "3.10" and python_version < "4.0" and (platform_machine == "aarch64" or platform_machine == "ppc64le" or platform_machine == "x86_64" or platform_machine == "amd64" or platform_machine == "AMD64" or platform_machine == "win32" or platform_machine == "WIN32")
idna==3.6 ; python_version >= "3.10" and python_version < "4.0"
importlib-metadata==7.0.0 ; python_version >= "3.10" and python_version < "4.0"
iniconfig==2.0.0 ; python_version >= "3.10" and python_version < "4.0"
isort==5.12.0 ; python_version >= "3.10" and python_version < "4.0"
itsdangerous==2.1.2 ; python_version >= "3.10" and python_version < "4.0"
jinja2==3.1.2 ; python_version >= "3.10" and python_version < "4.0"
jsmin==3.0.1 ; python_version >= "3.10" and python_version < "4.0"
lesscpy==0.15.1 ; python_version >= "3.10" and python_version < "4.0"
markupsafe==2.1.3 ; python_version >= "3.10" and python_version < "4.0"
mccabe==0.7.0 ; python_version >= "3.10" and python_version < "4.0"
mypy-extensions==1.0.0 ; python_version >= "3.10" and python_version < "4.0"
nest-asyncio==1.5.8 ; python_version >= "3.10" and python_version < "4.0"
numpy==1.26.1 ; python_version >= "3.10" and python_version <= "3.11"
numpy==1.26.2 ; python_version >= "3.10" and python_version <= "3.11" or python_version >= "3.12" and python_version < "4.0"
packaging==23.2 ; python_version >= "3.10" and python_version < "4.0"
pandas==2.1.1 ; python_version >= "3.10" and python_version < "4.0"
pandas==2.1.3 ; python_version >= "3.10" and python_version < "4.0"
pathspec==0.11.2 ; python_version >= "3.10" and python_version < "4.0"
platformdirs==3.11.0 ; python_version >= "3.10" and python_version < "4.0"
plotly==5.17.0 ; python_version >= "3.10" and python_version < "4.0"
platformdirs==4.1.0 ; python_version >= "3.10" and python_version < "4.0"
plotly==5.18.0 ; python_version >= "3.10" and python_version < "4.0"
pluggy==1.3.0 ; python_version >= "3.10" and python_version < "4.0"
ply==3.11 ; python_version >= "3.10" and python_version < "4.0"
pycodestyle==2.11.1 ; python_version >= "3.10" and python_version < "4.0"
pyflakes==3.1.0 ; python_version >= "3.10" and python_version < "4.0"
pymysql==1.1.0 ; python_version >= "3.10" and python_version < "4.0"
pytest==7.4.2 ; python_version >= "3.10" and python_version < "4.0"
pytest==7.4.3 ; python_version >= "3.10" and python_version < "4.0"
python-dateutil==2.8.2 ; python_version >= "3.10" and python_version < "4.0"
python-dotenv==1.0.0 ; python_version >= "3.10" and python_version < "4.0"
pytz==2023.3.post1 ; python_version >= "3.10" and python_version < "4.0"
redis==5.0.1 ; python_version >= "3.10" and python_version < "4.0"
requests==2.31.0 ; python_version >= "3.10" and python_version < "4.0"
retrying==1.3.4 ; python_version >= "3.10" and python_version < "4.0"
setuptools==68.2.2 ; python_version >= "3.10" and python_version < "4.0"
setuptools==69.0.2 ; python_version >= "3.10" and python_version < "4.0"
six==1.16.0 ; python_version >= "3.10" and python_version < "4.0"
sqlalchemy==2.0.22 ; python_version >= "3.10" and python_version < "4.0"
sqlalchemy==2.0.23 ; python_version >= "3.10" and python_version < "4.0"
tenacity==8.2.3 ; python_version >= "3.10" and python_version < "4.0"
tomli==2.0.1 ; python_version >= "3.10" and python_version < "3.11"
typing-extensions==4.8.0 ; python_version >= "3.10" and python_version < "4.0"
tzdata==2023.3 ; python_version >= "3.10" and python_version < "4.0"
urllib3==2.0.7 ; python_version >= "3.10" and python_version < "4.0"
uwsgi==2.0.22 ; python_version >= "3.10" and python_version < "4.0"
urllib3==2.1.0 ; python_version >= "3.10" and python_version < "4.0"
uwsgi==2.0.23 ; python_version >= "3.10" and python_version < "4.0"
webassets==2.0 ; python_version >= "3.10" and python_version < "4.0"
werkzeug==2.2.3 ; python_version >= "3.10" and python_version < "4.0"
wtforms==3.1.0 ; python_version >= "3.10" and python_version < "4.0"
werkzeug==3.0.1 ; python_version >= "3.10" and python_version < "4.0"
wtforms==3.1.1 ; python_version >= "3.10" and python_version < "4.0"
zipp==3.17.0 ; python_version >= "3.10" and python_version < "4.0"
27 changes: 20 additions & 7 deletions table/tableview.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@


def create_dash_view(server: Flask) -> Flask:
"""Initiate Plotly Dash view."""
"""
Initiate Plotly Dash view.
:param Flask server: Flask server object.
:returns: Flask
"""
external_stylesheets = [
"/static/dist/css/style.css",
"https://fonts.googleapis.com/css?family=Lato::300,700",
Expand All @@ -29,20 +35,27 @@ def create_dash_view(server: Flask) -> Flask:

# Get DataFrame
table_df = db.get_table_data()
datatable = create_data_table(table_df)
dash_table = create_data_table(table_df)

for column in table_df:
db.column_dist_chart(table_df, column)

# Create Dash Layout comprised of Data Tables
dash_app.layout = create_layout(datatable, table_df)
dash_app.layout = create_layout(dash_table, table_df)
init_callbacks(dash_app, table_df)

return dash_app.server


def create_layout(datatable: DataTable, table_df: DataFrame):
"""Create Dash layout for table editor."""
def create_layout(dash_table: DataTable, table_df: DataFrame) -> html.Div:
"""
Create Dash layout for table editor.
:param DataTable dash_table: Plotly Dash DataTable component.
:param DataFrame table_df: DataFrame created from SQL table.
:returns: html.Div
"""
return html.Div(
id="database-table-container",
children=[
Expand All @@ -58,7 +71,7 @@ def create_layout(datatable: DataTable, table_df: DataFrame):
),
],
),
datatable,
dash_table,
html.Div(id="callback-container"),
html.Div(id="container-button-basic", children=[html.Div(id="save-status")]),
],
Expand All @@ -80,7 +93,7 @@ def create_data_table(table_df: DataFrame) -> DataTable:
sort_action="native",
sort_mode="native",
page_size=9000,
editable=True,
editable=False,
)
return table

Expand Down
2 changes: 1 addition & 1 deletion wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
app = create_app()

if __name__ == "__main__":
app.run(host="0.0.0.0", load_dotenv=True, port=8091, debug=True)
app.run(host="0.0.0.0", load_dotenv=True, port=8091)

0 comments on commit 080d9e7

Please sign in to comment.