Skip to content

Commit

Permalink
add lint check
Browse files Browse the repository at this point in the history
  • Loading branch information
kfstorm committed Feb 20, 2024
1 parent 6bc86e6 commit 7703779
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 5 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 = 80
extend-select = B950
extend-ignore = E203,E501,E701
2 changes: 2 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Check lint
run: ./scripts/lint.sh
- name: Docker Login
uses: docker/[email protected]
with:
Expand Down
15 changes: 11 additions & 4 deletions bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,26 @@

async def bootstrap(collection_api: CollectionApi, imdb_api: ImdbApi):
"""
This function is called at the start of the application to regularly send HTTP requests
and cache the results. This can help saving time on incoming requests.
This function is called at the start of the application to regularly send
HTTP requests and cache the results.
This can help saving time on incoming requests.
"""
while True:
logging.info("Bootstrapping...")
all_collections = deque(COMMON_COLLECTIONS)
visited_collections = set()
while all_collections and len(visited_collections) < app_config.bootstrap_collections_max:
while (
all_collections
and len(visited_collections) < app_config.bootstrap_collections_max
):
collection_id = all_collections.popleft()
visited_collections.add(collection_id)

try:
collection_info = await collection_api.get_collection_info(collection_id)
collection_info = await collection_api.get_collection_info(
collection_id
)
for related_collection in collection_info["related_charts"]["items"]:
related_collection_id = related_collection["id"]
if related_collection_id not in visited_collections:
Expand Down
1 change: 0 additions & 1 deletion collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def __exit__(self, exc_type, exc_value, traceback):
self.client.close()
self.cache.close()


async def get_collection_info(self, collection_id: str):
return await get_json(self.client, f"/{collection_id}")

Expand Down
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ uvicorn[standard]==0.27.1
httpx[socks]==0.24.1
diskcache==5.6.3
pydantic-settings==2.2.0

# for linting
black==23.3.0
flake8==6.1.0
flake8-bugbear==24.2.6
5 changes: 5 additions & 0 deletions scripts/hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

set -euo pipefail

scripts/lint.sh --check
8 changes: 8 additions & 0 deletions scripts/init_repo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

set -euo pipefail

cd $(git rev-parse --show-toplevel)

rm -f .git/hooks/pre-commit
ln -s ../../scripts/hooks/pre-commit .git/hooks/pre-commit
22 changes: 22 additions & 0 deletions scripts/lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

set -euo pipefail

# read the `--check` arg from the command line
check=false
if [ $# -gt 0 ] && [[ $1 == "--check" ]]; then
check=true
fi

black_args=()
if [[ "$check" == "true" ]]; then
black_args+=(--check --diff)
fi

cd $(git rev-parse --show-toplevel)

# find all Python files
python_files=$(git ls-files | grep '\.py$' || true)

black "${black_args[@]}" $python_files
flake8 $python_files

0 comments on commit 7703779

Please sign in to comment.