Skip to content

Commit

Permalink
style: Fixes ruff, black & typing (#280)
Browse files Browse the repository at this point in the history
* ci: Updates CI jobs

* style: Switches to ruff

* style: Appllied ruff

* chore: Updates config of ruff

* chore: Updates ruff

* style: Updates precommit

* chore: Updates ruff config

* style: Fixes ruff

* style: Fixes ruff

* style: Fixes black & ruff

* style: Fixes typing

* fix: Removes abstract method

* chore: Updates conda

* chore: Bumps python CI version to 3.9

* chore: Adds python 3.11 to pyproject

* fix: Fixes typos

* style: Fixes imports
  • Loading branch information
frgfm authored Sep 16, 2023
1 parent 505b8b6 commit 75b8d71
Show file tree
Hide file tree
Showing 91 changed files with 1,007 additions and 873 deletions.
6 changes: 3 additions & 3 deletions .conda/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ requirements:

run:
- python>=3.8, <4.0
- pytorch >=1.9.1, <2.0.0
- torchvision >=0.10.1, <1.0.0
- pytorch >=2.0.0, <3.0.0
- torchvision >=0.15.0, <1.0.0
- tqdm >=4.1.0
- numpy >=1.17.2, <2.0.0
- fastprogress >=1.0.0, <2.0.0
- matplotlib >=3.0.0, <4.0.0
- pillow >=8.4.0
- pillow >=8.4.0, !=9.2.0
- huggingface_hub >=0.4.0

test:
Expand Down
43 changes: 20 additions & 23 deletions .github/collect_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
import re
import subprocess
import sys
from collections import namedtuple
from pathlib import Path
from typing import NamedTuple

try:
import holocron
Expand Down Expand Up @@ -44,21 +45,17 @@


# System Environment Information
SystemEnv = namedtuple(
"SystemEnv",
[
"holocron_version",
"torch_version",
"torchvision_version",
"os",
"python_version",
"is_cuda_available",
"cuda_runtime_version",
"nvidia_driver_version",
"nvidia_gpu_models",
"cudnn_version",
],
)
class SystemEnv(NamedTuple):
holocron_version: str
torch_version: str
torchvision_version: str
os: str
python_version: str
is_cuda_available: bool
cuda_runtime_version: str
nvidia_driver_version: str
nvidia_gpu_models: str
cudnn_version: str


def run(command):
Expand Down Expand Up @@ -134,18 +131,18 @@ def get_cudnn_version(run_lambda):
# find will return 1 if there are permission errors or if not found
if len(out) == 0 or rc not in (1, 0):
lib = os.environ.get("CUDNN_LIBRARY")
if lib is not None and os.path.isfile(lib):
if lib is not None and Path(lib).is_file():
return os.path.realpath(lib)
return None
files = set()
for fn in out.split("\n"):
fn = os.path.realpath(fn) # eliminate symbolic links
if os.path.isfile(fn):
if Path(fn).is_file():
files.add(fn)
if not files:
return None
# Alphabetize the result because the order is non-deterministic otherwise
files = list(sorted(files))
files = sorted(files)
if len(files) == 1:
return files[0]
result = "\n".join(files)
Expand All @@ -158,11 +155,11 @@ def get_nvidia_smi():
if get_platform() == "win32":
system_root = os.environ.get("SYSTEMROOT", "C:\\Windows")
program_files_root = os.environ.get("PROGRAMFILES", "C:\\Program Files")
legacy_path = os.path.join(program_files_root, "NVIDIA Corporation", "NVSMI", smi)
new_path = os.path.join(system_root, "System32", smi)
legacy_path = Path(program_files_root) / "NVIDIA Corporation" / "NVSMI" / smi
new_path = Path(system_root) / "System32" / smi
smis = [new_path, legacy_path]
for candidate_smi in smis:
if os.path.exists(candidate_smi):
if Path(candidate_smi).exists():
smi = '"{}"'.format(candidate_smi)
break
return smi
Expand Down Expand Up @@ -307,7 +304,7 @@ def maybe_start_on_next_line(string):
"nvidia_gpu_models",
"nvidia_driver_version",
]
all_cuda_fields = dynamic_cuda_fields + ["cudnn_version"]
all_cuda_fields = [*dynamic_cuda_fields, "cudnn_version"]
all_dynamic_cuda_fields_missing = all(mutable_dict[field] is None for field in dynamic_cuda_fields)
if TORCH_AVAILABLE and not torch.cuda.is_available() and all_dynamic_cuda_fields_missing:
for field in all_cuda_fields:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
python: [3.8]
python: [3.9]
steps:
- uses: actions/checkout@v2
- name: Set up Python
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/doc-status.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: 3.8
python-version: 3.9
architecture: x64
- name: check status
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Build docker image
run: docker build . -t holocron:python3.8-slim
run: docker build . -t holocron:python3.9-slim
- name: Run docker container
run: docker run holocron:python3.8-slim python -c 'import holocron'
run: docker run holocron:python3.9-slim python -c 'import holocron'

api:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
python: [3.8]
python: [3.9]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python: [3.8]
python: [3.9]
steps:
- uses: actions/checkout@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull_requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: 3.9
architecture: x64
- name: Cache python modules
uses: actions/cache@v2
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: 3.8
python-version: 3.9
architecture: x64
- name: Cache python modules
uses: actions/cache@v2
Expand Down Expand Up @@ -47,7 +47,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: 3.8
python-version: 3.9
architecture: x64
- name: Install package
run: |
Expand All @@ -64,7 +64,7 @@ jobs:
uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
python-version: 3.8
python-version: 3.9
- name: Install dependencies
run: conda install -y conda-build conda-verify anaconda-client
- name: Get release tag
Expand All @@ -91,7 +91,7 @@ jobs:
uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
python-version: 3.8
python-version: 3.9
- name: Install package
run: |
conda install -c frgfm pylocron
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scripts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
python: [3.8]
python: [3.9]
steps:
- uses: actions/checkout@v2
- name: Set up Python
Expand Down
51 changes: 6 additions & 45 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python: [3.8]
python: [3.9]
steps:
- uses: actions/checkout@v2
- name: Set up Python
Expand All @@ -26,32 +26,12 @@ jobs:
ruff --version
ruff check --diff .
isort:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
python: [3.8]
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python }}
architecture: x64
- name: Run isort
run: |
pip install isort
isort --version
isort .
if [ -n "$(git status --porcelain --untracked-files=no)" ]; then exit 1; else echo "All clear"; fi
mypy:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
python: [3.8]
python: [3.9]
steps:
- uses: actions/checkout@v2
- name: Set up Python
Expand All @@ -68,37 +48,18 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -e . --upgrade
pip install mypy
pip install "mypy==1.4.1"
- name: Run mypy
run: |
mypy --version
mypy
pydocstyle:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
python: [3.8]
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
architecture: x64
- name: Run pydocstyle
run: |
pip install pydocstyle[toml]
pydocstyle --version
pydocstyle
black:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
python: [3.8]
python: [3.9]
steps:
- uses: actions/checkout@v2
- name: Set up Python
Expand All @@ -108,7 +69,7 @@ jobs:
architecture: x64
- name: Run black
run: |
pip install "black==22.3.0"
pip install "black==23.3.0"
black --version
black --check --diff .
Expand All @@ -117,7 +78,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python: [3.8]
python: [3.9]
steps:
- uses: actions/checkout@v2
- name: Set up Python
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python: [3.8]
python: [3.9]
steps:
- uses: actions/checkout@v2
with:
Expand Down
15 changes: 7 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
default_language_version:
python: python3.9
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.4.0
hooks:
- id: check-ast
- id: check-yaml
Expand All @@ -16,15 +18,12 @@ repos:
- id: no-commit-to-branch
args: ['--branch', 'main']
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 23.3.0
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
exclude: "(__init__.py)$"
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.260'
rev: 'v0.0.289'
hooks:
- id: ruff
args:
- --fix
4 changes: 0 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
# this target runs checks on all files
quality:
isort . -c
ruff check .
mypy
pydocstyle
black --check .
bandit -r . -c pyproject.toml
autoflake -r .

# this target runs checks on all files and potentially modifies some of them
style:
isort .
black .
ruff --fix .

Expand Down
2 changes: 1 addition & 1 deletion api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.8-slim
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.9-slim

WORKDIR /app

Expand Down
2 changes: 2 additions & 0 deletions api/app/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@


class ClsCandidate(BaseModel):
"""Classification result"""

value: str = Field(..., example="Wookie")
confidence: float = Field(..., gte=0, lte=1)
Loading

0 comments on commit 75b8d71

Please sign in to comment.