Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lint: add pre-commit and ruff configurations #36

Merged
merged 2 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-json
- id: check-merge-conflict
- id: check-symlinks
- id: check-toml
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.4.1
hooks:
- id: ruff
args: ["--fix"]
- id: ruff-format
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Pypi downloads](https://img.shields.io/pypi/dw/nodejs-wheel)](https://pypi.org/project/nodejs-wheel/)
[![Pypi downloads](https://img.shields.io/pypi/dd/nodejs-wheel)](https://pypi.org/project/nodejs-wheel/)

`nodejs-wheel` is an unofficial repository to distribute Node.js prebuilt wheels through PyPI using
`nodejs-wheel` is an unofficial repository to distribute Node.js prebuilt wheels through PyPI using

```sh
pip install nodejs-wheel
Expand Down
2 changes: 1 addition & 1 deletion cmd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Pypi downloads](https://img.shields.io/pypi/dw/nodejs-wheel)](https://pypi.org/project/nodejs-wheel/)
[![Pypi downloads](https://img.shields.io/pypi/dd/nodejs-wheel)](https://pypi.org/project/nodejs-wheel/)

`nodejs-wheel` is an unofficial repository to distribute Node.js prebuilt wheels through PyPI using
`nodejs-wheel` is an unofficial repository to distribute Node.js prebuilt wheels through PyPI using

```sh
pip install nodejs-wheel
Expand Down
21 changes: 14 additions & 7 deletions nodejs_wheel/executable.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import os
import subprocess
import sys
Expand All @@ -8,13 +7,13 @@


def _program(name, args, **kwargs):
bin_dir = ROOT_DIR if os.name == 'nt' else os.path.join(ROOT_DIR, "bin")
return subprocess.call([os.path.join(bin_dir, name)] + args, **kwargs)
bin_dir = ROOT_DIR if os.name == "nt" else os.path.join(ROOT_DIR, "bin")
return subprocess.call([os.path.join(bin_dir, name), *args], **kwargs)


def call_node(*args, **kwargs):
suffix = '.exe' if os.name == 'nt' else ''
return _program('node' + suffix, list(args), **kwargs)
suffix = ".exe" if os.name == "nt" else ""
return _program("node" + suffix, list(args), **kwargs)


def node(args=None, **kwargs):
Expand Down Expand Up @@ -56,7 +55,11 @@ def npm(args=None, **kwargs):
"""
if args is None:
args = sys.argv[1:]
return call_node(os.path.join(ROOT_DIR, "lib", "node_modules", "npm", "bin", "npm-cli.js"), *args, **kwargs)
return call_node(
os.path.join(ROOT_DIR, "lib", "node_modules", "npm", "bin", "npm-cli.js"),
*args,
**kwargs,
)


def npx(args=None, **kwargs):
Expand All @@ -77,7 +80,11 @@ def npx(args=None, **kwargs):
"""
if args is None:
args = sys.argv[1:]
return call_node(os.path.join(ROOT_DIR, "lib", "node_modules", "npm", "bin", "npx-cli.js"), *args, **kwargs)
return call_node(
os.path.join(ROOT_DIR, "lib", "node_modules", "npm", "bin", "npx-cli.js"),
*args,
**kwargs,
)


def _node_entry_point():
Expand Down
35 changes: 35 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,38 @@ skip = ["*-win32", "*-manylinux_i686", "*-musllinux*"]
build-verbosity = 1
before-test = ["pip install --no-deps cmd/"]
test-command = "node -h && npm --version && npx --version && python -m nodejs_wheel --version && python {project}/tests/test_api.py"

[tool.ruff.format]
docstring-code-format = true

[tool.ruff.lint]
select = [
"E", # errors
"F", # pyflakes
"D", # pydocstyle
"UP", # pyupgrade
"C4", # flake8-comprehensions
"RUF", # ruff
"NPY", # numpy
"T20", # ban print
]

ignore = [
"E501", # line too long
"F841", # local variable is assigned to but never used
"E741", # ambiguous variable name
"E402", # module level import not at top of file
"D100", # TODO: missing docstring in public module
"D101", # TODO: missing docstring in public class
"D102", # TODO: missing docstring in public method
"D103", # TODO: missing docstring in public function
"D104", # TODO: missing docstring in public package
"D105", # TODO: missing docstring in magic method
"D205", # 1 blank line required between summary line and description
"D401", # TODO: first line should be in imperative mood
"D404", # TODO: first word of the docstring should not be This
]
ignore-init-module-imports = true

[tool.ruff.lint.pydocstyle]
convention = "numpy"
Loading