Skip to content

Commit

Permalink
style: Bumps ruff and updates torch & torchvision version specifiers (#…
Browse files Browse the repository at this point in the history
…219)

* chore: Bumps torch and torchvision

* chore: Bumps ruff

* ci: Bumps CI to Python 3.9

* style: Fixes ruff

* fix: Fixes ruff
  • Loading branch information
frgfm authored Sep 16, 2023
1 parent dee2e74 commit 0b201aa
Show file tree
Hide file tree
Showing 21 changed files with 113 additions and 97 deletions.
6 changes: 3 additions & 3 deletions .conda/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ requirements:
- setuptools

run:
- pytorch >=1.7.0, <2.0.0
- numpy >=1.14.0, <2.0.0
- pillow >=8.3.2
- pytorch >=2.0.0, <3.0.0
- numpy >=1.17.2, <2.0.0
- pillow >=8.4.0, !=9.2.0
- matplotlib >=3.0.0, <4.0.0

test:
Expand Down
37 changes: 17 additions & 20 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 torchcam
Expand All @@ -36,20 +37,16 @@


# System Environment Information
SystemEnv = namedtuple(
"SystemEnv",
[
"torchcam_version",
"torch_version",
"os",
"python_version",
"is_cuda_available",
"cuda_runtime_version",
"nvidia_driver_version",
"nvidia_gpu_models",
"cudnn_version",
],
)
class SystemEnv(NamedTuple):
torchcam_version: str
torch_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 @@ -125,13 +122,13 @@ 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
Expand All @@ -149,11 +146,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
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, 3.9]
python: [3.9]
steps:
- uses: actions/checkout@v2
- name: Set up Python
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/doc-status.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ jobs:
see-page-build-payload:
runs-on: ubuntu-latest
steps:
- name: Set up Python
uses: actions/setup-python@v4
- uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: 3.9
architecture: x64
- name: check status
run: |
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@v4
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@v4
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@v4
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
auto-activate-base: true
- name: Install dependencies
run: |
Expand Down Expand Up @@ -93,7 +93,7 @@ jobs:
uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
python-version: 3.8
python-version: 3.9
auto-activate-base: true
- name: Install package
run: |
Expand Down
4 changes: 2 additions & 2 deletions .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 Expand Up @@ -41,7 +41,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
8 changes: 4 additions & 4 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 @@ -31,7 +31,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python: [3.8]
python: [3.9]
steps:
- uses: actions/checkout@v2
- name: Set up Python
Expand Down Expand Up @@ -59,7 +59,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python: [3.8]
python: [3.9]
steps:
- uses: actions/checkout@v2
- name: Set up Python
Expand All @@ -78,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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ repos:
hooks:
- id: black
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.278'
rev: 'v0.0.290'
hooks:
- id: ruff
args:
Expand Down
2 changes: 1 addition & 1 deletion demo/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

def main():
# Wide mode
st.set_page_config(layout="wide")
st.set_page_config(page_title="TorchCAM - Class activation explorer", layout="wide")

# Designing the interface
st.title("TorchCAM: class activation explorer")
Expand Down
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
from datetime import datetime
from pathlib import Path

sys.path.insert(0, os.path.abspath("../.."))
sys.path.insert(0, Path().resolve().parent.parent)
import torchcam

# -- Project information -----------------------------------------------------
Expand Down
39 changes: 26 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,20 @@ classifiers = [
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Mathematics",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
]
dynamic = ["version"]
dependencies = [
# cf. https://github.com/frgfm/torch-cam/discussions/148
"torch>=1.7.0,<2.0.0",
"torch>=2.0.0,<3.0.0",
"numpy>=1.14.0,<2.0.0",
# cf. https://github.com/advisories/GHSA-98vv-pw6r-q6q4
"Pillow>=8.3.2",
# cf. https://github.com/pytorch/vision/issues/4934
# https://github.com/frgfm/Holocron/security/dependabot/5
"Pillow>=8.4.0,!=9.2.0",
"matplotlib>=3.0.0,<4.0.0",
]

