Skip to content

Commit

Permalink
Cleanup the quality checks and document them
Browse files Browse the repository at this point in the history
  • Loading branch information
sgugger committed Nov 3, 2021
1 parent b69f1ca commit a46ed5d
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 112 deletions.
31 changes: 21 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -811,24 +811,35 @@ jobs:
- run: python utils/custom_init_isort.py --check_only
- run: flake8 examples tests src utils
- run: python utils/style_doc.py src/transformers docs/source --max_len 119 --check_only
- run: python utils/check_copies.py
- run: python utils/check_table.py
- run: python utils/check_dummies.py
- run: python utils/check_repo.py
- run: python utils/check_inits.py
- run: make deps_table_check_updated
- run: python utils/tests_fetcher.py --sanity_check

check_repository_consistency:
working_directory: ~/transformers
docker:
- image: circleci/python:3.6
resource_class: small
resource_class: large
environment:
TRANSFORMERS_IS_CI: yes
parallelism: 1
steps:
- checkout
- run: pip install requests
- run: python ./utils/link_tester.py
- restore_cache:
keys:
- v0.4-repository_consistency-{{ checksum "setup.py" }}
- v0.4-{{ checksum "setup.py" }}
- run: pip install --upgrade pip
- run: pip install isort GitPython
- run: pip install .[all,quality]
- save_cache:
key: v0.4-repository_consistency-{{ checksum "setup.py" }}
paths:
- '~/.cache/pip'
- run: python utils/check_copies.py
- run: python utils/check_table.py
- run: python utils/check_dummies.py
- run: python utils/check_repo.py
- run: python utils/check_inits.py
- run: make deps_table_check_updated
- run: python utils/tests_fetcher.py --sanity_check

run_tests_layoutlmv2:
working_directory: ~/transformers
Expand Down
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ deps_table_check_updated:

autogenerate_code: deps_table_update

# Check that source code meets quality standards
# Check that the repo is in a good state

extra_quality_checks:
repo-consistency:
python utils/check_copies.py
python utils/check_table.py
python utils/check_dummies.py
Expand All @@ -42,12 +42,13 @@ extra_quality_checks:
python utils/tests_fetcher.py --sanity_check

# this target runs checks on all files

quality:
black --check $(check_dirs)
isort --check-only $(check_dirs)
python utils/custom_init_isort.py --check_only
flake8 $(check_dirs)
${MAKE} extra_quality_checks
python utils/style_doc.py src/transformers docs/source --max_len 119 --check_only

# Format source code automatically and check is there are any problems left that need manual fixing

Expand All @@ -56,6 +57,7 @@ extra_style_checks:
python utils/style_doc.py src/transformers docs/source --max_len 119

# this target runs checks on all files and potentially modifies some of them

style:
black $(check_dirs)
isort $(check_dirs)
Expand All @@ -64,7 +66,7 @@ style:

# Super fast fix and check target that only works on relevant modified files since the branch was made

fixup: modified_only_fixup extra_style_checks autogenerate_code extra_quality_checks
fixup: modified_only_fixup extra_style_checks autogenerate_code repo-consistency

# Make marked copies of snippets of codes conform to the original

Expand Down
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ Flax), PyTorch, and/or TensorFlow.
testing
debugging
serialization
pr_tests

.. toctree::
:maxdepth: 2
Expand Down
36 changes: 34 additions & 2 deletions docs/source/pr_tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Sphinx is not known for its helpful error messages, so you might have to try a f

## Code and documentation style

Code formatting is applied to all the source files, the examples and the tests using black and isort. We also have a custom tool taking care of the formatting of docstrings and rst files. Both can be launched by executing
Code formatting is applied to all the source files, the examples and the tests using black and isort. We also have a custom tool taking care of the formatting of docstrings and rst files (`utils/style_doc.py`), as well as the order of the lazy imports performed in the Transformers `__init__.py` files (`utils/custom_init_isort.py`). All of this can be launched by executing

```bash
make style
Expand All @@ -93,7 +93,39 @@ This can take a lot of time, so to run the same thing on only the scripts you mo
make fixup
```

Those two commands will also run all the additional checks for the repository consistency. Let's have a look at them.
This last command will also run all the additional checks for the repository consistency. Let's have a look at them.

## Repository consistency

This regroups all the tests to make sure your PR leaves the repository in a good state, and is performed by the `ci/circleci: check_repository_consistency` check. You can locally run that check by executing the following:

```bash
make repo-consistency
```

This checks that:

- All objects added to the init are documented (performed by `utils/check_repo.py`)
- All `__init__.py` files have the same content in their two sections (performed by `utils/check_inits.py`)
- All code identified as a copy from another module is consistent with the original (performed by `utils/check_copies.py`)
- The translations of the READMEs and the index of the doc have the same model list as the main README (performed by `utils/check_copies.py`)
- The auto-generated tables in the documentation are up to date (performed by `utils/check_table.py`)
- The library has all objects available even if not all optional dependencies are installed (performed by `utils/check_dummies.py`)

The first two need to be manually fixed, the last four can be fixed automatically for you by running the command

```bash
make fix-copies
```

Additional checks concern PRs that add a new model, mainly that:

- All models added are in an Auto-mapping (performed by `utils/check_repo.py`)
<!-- TODO Sylvain, add a check that makes sure the common tests are implemented.-->
- All models are properly tested (performed by `utils/check_repo.py`)

<!-- TODO Sylvain, add the following
- All models are added to the main README, inside the master doc
- All checkpoints used actually exist on the Hub
-->
96 changes: 0 additions & 96 deletions utils/link_tester.py

This file was deleted.

0 comments on commit a46ed5d

Please sign in to comment.