Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre-commit and poetry tasks #181

Merged
merged 7 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
rev: v4.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort

- repo: https://github.com/psf/black
rev: 21.4b2
rev: 22.8.0
hooks:
- id: black

# - repo: https://github.com/pycqa/flake8
# rev: 5.0.4
# hooks:
# - id: flake8

# Pylint needs to be installed locally for precommit
# https://pylint.pycqa.org/en/latest/user_guide/installation/pre-commit-integration.html
# - repo: local
# hooks:
# - id: pylint
# name: pylint
# entry: pylint
# language: system
# types: [python]
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Anatomical fiducials (AFIDs) is an open framework for evaluating correspondence
curl -sSL https://install.python-poetry.org | python3 - --version 1.2.0
```

For detailed setup instructions, see the documentation (here)[https://python-poetry.org/].
For detailed setup instructions, see the documentation [here](https://python-poetry.org/).



Expand All @@ -30,16 +30,17 @@ _Install via `apt-get` or `snap`_
1. Git clone the afids-validator repository `git clone https://github.com/afids/afids-validator.git`
2. Set up python environment via `poetry shell`
3. Install the required libraries via `poetry install --with dev`
4. Access the postgres CLI via `sudo su - postgres`
5. Create a database via postgres `createdb fid_db`
6. Set password for the created database
4. Install the pre-commit action via `poetry run poe setup`. This will automatically perform quality tasks for each new commit.
5. Access the postgres CLI via `sudo su - postgres`
6. Create a database via postgres `createdb fid_db`
7. Set password for the created database
```
psql fid_db
\password
```
8. Update configuration in `.env.template` and rename to `.env` file
10. `python manage.py db upgrade`
11. `python manage.py runserver`
9. `python manage.py db upgrade`
10. `python manage.py runserver`

If there are no errors, you can test it out locally at http://localhost:5000

Expand Down
5 changes: 2 additions & 3 deletions afidsvalidator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

from flask import Flask

from config import *

from afidsvalidator.views import validator
from afidsvalidator.model import db, login_manager
from afidsvalidator.orcid import orcid_blueprint
from afidsvalidator.views import validator
from config import *


class ConfigException(Exception):
Expand Down
11 changes: 5 additions & 6 deletions afidsvalidator/model.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
"""Handle parsing files to internal AFIDs representation."""

import io
import csv
import io
import json
import math
import re

from flask_dance.consumer.storage.sqla import OAuthConsumerMixin
from flask_login import LoginManager, UserMixin
from flask_sqlalchemy import SQLAlchemy
from pkg_resources import parse_version
from sqlalchemy.orm import composite
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager, UserMixin
from flask_dance.consumer.storage.sqla import OAuthConsumerMixin


EXPECTED_LABELS = [str(x + 1) for x in range(32)]
EXPECTED_DESCS = [
Expand Down Expand Up @@ -137,7 +136,7 @@ def validate(self):
True if the Afids set is valid.
"""
valid = True
for label, name in EXPECTED_MAP.items():
for _, name in EXPECTED_MAP.items():
try:
valid = valid and math.isfinite(getattr(self, name[-1]).x)
valid = valid and math.isfinite(getattr(self, name[-1]).y)
Expand Down
2 changes: 1 addition & 1 deletion afidsvalidator/orcid.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from flask_login import current_user, login_user
from sqlalchemy.orm.exc import NoResultFound

from afidsvalidator.model import db, OAuth, User
from afidsvalidator.model import OAuth, User, db

orcid_blueprint = OAuth2ConsumerBlueprint(
"orcid",
Expand Down
21 changes: 10 additions & 11 deletions afidsvalidator/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,31 @@
import os
from datetime import datetime, timezone

import numpy as np
import wtforms as wtf
from flask import (
render_template,
request,
jsonify,
Blueprint,
current_app,
jsonify,
redirect,
render_template,
request,
)
from flask_login import logout_user, current_user
import numpy as np
import wtforms as wtf
from flask_login import current_user, logout_user

from afidsvalidator.model import (
db,
csv_to_afids,
json_to_afids,
InvalidFileError,
EXPECTED_DESCS,
HumanFiducialSet,
InvalidFileError,
csv_to_afids,
db,
json_to_afids,
)
from afidsvalidator.visualizations import (
generate_3d_scatter,
generate_histogram,
)


validator = Blueprint("validator", __name__, template_folder="templates")


Expand Down
1 change: 1 addition & 0 deletions afidsvalidator/visualizations.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Utilities for generating AFIDs-related graphics"""

import plotly.graph_objects as go

from afidsvalidator.model import EXPECTED_DESCS


Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ poethepoet = "^0.16.2"

[tool.poe.tasks]
setup = "pre-commit install"
quality = {shell = "isort afidsvalidator && black afidsvalidator -l 79 && flake8 afidsvalidator && pylint afidsvalidator" }
test = { shell = "python -m unittest" }

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down