Skip to content

Commit

Permalink
Edits to isort and contribution instructions (#714)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #714

1. Add command for earlier versions of isort
2. For contributions in the `research` folder, add instructions about code fomratting.
3. Specify version of isort in dev requirements
4. Remove -v (verbose) arg since this arg seems to alter the behavior of isort in some cases.

Reviewed By: EnayatUllah

Differential Revision: D68078254

fbshipit-source-id: 21b75ade5c651cb4b890a4906afca002394e7aee
  • Loading branch information
iden-kalemaj authored and facebook-github-bot committed Jan 21, 2025
1 parent b4c075d commit 3e97447
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci_cpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Lint with black
run: black --check --diff --color .
- name: Check import order with isort
run: isort -v -l 88 -o opacus --lines-after-imports 2 -m 3 --trailing-comma --check-only .
run: isort -l 88 -o opacus --lines-after-imports 2 -m 3 --trailing-comma --check-only .

########### UNIT TESTS ##############
unittest_py38_torch_release:
Expand Down
11 changes: 8 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,16 @@ for advanced usage).

Opacus also uses [isort](https://github.com/timothycrosley/isort) to sort imports
alphabetically and separate into sections. isort is installed easily via
pip using `pip install isort`, and run locally by calling
pip using `pip install isort --upgrade`, and run locally by calling
```bash
isort -v -l 88 -o opacus --lines-after-imports 2 -m 3 --trailing-comma .
isort -l 88 -o opacus --lines-after-imports 2 -m 3 --trailing-comma .
```
from the repository root. Configuration for isort is located in .isort.cfg.
If using `isort` versions `<5.0.0` call
```bash
isort -l 88 -o opacus --lines-after-imports 2 -m 3 --trailing-comma --recursive
```


We feel strongly that having a consistent code style is extremely important, so
CircleCI will fail on your PR if it does not adhere to the black or flake8 formatting style or isort import ordering.
Expand Down Expand Up @@ -96,7 +101,7 @@ Run following command from `website` folder. It will build the docs and serve th
```

You can also perform spell checks on documentation automatically (besides IDEs) using [```sphinxcontrib-spelling```](https://sphinxcontrib-spelling.readthedocs.io/en/latest/install.html)
Note that you will also need [```PyEnchant```](https://pyenchant.github.io/pyenchant/) to run ```sphinxcontrib-spelling```, and thus the Enchant C library. Use this guide for ```PyEnchant```.
Note that you will also need [```PyEnchant```](https://pyenchant.github.io/pyenchant/) to run ```sphinxcontrib-spelling```, and thus the Enchant C library. Use this guide for ```PyEnchant```.

Steps:
1. Install the extension with pip: ```pip install sphinxcontrib-spelling```
Expand Down
2 changes: 1 addition & 1 deletion dev_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ flake8
sphinx
sphinx-autodoc-typehints
mypy>=0.760
isort
isort>=5.0.0
hypothesis
tensorboard
datasets
Expand Down
2 changes: 2 additions & 0 deletions research/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ We warmly welcome and encourage contributions of new methods! To contribute, ple
1. Fork the repo and create your branch from `main`.
2. Place the new method in a separate subfolder within the `research` directory.
3. The new folder should include a `README.md` that explains the method at a high level, demonstrates usage (e.g., introducing new parameters to the `PrivacyEngine`), and cites relevant sources. The subfolder name should aptly represent the method.
4. Format code using `black`, `flake8`, and `isort` following the instructions under `Code Style` [here](https://github.com/pytorch/opacus/blob/main/CONTRIBUTING.md).
5. Add copyright headers to each `.py` file contributed in the format `# Copyright (c) [copy-right holder]`.

More detailed PR instructions can be found [here](https://github.com/pytorch/opacus/blob/main/CONTRIBUTING.md).

Expand Down

0 comments on commit 3e97447

Please sign in to comment.