Skip to content

Commit 10f2307

Browse files
Merge pull request #50 from PascalEgn/add-ruff-and-pre-commit
add ruff and pre-commit
2 parents 0d357d5 + 9856f4c commit 10f2307

24 files changed

+2125
-1691
lines changed

.github/workflows/bump-and-publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
github_token: ${{ secrets.GITHUB_TOKEN }}
4141
branch: ${{ github.ref }}
4242
tags: true
43-
43+
4444
- name: get sha
4545
id: sha
4646
run: |

.github/workflows/lint.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Lint
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
ref:
7+
description: The reference to build
8+
type: string
9+
required: true
10+
11+
jobs:
12+
linter:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout Code
16+
uses: actions/checkout@v4
17+
with:
18+
ref: ${{ inputs.ref }}
19+
20+
- name: Pre-commit check
21+
uses: pre-commit/action@v3.0.1

.github/workflows/pull-request-master.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ on:
55
branches: [master]
66

77
jobs:
8+
lint:
9+
uses: ./.github/workflows/lint.yml
10+
with:
11+
ref: ${{ github.event.pull_request.head.sha }}
812
python3_tests:
13+
needs: lint
914
uses: ./.github/workflows/test-python.yml
1015

1116
python2_tests:
17+
needs: lint
1218
uses: ./.github/workflows/test-python-py2.yml

.pre-commit-config.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v5.0.0
4+
hooks:
5+
- id: check-yaml
6+
- id: end-of-file-fixer
7+
- id: trailing-whitespace
8+
- id: fix-byte-order-marker
9+
- id: mixed-line-ending
10+
- id: name-tests-test
11+
args: [ --pytest-test-first ]
12+
exclude: '^(?!factories/)'
13+
- repo: https://github.com/astral-sh/ruff-pre-commit
14+
rev: v0.6.9
15+
hooks:
16+
- id: ruff
17+
args: [ --fix ]
18+
- id: ruff-format

.tx/config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
# $ python setup.py extract_messages
3030
# $ python setup.py init_catalog -l <lang>
3131
# $ python setup.py compile_catalog
32-
# 2) Ensure project has been created on Transifex under the
32+
# 2) Ensure project has been created on Transifex under the
3333
# inveniosoftware-contrib organisation.
3434
# 3) Install the transifex-client
3535
# $ pip install transifex-client

docs/_ext/ultramock.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
# as an Intergovernmental Organization or submit itself to any jurisdiction.
2424

2525
"""Hijacks `mock` to fake as many non-available modules as possible."""
26+
2627
import sys
2728
import types
2829

@@ -33,13 +34,17 @@
3334

3435
# skip `_is_magic` check.
3536
orig_is_magic = mock._is_magic
37+
38+
3639
def always_false(*args, **kwargs):
3740
return False
3841

3942

4043
# avoid spec configuration for mocked classes with super classes.
4144
# honestly this does not happen very often and is kind of a tricky case.
4245
orig_mock_add_spec = mock.NonCallableMock._mock_add_spec
46+
47+
4348
def mock_add_spec_fake(self, spec, spec_set):
4449
orig_mock_add_spec(self, None, None)
4550

@@ -66,7 +71,7 @@ class MockedModule(types.ModuleType):
6671
def __init__(self, name):
6772
super(types.ModuleType, self).__init__(name)
6873
self.__name__ = super.__name__
69-
self.__file__ = self.__name__.replace('.', '/') + '.py'
74+
self.__file__ = self.__name__.replace(".", "/") + ".py"
7075
sys.modules[self.__name__] = self
7176

7277
def __getattr__(self, key):
@@ -77,12 +82,16 @@ def __getattr__(self, key):
7782

7883
# overwrite imports
7984
orig_import = __import__
85+
86+
8087
def import_mock(name, *args, **kwargs):
8188
try:
8289
return orig_import(name, *args, **kwargs)
8390
except ImportError:
8491
return MockedModule(name)
85-
import_patch = mock.patch('__builtin__.__import__', side_effect=import_mock)
92+
93+
94+
import_patch = mock.patch("__builtin__.__import__", side_effect=import_mock)
8695

8796

8897
# public methods

0 commit comments

Comments
 (0)