Skip to content

Commit

Permalink
🔧 chore: Add-pre-commit-config
Browse files Browse the repository at this point in the history
- Handel-Isort for sorting imports
- Handel-black for formatting code
  • Loading branch information
ARYAN-NIKNEZHAD committed Aug 18, 2024
1 parent 717c88e commit 4119634
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ jobs:
- name: Upload coverage to Codecov
run: codecov
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,4 @@ uwsgi.ini
nginx.conf
test_app/
myenv/
myenv3_8/
myenv3_8/
29 changes: 29 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: trailing-whitespace
exclude: (migrations/|tests/|docs/|static/|media/).*
- id: end-of-file-fixer
exclude: (migrations/|tests/|docs/|static/|media/).*
- id: check-added-large-files
exclude: (migrations/|tests/|docs/|static/|media/).*
- id: check-case-conflict
exclude: (migrations/|tests/|docs/|static/|media/).*
- id: check-merge-conflict
exclude: (migrations/|tests/|docs/|static/|media/).*
- id: check-docstring-first
exclude: (migrations/|tests/|docs/|static/|media/).*


- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.10.1
hooks:
- id: isort
exclude: (migrations/|tests/|docs/|static/|media/).*

- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
exclude: (migrations/|tests/|docs/|static/|media/).*
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Changelog

All notable changes to this project will be documented in this file.
All notable changes to this project will be documented in this file.
2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,4 @@ perf(parser): enhance parsing speed
- Added benchmarks to track performance improvements
```
These examples cover various types of commits such as feature additions, bug fixes, documentation updates, dependency updates, versioning, testing, refactoring, and performance improvements.
These examples cover various types of commits such as feature additions, bug fixes, documentation updates, dependency updates, versioning, testing, refactoring, and performance improvements.
14 changes: 7 additions & 7 deletions Django_Iranian_Cities_Pytest_Guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ User = get_user_model()

class TestMyModelAdmin:
"""Class for testing MyModelAdmin functionality."""

def test_some_functionality(self) -> None:
# Test logic goes here
pass
Expand All @@ -53,7 +53,7 @@ class TestMyModelAdmin:
## Class and Function Naming Conventions

- **Class Names:** Use the `Test` prefix followed by the name of the class or module being tested. For example, if you're testing the `MyModelAdmin` class, name your test class `TestMyModelAdmin`.

- **Function Names:** Start function names with `test_` followed by a description of the functionality being tested. For example, `test_formfield_for_foreignkey_sets_queryset`.

## Markers
Expand Down Expand Up @@ -139,7 +139,7 @@ User = get_user_model()

class TestMyModelAdmin:
"""Class for testing MyModelAdmin functionality."""

def test_formfield_for_foreignkey_sets_queryset(self) -> None:
"""
Test that the formfield for the ForeignKey correctly sets the queryset.
Expand All @@ -149,10 +149,10 @@ class TestMyModelAdmin:
admin_site = AdminSite()
request = HttpRequest()
request.user = User.objects.create_superuser('admin', '[email protected]', 'password')

model_admin = MyModelAdmin(model=MyModel, admin_site=admin_site)
db_field = MyModel._meta.get_field('related_model')

with patch.object(MyModelAdmin, 'get_field_queryset', return_value=MyModel.objects.filter(name="Test")) as mock_get_field_queryset:
formfield = model_admin.formfield_for_foreignkey(db_field, request)
mock_get_field_queryset.assert_called_once_with(None, db_field, request)
Expand All @@ -176,7 +176,7 @@ pytestmark = [

class TestMyAppConfig:
"""Test MyApp configuration and settings."""

def test_check_my_app_config_correct_settings(self, settings) -> None:
"""
Test the MyApp configuration checker with correct settings.
Expand All @@ -186,7 +186,7 @@ class TestMyAppConfig:
settings.MY_SETTING_ENABLED = True
errors = check_my_app_config({})
assert len(errors) == 0

def test_check_my_app_config_invalid_type(self, settings) -> None:
"""
Test the MyApp configuration checker with invalid type settings.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -670,4 +670,4 @@ into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.
<https://www.gnu.org/licenses/why-not-lgpl.html>.
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
include iranian_cities/data/*.csv
include README.md
include README.md
1 change: 0 additions & 1 deletion iranian_cities/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def check_iranian_cities_config(
errors: List[Error] = []

def get_iranian_cities_settings() -> Dict[str, Any]:

sage_iranian_cities_admin_add_readonly_enabled: bool = (
sage_iranian_cities_settings.IRANIAN_CITIES_ADMIN_ADD_READONLY_ENABLED
)
Expand Down
1 change: 0 additions & 1 deletion iranian_cities/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class SageIranianCitiesSettings:
_settings: Dict[str, bool]

def __init__(self):

self._settings = {}
for setting, default in DEFAULT_SETTINGS.items():
value: Any = getattr(settings, setting, default)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ django-settings-module= "kernel.settings"
load-plugins = [
"pylint_django",
"pylint.extensions.docparams",

]
good-names = [
"qs", # QuerySet abbreviation
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ classifiers =

[options]
include_package_data = true
python_requires = >=3.8
python_requires = >=3.8
30 changes: 15 additions & 15 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
from setuptools import setup, find_packages
from setuptools import find_packages, setup

setup(
name='django-iranian-cities',
packages=find_packages(exclude=['tests*']),
package_data={'iranian_cities/data': ['*.txt']},
name="django-iranian-cities",
packages=find_packages(exclude=["tests*"]),
package_data={"iranian_cities/data": ["*.txt"]},
include_package_data=True,
version='1.0.2',
description='Iranian cities support for Django',
long_description=open('README.md').read(),
long_description_content_type='text/markdown',
author='Sage Team',
author_email='[email protected]',
url='https://github.com/sageteam-org/django-iranian-cities',
download_url='https://github.com/sageteam-org/django-iranian-cities/archive/refs/tags/1.0.0.tar.gz',
keywords=['django', 'python', 'fields', 'city field'],
version="1.0.2",
description="Iranian cities support for Django",
long_description=open("README.md").read(),
long_description_content_type="text/markdown",
author="Sage Team",
author_email="[email protected]",
url="https://github.com/sageteam-org/django-iranian-cities",
download_url="https://github.com/sageteam-org/django-iranian-cities/archive/refs/tags/1.0.0.tar.gz",
keywords=["django", "python", "fields", "city field"],
install_requires=[
'Django',
]
"Django",
],
)
9 changes: 8 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,11 @@ commands =
pytest --cov

setenv =
DJANGO_SETTINGS_MODULE = kernel.settings
DJANGO_SETTINGS_MODULE = kernel.settings

[testenv:pre-commit]
description = Run pre-commit hooks
deps =
pre-commit
commands =
pre-commit run --all-files

0 comments on commit 4119634

Please sign in to comment.