Skip to content

Commit

Permalink
Add a GitHub Action to run codespell and ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
cclauss committed Dec 26, 2023
1 parent a9c012b commit eabde36
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 13 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/codespell_and_ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This Action uses minimal steps to run in ~5 seconds to rapidly:
# look for typos in the codebase using codespell, and
# lint Python code using ruff and provide intuitive GitHub Annotations to contributors.
# https://github.com/codespell-project/codespell#readme
# https://docs.astral.sh/ruff/
name: codespell_and_ruff
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
codespell_and_ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: pip install --user codespell[toml] ruff
- run: codespell
- run: ruff --output-format=github
2 changes: 1 addition & 1 deletion README-gdb.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Enable `python-gdb.py`
----------------------

`python-gdb.py` is a GDB script to make it easier to inspect the state of a
Python process from whitin GDB. It is documented
Python process from within GDB. It is documented
[in the CPython's dev guide](https://devguide.python.org/gdb/).

The script add a series of GBD commands such as:
Expand Down
8 changes: 4 additions & 4 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Changelog
Version 0.9 (April 25th, 2023)
------------------------------

This release adds numerous major features and indicates the end of HPy's *alhpa*
This release adds numerous major features and indicates the end of HPy's *alpha*
phase. We've migrated several key packages to HPy (for a list, see our website
https://hpyproject.org) and we are now confident that HPy is mature enough for
being used as serious extension API. We also plan that the next major release
Expand Down Expand Up @@ -56,7 +56,7 @@ HPy :ref:`porting-guide:calling protocol`
convention. This is: the arguments are passed in a C array and the keyword
argument names are provided as a Python tuple. Before this release, the only
way to create a callable type was to set the special method ``__call__``.
However, this has several disadvantages. In particlar, poor performance on
However, this has several disadvantages. In particular, poor performance on
CPython (and maybe other implementations) and it was not possible to have
specialized call function implementations per object (see
:c:func:`HPy_SetCallFunction`)
Expand Down Expand Up @@ -117,7 +117,7 @@ Documentation
* Added :doc:`quickstart` guide
* Extended :doc:`api-reference/index`
* Added :doc:`api-reference/function-index`
* Added possiblity to generate examples from tests with argument ``--dump-dir``
* Added possibility to generate examples from tests with argument ``--dump-dir``
(see :ref:`api:hpy unit tests`)
* Added initial :doc:`contributing/index` docs

Expand Down Expand Up @@ -206,7 +206,7 @@ Debug mode:
Misc Changes:

- Removed unnecessary prefix ``"m_"`` from fields of ``HPyModuleDef`` (incompatible change)
- For HPy implementors: new pytest mark for HPy tests assuming synchronous GC
- For HPy implementers: new pytest mark for HPy tests assuming synchronous GC

Version 0.0.3 (September 22nd, 2021)
------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ Benefits for the Python ecosystem
The HPy project offers some benefits to the python ecosystem, both to Python
users and to library developers.

- C extensions can achieve much better speed on alternative implementions,
- C extensions can achieve much better speed on alternative implementations,
including PyPy and GraalPy: according to early :ref:`benchmarks`, an
extension written in HPy can be ~3x faster than the equivalent extension
written using ``Python.h``.
Expand Down
2 changes: 1 addition & 1 deletion hpy/devel/include/hpy.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ extern "C" {
*
* * In Universal-ABI mode, they always resolve to an indirect call
* through ``HPyContext *``, i.e. ``ctx->ctx_Add(...)``, which on CPython
* dispaches to ``ctx_Add``.
* dispatches to ``ctx_Add``.
*/
#define HPyAPI_FUNC _HPy_UNUSED static inline

Expand Down
24 changes: 24 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
[build-system]
requires = [ "setuptools>=64.0", "setuptools-scm[toml]>=6.0", "wheel>=0.34.2",]
build-backend = "setuptools.build_meta"

[tool.codespell]
ignore-words-list = "acount,crate,fo,ois,ot,seh"

[tool.ruff]
extend-ignore = ["E702", "F401", "F541"]

[tool.ruff.per-file-ignores]
"docs/examples/debug-example.py" = ["E402"]
"docs/examples/tests.py" = ["E402", "F811", "F841"]
"test/check_py27_compat.py" = ["E722"]
"test/debug/test_charptr.py" = ["E703"]
"test/support.py" = ["E401"]
"test/test_call.py" = ["E703"]
"test/test_capsule.py" = ["E711"]
"test/test_capsule_legacy.py" = ["F811"]
"test/test_hpyerr.py" = ["F841"]
"test/test_hpyfield.py" = ["F811"]
"test/test_hpylong.py" = ["E701", "E712", "F841"]
"test/test_hpytype.py" = ["E701", "F841"]
"test/test_hpytype_legacy.py" = ["F841"]
"test/test_hpyunicode.py" = ["E721", "E722"]
"test/test_slots.py" = ["F841"]
"test/test_support.py" = ["F811"]
2 changes: 1 addition & 1 deletion test/debug/test_charptr.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def test_charptr_correct_usage(compiler):
@EXPORT(f)
@INIT
""")
assert mod.f('I wont be leaked!') == 'I wont be leaked!';
assert mod.f('I will not be leaked!') == 'I will not be leaked!';


def test_charptr_limit_stress_test(compiler):
Expand Down
10 changes: 5 additions & 5 deletions test/debug/test_context_reuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_reuse_context_from_global_variable(compiler, python_subprocess):
return HPy_Dup(ctx, ctx->h_None);
}
HPy_Close(ctx, t);
fprintf(stdout, "Heavy Marmelade\\n");
fprintf(stdout, "Heavy Marmalade\\n");
fflush(stdout);
// Here we wrongly use "keep" instead of "ctx"
return HPy_Dup(keep, ctx->h_None);
Expand Down Expand Up @@ -65,13 +65,13 @@ def test_reuse_context_from_global_variable(compiler, python_subprocess):
result = python_subprocess.run(mod, code)
assert result.returncode != 0
assert b"Error: Wrong HPy Context!" in result.stderr
assert result.stdout == b"Heavy Marmelade\n"
assert result.stdout == b"Heavy Marmalade\n"

code = "mod.f(); mod.bounce(lambda: mod.g())"
result = python_subprocess.run(mod, code)
assert result.returncode != 0
assert b"Error: Wrong HPy Context!" in result.stderr
assert result.stdout == b"Bouncing...\nHeavy Marmelade\n"
assert result.stdout == b"Bouncing...\nHeavy Marmalade\n"

# checks the situation when the context cache runs out,
# and we start reusing cached contexts
Expand All @@ -91,12 +91,12 @@ def test_reuse_context_from_global_variable(compiler, python_subprocess):
HPY_DEBUG_CTX_CACHE_SIZE = 16
for size in range(HPY_DEBUG_CTX_CACHE_SIZE-1, HPY_DEBUG_CTX_CACHE_SIZE+2):
result = python_subprocess.run(mod, code.format(size))
assert result.stdout == (b"Bouncing...\n" * size) + b"Heavy Marmelade\n"
assert result.stdout == (b"Bouncing...\n" * size) + b"Heavy Marmalade\n"
if result.returncode != 0:
assert b"Error: Wrong HPy Context!" in result.stderr

code = 'mod.keep_and_bounce(lambda: mod.g())'
result = python_subprocess.run(mod, code)
assert result.returncode != 0
assert b"Error: Wrong HPy Context!" in result.stderr
assert result.stdout == b"Bouncing differently...\n" + b"Heavy Marmelade\n"
assert result.stdout == b"Bouncing differently...\n" + b"Heavy Marmalade\n"

0 comments on commit eabde36

Please sign in to comment.