Skip to content

Commit c31a400

Browse files
pmeierabhinavarora
andauthored
prepare repo for auto-formatters (#1546)
* prepare repo for aut-formatters * fix CircleCI config * reactivate lint jobs * install libtinfo for linting c code * disable git diff for required action * fix config * fix clang format * fix lint failure behavior * fix circleci consistency check * try different failure messages * change failure format * fix config template * use clang-format as pre-commit hook * fix rev * fix rev * rename job from lint to format * fix step names * update template * remove flake8-docstrings * revert * remove pydocstyle job * remove pyupgrade as hook * add usage explanation to contributing guide * remove docstring job remnants * add explanation of clang-format to contribution guide * remove flake8 from unittest environments * apply changes from auto formatters * Change Black and usort version to match Meta's internal version * Add formatting changes after changing black and usort version * Add .clang-format to ensure clang changes align with Meta's internal workflow * Add clang-format changes * Merge main into branch * Run pre-commit after merge * Run clang-format after merge * Fix regenerate.py merge conflict * Fix merge issue Co-authored-by: Abhinav Arora <[email protected]>
1 parent 8808e7e commit c31a400

File tree

190 files changed

+11855
-11156
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

190 files changed

+11855
-11156
lines changed

.circleci/config.yml

+60-30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.circleci/config.yml.in

+60-22
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,62 @@ jobs:
8787
steps:
8888
- checkout
8989
- run:
90+
name: Install check utilities
91+
command: pip install --user --progress-bar=off jinja2 pyyaml
92+
- run:
93+
name: Check CircleCI config consistency
94+
command: python .circleci/regenerate.py && git diff --quiet
95+
- run:
96+
when: on_fail
97+
name: .circleci/config.yml not in sync with config.yml.in! Run '$ python .circleci/regenerate.py' to fix this.
98+
command: exit 1
99+
100+
lint_python_and_config:
101+
docker:
102+
- image: circleci/python:3.7
103+
steps:
104+
- checkout
105+
- run:
106+
name: Install lint utilities
107+
command: pip install --user --progress-bar=off pre-commit
108+
- run:
109+
name: Install pre-commit hooks
110+
command: pre-commit install-hooks
111+
- run:
112+
name: Lint Python code and config files
113+
command: pre-commit run --all-files
114+
- run:
115+
when: on_fail
116+
name: Code format not compliant with the rules! Run '$ pre-commit run --all-files' to fix this.
117+
command: exit 1
118+
119+
lint_c:
120+
docker:
121+
- image: circleci/python:3.7
122+
steps:
123+
- run:
124+
name: Install additional system libraries
125+
command: |
126+
sudo apt update -qy
127+
sudo apt install libtinfo5
128+
- checkout
129+
- run:
130+
name: Install lint utilities
90131
command: |
91-
pip install --user --progress-bar off jinja2 pyyaml
92-
python .circleci/regenerate.py
93-
git diff --exit-code || (echo ".circleci/config.yml not in sync with config.yml.in! Run .circleci/regenerate.py to update config"; exit 1)
132+
curl https://oss-clang-format.s3.us-east-2.amazonaws.com/linux64/clang-format-linux64 -o clang-format
133+
chmod +x clang-format
134+
./clang-format --version
135+
- run:
136+
name: Lint C code
137+
command: >
138+
python run-clang-format.py
139+
--recursive
140+
--clang-format-executable=./clang-format
141+
torchtext/csrc
142+
- run:
143+
when: on_fail
144+
name: Code format not compliant with the rules! Run '$ python run-clang-format.py' to fix this.
145+
command: exit 1
94146

95147
binary_linux_wheel:
96148
<<: *binary_common
@@ -512,28 +564,14 @@ jobs:
512564
target=${tag:-main}
513565
~/workspace/.circleci/build_docs/commit_docs.sh ~/workspace $target
514566

515-
docstring_parameters_sync:
516-
<<: *binary_common
517-
docker:
518-
- image: continuumio/miniconda3
519-
resource_class: medium
520-
steps:
521-
- attach_workspace:
522-
at: ~/workspace
523-
- designate_upload_channel
524-
- checkout
525-
- run:
526-
name: Check parameters docstring sync
527-
command: |
528-
pip install --user pydocstyle
529-
export PATH="$HOME/.local/bin:$PATH"
530-
pydocstyle torchtext
531-
532-
533567
workflows:
534-
build:
568+
lint:
535569
jobs:
536570
- circleci_consistency
571+
- lint_python_and_config
572+
- lint_c
573+
build:
574+
jobs:
537575
{{ build_workflows() }}
538576
unittest:
539577
jobs:

.circleci/regenerate.py

+36-51
Original file line numberDiff line numberDiff line change
@@ -14,48 +14,46 @@
1414
https://github.com/pytorch/vision/pull/1321#issuecomment-531033978
1515
"""
1616

17+
import os.path
18+
1719
import jinja2
18-
from jinja2 import select_autoescape
1920
import yaml
20-
import os.path
21+
from jinja2 import select_autoescape
2122

2223

2324
PYTHON_VERSIONS = ["3.7", "3.8", "3.9"]
2425

25-
DOC_VERSION = ('linux', '3.8')
26+
DOC_VERSION = ("linux", "3.8")
2627

2728

28-
def build_workflows(prefix='', upload=False, filter_branch=None, indentation=6):
29+
def build_workflows(prefix="", upload=False, filter_branch=None, indentation=6):
2930
w = []
3031
for btype in ["wheel", "conda"]:
3132
for os_type in ["linux", "macos", "windows"]:
3233
for python_version in PYTHON_VERSIONS:
3334
fb = filter_branch
34-
if not fb and (os_type == 'linux' and
35-
btype == 'wheel' and
36-
python_version == '3.8'):
35+
if not fb and (os_type == "linux" and btype == "wheel" and python_version == "3.8"):
3736
# the fields must match the build_docs "requires" dependency
38-
fb = '/.*/'
37+
fb = "/.*/"
3938
w += build_workflow_pair(btype, os_type, python_version, fb, prefix, upload)
4039

4140
if not filter_branch:
4241
# Build on every pull request, but upload only on nightly and tags
43-
w += build_doc_job('/.*/')
44-
w += upload_doc_job('nightly')
45-
w += docstring_parameters_sync_job(None)
42+
w += build_doc_job("/.*/")
43+
w += upload_doc_job("nightly")
4644

4745
return indent(indentation, w)
4846

4947

50-
def build_workflow_pair(btype, os_type, python_version, filter_branch, prefix='', upload=False):
48+
def build_workflow_pair(btype, os_type, python_version, filter_branch, prefix="", upload=False):
5149
w = []
5250
base_workflow_name = f"{prefix}binary_{os_type}_{btype}_py{python_version}"
5351
w.append(generate_base_workflow(base_workflow_name, python_version, filter_branch, os_type, btype))
5452

5553
if upload:
5654
w.append(generate_upload_workflow(base_workflow_name, filter_branch, btype))
57-
if filter_branch == 'nightly' and os_type in ['linux', 'windows']:
58-
pydistro = 'pip' if btype == 'wheel' else 'conda'
55+
if filter_branch == "nightly" and os_type in ["linux", "windows"]:
56+
pydistro = "pip" if btype == "wheel" else "conda"
5957
w.append(generate_smoketest_workflow(pydistro, base_workflow_name, filter_branch, python_version, os_type))
6058
return w
6159

@@ -64,7 +62,9 @@ def build_doc_job(filter_branch):
6462
job = {
6563
"name": "build_docs",
6664
"python_version": "3.8",
67-
"requires": ["binary_linux_wheel_py3.8", ],
65+
"requires": [
66+
"binary_linux_wheel_py3.8",
67+
],
6868
}
6969

7070
if filter_branch:
@@ -77,26 +77,16 @@ def upload_doc_job(filter_branch):
7777
"name": "upload_docs",
7878
"context": "org-member",
7979
"python_version": "3.8",
80-
"requires": ["build_docs", ],
80+
"requires": [
81+
"build_docs",
82+
],
8183
}
8284

8385
if filter_branch:
8486
job["filters"] = gen_filter_branch_tree(filter_branch)
8587
return [{"upload_docs": job}]
8688

8789

88-
def docstring_parameters_sync_job(filter_branch):
89-
job = {
90-
"name": "docstring_parameters_sync",
91-
"python_version": "3.8",
92-
"requires": ["binary_linux_wheel_py3.8", ],
93-
}
94-
95-
if filter_branch:
96-
job["filters"] = gen_filter_branch_tree(filter_branch)
97-
return [{"docstring_parameters_sync": job}]
98-
99-
10090
def generate_base_workflow(base_workflow_name, python_version, filter_branch, os_type, btype):
10191
d = {
10292
"name": base_workflow_name,
@@ -111,14 +101,12 @@ def generate_base_workflow(base_workflow_name, python_version, filter_branch, os
111101

112102
def gen_filter_branch_tree(branch_name):
113103
return {
114-
"branches": {
115-
"only": branch_name
116-
},
104+
"branches": {"only": branch_name},
117105
"tags": {
118106
# Using a raw string here to avoid having to escape
119107
# anything
120108
"only": r"/v[0-9]+(\.[0-9]+)*-rc[0-9]+/"
121-
}
109+
},
122110
}
123111

124112

@@ -160,21 +148,16 @@ def indent(indentation, data_list):
160148
def unittest_workflows(indentation=6):
161149
w = []
162150
for os_type in ["linux", "windows"]:
163-
for i, python_version in enumerate(PYTHON_VERSIONS):
164-
w.append({
165-
f"unittest_{os_type}": {
166-
"name": f"unittest_{os_type}_py{python_version}",
167-
"python_version": python_version,
168-
}
169-
})
170-
171-
if i == 0 and os_type == "linux":
172-
w.append({
173-
"stylecheck": {
174-
"name": f"stylecheck_py{python_version}",
151+
for python_version in PYTHON_VERSIONS:
152+
w.append(
153+
{
154+
f"unittest_{os_type}": {
155+
"name": f"unittest_{os_type}_py{python_version}",
175156
"python_version": python_version,
176157
}
177-
})
158+
}
159+
)
160+
178161
return indent(indentation, w)
179162

180163

@@ -183,12 +166,14 @@ def unittest_workflows(indentation=6):
183166
env = jinja2.Environment(
184167
loader=jinja2.FileSystemLoader(d),
185168
lstrip_blocks=True,
186-
autoescape=select_autoescape(enabled_extensions=('html', 'xml')),
169+
autoescape=select_autoescape(enabled_extensions=("html", "xml")),
187170
)
188171

189-
with open(os.path.join(d, 'config.yml'), 'w') as f:
190-
f.write(env.get_template('config.yml.in').render(
191-
build_workflows=build_workflows,
192-
unittest_workflows=unittest_workflows,
193-
))
172+
with open(os.path.join(d, "config.yml"), "w") as f:
173+
f.write(
174+
env.get_template("config.yml.in").render(
175+
build_workflows=build_workflows,
176+
unittest_workflows=unittest_workflows,
177+
)
178+
)
194179
f.write("\n")

0 commit comments

Comments
 (0)