Skip to content

Commit

Permalink
Merge pull request #490 from BoostryJP/feature/black
Browse files Browse the repository at this point in the history
lint check with isort and black
  • Loading branch information
YoshihitoAso authored Mar 8, 2023
2 parents b2f1667 + 7cd8382 commit 237ec2e
Show file tree
Hide file tree
Showing 321 changed files with 29,968 additions and 26,288 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/test.yml → .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ name: Unit Test
on: [pull_request]

jobs:
lint-black:
name: 'Lint check (black)'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: psf/black@stable
unit-test-postgres:
name: 'Unit tests (PostgreSQL)'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
repos:
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black
language_version: python3.10
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.PHONY: isort black test run

format: isort black

isort:
isort .

black:
black .

test:
pytest tests/

run:
poetry run gunicorn --worker-class server.AppUvicornWorker app.main:app
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ Install python packages with:
$ poetry install --no-root --only main -E explorer
```

### Install pre-commit hook
```bash
$ poetry run pre-commit install
```

### Setting environment variables

The main environment variables are as follows.
Expand Down
5 changes: 5 additions & 0 deletions README_JA.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@
$ poetry install --no-root --only main -E explorer
```

### pre-commit hookのインストール
```bash
$ poetry run pre-commit install
```

### 環境変数の設定

主要な環境変数は以下の通りです。
Expand Down
8 changes: 2 additions & 6 deletions app/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,15 @@
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

from config import (
DATABASE_URL,
DATABASE_SCHEMA,
DB_ECHO
)
from config import DATABASE_SCHEMA, DATABASE_URL, DB_ECHO

options = {
"pool_recycle": 3600,
"pool_size": 10,
"pool_timeout": 30,
"pool_pre_ping": True,
"max_overflow": 30,
"echo": DB_ECHO
"echo": DB_ECHO,
}
engine = create_engine(DATABASE_URL, **options)
SessionLocal = sessionmaker(autocommit=False, autoflush=True, bind=engine)
Expand Down
2 changes: 1 addition & 1 deletion app/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class SendTransactionError(Exception):


class ContractRevertError(Exception):

def __init__(self, code_msg: str):
code, message = error_code_msg(code_msg)
self.code = code
Expand All @@ -50,5 +49,6 @@ class ServiceUnavailableError(Exception):
class AuthTokenAlreadyExistsError(Exception):
pass


class ResponseLimitExceededError(Exception):
pass
41 changes: 24 additions & 17 deletions app/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,14 @@
SPDX-License-Identifier: Apache-2.0
"""
import sys
import logging
import sys
import urllib
from datetime import datetime
from fastapi import (
Request,
Response
)

from config import (
LOG_LEVEL,
APP_ENV,
AUTH_LOGFILE,
ACCESS_LOGFILE
)

from fastapi import Request, Response

from config import ACCESS_LOGFILE, APP_ENV, AUTH_LOGFILE, LOG_LEVEL

logging.basicConfig(level=LOG_LEVEL)
LOG = logging.getLogger("issuer_api")
Expand Down Expand Up @@ -58,13 +51,17 @@

# Auth Log
stream_handler_auth = logging.StreamHandler(open(AUTH_LOGFILE, "a"))
formatter_auth = logging.Formatter(INFO_FORMAT.format("[AUTH-LOG] "), TIMESTAMP_FORMAT)
formatter_auth = logging.Formatter(
INFO_FORMAT.format("[AUTH-LOG] "), TIMESTAMP_FORMAT
)
stream_handler_auth.setFormatter(formatter_auth)
AUTH_LOG.addHandler(stream_handler_auth)

# Access Log
stream_handler_access = logging.StreamHandler(open(ACCESS_LOGFILE, "a"))
formatter_access = logging.Formatter(INFO_FORMAT.format("[ACCESS-LOG] "), TIMESTAMP_FORMAT)
formatter_access = logging.Formatter(
INFO_FORMAT.format("[ACCESS-LOG] "), TIMESTAMP_FORMAT
)
stream_handler_access.setFormatter(formatter_access)
ACCESS_LOG.addHandler(stream_handler_access)

Expand All @@ -77,13 +74,17 @@

# Auth Log
stream_handler_auth = logging.StreamHandler(open(AUTH_LOGFILE, "a"))
formatter_auth = logging.Formatter(DEBUG_FORMAT.format("[AUTH-LOG] "), TIMESTAMP_FORMAT)
formatter_auth = logging.Formatter(
DEBUG_FORMAT.format("[AUTH-LOG] "), TIMESTAMP_FORMAT
)
stream_handler_auth.setFormatter(formatter_auth)
AUTH_LOG.addHandler(stream_handler_auth)

# Access Log
stream_handler_access = logging.StreamHandler(open(ACCESS_LOGFILE, "a"))
formatter_access = logging.Formatter(INFO_FORMAT.format("[ACCESS-LOG] "), TIMESTAMP_FORMAT) # Same live's formatter
formatter_access = logging.Formatter(
INFO_FORMAT.format("[ACCESS-LOG] "), TIMESTAMP_FORMAT
) # Same live's formatter
stream_handler_access.setFormatter(formatter_access)
ACCESS_LOG.addHandler(stream_handler_access)

Expand All @@ -107,7 +108,13 @@ def output_access_log(req: Request, res: Response, request_start_time: datetime)
http_version = req.scope.get("http_version", "")
status_code = res.status_code
response_time = (datetime.utcnow() - request_start_time).total_seconds()
access_msg = ACCESS_FORMAT % (method, url, http_version, status_code, response_time)
access_msg = ACCESS_FORMAT % (
method,
url,
http_version,
status_code,
response_time,
)

address = "None" # Initial value
headers = req.scope.get("headers", [])
Expand Down
Loading

0 comments on commit 237ec2e

Please sign in to comment.