Skip to content

Commit

Permalink
style: migrate to ruff (#562)
Browse files Browse the repository at this point in the history
Co-authored-by: Pete <[email protected]>
  • Loading branch information
SauravMaheshkar and epwalsh authored Jun 12, 2023
1 parent 416ffa6 commit 4c3edce
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 49 deletions.
22 changes: 0 additions & 22 deletions .flake8

This file was deleted.

49 changes: 25 additions & 24 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ code sample or an executable test case demonstrating the expected behavior.

We use GitHub issues to track feature requests. Before you create a feature request:

* Make sure you have a clear idea of the enhancement you would like. If you have a vague idea, consider discussing
it first on a GitHub issue.
* Check the documentation to make sure your feature does not already exist.
* Do [a quick search](https://github.com/allenai/tango/issues) to see whether your feature has already been suggested.
- Make sure you have a clear idea of the enhancement you would like. If you have a vague idea, consider discussing
it first on a GitHub issue.
- Check the documentation to make sure your feature does not already exist.
- Do [a quick search](https://github.com/allenai/tango/issues) to see whether your feature has already been suggested.

When creating your request, please:

* Provide a clear title and description.
* Explain why the enhancement would be useful. It may be helpful to highlight the feature in other libraries.
* Include code examples to demonstrate how the enhancement would be used.
- Provide a clear title and description.
- Explain why the enhancement would be useful. It may be helpful to highlight the feature in other libraries.
- Include code examples to demonstrate how the enhancement would be used.

## Making a pull request

When you're ready to contribute code to address an open issue, please follow these guidelines to help us be able to review your pull request (PR) quickly.

1. **Initial setup** (only do this once)
1. **Initial setup** (only do this once)

<details><summary>Expand details 👇</summary><br/>

Expand All @@ -47,7 +47,7 @@ When you're ready to contribute code to address an open issue, please follow the

git clone [email protected]:USERNAME/tango.git

At this point the local clone of your fork only knows that it came from *your* repo, github.com/USERNAME/tango.git, but doesn't know anything the *main* repo, [https://github.com/allenai/tango.git](https://github.com/allenai/tango). You can see this by running
At this point the local clone of your fork only knows that it came from _your_ repo, github.com/USERNAME/tango.git, but doesn't know anything the _main_ repo, [https://github.com/allenai/tango.git](https://github.com/allenai/tango). You can see this by running

git remote -v

Expand Down Expand Up @@ -93,7 +93,7 @@ When you're ready to contribute code to address an open issue, please follow the

</details>

2. **Ensure your fork is up-to-date**
2. **Ensure your fork is up-to-date**

<details><summary>Expand details 👇</summary><br/>

Expand All @@ -105,7 +105,7 @@ When you're ready to contribute code to address an open issue, please follow the

</details>

3. **Create a new branch to work on your fix or enhancement**
3. **Create a new branch to work on your fix or enhancement**

<details><summary>Expand details 👇</summary><br/>

Expand All @@ -119,11 +119,11 @@ When you're ready to contribute code to address an open issue, please follow the

</details>

4. **Test your changes**
4. **Test your changes**

<details><summary>Expand details 👇</summary><br/>

Our continuous integration (CI) testing runs [a number of checks](https://github.com/allenai/tango/actions) for each pull request on [GitHub Actions](https://github.com/features/actions). You can run most of these tests locally, which is something you should do *before* opening a PR to help speed up the review process and make it easier for us.
Our continuous integration (CI) testing runs [a number of checks](https://github.com/allenai/tango/actions) for each pull request on [GitHub Actions](https://github.com/features/actions). You can run most of these tests locally, which is something you should do _before_ opening a PR to help speed up the review process and make it easier for us.

First, you should run [`isort`](https://github.com/PyCQA/isort) and [`black`](https://github.com/psf/black) to make sure you code is formatted consistently.
Many IDEs support code formatters as plugins, so you may be able to setup isort and black to run automatically everytime you save.
Expand All @@ -133,9 +133,9 @@ When you're ready to contribute code to address an open issue, please follow the
isort .
black .

Our CI also uses [`flake8`](https://github.com/allenai/tango/tree/main/tests) to lint the code base and [`mypy`](http://mypy-lang.org/) for type-checking. You should run both of these next with
Our CI also uses [`ruff`](https://github.com/charliermarsh/ruff) to lint the code base and [`mypy`](http://mypy-lang.org/) for type-checking. You should run both of these next with

flake8 .
ruff check .

and

Expand Down Expand Up @@ -177,19 +177,20 @@ in addition to everything listed in [Making a pull request](#making-a-pull-reque

1. First start by creating a new submodule `tango.integrations.name_of_integration` and put all of the code for your integration in there.
2. Then you must add a module docstring to the `__init__.py` file of the submodule which imports all of the public components of the integration,
and defines the [`__all__`](https://docs.python.org/3/tutorial/modules.html#importing-from-a-package) special variable to include all of those components.
This ensures all of the public components will show up in the documentation.
and defines the [`__all__`](https://docs.python.org/3/tutorial/modules.html#importing-from-a-package) special variable to include all of those components.
This ensures all of the public components will show up in the documentation.
3. Next that you should add unit tests of your code to `tests/integrations/name_of_integration/`.
4. Then add a new file `docs/source/api/integrations/name_of_integration.rst`, and include the directive:

```
.. automodule:: tango.integrations.name_of_integration
:members:
```
```
.. automodule:: tango.integrations.name_of_integration
:members:
```

Take a look at any of the other files in that folder to see how it should look exactly.

Take a look at any of the other files in that folder to see how it should look exactly.
5. And then add `name_of_integration` to the `toctree` in `docs/source/api/integrations/index.rst`.
6. After that, add any additional requirements that your integration depends on to `requirements.txt`. Be sure to put those under the "Extra dependencies for integrations" section,
and add the special inline comment `# needed by: name_of_integration`.
and add the special inline comment `# needed by: name_of_integration`.
7. And finally, in the `checks` job definition in `.github/workflows/main.yml`, add a new object
to the matrix for your integration following the other examples there.
to the matrix for your integration following the other examples there.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
extras: dev,all
requires_torch: true
run: |
flake8 .
ruff check .
- name: Type check
extras: dev,all
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ docs :
run-checks :
isort --check .
black --check .
flake8 .
ruff check .
mypy --check-untyped-defs .
CUDA_VISIBLE_DEVICES='' pytest -v --color=yes --doctest-modules --ignore=tests/integrations --ignore=tango/integrations tests/ tango/
CUDA_VISIBLE_DEVICES='' pytest -v --color=yes --doctest-modules tango/integrations/torch tests/integrations/torch
Expand Down
18 changes: 17 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ dependencies = [

[project.optional-dependencies]
dev = [
"flake8",
"ruff",
"mypy==1.2.0",
"types-PyYAML",
"types-setuptools",
Expand Down Expand Up @@ -156,6 +156,22 @@ exclude = '''
profile = "black"
multi_line_output = 3

[tool.ruff]
line-length = 115
select = ["E"]
exclude = [
".venv",
".git",
"__pycache__",
".mypy_cache",
"docs/build",
"dist"
]

[tool.ruff.per-file-ignores]
"__init__.py" = ["F401"]
"*/**/**/__init__.py" = ["F401","E501"]

[tool.mypy]
ignore_missing_imports = true
no_site_packages = false
Expand Down

0 comments on commit 4c3edce

Please sign in to comment.