Skip to content

Commit

Permalink
add flake8 into project
Browse files Browse the repository at this point in the history
  • Loading branch information
lunakv committed Feb 12, 2023
1 parent 48cd873 commit 2451e43
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 24 deletions.
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[flake8]
exclude = .git,__pychache__,app/static/raw_docs
extend-ignore = E203
max-line-length = 120
4 changes: 3 additions & 1 deletion .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
pip install poetry==1.2.1
- name: Install dependencies
run: poetry install
- name: Check formatting
- name: Check formatting with Black
run: poetry run black --check --diff .
- name: Lint with flake8
run: flake8 . --count --statistics --show-source

2 changes: 1 addition & 1 deletion alembic/versions/0cb715a5aac5_initial_autogen.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""initial_autogen
Revision ID: 0cb715a5aac5
Revises:
Revises:
Create Date: 2022-09-28 11:30:45.896529
"""
Expand Down
7 changes: 6 additions & 1 deletion app/database/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

SQLALCHEMY_DATABASE_URL = f'postgresql+psycopg2://{os.environ["DB_USER"]}:{os.environ["DB_PASS"]}@{os.environ["DB_HOST"]}/{os.environ["DB_DATABASE"]}'
_user = os.environ["DB_USER"]
_pass = os.environ["DB_PASS"]
_host = os.environ["DB_HOST"]
_db = os.environ["DB_DATABASE"]

SQLALCHEMY_DATABASE_URL = f"postgresql+psycopg2://{_user}:{_pass}@{_host}/{_db}"

engine = create_engine(SQLALCHEMY_DATABASE_URL)

Expand Down
2 changes: 1 addition & 1 deletion app/database/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sqlalchemy import Column, Date, ForeignKey, Integer, String, Text, text
from sqlalchemy import Column, Date, ForeignKey, Integer, String, Text
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.orm import relationship, declarative_base

Expand Down
2 changes: 1 addition & 1 deletion app/database/operations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import datetime
from typing import Union, Tuple, Type
from typing import Tuple, Type

from sqlalchemy import select
from sqlalchemy.orm import Session, aliased
Expand Down
2 changes: 1 addition & 1 deletion app/parsing/docs_scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ async def scrape_docs_page():

if len(found) != len(docs):
# not all links were found correctly, so we don't wanna update anything to be safe
notify_scrape_error(f"Couldn't find links for all WPN documents")
notify_scrape_error("Couldn't find links for all WPN documents")
logger.error("Couldn't find links for all WPN documents")
logger.error(found)
await set_broken(session)
Expand Down
6 changes: 3 additions & 3 deletions app/parsing/extract_cr.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
keyword_action_regex = r"701.(?:[2-9]|\d\d+)"
ability_words_rule = "207.2c"


# TODO rework into new class hierarchy

# parse plaintext CR into structured representations
# lifted directly from an old VensersJournal file, should be cleaned up at some point
async def extract(comp_rules):
rules_json = {}
rules_flattened = {}
glossary_json, examples_json = {}, []
glossary_json = {}

def split_ability_words(rules_text):
splitter = re.compile(r", (?:and )?")
Expand Down Expand Up @@ -52,7 +53,6 @@ def split_ability_words(rules_text):
nonempty_examples.append(ex)
if len(nonempty_examples) == 0:
nonempty_examples = None
new_example = {"examples": nonempty_examples, "ruleNumber": rule[0]}

previous_rule = ""
next_rule = ""
Expand All @@ -73,7 +73,7 @@ def split_ability_words(rules_text):
try:
if not rule_object_ref[rule_from_previous_section.split(".")[1]]["navigation"]["nextRule"]:
rule_object_ref[rule_from_previous_section.split(".")[1]]["navigation"]["nextRule"] = rule[0]
except (KeyError, IndexError) as e:
except (KeyError, IndexError):
pass
new_rule = {
"ruleNumber": rule[0],
Expand Down
2 changes: 1 addition & 1 deletion app/routers/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ async def mtr_metadata(db: Session = Depends(get_db)):


@router.get("/ipg")
async def mtr_metadata(db: Session = Depends(get_db)):
async def ipg_metadata(db: Session = Depends(get_db)):
meta = ops.get_creation_dates(db, Ipg)
return {"data": meta}
2 changes: 1 addition & 1 deletion app/routers/rawfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Format(str, Enum):
)
def raw_latest_cr(db: Session = Depends(get_db)):
"""
Returns a raw text file of the latest CR. This route is similar to the `/link/cr` route, with three main differences:
Returns the raw text of the latest CR. This route is similar to the `/link/cr` route, with three main differences:
1. This route returns a response directly rather than a redirect to WotC servers.
2. The response of this route is guaranteed to be in UTF-8 (see also
[Response Encoding and Formatting](#section/Response-Encoding-and-Formatting)).
Expand Down
20 changes: 10 additions & 10 deletions app/utils/docs.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
description = """
This API provides information about Magic: the Gathering rules and policy documents. It was
primarily created to serve the [Academy Ruins](https://academyruins.com) project and the [Fryatog](
https://github.com/Fryyyyy/Fryatog/) rules bot, but it has found other uses since. You can find the source for the
This API provides information about Magic: the Gathering rules and policy documents. It was
primarily created to serve the [Academy Ruins](https://academyruins.com) project and the [Fryatog](
https://github.com/Fryyyyy/Fryatog/) rules bot, but it has found other uses since. You can find the source for the
project on [GitHub](https://github.com/lunakv/academyruins-api).
## Response Encoding and Formatting
All text responses returned by this API are guaranteed to be served in the form of UTF-8 encoded strings without a
BOM with LF (0x0A) line endings. *(Some very old CR text files may not yet be fully converted to this format)* Note
that the `/link` routes simply redirect to content hosted by other parties, and as such this API cannot make any
guarantees about their format.
All text responses returned by this API are guaranteed to be served in the form of UTF-8 encoded strings without a
BOM with LF (0x0A) line endings. *(Some very old CR text files may not yet be fully converted to this format)* Note
that the `/link` routes simply redirect to content hosted by other parties, and as such this API cannot make any
guarantees about their format.
The API preserves all typography extracted from the source files. This means using—among other things—“angled
quotation marks” and apostrophes, actual en and em dashes where appropriate, real ™ and ® symbols, etc. If you're
going to display data obtained by this API, make sure you’re able to handle characters outside of the standard ASCII
The API preserves all typography extracted from the source files. This means using—among other things—“angled
quotation marks” and apostrophes, actual en and em dashes where appropriate, real ™ and ® symbols, etc. If you're
going to display data obtained by this API, make sure you’re able to handle characters outside of the standard ASCII
range. """
2 changes: 0 additions & 2 deletions app/utils/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import datetime
from typing import Union

import pydantic
from pydantic import BaseModel


Expand Down
55 changes: 54 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ thefuzz = {extras = ["speedup"], version = "^0.19.0"}
python-dotenv = "^0.21.0"
black = "^22.8.0"
alembic = "^1.8.1"
flake8 = "^6.0.0"

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

0 comments on commit 2451e43

Please sign in to comment.