Browse Source

ruff as new formatter and linter

main
crunk 6 months ago
parent
commit
23ac3e7699
  1. 68
      pyproject.toml
  2. 10
      verse/describer/describe_files.py
  3. 1
      verse/describer/forms/describe_file_form.py
  4. 10
      verse/file_crawler.py
  5. 20
      verse/migrations/env.py
  6. 17
      verse/start.py

68
pyproject.toml

@ -1,25 +1,49 @@
[tool.black]
[tool.ruff]
line-length = 79
target-version = ['py311']
include = '\.pyi?$'
exclude = '''
/(
\.eggs
| \.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| _build
| buck-out
| build
| dist
# The following are specific to Black, you probably don't want those.
| blib2to3
| tests/data
| profiling
)/
'''
target-version = "py311"
#include = '\.pyi?$'
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".ipynb_checkpoints",
".mypy_cache",
".nox",
".pants.d",
".pyenv",
".pytest_cache",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
".vscode",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"site-packages",
"venv",
]
[tool.ruff.lint]
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
select = ["E4", "E7", "E9", "F"]
ignore = []
# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []
# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
[tool.ruff.format]
quote-style = "double"
indent-style = "tab"
docstring-code-format = true
line-ending = "auto"
skip-magic-trailing-comma = false

10
verse/describer/describe_files.py

@ -2,6 +2,7 @@ from flask import Blueprint, render_template, redirect, url_for
from flask_login import current_user
from models.distribusi_model import Distribusis
from models.distribusi_file_model import DistribusiFiles
from describer.forms.describe_file_form import DescribeFileForm
describer = Blueprint(
"describer",
@ -21,4 +22,11 @@ def describe_distribusi_files(distribusiname):
distribusi_files = DistribusiFiles.query.filter_by(
distribusi=distribusi.id
).all()
return render_template("describe.html", distribusi_files=distribusi_files)
# distribusi_file_forms = {}
# for distribusi_file in distribusi_files:
describe_form = DescribeFileForm()
return render_template(
"describe.html",
distribusi_files=distribusi_files,
describe_form=describe_form,
)

1
verse/describer/forms/describe_file_form.py

@ -4,6 +4,7 @@ from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField, validators
from wtforms.validators import Length
class DescribeFileForm(FlaskForm):
"""DescribeFileForm selection form."""

10
verse/file_crawler.py

@ -22,10 +22,12 @@ def _distribusi_file_with_type(distribusi, full_path):
if type_ in FILE_TYPES:
_add_distribusi_file_to_db(distribusi, full_path, type_)
def _get_distribusi_from_path(path):
distribusi = Distribusis.query.filter_by(distribusiname=path).first()
return distribusi
def _add_distribusi_file_to_db(distribusi, full_path, type):
app = get_app()
print(f"adding file to database: {full_path} type: {type}")
@ -49,14 +51,10 @@ def _add_distribusi_file_to_db(distribusi, full_path, type):
app.logger.error("%s Invalid Entry", full_path)
except InterfaceError:
db.session.rollback()
app.logger.error(
"Error connecting to the database"
)
app.logger.error("Error connecting to the database")
except DatabaseError:
db.session.rollback()
app.logger.error(
"Error connecting to the database"
)
app.logger.error("Error connecting to the database")
def add_distribusi_files(path):

20
verse/migrations/env.py

@ -14,17 +14,19 @@ config = context.config
# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)
logger = logging.getLogger('alembic.env')
logger = logging.getLogger("alembic.env")
# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
config.set_main_option(
'sqlalchemy.url',
str(current_app.extensions['migrate'].db.get_engine().url).replace(
'%', '%%'))
target_metadata = current_app.extensions['migrate'].db.metadata
"sqlalchemy.url",
str(current_app.extensions["migrate"].db.get_engine().url).replace(
"%", "%%"
),
)
target_metadata = current_app.extensions["migrate"].db.metadata
# other values from the config, defined by the needs of env.py,
# can be acquired:
@ -65,20 +67,20 @@ def run_migrations_online():
# when there are no changes to the schema
# reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html
def process_revision_directives(context, revision, directives):
if getattr(config.cmd_opts, 'autogenerate', False):
if getattr(config.cmd_opts, "autogenerate", False):
script = directives[0]
if script.upgrade_ops.is_empty():
directives[:] = []
logger.info('No changes in schema detected.')
logger.info("No changes in schema detected.")
connectable = current_app.extensions['migrate'].db.get_engine()
connectable = current_app.extensions["migrate"].db.get_engine()
with connectable.connect() as connection:
context.configure(
connection=connection,
target_metadata=target_metadata,
process_revision_directives=process_revision_directives,
**current_app.extensions['migrate'].configure_args
**current_app.extensions["migrate"].configure_args,
)
with context.begin_transaction():

17
verse/start.py

@ -2,8 +2,14 @@
from datetime import timedelta
from flask import (Blueprint, redirect, render_template, send_from_directory,
session, url_for)
from flask import (
Blueprint,
redirect,
render_template,
send_from_directory,
session,
url_for,
)
from flask_login import current_user, login_required, logout_user
from flask_wtf.csrf import CSRFError
@ -31,7 +37,6 @@ APP.register_blueprint(forgot_password, url_prefix="/login/forgotpassword")
APP.register_blueprint(distribusikan)
@APP.before_request
def session_handler():
session.permanent = True
@ -56,7 +61,7 @@ def index():
distribusisindex[distribusi.distribusiname] = singledistribusi
years = uploadform.year.choices
categories = uploadform.category.choices
adminuser = isadminuser()
adminuser = is_adminuser()
template = render_template(
"base/index.html",
distribusisindex=distribusisindex,
@ -88,7 +93,7 @@ def shortstashurl():
@APP.route("/admin", methods=["GET", "POST"])
@login_required
def admin():
if not isadminuser():
if not is_adminuser():
return redirect(url_for("index"))
return AdminPage()
@ -110,7 +115,7 @@ def load_user(user_id):
return User.query.get(int(user_id))
def isadminuser():
def is_adminuser():
if not current_user.is_authenticated:
return False
user = User.query.filter_by(email=current_user.email).first()

Loading…
Cancel
Save