Skip to content

prepare repo for auto-formatters #1546

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 39 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
bd2998a
prepare repo for aut-formatters
pmeier Jan 28, 2022
ce9adea
fix CircleCI config
pmeier Jan 28, 2022
169b66d
reactivate lint jobs
pmeier Jan 28, 2022
b3194ad
install libtinfo for linting c code
pmeier Jan 28, 2022
207906e
disable git diff for required action
pmeier Jan 28, 2022
561da34
fix config
pmeier Jan 28, 2022
a63c6c8
fix clang format
pmeier Jan 28, 2022
a8f3258
fix lint failure behavior
pmeier Jan 28, 2022
8fb0176
fix circleci consistency check
pmeier Jan 28, 2022
f04646e
try different failure messages
pmeier Jan 28, 2022
c657a2c
change failure format
pmeier Jan 28, 2022
5da9f8b
fix config template
pmeier Jan 28, 2022
bc17ab1
use clang-format as pre-commit hook
pmeier Jan 31, 2022
6b94331
fix rev
pmeier Jan 31, 2022
e643c57
fix rev
pmeier Jan 31, 2022
4b35cad
rename job from lint to format
pmeier Jan 31, 2022
117a72d
fix step names
pmeier Jan 31, 2022
baf4b26
update template
pmeier Jan 31, 2022
be0ec70
remove flake8-docstrings
pmeier Jan 31, 2022
f2dfd94
revert
pmeier Feb 1, 2022
4e1730a
remove pydocstyle job
pmeier Feb 1, 2022
41d644d
remove pyupgrade as hook
pmeier Feb 1, 2022
751745b
add usage explanation to contributing guide
pmeier Feb 1, 2022
ced0e2d
Merge branch 'main' into pre-commit
pmeier Feb 1, 2022
eccdc70
remove docstring job remnants
pmeier Feb 1, 2022
6769019
add explanation of clang-format to contribution guide
pmeier Feb 1, 2022
e707a17
remove flake8 from unittest environments
pmeier Feb 1, 2022
bb3d1b1
apply changes from auto formatters
pmeier Feb 3, 2022
3a304ce
Change Black and usort version to match Meta's internal version
abhinavarora Feb 3, 2022
f4e0535
Add formatting changes after changing black and usort version
abhinavarora Feb 3, 2022
1f90bc5
Add .clang-format to ensure clang changes align with Meta's internal …
abhinavarora Feb 3, 2022
88ed954
Add clang-format changes
abhinavarora Feb 3, 2022
b86c069
Merge branch 'main' into pre-commit
abhinavarora Feb 3, 2022
17d3337
Merge main into branch
abhinavarora Feb 3, 2022
314387b
Merge branch 'main' into pre-commit
abhinavarora Feb 16, 2022
4993090
Run pre-commit after merge
abhinavarora Feb 16, 2022
f75495e
Run clang-format after merge
abhinavarora Feb 16, 2022
b1e3a69
Fix regenerate.py merge conflict
abhinavarora Feb 16, 2022
8a12398
Fix merge issue
abhinavarora Feb 16, 2022
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
90 changes: 60 additions & 30 deletions .circleci/config.yml

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

82 changes: 60 additions & 22 deletions .circleci/config.yml.in
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,62 @@ jobs:
steps:
- checkout
- run:
name: Install check utilities
command: pip install --user --progress-bar=off jinja2 pyyaml
- run:
name: Check CircleCI config consistency
command: python .circleci/regenerate.py && git diff --quiet
- run:
when: on_fail
name: .circleci/config.yml not in sync with config.yml.in! Run '$ python .circleci/regenerate.py' to fix this.
command: exit 1

lint_python_and_config:
docker:
- image: circleci/python:3.7
steps:
- checkout
- run:
name: Install lint utilities
command: pip install --user --progress-bar=off pre-commit
- run:
name: Install pre-commit hooks
command: pre-commit install-hooks
- run:
name: Lint Python code and config files
command: pre-commit run --all-files
- run:
when: on_fail
name: Code format not compliant with the rules! Run '$ pre-commit run --all-files' to fix this.
command: exit 1

lint_c:
docker:
- image: circleci/python:3.7
steps:
- run:
name: Install additional system libraries
command: |
sudo apt update -qy
sudo apt install libtinfo5
- checkout
- run:
name: Install lint utilities
command: |
pip install --user --progress-bar off jinja2 pyyaml
python .circleci/regenerate.py
git diff --exit-code || (echo ".circleci/config.yml not in sync with config.yml.in! Run .circleci/regenerate.py to update config"; exit 1)
curl https://oss-clang-format.s3.us-east-2.amazonaws.com/linux64/clang-format-linux64 -o clang-format
chmod +x clang-format
./clang-format --version
- run:
name: Lint C code
command: >
python run-clang-format.py
--recursive
--clang-format-executable=./clang-format
torchtext/csrc
- run:
when: on_fail
name: Code format not compliant with the rules! Run '$ python run-clang-format.py' to fix this.
command: exit 1