Expand All @@ -42,10 +45,10 @@ test = [
"pytest>=5.3.2",
"coverage[toml]>=4.5.4",
"requests>=2.20.0,<3.0.0",
"torchvision>=0.4.0,<1.0.0",
"torchvision>=0.15.0,<1.0.0",
]
quality = [
"ruff>=0.0.273,<1.0.0",
"ruff>=0.0.290,<1.0.0",
"mypy==1.4.1",
"black==23.3.0",
"bandit[toml]>=1.7.0,<1.8.0",
Expand All @@ -64,16 +67,16 @@ docs = [
]
demo = [
"streamlit>=0.65.0,<2.0.0",
"torchvision>=0.12.0,<1.0.0",
"torchvision>=0.15.0,<1.0.0",
]
dev = [
# test
"pytest>=5.3.2",
"coverage[toml]>=4.5.4",
"requests>=2.20.0,<3.0.0",
"torchvision>=0.4.0,<1.0.0",
"torchvision>=0.15.0,<1.0.0",
# style
"ruff>=0.0.273,<1.0.0",
"ruff>=0.0.290,<1.0.0",
"mypy==1.4.1",
"black==23.3.0",
"bandit[toml]>=1.7.0,<1.8.0",
Expand Down Expand Up @@ -111,14 +114,21 @@ select = [
"D201","D202","D207","D208","D214","D215","D300","D301","D417", "D419", # pydocstyle
"F", # pyflakes
"I", # isort
"C", # flake8-comprehensions
"C4", # flake8-comprehensions
"B", # flake8-bugbear
"CPY001", # flake8-copyright
"ISC", # flake8-implicit-str-concat
"PYI", # flake8-pyi
"NPY", # numpy
"PERF", # perflint
"RUF", # ruff specific
"PTH", # flake8-use-pathlib
"S", # flake8-bandit
"N", # pep8-naming
"T10", # flake8-debugger
"T20", # flake8-print
"PT", # flake8-pytest-style
"LOG", # flake8-logging
]
ignore = [
"E501", # line too long, handled by black
Expand All @@ -128,28 +138,31 @@ ignore = [
"F403", # star imports
"E731", # lambda assignment
"C416", # list comprehension to list()
"N812", # lowercase imported as non-lowercase
]
exclude = [".git"]
line-length = 120
target-version = "py39"
preview = true

[tool.ruff.per-file-ignores]
"**/__init__.py" = ["I001", "F401", "CPY001"]
"scripts/**.py" = ["D"]
".github/**.py" = ["D"]
"scripts/**.py" = ["D", "T201", "N812"]
".github/**.py" = ["D", "T201", "S602"]
"docs/**.py" = ["E402", "D103"]
"tests/**.py" = ["D103", "CPY001"]
"tests/**.py" = ["D103", "CPY001", "S101", "PT011",]
"demo/**.py" = ["D103"]
"setup.py" = ["T201"]

[tool.ruff.flake8-quotes]
docstring-quotes = "double"

[tool.ruff.isort]
known-first-party = ["app"]
known-first-party = ["torchcam", "app"]
known-third-party = ["torch", "torchvision"]

[tool.mypy]
python_version = "3.8"
python_version = "3.9"
files = "torchcam/"
show_error_codes = true
pretty = true
Expand Down
3 changes: 2 additions & 1 deletion scripts/eval_perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import math
import os
from functools import partial
from pathlib import Path

import torch
from torch.utils.data import SequentialSampler
Expand Down Expand Up @@ -49,7 +50,7 @@ def main(args):
)

ds = ImageFolder(
os.path.join(args.data_path, "val"),
Path(args.data_path).joinpath("val"),
T.Compose(eval_tf),
)
loader = torch.utils.data.DataLoader(
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

# Dynamically set the __version__ attribute
cwd = Path(__file__).parent.absolute()
with open(cwd.joinpath("torchcam", "version.py"), "w", encoding="utf-8") as f:
with cwd.joinpath("torchcam", "version.py").open("w", encoding="utf-8") as f:
f.write(f"__version__ = '{VERSION}'\n")

setup(name=PKG_NAME, version=VERSION)
Loading

0 comments on commit 0b201aa

Please sign in to comment.