diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..769ad93 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,33 @@ +name: lint + +on: [push, pull_request] + +jobs: + format: + runs-on: ${{ matrix.os }}-latest + strategy: + matrix: + os: [ubuntu] + python-version: ["3.10"] + + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - uses: actions/cache@v3 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }} + restore-keys: | + ${{ runner.os }}-pip- + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install .[lint] + + - name: Lint + run: pre-commit run --all-files --show-diff-on-failure --color always diff --git a/.gitignore b/.gitignore index 96b11ff..f50ae6f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ *~ \#* dev.py.egg-info -__pycache__ \ No newline at end of file +__pycache__ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..9ea3652 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,37 @@ +# Install pre-commit hooks via +# pre-commit install + +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.3.0 + hooks: + - id: check-added-large-files + - id: check-ast + - id: check-builtin-literals + - id: check-case-conflict + - id: check-json + - id: check-toml + - id: check-yaml + args: [--allow-multiple-documents] + - id: debug-statements + - id: end-of-file-fixer + - id: mixed-line-ending + - id: trailing-whitespace + + - repo: https://github.com/psf/black + rev: 22.10.0 + hooks: + - id: black + + - repo: https://github.com/pre-commit/mirrors-prettier + rev: v2.7.1 + hooks: + - id: prettier + files: \.(css|md|yml|yaml) + args: [--prose-wrap=preserve] + + - repo: https://github.com/asottile/pyupgrade + rev: v3.1.0 + hooks: + - id: pyupgrade + args: [--py37-plus] diff --git a/dev.py b/dev.py index 957ea7e..6c8f81f 100755 --- a/dev.py +++ b/dev.py @@ -7,12 +7,13 @@ import os import sys import runpy + sys.path.remove(os.path.abspath(os.path.dirname(sys.argv[0]))) try: - runpy.run_module('dev.py', run_name="__main__") + runpy.run_module("dev.py", run_name="__main__") except ImportError: - print('Cannot import dev.py; please install it using') + print("Cannot import dev.py; please install it using") print() - print(' pip install dev.py') + print(" pip install dev.py") print() sys.exit(1) diff --git a/dev/cmds/_build.py b/dev/cmds/_build.py index 113e80e..84d0a2f 100644 --- a/dev/cmds/_build.py +++ b/dev/cmds/_build.py @@ -7,14 +7,16 @@ @click.command() -@click.option('--build-dir', default='build', help='Build directory; default is `$PWD/build`') -@click.option('-j', '--jobs', help='Nr of parallel tasks to launch', type=int) +@click.option( + "--build-dir", default="build", help="Build directory; default is `$PWD/build`" +) +@click.option("-j", "--jobs", help="Nr of parallel tasks to launch", type=int) def build(build_dir, jobs=None): """🔧 Build package with Meson/ninja""" build_dir = os.path.abspath(build_dir) - build_cmd = ['meson', f'--prefix={build_dir}', 'build'] + build_cmd = ["meson", f"--prefix={build_dir}", "build"] if os.path.exists(build_dir): - build_cmd += ['--reconfigure'] + build_cmd += ["--reconfigure"] run(build_cmd) - run(['ninja', '-C', build_dir]) - run(['meson', f'--prefix={build_dir}', 'install']) + run(["ninja", "-C", build_dir]) + run(["meson", f"--prefix={build_dir}", "install"]) diff --git a/dev/cmds/_test.py b/dev/cmds/_test.py index 60c28fb..273fc2a 100644 --- a/dev/cmds/_test.py +++ b/dev/cmds/_test.py @@ -4,13 +4,12 @@ @click.command() -@click.argument('pytest_args', nargs=-1) +@click.argument("pytest_args", nargs=-1) def test(pytest_args): """🔧 Run tests PYTEST_ARGS are passed through directly to pytest. """ if not pytest_args: - pytest_args = ('TODO__PROJECT_NAME_FROM_CONFIG',) - run(['pytest'] + list(pytest_args)) - + pytest_args = ("TODO__PROJECT_NAME_FROM_CONFIG",) + run(["pytest"] + list(pytest_args)) diff --git a/dev/py.py b/dev/py.py index bc45b0a..2ed81a4 100644 --- a/dev/py.py +++ b/dev/py.py @@ -10,35 +10,35 @@ if __name__ == "__main__": - if not os.path.exists('pyproject.toml'): - print('Error: cannot find [pyproject.toml]') + if not os.path.exists("pyproject.toml"): + print("Error: cannot find [pyproject.toml]") sys.exit(1) - with open('pyproject.toml', 'r') as f: + with open("pyproject.toml") as f: try: toml_config = toml.load(f) except: - print('Cannot parse [pyproject.toml]') + print("Cannot parse [pyproject.toml]") sys.exit(1) try: - project_config = toml_config['project'] - config = toml_config['tool']['dev']['py'] + project_config = toml_config["project"] + config = toml_config["tool"]["dev"]["py"] except KeyError: - print('No configuration found in [pyproject.toml] for [tool.dev.py]') + print("No configuration found in [pyproject.toml] for [tool.dev.py]") sys.exit(1) commands = { - f'dev.py.{name}': getattr(cmds, name) + f"dev.py.{name}": getattr(cmds, name) for name in dir(cmds) - if not name.startswith('_') + if not name.startswith("_") } @click.group(help=f"Developer tool for {project_config['name']}") def group(): pass - for cmd in config['commands']: + for cmd in config["commands"]: group.add_command(commands[cmd]) group() diff --git a/pyproject.toml b/pyproject.toml index 31e0ba8..fe1e96f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ version = "0.1a1.dev0" description = "Developer tool for scientific Python libraries" license = {file = "LICENSE"} maintainers = [ - {name = "Scientific Python", email = "dev.py@scientific-python.org"} + {name = "Scientific Python", email = "dev.py@discuss.scientific-python.org"} ] classifiers = [ "Development Status :: 4 - Beta", @@ -15,6 +15,9 @@ dependencies = [ "toml" ] +[project.optional-dependencies] +lint = ["pre-commit >= 2.20"] + [project.urls] homepage = "https://github.com/scientific-python/dev.py"