Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Major Refactor: Add Ruff Linting, Nox, and Pre-Commit Hook (#266)
* added ruff and nox. * config nox for the py3.12 * add `nox`, `ruff` and a section on managing multiple python versions * adds src to ruff config * updates ruff version (to work with src config) * added ruff and pre-commit configurations * basic precommit confi * ruff linter added to ci * formatter added * default check added to ci * assigned separate github actions to ruff code formatter and linters * test * test * ruff badge added to readme * noxfile added for automated testing across environments after commits * ruff linters, both ignore and select, specified * ruff check runs * toml formatting * added addtional pre-commit hooks * pre-commit edits * default for max line length is 88 * error in deploy file: pypi environment not defined * link changed to previous one in ci.yml * ruff linting and formatting combined in 1 action in CI and added to needs field in check * ci -- calling ruff directly instead of via action * test * . * null changes in notebook reverted * in ci, specifying to use ruff config from pyproject.toml * updating some deprecated imports, isinstance for union of types, unsorted imports, f-strings, replaced single quote with double quotes and deleted trailing whitespace * notebooks 00-quickstart and 02-eigendistortions line-length correction * Revert "notebooks 00-quickstart and 02-eigendistortions line-length correction" This reverts commit 4bb4333. * Revert "updating some deprecated imports, isinstance for union of types, unsorted imports, f-strings, replaced single quote with double quotes and deleted trailing whitespace" This reverts commit c1fd8bc. * additional line length and double quote fixes in 02-eigendistortions.ipynb * all notebooks in experiments refactored to meet pydocstyle and pyflakes criteria * all files in metric refactored to meet pydocstyle and pyflakes criteria * all files in simulate and models refactored to meet pydocstyle and pyflakes criteria * all files in src refactored to meet pydocstyle and pyflakes criteria * running pyupgrade linter to upgrade syntac for newer versions * running flake8 simplify on entire codebase * removing # noqa: UP035 tag * test coverage session added to noxfile * pytest ini_options adjustments to accomodate module not implemented error when runnin nox sesssion tests * updating test session in nox file to install all dependencies as listes in toml file and fixing none-type error in eigendistortions.py * pytest can now be run with nox including test coverage * resolving some too long lines * too long lines in validate.py corrected * formatting with line-length set to 88 * too long lines shortened to 88 characters in data and metric * . * some more fixes * removed .keys() from dictionary iteration, replaced if-else with 1-liners, used f-strings, shortened if statements with boolean expressions, added contextlib for with statements, and refactored lambda expressions into methods. * ignored SIM105 or do we want to use contextlib package instead of try-except-pass blocks? * ambigious variable name in external refactored * tests test_metric and test_models fail * replacing if-else block with ternary conditional operator * removing too long lines * replacing if-else block by returning boolean expression directly * returning boolean expression as opposed to if-if-else block * replacing nested if-else blocks with elif for readability * too long lines fixed * in optimizer_step in metamer.py condensed if statements and added check for index out of bound * simplified decision tree conditions in check_convergence * metamers.py refactoring finnished and all tests in test_metamers.py pass * checking if module is available without importing it unnecessarily * ignoring import not being at top of file for fetch.py * updating union syntax to python 3.10 bar version, unrelated 420 sha-errors and 2 failed tests asserting x < some threshold * ignoring unused imports linting error F401 in tools init file * ignoring unused imports linting error F401 in metric init file * ignoring wildcard imports linting error F403 in canonical computations init file * ignoring wildcard imports linting error F403 and unused imports F401 in tools init file * added predicate ignore-init-module-imports to tool.ruff.lint in pyproject.toml and set it to true * removed predicate ignore-init-module-imports since deprecated * ignoring unused imports F401 and wildcard imports F403 * ignoring unused imports F401 in synthesize init file * ignoring wildcard imports F401 in simlute init file * resolving linting error E402 imports not at top of cell * replacing union with pipe operator which resolves UP007 in steerable_pyramid_freq.py * cutting line lenght * making if-blocks more readable and cutting long lines in mad_comptetition.py * placing imports to top of cell and shortening too long lines * fixing too long lines and placing imports at top of cell in notebookds 08 and 06. * reordering imports and fixing too long lines in notebook geodesics * . * shortening lines in eigendistortions.py * too long lines fixed in notebook metamer-portilla-simoncelli * too long lines fixed in notebook metamer-portilla-simoncelli * too long lines fixed in notebooks * too long lines fixed in notebooks * too long lines fixed in notebooks * too long lines fixed in notebooks * too long lines fixed in notebooks * replacing misleading characters l * replacing ambigious l with layer * shortening lines * replacing ambigious variable names * . * fixing too long lines * ignoring too long lines in notebook 05 does not work for curl statement * added isort linter and fixed 44 isort errors * reformatting * tests run again and circular import error resolved * adding missing import data to init file * fixing linting error * ruff version updated to 0.6.8, same as on cluster * adding missing import conv to init in tools * formatting fix * editing string to mitigate notebook error for versions 3.10 and 3.11 * updated 3 cns links from http to https * imports sorted in init * isort ignored in init file, otherwise errors due to circulr inputs * unused imports uncommented * when unused imports are removed, tests fail, so included them again * reformatting tests and updating contributing file * contributing file update completed * deleting pypi environment in deploy.yml which slipped in from a merge but doesn't belong into this PR * Update CONTRIBUTING.md Co-authored-by: William F. Broderick <billbrod@gmail.com> * Update CONTRIBUTING.md Co-authored-by: William F. Broderick <billbrod@gmail.com> * Update CONTRIBUTING.md Co-authored-by: William F. Broderick <billbrod@gmail.com> * Update CONTRIBUTING.md Co-authored-by: William F. Broderick <billbrod@gmail.com> * Update CONTRIBUTING.md Co-authored-by: William F. Broderick <billbrod@gmail.com> * Update CONTRIBUTING.md Co-authored-by: William F. Broderick <billbrod@gmail.com> * Update CONTRIBUTING.md Co-authored-by: William F. Broderick <billbrod@gmail.com> * Update CONTRIBUTING.md Co-authored-by: William F. Broderick <billbrod@gmail.com> * Update CONTRIBUTING.md Co-authored-by: William F. Broderick <billbrod@gmail.com> * replacing os.path.join with pathlib and / operator to concatenate paths * removing ignore in nox lint session * nox removed from mandatory installments * moved import pathlib to top of fetch.py file * adding two singleton dimensinos using the unsqueeze function twice, replacing the None, None expression, for better readability * added examples to tool.ruff in pyproject.toml * removed pydocstyle inting from pyproject.toml as we are currently not using this linter * Update CONTRIBUTING.md Co-authored-by: William F. Broderick <billbrod@gmail.com> * Update CONTRIBUTING.md Co-authored-by: William F. Broderick <billbrod@gmail.com> * pyproject.toml parse error for ruff linter, to be fixed * ruff actions on ci should work now, removed numpy convention, to be added in separeate PR where the pydocstyle linter will be added * fixed SIM105 errors, i.e., replaced try-except blocks using contextlib and specifc error that will be raised * reverting flowcharts to original version with too long lines and ignored too long lines * removed file extension to be excluded by ruff as they should be ignored through gitignore * replace assert with if/raise looks cleaner * mention pre-commit.ci in contributing * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * linting tests and import order * added explicit isort skips to imports which need to be in a specific order * fixing failing tests by making it catch Value error as opposed to assertion error * fixing too long lines in tests * lambda functions assigned to variables are replaced by acutal function definitions in test validate metrics. Resolved E731 linting error * removing unused variables in test_models.py in TestNaive class resolving F841 * removing .keys() when iterating over dictionary keys resolving SIM118 * replacing if-else blocks with ternary operator resolving SIM108 * resolving SIM105 by using contextlib instead of try except block * replacing percentage sign in print statements with format * replacing lambda assigned to variable with function * replacing for loop keeping track of each index with enumerate resolving SIM113 * resoving 2 failed tests by calling model on image in test_models * removing unused variabl assignments in test_models * simplifying counter variable in enumeration loop * updating contributing file: introducing examples for ruff noqa and adding action comments for ruff to disable linting rules * move cones/primaries to json file * run ruff on conceptual intro * remove unnecessary isort:skip * puts """ on newline * be consistent with contextlib.suppress * more changes for suppress * switch nox test install to use ".[dev]" * Apply suggestions from code review --------- Co-authored-by: BalzaniEdoardo <edoardo.balzani87@gmail.com> Co-authored-by: William F. Broderick <billbrod@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information