binary_linux_wheel:
<<: *binary_common
Expand Down Expand Up @@ -591,28 +643,14 @@ jobs:
target=${tag:-main}
~/workspace/.circleci/build_docs/commit_docs.sh ~/workspace $target

docstring_parameters_sync:
<<: *binary_common
docker:
- image: continuumio/miniconda3
resource_class: medium
steps:
- attach_workspace:
at: ~/workspace
- designate_upload_channel
- checkout
- run:
name: Check parameters docstring sync
command: |
pip install --user pydocstyle
export PATH="$HOME/.local/bin:$PATH"
pydocstyle torchtext


workflows:
build:
lint:
jobs:
- circleci_consistency
- lint_python_and_config
- lint_c
build:
jobs:
{{ build_workflows() }}
unittest:
jobs:
Expand Down
22 changes: 1 addition & 21 deletions .circleci/regenerate.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def build_workflows(prefix='', upload=False, filter_branch=None, indentation=6):
# Build on every pull request, but upload only on nightly and tags
w += build_doc_job('/.*/')
w += upload_doc_job('nightly')
w += docstring_parameters_sync_job(None)

return indent(indentation, w)

Expand Down Expand Up @@ -85,18 +84,6 @@ def upload_doc_job(filter_branch):
return [{"upload_docs": job}]


def docstring_parameters_sync_job(filter_branch):
job = {
"name": "docstring_parameters_sync",
"python_version": "3.8",
"requires": ["binary_linux_wheel_py3.8", ],
}

if filter_branch:
job["filters"] = gen_filter_branch_tree(filter_branch)
return [{"docstring_parameters_sync": job}]


def generate_base_workflow(base_workflow_name, python_version, filter_branch, os_type, btype):
d = {
"name": base_workflow_name,
Expand Down Expand Up @@ -167,7 +154,7 @@ def unittest_workflows(indentation=6):
}
})

for i, python_version in enumerate(PYTHON_VERSIONS):
for python_version in PYTHON_VERSIONS:
w.append({
f"unittest_{os_type}": {
"name": f"unittest_{os_type}_py{python_version}",
Expand All @@ -176,13 +163,6 @@ def unittest_workflows(indentation=6):
}
})

if i == 0 and os_type == "linux":
w.append({
"stylecheck": {
"name": f"stylecheck_py{python_version}",
"python_version": python_version,
}
})
return indent(indentation, w)


Expand Down
32 changes: 0 additions & 32 deletions .circleci/unittest/linux/scripts/run_style_checks.sh

This file was deleted.

5 changes: 0 additions & 5 deletions .circleci/unittest/linux/scripts/setup_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ conda activate "${env_dir}"
# 3. Install Conda dependencies
printf "* Installing dependencies (except PyTorch)\n"
conda env update --file "${this_dir}/environment.yml" --prune
if [ "${os}" == Linux ] ; then
clangformat_path="${root_dir}/clang-format"
curl https://oss-clang-format.s3.us-east-2.amazonaws.com/linux64/clang-format-linux64 -o "${clangformat_path}"
chmod +x "${clangformat_path}"
fi

# 4. Download
printf "* Downloading SpaCy English models\n"
Expand Down
4 changes: 2 additions & 2 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[flake8]
# E501 is not flexible enough, we're using B950 instead. Consistent with pytorch
ignore = E402,E722,W503,W504,F821,E501
ignore = E401,E402,E501,E722,W503,W504,F821,B006,B007,B008,B009
select = D417 # Missing argument descriptions in the docstring
max-line-length = 120
exclude = docs/source,third_party
35 changes: 35 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: trailing-whitespace
- id: mixed-line-ending
args:
- --fix=lf
- id: end-of-file-fixer

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.5.1
hooks:
- id: prettier
types_or:
- markdown
- toml
- yaml

- repo: https://github.com/omnilib/ufmt
rev: v1.3.1
hooks:
- id: ufmt
additional_dependencies:
- black == 21.12b0
- usort == 1.0.1

- repo: https://github.com/pycqa/flake8
rev: 4.0.1
hooks:
- id: flake8
additional_dependencies:
- flake8-docstrings == 1.6.0
args:
- --config=.flake8
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
packaging/*
.circleci/config.yml
2 changes: 2 additions & 0 deletions .prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
proseWrap: always
printWidth: 120
20 changes: 18 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,24 @@ We actively welcome your pull requests.
2. If you've added code that should be tested, add tests.
3. If you've changed APIs, update the documentation.
4. Ensure the test suite passes.
5. Make sure your code lints.
6. If you haven't already, complete the Contributor License Agreement ("CLA").
5. If you haven't already, complete the Contributor License Agreement ("CLA").

### Code style

`torchtext` enforces a fairly strict code format through [`pre-commit`](https://pre-commit.com). You can install it with

```shell
pip install pre-commit
```

or

```shell
conda install -c conda-forge pre-commit
```

To check and in most cases fix the code format, stage all your changes (`git add`) and execute `pre-commit run`. To perform
the checks automatically before every `git commit`, you can install the checks as hooks with `pre-commit install`.

## Contributor License Agreement ("CLA")
In order to accept your pull request, we need you to submit a CLA. You only need
Expand Down
Loading