From 6de1c39c31dba1ffc0b20a2a71c3243c96ff8b01 Mon Sep 17 00:00:00 2001 From: Iden Kalemaj Date: Mon, 20 Jan 2025 10:31:57 -0800 Subject: [PATCH] Edits to isort and contribution instructions (#714) Summary: 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. Differential Revision: D68078254 --- .github/workflows/ci_cpu.yml | 2 +- CONTRIBUTING.md | 11 ++++++++--- dev_requirements.txt | 2 +- research/README.md | 2 ++ 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci_cpu.yml b/.github/workflows/ci_cpu.yml index 428d9741..4196cd23 100644 --- a/.github/workflows/ci_cpu.yml +++ b/.github/workflows/ci_cpu.yml @@ -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: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e5a35b8e..22b44ba9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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. @@ -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``` diff --git a/dev_requirements.txt b/dev_requirements.txt index fe57472f..0ba47b6e 100644 --- a/dev_requirements.txt +++ b/dev_requirements.txt @@ -8,7 +8,7 @@ flake8 sphinx sphinx-autodoc-typehints mypy>=0.760 -isort +isort>=5.0.0 hypothesis tensorboard datasets diff --git a/research/README.md b/research/README.md index 952b0d40..806c7f83 100644 --- a/research/README.md +++ b/research/README.md @@ -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).