Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Ruff #19

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions .flake8

This file was deleted.

10 changes: 4 additions & 6 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ updates:
directory: "/"
schedule:
interval: "weekly"
reviewers:
- "isaaccorley"
- package-ecosystem: "pip"
directory: "/requirements"
schedule:
interval: "daily"
ignore:
# setuptools releases new versions almost daily
- dependency-name: "setuptools"
update-types: ["version-update:semver-patch"]
- dependency-name: "timm"
- dependency-name: "torch"
reviewers:
- "isaaccorley"
4 changes: 3 additions & 1 deletion .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: "labeler"
on:
- pull_request_target

jobs:
labeler:
permissions:
Expand All @@ -13,4 +14,5 @@ jobs:
- name: Add label
uses: actions/[email protected]
with:
sync-labels: true
configuration-path: .github/labeler.yml
sync-labels: true
90 changes: 4 additions & 86 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ on:
- main
- release**
jobs:
black:
name: black
ruff:
name: ruff
runs-on: ubuntu-latest
steps:
- name: Clone repo
Expand All @@ -19,96 +19,14 @@ jobs:
uses: actions/[email protected]
with:
python-version: '3.11'
- name: Cache dependencies
uses: actions/[email protected]
id: cache
with:
path: ${{ env.pythonLocation }}
key: ${{ env.pythonLocation }}-${{ hashFiles('requirements/style.txt') }}
- name: Install pip dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
pip install -r requirements/style.txt
pip cache purge
- name: List pip dependencies
run: pip list
- name: Run black checks
run: black . --check --diff
flake8:
name: flake8
runs-on: ubuntu-latest
steps:
- name: Clone repo
uses: actions/[email protected]
- name: Set up python
uses: actions/[email protected]
with:
python-version: '3.11'
- name: Cache dependencies
uses: actions/[email protected]
id: cache
with:
path: ${{ env.pythonLocation }}
key: ${{ env.pythonLocation }}-${{ hashFiles('requirements/style.txt') }}
- name: Install pip dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
pip install -r requirements/style.txt
pip cache purge
- name: List pip dependencies
run: pip list
- name: Run flake8 checks
run: flake8
isort:
name: isort
runs-on: ubuntu-latest
steps:
- name: Clone repo
uses: actions/[email protected]
- name: Set up python
uses: actions/[email protected]
with:
python-version: '3.11'
- name: Cache dependencies
uses: actions/[email protected]
id: cache
with:
path: ${{ env.pythonLocation }}
key: ${{ env.pythonLocation }}-${{ hashFiles('requirements/style.txt') }}
- name: Install pip dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
pip install -r requirements/style.txt
pip cache purge
- name: List pip dependencies
run: pip list
- name: Run isort checks
run: isort . --check --diff
pyupgrade:
name: pyupgrade
runs-on: ubuntu-latest
steps:
- name: Clone repo
uses: actions/[email protected]
- name: Set up python
uses: actions/[email protected]
with:
python-version: '3.11'
- name: Cache dependencies
uses: actions/[email protected]
id: cache
with:
path: ${{ env.pythonLocation }}
key: ${{ env.pythonLocation }}-${{ hashFiles('requirements/style.txt') }}
- name: Install pip dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
pip install -r requirements/style.txt
pip cache purge
- name: List pip dependencies
run: pip list
- name: Run pyupgrade checks
run: pyupgrade --py39-plus
- name: Run ruff checks
run: ruff format --check -v
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.head.label || github.head_ref || github.ref }}
cancel-in-progress: true
8 changes: 3 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ['3.9', '3.10', '3.11']
python-version: ['3.9', '3.10', '3.11', '3.12']
steps:
- name: Clone repo
uses: actions/[email protected]
Expand All @@ -31,9 +31,7 @@ jobs:
with:
path: ${{ env.pythonLocation }}
key: ${{ env.pythonLocation }}-${{ hashFiles('requirements/required.txt') }}-${{ hashFiles('requirements/tests.txt') }}
if: ${{ ! (runner.os == 'macOS' && matrix.python-version == '3.11') }}
- name: Setup headless display for pyvista
uses: pyvista/setup-headless-display-action@v2
if: ${{ ! (runner.os == 'macOS' && (matrix.python-version == '3.11' || matrix.python-version == '3.12')) }}
- name: Install pip dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
Expand All @@ -45,7 +43,7 @@ jobs:
run: |
pytest --cov=torchseg --cov-report=xml --durations=10
- name: Report coverage
uses: codecov/[email protected].4
uses: codecov/[email protected].6
with:
token: ${{ secrets.CODECOV_TOKEN }}
concurrency:
Expand Down
59 changes: 44 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ classifiers = [
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
]
dependencies = [
Expand All @@ -39,10 +40,7 @@ dynamic = ["version"]

[project.optional-dependencies]
style = [
"black[jupyter]>=21.8",
"flake8>=3.8",
"isort[colors]>=5.8",
"pyupgrade>=2.8",
"ruff>=0.3.0"
]
tests = [
"pytest>=7.3",
Expand All @@ -55,11 +53,6 @@ all = [
[project.urls]
Homepage = "https://github.com/isaaccorley/torchseg"

[tool.black]
target-version = ["py39", "py310"]
color = true
skip_magic_trailing_comma = true

[tool.coverage.report]
# Ignore warnings for overloads
# https://github.com/nedbat/coveragepy/issues/970#issuecomment-612602180
Expand All @@ -68,12 +61,6 @@ exclude_lines = [
"@overload",
]

[tool.isort]
profile = "black"
known_first_party = ["tests", "torchseg", "train"]
skip_gitignore = true
color_output = true

[tool.pytest.ini_options]
norecursedirs = [
".ipynb_checkpoints",
Expand All @@ -94,3 +81,45 @@ torchseg = ["py.typed"]

[tool.setuptools.packages.find]
include = ["torchseg*"]

[tool.ruff]
exclude = [
# Extra files
"data/",
"images/",
"logo/",
"logs/",
"output/",

# Docs
"docs/src/",

# Spack
".spack-env/",

# Python
"build/",
"dist/",
".cache/",
".mypy_cache/",
".pytest_cache/",
"__pycache__/",
"*.egg-info/",

# Git
".git/",
".github/",
]

line-length = 88
indent-width = 4
target-version = "py311"

[tool.ruff.format]
skip-magic-trailing-comma = true

[tool.ruff.lint]
ignore = ["E203"]

[tool.ruff.lint.isort]
known-first-party = ["tests", "torchseg"]
4 changes: 2 additions & 2 deletions requirements/required.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ setuptools==69.0.0

# install
einops==0.7.0
timm==0.9.12
torch==2.1.2
timm==0.9.16
torch==2.2.2
5 changes: 1 addition & 4 deletions requirements/style.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
# style
black[jupyter]==23.12.1
flake8==7.0.0
isort[colors]==5.13.2
pyupgrade==3.15.0
ruff==0.3.5
1 change: 1 addition & 0 deletions torchseg/losses/lovasz.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Lovasz-Softmax and Jaccard hinge loss in PyTorch
Maxim Berman 2018 ESAT-PSI KU Leuven (MIT License)
"""

from typing import Optional

import torch
Expand Down
Loading