From 57e83755d8beb1dbbb880a4d3b4657770812d36d Mon Sep 17 00:00:00 2001 From: Talley Lambert Date: Fri, 17 Sep 2021 16:24:20 -0400 Subject: [PATCH] Add .pre-commit-config.yaml (#308) * commit config * remove pass * working * use pre-commit for ci and tox * add note to contributing --- .github/workflows/test-and-lint.yml | 6 +++--- .pre-commit-config.yaml | 26 ++++++++++++++++++++++++++ aicsimageio/exceptions.py | 6 ------ aicsimageio/readers/reader.py | 4 ---- aicsimageio/writers/writer.py | 1 - docs/CONTRIBUTING.md | 11 +++++++++-- setup.cfg | 7 ++++--- setup.py | 10 +++++----- tox.ini | 10 +++------- 9 files changed, 50 insertions(+), 31 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/test-and-lint.yml b/.github/workflows/test-and-lint.yml index 90323f4ef..aeea6befc 100644 --- a/.github/workflows/test-and-lint.yml +++ b/.github/workflows/test-and-lint.yml @@ -50,9 +50,9 @@ jobs: - name: Install Dependencies run: | python -m pip install --upgrade pip - pip install .[test] + pip install pre-commit - name: Lint - run: tox -e lint + run: pre-commit run --all-files --show-diff-on-failure docs: runs-on: ubuntu-latest @@ -72,4 +72,4 @@ jobs: - name: Generate Docs run: | gitchangelog - make gen-docs \ No newline at end of file + make gen-docs diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..1a58eb748 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,26 @@ +exclude: aicsimageio/metadata/czi-to-ome-xslt/ +files: aicsimageio +repos: + - repo: https://github.com/PyCQA/flake8 + rev: 3.9.2 + hooks: + - id: flake8 + additional_dependencies: [flake8-typing-imports, flake8-debugger] + args: [--count, --show-source, --statistics, --min-python-version=3.7.0] + - repo: https://github.com/myint/autoflake + rev: v1.4 + hooks: + - id: autoflake + args: ["--in-place", "--remove-all-unused-imports"] + - repo: https://github.com/PyCQA/isort + rev: 5.9.3 + hooks: + - id: isort + - repo: https://github.com/psf/black + rev: 21.9b0 + hooks: + - id: black + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v0.910 + hooks: + - id: mypy diff --git a/aicsimageio/exceptions.py b/aicsimageio/exceptions.py index 0b8bd160d..36e06679a 100644 --- a/aicsimageio/exceptions.py +++ b/aicsimageio/exceptions.py @@ -9,8 +9,6 @@ class ConflictingArgumentsError(Exception): This exception is returned when 2 arguments to the same function are in conflict. """ - pass - class InvalidDimensionOrderingError(Exception): """ @@ -18,8 +16,6 @@ class InvalidDimensionOrderingError(Exception): validation. Should be provided with a message for the user to be given more context. """ - pass - class UnexpectedShapeError(Exception): """ @@ -27,8 +23,6 @@ class UnexpectedShapeError(Exception): Should be provided with a message for the user to be given more context. """ - pass - class UnsupportedFileFormatError(Exception): """ diff --git a/aicsimageio/readers/reader.py b/aicsimageio/readers/reader.py index 1b5937e3c..c238cc60c 100644 --- a/aicsimageio/readers/reader.py +++ b/aicsimageio/readers/reader.py @@ -68,7 +68,6 @@ def _is_supported_image(fs: AbstractFileSystem, path: str, **kwargs: Any) -> boo supported: bool Boolean value indicating if the file is supported by the reader. """ - pass @classmethod def is_supported_image(cls, image: types.ImageLike, **kwargs: Any) -> bool: @@ -153,7 +152,6 @@ def scenes(self) -> Tuple[str, ...]: >>> for i in range(len(image.scenes)) """ - pass @property def current_scene(self) -> str: @@ -264,7 +262,6 @@ def _read_delayed(self) -> xr.DataArray: * If a channel dimension is present, please populate the channel dimensions coordinate array the respective channel coordinate values. """ - pass @abstractmethod def _read_immediate(self) -> xr.DataArray: @@ -283,7 +280,6 @@ def _read_immediate(self) -> xr.DataArray: * If a channel dimension is present, please populate the channel dimensions coordinate array the respective channel coordinate values. """ - pass def _get_stitched_dask_mosaic(self) -> xr.DataArray: """ diff --git a/aicsimageio/writers/writer.py b/aicsimageio/writers/writer.py index 46a9e6d03..aa93e3826 100644 --- a/aicsimageio/writers/writer.py +++ b/aicsimageio/writers/writer.py @@ -45,4 +45,3 @@ def save( """ # There are no requirements for n-dimensions of data. # The data provided can be 2D - ND. - pass diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index d3f0177aa..eba20f323 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -49,13 +49,20 @@ Ready to contribute? Here's how to set up `aicsimageio` for local development. make build-with-remote -8. Commit your changes and push your branch to GitHub: +8. (Optional) If you'd like to have linting checks run automatically prior to + every `git commit`, then you can install a commit-hook that runs + [pre-commit](https://pre-commit.com/), as follows: + + pip install pre-commit + pre-commit install + +9. Commit your changes and push your branch to GitHub: git add . git commit -m "Resolves gh-###. Your detailed description of your changes." git push origin {your_development_type}/short-description -9. Submit a pull request through the GitHub website. +10. Submit a pull request through the GitHub website. ## Adding a New Custom Reader diff --git a/setup.cfg b/setup.cfg index 0b9f41e2b..8c098c1bc 100644 --- a/setup.cfg +++ b/setup.cfg @@ -26,15 +26,15 @@ test = pytest [tool:pytest] collect_ignore = ['setup.py'] xfail_strict = true -filterwarnings = +filterwarnings = ignore::UserWarning ignore::FutureWarning [flake8] -exclude = +exclude = docs/ aicsimageio/vendor/ -ignore = +ignore = E203 E402 W291 @@ -42,6 +42,7 @@ ignore = max-line-length = 88 [isort] +profile = black multi_line_output = 3 include_trailing_comma = True force_grid_wrap = 0 diff --git a/setup.py b/setup.py index dc0bba5b9..bbec0bf7f 100644 --- a/setup.py +++ b/setup.py @@ -40,14 +40,9 @@ def run(self): test_requirements = [ *all_formats, - "black>=19.10b0", "codecov>=2.1.4", "distributed>=2021.4.1", "docutils>=0.10,<0.16", - "flake8>=3.8.3", - "flake8-debugger>=3.2.1", - "isort>=5.7.0", - "mypy>=0.800", "psutil>=5.7.0", "pytest>=5.4.3", "pytest-cov>=2.9.0", @@ -61,11 +56,16 @@ def run(self): *setup_requirements, *test_requirements, "asv>=0.4.2", + "black>=19.10b0", "bump2version>=1.0.1", "coverage>=5.1", + "flake8>=3.8.3", + "flake8-debugger>=3.2.1", "gitchangelog>=3.0.4", "ipython>=7.15.0", + "isort>=5.7.0", "m2r2>=0.2.7", + "mypy>=0.800", "pytest-runner>=5.2", "Sphinx>=3.4.3", "sphinx_rtd_theme>=0.5.1", diff --git a/tox.ini b/tox.ini index 44444f42e..66cd87a4b 100644 --- a/tox.ini +++ b/tox.ini @@ -2,13 +2,9 @@ envlist = py37, py38, py39, lint [testenv:lint] -deps = - .[test] -commands = - flake8 aicsimageio --count --verbose --show-source --statistics --exclude aicsimageio/metadata/czi-to-ome-xslt/ - isort aicsimageio --check-only --skip aicsimageio/metadata/czi-to-ome-xslt/ - mypy aicsimageio --exclude aicsimageio/metadata/czi-to-ome-xslt/ - black --check aicsimageio --exclude aicsimageio/metadata/czi-to-ome-xslt/ +skip_install = true +deps = pre-commit +commands = pre-commit run --all-files --show-diff-on-failure [testenv] passenv =