From 8f238751dfcf1315963c2804b0d6205385b6e6b0 Mon Sep 17 00:00:00 2001 From: George Dang <53052793+gtdang@users.noreply.github.com> Date: Mon, 18 Mar 2024 16:18:33 -0400 Subject: [PATCH] feat: Add black, isort, pre-commit hooks. --- .pre-commit-config.yaml | 24 ++++++ pyproject.toml | 4 + setup.cfg | 4 +- setup.py | 178 +++++++++++++++++++++++----------------- 4 files changed, 133 insertions(+), 77 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..ffec68f81 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,24 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - repo: https://github.com/ambv/black + rev: 24.3.0 + hooks: + - id: black + - repo: https://github.com/pycqa/isort + rev: 5.13.2 + hooks: + - id: isort + args: + - "--profile=black" + - "--filter-files" + - "--project=autora" + - repo: https://github.com/pycqa/flake8 + rev: 7.0.0 + hooks: + - id: flake8 +default_language_version: + python: python3 diff --git a/pyproject.toml b/pyproject.toml index 25cd619b7..ca1d23ff6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,9 +1,13 @@ [build-system] requires = ["setuptools>=40.8.0", "NEURON >=7.7; platform_system != 'Windows'"] build-backend = "setuptools.build_meta:__legacy__" + [tool.codespell] skip = '.git,*.pdf,*.svg' check-hidden = true # in jupyter notebooks - images and also some embedded outputs ignore-regex = '^\s*"image/\S+": ".*|.*%22%3A%20.*' ignore-words-list = 'tha,nam,sherif,dout' + +[tool.isort] +profile = "black" diff --git a/setup.cfg b/setup.cfg index f6c32644d..2939e2b28 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,8 @@ [flake8] exclude = __init__.py -ignore = E722, W504 +max-line-length = 80 +extend-select = B950 +extend-ignore = E203,E501,E701 [check-manifest] ignore = diff --git a/setup.py b/setup.py index 65bfe3544..75157d808 100644 --- a/setup.py +++ b/setup.py @@ -1,34 +1,33 @@ #! /usr/bin/env python -import platform -import os.path as op import os -import subprocess +import os.path as op +import platform import shutil - -from setuptools import setup, find_packages - -from distutils.command.build_py import build_py +import subprocess from distutils.cmd import Command +from distutils.command.build_py import build_py + +from setuptools import find_packages, setup descr = """Code for biophysical simulation of a cortical column using Neuron""" -DISTNAME = 'hnn-core' +DISTNAME = "hnn-core" DESCRIPTION = descr -MAINTAINER = 'Mainak Jas' -MAINTAINER_EMAIL = 'mainakjas@gmail.com' -URL = '' -LICENSE = 'BSD (3-clause)' -DOWNLOAD_URL = 'http://github.com/jonescompneurolab/hnn-core' +MAINTAINER = "Mainak Jas" +MAINTAINER_EMAIL = "mainakjas@gmail.com" +URL = "" +LICENSE = "BSD (3-clause)" +DOWNLOAD_URL = "http://github.com/jonescompneurolab/hnn-core" # get the version version = None -with open(os.path.join('hnn_core', '__init__.py'), 'r') as fid: +with open(os.path.join("hnn_core", "__init__.py"), "r") as fid: for line in (line.strip() for line in fid): - if line.startswith('__version__'): - version = line.split('=')[1].strip().strip('\'') + if line.startswith("__version__"): + version = line.split("=")[1].strip().strip("'") break if version is None: - raise RuntimeError('Could not determine version') + raise RuntimeError("Could not determine version") # test install with: @@ -51,15 +50,19 @@ def finalize_options(self): def run(self): print("=> Building mod files ...") - if platform.system() == 'Windows': + if platform.system() == "Windows": shell = True else: shell = False - mod_path = op.join(op.dirname(__file__), 'hnn_core', 'mod') - process = subprocess.Popen(['nrnivmodl'], cwd=mod_path, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, shell=shell) + mod_path = op.join(op.dirname(__file__), "hnn_core", "mod") + process = subprocess.Popen( + ["nrnivmodl"], + cwd=mod_path, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + shell=shell, + ) outs, errs = process.communicate() print(outs) @@ -68,8 +71,8 @@ class build_py_mod(build_py): def run(self): self.run_command("build_mod") - build_dir = op.join(self.build_lib, 'hnn_core', 'mod') - mod_path = op.join(op.dirname(__file__), 'hnn_core', 'mod') + build_dir = op.join(self.build_lib, "hnn_core", "mod") + mod_path = op.join(op.dirname(__file__), "hnn_core", "mod") shutil.copytree(mod_path, build_dir) build_py.run(self) @@ -77,56 +80,79 @@ def run(self): if __name__ == "__main__": extras = { - 'opt': ['scikit-learn'], - 'parallel': ['joblib', 'psutil'], - 'test': ['flake8', 'pytest', 'pytest-cov', ], - 'docs': ['mne', 'nibabel', 'pooch', 'tdqm', - 'sphinx', 'nbsphinx', 'sphinx-gallery', - 'sphinx_bootstrap_theme', 'sphinx-copybutton', - 'pillow', 'numpydoc', - ], - 'gui': ['ipywidgets>=8.0.0', 'ipykernel', 'ipympl', 'voila', ], + "opt": ["scikit-learn"], + "parallel": ["joblib", "psutil"], + "test": [ + "flake8", + "flake8-bugbear", + "black", + "pre-commit", + "isort", + "pytest", + "pytest-cov", + ], + "docs": [ + "mne", + "nibabel", + "pooch", + "tdqm", + "sphinx", + "nbsphinx", + "sphinx-gallery", + "sphinx_bootstrap_theme", + "sphinx-copybutton", + "pillow", + "numpydoc", + ], + "gui": [ + "ipywidgets>=8.0.0", + "ipykernel", + "ipympl", + "voila", + ], } - extras['dev'] = (extras['opt'] + extras['parallel'] + extras['test'] + - extras['docs'] + extras['gui'] - ) - - - setup(name=DISTNAME, - maintainer=MAINTAINER, - maintainer_email=MAINTAINER_EMAIL, - description=DESCRIPTION, - license=LICENSE, - url=URL, - version=version, - download_url=DOWNLOAD_URL, - long_description=open('README.rst').read(), - classifiers=[ - 'Intended Audience :: Science/Research', - 'Intended Audience :: Developers', - 'License :: OSI Approved', - 'Programming Language :: Python', - 'Topic :: Software Development', - 'Topic :: Scientific/Engineering', - 'Operating System :: Microsoft :: Windows', - 'Operating System :: POSIX', - 'Operating System :: Unix', - 'Operating System :: MacOS', - ], - platforms='any', - install_requires=[ - 'numpy >=1.14', - 'NEURON >=7.7; platform_system != "Windows"', - 'matplotlib>=3.5.3', - 'scipy', - 'h5io' - ], - extras_require=extras, - python_requires='>=3.8', - packages=find_packages(), - package_data={'hnn_core': [ - 'param/*.json', - 'gui/*.ipynb']}, - cmdclass={'build_py': build_py_mod, 'build_mod': BuildMod}, - entry_points={'console_scripts': ['hnn-gui=hnn_core.gui.gui:launch']} - ) + extras["dev"] = ( + extras["opt"] + + extras["parallel"] + + extras["test"] + + extras["docs"] + + extras["gui"] + ) + + setup( + name=DISTNAME, + maintainer=MAINTAINER, + maintainer_email=MAINTAINER_EMAIL, + description=DESCRIPTION, + license=LICENSE, + url=URL, + version=version, + download_url=DOWNLOAD_URL, + long_description=open("README.rst").read(), + classifiers=[ + "Intended Audience :: Science/Research", + "Intended Audience :: Developers", + "License :: OSI Approved", + "Programming Language :: Python", + "Topic :: Software Development", + "Topic :: Scientific/Engineering", + "Operating System :: Microsoft :: Windows", + "Operating System :: POSIX", + "Operating System :: Unix", + "Operating System :: MacOS", + ], + platforms="any", + install_requires=[ + "numpy >=1.14", + 'NEURON >=7.7; platform_system != "Windows"', + "matplotlib>=3.5.3", + "scipy", + "h5io", + ], + extras_require=extras, + python_requires=">=3.8", + packages=find_packages(), + package_data={"hnn_core": ["param/*.json", "gui/*.ipynb"]}, + cmdclass={"build_py": build_py_mod, "build_mod": BuildMod}, + entry_points={"console_scripts": ["hnn-gui=hnn_core.gui.gui:launch"]}, + )