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

prepare repo for auto-formatters #1546

Merged
merged 39 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
pmeier marked this conversation as resolved.
Show resolved Hide resolved
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
pmeier marked this conversation as resolved.
Show resolved Hide resolved
- 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 @@ -512,28 +564,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:
pmeier marked this conversation as resolved.
Show resolved Hide resolved
jobs:
- circleci_consistency
- lint_python_and_config
- lint_c
build:
jobs:
{{ build_workflows() }}
unittest:
jobs:
Expand Down
87 changes: 36 additions & 51 deletions .circleci/regenerate.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,48 +14,46 @@
https://github.com/pytorch/vision/pull/1321#issuecomment-531033978
"""

import os.path

import jinja2
from jinja2 import select_autoescape
import yaml
import os.path
from jinja2 import select_autoescape


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

DOC_VERSION = ('linux', '3.8')
DOC_VERSION = ("linux", "3.8")


def build_workflows(prefix='', upload=False, filter_branch=None, indentation=6):
def build_workflows(prefix="", upload=False, filter_branch=None, indentation=6):
w = []
for btype in ["wheel", "conda"]:
for os_type in ["linux", "macos", "windows"]:
for python_version in PYTHON_VERSIONS:
fb = filter_branch
if not fb and (os_type == 'linux' and
btype == 'wheel' and
python_version == '3.8'):
if not fb and (os_type == "linux" and btype == "wheel" and python_version == "3.8"):
# the fields must match the build_docs "requires" dependency
fb = '/.*/'
fb = "/.*/"
w += build_workflow_pair(btype, os_type, python_version, fb, prefix, upload)

if not filter_branch:
# 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)
w += build_doc_job("/.*/")
w += upload_doc_job("nightly")

return indent(indentation, w)


def build_workflow_pair(btype, os_type, python_version, filter_branch, prefix='', upload=False):
def build_workflow_pair(btype, os_type, python_version, filter_branch, prefix="", upload=False):
w = []
base_workflow_name = f"{prefix}binary_{os_type}_{btype}_py{python_version}"
w.append(generate_base_workflow(base_workflow_name, python_version, filter_branch, os_type, btype))

if upload:
w.append(generate_upload_workflow(base_workflow_name, filter_branch, btype))
if filter_branch == 'nightly' and os_type in ['linux', 'windows']:
pydistro = 'pip' if btype == 'wheel' else 'conda'
if filter_branch == "nightly" and os_type in ["linux", "windows"]:
pydistro = "pip" if btype == "wheel" else "conda"
w.append(generate_smoketest_workflow(pydistro, base_workflow_name, filter_branch, python_version, os_type))
return w

Expand All @@ -64,7 +62,9 @@ def build_doc_job(filter_branch):
job = {
"name": "build_docs",
"python_version": "3.8",
"requires": ["binary_linux_wheel_py3.8", ],
"requires": [
"binary_linux_wheel_py3.8",
],
}

if filter_branch:
Expand All @@ -77,26 +77,16 @@ def upload_doc_job(filter_branch):
"name": "upload_docs",
"context": "org-member",
"python_version": "3.8",
"requires": ["build_docs", ],
"requires": [
"build_docs",
],
}

if filter_branch:
job["filters"] = gen_filter_branch_tree(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 All @@ -111,14 +101,12 @@ def generate_base_workflow(base_workflow_name, python_version, filter_branch, os

def gen_filter_branch_tree(branch_name):
return {
"branches": {
"only": branch_name
},
"branches": {"only": branch_name},
"tags": {
# Using a raw string here to avoid having to escape
# anything
"only": r"/v[0-9]+(\.[0-9]+)*-rc[0-9]+/"
}
},
}


Expand Down Expand Up @@ -160,21 +148,16 @@ def indent(indentation, data_list):
def unittest_workflows(indentation=6):
w = []
for os_type in ["linux", "windows"]:
for i, python_version in enumerate(PYTHON_VERSIONS):
w.append({
f"unittest_{os_type}": {
"name": f"unittest_{os_type}_py{python_version}",
"python_version": python_version,
}
})

if i == 0 and os_type == "linux":
w.append({
"stylecheck": {
"name": f"stylecheck_py{python_version}",
for python_version in PYTHON_VERSIONS:
w.append(
{
f"unittest_{os_type}": {
"name": f"unittest_{os_type}_py{python_version}",
"python_version": python_version,
}
})
}
)

return indent(indentation, w)


Expand All @@ -183,12 +166,14 @@ def unittest_workflows(indentation=6):
env = jinja2.Environment(
loader=jinja2.FileSystemLoader(d),
lstrip_blocks=True,
autoescape=select_autoescape(enabled_extensions=('html', 'xml')),
autoescape=select_autoescape(enabled_extensions=("html", "xml")),
)

with open(os.path.join(d, 'config.yml'), 'w') as f:
f.write(env.get_template('config.yml.in').render(
build_workflows=build_workflows,
unittest_workflows=unittest_workflows,
))
with open(os.path.join(d, "config.yml"), "w") as f:
f.write(
env.get_template("config.yml.in").render(
build_workflows=build_workflows,
unittest_workflows=unittest_workflows,
)
)
f.write("\n")
Loading