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

Ruff #23

Merged
merged 12 commits into from
Apr 17, 2024
Merged

Ruff #23

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.

91 changes: 9 additions & 82 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ on:
- main
- release**
jobs:
black:
name: black
ruff:
name: ruff
runs-on: ubuntu-latest
steps:
- name: Clone repo
uses: actions/[email protected].1
uses: actions/[email protected].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/[email protected].0
uses: actions/[email protected].2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of these version bumps should be saved for another PR, probably by dependabot

id: cache
with:
path: ${{ env.pythonLocation }}
Expand All @@ -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/[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'
- 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/[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
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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
data/
images/
logo/
logs/
output/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down Expand Up @@ -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]'.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should really be in a separate PR too


#### Code Formatting/Linting

To format files run `ruff format`. To check for linting errors run `ruff check`.

#### Tests

To run tests use `pytest -ra`
33 changes: 18 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
Expand All @@ -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",
Expand All @@ -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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't being used yet

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]==24.3.0
flake8==7.0.0
isort[colors]==5.13.2
pyupgrade==3.15.2
ruff==0.3.7
Loading