Skip to content

add ufmt as code formatter #4384

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

Merged
merged 24 commits into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
9 changes: 4 additions & 5 deletions .circleci/config.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions .circleci/config.yml.in
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,9 @@ jobs:
- image: circleci/python:3.7
steps:
- checkout
- run:
command: |
pip install --user --progress-bar off flake8 typing
flake8 --config=setup.cfg .
- run: pip install --user --progress-bar=off ufmt>=1.3 usort==0.6.4 black==21.8b0 flake8
- run: ufmt check .
- run: flake8 --config=setup.cfg .

python_type_check:
docker:
Expand All @@ -207,7 +206,7 @@ jobs:
pip install --user --progress-bar off mypy
pip install --user --progress-bar off types-requests
pip install --user --progress-bar off --pre torch -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
pip install --user --progress-bar off --editable .
pip install --user --progress-bar off --no-build-isolation --editable .
mypy --config-file mypy.ini

docstring_parameters_sync:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests-schedule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
run: pip install --pre torch -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html

- name: Install torchvision
run: pip install -e .
run: pip install --no-build-isolation --editable .

- name: Install all optional dataset requirements
run: pip install scipy pandas pycocotools lmdb requests
Expand Down
16 changes: 16 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[tool.usort]

[tool.usort.known]

first_party = ["torch", "torchvision"]

[tool.black]

line-length = 120
target-version = ["py36"]

[tool.ufmt]

excludes = [
"gallery",
]
10 changes: 8 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ max-line-length = 120

[flake8]
max-line-length = 120
ignore = F401,E402,F403,W503,W504,F821
ignore = E203, E402, W503, W504, F821
per-file-ignores =
__init__.py: F401, F403, F405
./hubconf.py: F401
torchvision/models/mobilenet.py: F401, F403
torchvision/models/quantization/mobilenet.py: F401, F403
test/smoke_test.py: F401
Comment on lines +12 to +18
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

See #4178 (comment) for details on this change.

exclude = venv

[pydocstyle]
select = D417 # Missing argument descriptions in the docstring
select = D417 # Missing argument descriptions in the docstring
2 changes: 1 addition & 1 deletion torchvision/ops/poolers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from torch import nn, Tensor

import torchvision
from torchvision.ops import roi_align
from .roi_align import roi_align
Copy link
Member

Choose a reason for hiding this comment

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

just curious, was this flagged somehow?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

See #4178 (comment). In short: we relied on a specific order of the imports due to a naming conflict. Without this fix we need to exclude these imports from being sorted.

Copy link
Member

Choose a reason for hiding this comment

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

There might have been a reason for that initially, but I'm wondering why we even use absolute imports within the torchvision package. Every torchvision improt should be relative there. Perhaps @fmassa knows?

(anyway, this is for another PR, let's leave it as is :) )

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps because absolute import is recommended by PEP8?

from torchvision.ops.boxes import box_area

from typing import Optional, List, Dict, Tuple, Union
Expand Down