Skip to content

Commit 46ff60f

Browse files
committed
Added pre-commit hook & black, isort, flake for lint code and auto-update
1 parent 0f7fc40 commit 46ff60f

File tree

10 files changed

+80
-22
lines changed

10 files changed

+80
-22
lines changed

.flake8

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[flake8]
2+
max-line-length = 88

.github/workflows/tests.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,25 @@ jobs:
3333
run: |
3434
python manage.py test
3535
36+
pre-commit:
37+
runs-on: ubuntu-latest
38+
steps:
39+
- uses: actions/checkout@v4
40+
- name: Set up Python
41+
uses: actions/setup-python@v4
42+
with:
43+
python-version: 3.11
44+
- uses: pre-commit/[email protected]
45+
3646
coverage:
3747
runs-on: ubuntu-latest
3848
steps:
3949
- uses: actions/checkout@v4
4050

41-
- name: Set up Python 3.10
51+
- name: Set up Python 3.11
4252
uses: actions/setup-python@v4
4353
with:
44-
python-version: 3.10
54+
python-version: 3.11
4555

4656
- name: Install dependencies
4757
run: |
@@ -50,7 +60,7 @@ jobs:
5060
5161
- name: Run tests with coverage
5262
run: |
53-
python -m coverage run --source='.' manage.py test
63+
python -m coverage run --source='.' manage.py test
5464
5565
- name: Upload coverage reports to Codecov
5666
uses: codecov/codecov-action@v3

.pre-commit-config.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.5.0
4+
hooks:
5+
- id: check-yaml
6+
- id: end-of-file-fixer
7+
- id: check-toml
8+
- id: trailing-whitespace
9+
10+
- repo: https://github.com/psf/black-pre-commit-mirror
11+
rev: 23.10.1
12+
hooks:
13+
- id: black
14+
language_version: python3.11
15+
16+
- repo: https://github.com/pycqa/isort
17+
rev: 5.12.0
18+
hooks:
19+
- id: isort
20+
name: isort (python)
21+
22+
- repo: https://github.com/pycqa/flake8
23+
rev: 6.1.0
24+
hooks:
25+
- id: flake8

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
21+
SOFTWARE.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ If you choose not use it as a built-in, you will need to add `{% load simple_com
6565
### 3. Hooray! Everything is ready to use it.
6666

6767
## Contributing
68-
If you would like to suggest a new feature, you can create an issue on the GitHub repository for this project.
69-
If you'd like to contribute code, you can fork the repository and submit a pull request with your changes.
68+
If you would like to suggest a new feature, you can create an issue on the GitHub repository for this project.
69+
Also you can fork the repository and submit a pull request with your changes.
7070

7171
## License
7272
This project is licensed under the MIT License. See the LICENSE file for more information.

pyproject.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,17 @@ omit = [
4343
"setup.py",
4444
"tests/*"
4545
]
46+
47+
[tool.black]
48+
line-length = 88
49+
target-version = ["py311"]
50+
include = "\\.pyi?$"
51+
skip-string-normalization=true
52+
53+
[tool.isort]
54+
profile = "django"
55+
combine_as_imports = true
56+
include_trailing_comma = true
57+
line_length = 88
58+
multi_line_output = 3
59+
known_first_party = ["config"]

simple_components/templatetags/simple_components.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import re
2+
23
from django import template
34

4-
from ..exceptions import SetComponentNameError, ComponentNameError, ComponentArgsError, ComponentNotDefined
5+
from ..exceptions import (
6+
ComponentArgsError,
7+
ComponentNameError,
8+
ComponentNotDefined,
9+
SetComponentNameError,
10+
)
511

612
# allow line breaks inside tags
713
template.base.tag_re = re.compile(template.base.tag_re.pattern, re.DOTALL)
@@ -41,10 +47,11 @@ def render(self, context):
4147
@register.tag
4248
def component(parser, token):
4349
bits = token.split_contents()
44-
if len(bits) < 2 or '=' in bits[1]:
45-
example = '{% component \"name\" ' + ' '.join(bits[1:]) + ' %}'
50+
if len(bits) < 2 or "=" in bits[1]:
51+
example = '{% component "name" ' + ' '.join(bits[1:]) + ' %}'
4652
raise ComponentNameError(
47-
'Component takes at least one required argument (name of component):\n%s' % example
53+
'Component takes at least one required argument (name of component):\n%s'
54+
% example
4855
)
4956

5057
component_name = str(parser.compile_filter(bits[1]))
@@ -58,7 +65,9 @@ def component(parser, token):
5865
if name:
5966
kwargs[name] = parser.compile_filter(value)
6067
else:
61-
example = '{% component "' + component_name + '" param1=%s' % bit + ' ... %}'
68+
example = (
69+
'{% component "' + component_name + '" param1=%s' % bit + ' ... %}'
70+
)
6271
raise ComponentArgsError(
6372
'Argument %s must be takes as kwargs:\n%s' % (bit, example)
6473
)
@@ -76,8 +85,8 @@ def render(self, context):
7685
nodelist = context['components'][self.component_name]
7786
except KeyError:
7887
raise ComponentNotDefined(
79-
'The component \'%s\' has not been previously defined. Check that the component is named correctly.'
80-
% self.component_name
88+
'The component \'%s\' has not been previously defined. '
89+
'Check that the component is named correctly.' % self.component_name
8190
)
8291

8392
if self.kwargs is not None:

tests/settings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77

88
ALLOWED_HOSTS = []
99

10+
# fmt: off
1011
INSTALLED_APPS = [
1112
'tests',
1213
'simple_components'
1314
]
15+
# fmt: on
1416

1517
ROOT_URLCONF = 'tests.urls'
1618

@@ -27,9 +29,11 @@
2729
},
2830
]
2931

32+
# fmt: off
3033
DATABASES = {
3134
'default': {
3235
'ENGINE': 'django.db.backends.sqlite3',
3336
'NAME': ':memory:'
3437
}
3538
}
39+
# fmt: on

tests/templates/newlines.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ <h3>{{ title }}</h3>
1616
description="World"
1717

1818
other="..."
19-
%}
19+
%}

tests/tests.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from django.test import TestCase
21
from django.template.loader import render_to_string
2+
from django.test import TestCase
33

44
from simple_components import exceptions
55

@@ -37,13 +37,7 @@ def test_components_with_context(self):
3737
context = {
3838
'list': ['apple', 'banana', 'tomato'],
3939
'string': 'django',
40-
'dict': {
41-
'a': {
42-
'b': {
43-
'c': 123
44-
}
45-
}
46-
}
40+
'dict': {'a': {'b': {'c': 123}}},
4741
}
4842

4943
template = render_to_string('context.html', context)

0 commit comments

Comments
 (0)