diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 9c96dfa8..00000000 --- a/.flake8 +++ /dev/null @@ -1,31 +0,0 @@ -[flake8] -max-line-length = 88 -extend-ignore = - # See https://github.com/PyCQA/pycodestyle/issues/373 - E203, -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/, \ No newline at end of file diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index 61278910..d688e81f 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -9,18 +9,18 @@ on: - main - release** jobs: - black: - name: black + ruff: + name: ruff runs-on: ubuntu-latest steps: - name: Clone repo - uses: actions/checkout@v4.1.1 + uses: actions/checkout@v4.1.2 - name: Set up python - uses: actions/setup-python@v5.0.0 + uses: actions/setup-python@v5.1.0 with: - python-version: '3.11' + python-version: '3.12' - name: Cache dependencies - uses: actions/cache@v4.0.0 + uses: actions/cache@v4.0.2 id: cache with: path: ${{ env.pythonLocation }} @@ -32,83 +32,10 @@ jobs: 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/checkout@v4.1.1 - - name: Set up python - uses: actions/setup-python@v5.0.0 - with: - python-version: '3.11' - - name: Cache dependencies - uses: actions/cache@v4.0.0 - 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/checkout@v4.1.1 - - name: Set up python - uses: actions/setup-python@v5.0.0 - with: - python-version: '3.11' - - name: Cache dependencies - uses: actions/cache@v4.0.0 - id: cache - with: - path: ${{ env.pythonLocation }} - key: ${{ env.pythonLocation }}-${{ hashFiles('requirements/style.txt') }} - - name: Install pip dependencies - if: steps.cache.outputs.cache-hit != 'true' + - name: Run ruff checks 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/checkout@v4.1.1 - - name: Set up python - uses: actions/setup-python@v5.0.0 - with: - python-version: '3.11' - - name: Cache dependencies - uses: actions/cache@v4.0.0 - 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 + ruff check --output-format=github --no-fix . + ruff format --diff concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.head.label || github.head_ref || github.ref }} cancel-in-progress: true \ No newline at end of file diff --git a/.gitignore b/.gitignore index b0990628..21cb8ecb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,9 @@ +data/ +images/ +logo/ +logs/ +output/ + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/README.md b/README.md index d3cf3009..b68f91c0 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ The goal of this fork is to 1) provide maintenance support for the original libr Additionally we have performed the following for improved software standards: - More thorough testing and CI -- Formatting using `black`, `isort`, `flake8`, `mypy` +- Formatting using `ruff` and `mypy` - Reduction of dependence on unmaintained libraries (now depends only on `torch`, `timm`, and `einops`) - Reduce lines of code to maintain (removed custom utils, metrics, encoders) in favor of newer libraries such as `torchmetrics` and `timm` @@ -227,3 +227,19 @@ Note that some models like `ConvNext` and `Swin` only have 4 intermediate featur ```python model = torchseg.Unet('resnet50', encoder_depth=4) ``` + +## Contribute + +We welcome new contributions for modern semantic segmentation models, losses, and methods! + +#### Install dev dependencies + +For development you can install the required dependencies using `pip install '.[all]'. + +#### Code Formatting/Linting + +To format files run `ruff format`. To check for linting errors run `ruff check`. + +#### Tests + +To run tests use `pytest -ra` diff --git a/pyproject.toml b/pyproject.toml index 7dd46c4c..4f7e5eb0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,10 +40,8 @@ dynamic = ["version"] [project.optional-dependencies] style = [ - "black[jupyter]>=21.8", - "flake8>=3.8", - "isort[colors]>=5.8", - "pyupgrade>=2.8", + # ruff 0.2+ required for [ruff.lint] + "ruff>=0.2.0" ] tests = [ "pytest>=7.3", @@ -56,11 +54,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 @@ -69,12 +62,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", @@ -95,3 +82,19 @@ torchseg = ["py.typed"] [tool.setuptools.packages.find] include = ["torchseg*"] + +[tool.ruff] +fix = true +show-fixes = true + +[tool.ruff.format] +skip-magic-trailing-comma = true + +[tool.ruff.lint] +extend-select = ["I", "UP"] + +[tool.ruff.lint.isort] +split-on-trailing-comma = false + +[tool.ruff.lint.pydocstyle] +convention = "google" diff --git a/requirements/style.txt b/requirements/style.txt index 5080345a..038caa5a 100644 --- a/requirements/style.txt +++ b/requirements/style.txt @@ -1,5 +1,2 @@ # style -black[jupyter]==24.3.0 -flake8==7.0.0 -isort[colors]==5.13.2 -pyupgrade==3.15.2 \ No newline at end of file +ruff==0.3.7 \ No newline at end of file