From 4119634b5e13f312948b17e051aa9f5724a10a3d Mon Sep 17 00:00:00 2001 From: ARYAN-NIKNEZHAD Date: Mon, 19 Aug 2024 02:33:10 +0430 Subject: [PATCH] :wrench: chore: Add-pre-commit-config - Handel-Isort for sorting imports - Handel-black for formatting code --- .github/workflows/ci.yml | 2 +- .gitignore | 2 +- .pre-commit-config.yaml | 29 ++++++++++++++++++++++++++ CHANGELOG.md | 2 +- CODE_OF_CONDUCT.md | 2 +- Django_Iranian_Cities_Pytest_Guide.md | 14 ++++++------- LICENSE | 2 +- MANIFEST.in | 2 +- iranian_cities/checks.py | 1 - iranian_cities/conf.py | 1 - pyproject.toml | 2 +- setup.cfg | 2 +- setup.py | 30 +++++++++++++-------------- tox.ini | 9 +++++++- 14 files changed, 67 insertions(+), 33 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b0659af..0d1371b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,4 +27,4 @@ jobs: - name: Upload coverage to Codecov run: codecov env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/.gitignore b/.gitignore index 3221e55..187779e 100644 --- a/.gitignore +++ b/.gitignore @@ -139,4 +139,4 @@ uwsgi.ini nginx.conf test_app/ myenv/ -myenv3_8/ \ No newline at end of file +myenv3_8/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..792497c --- /dev/null +++ b/.pre-commit-config.yaml @@ -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/).* diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f9b128..6361e43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,3 @@ # Changelog -All notable changes to this project will be documented in this file. \ No newline at end of file +All notable changes to this project will be documented in this file. diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 2dfaddd..afc21e1 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -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. \ No newline at end of file +These examples cover various types of commits such as feature additions, bug fixes, documentation updates, dependency updates, versioning, testing, refactoring, and performance improvements. diff --git a/Django_Iranian_Cities_Pytest_Guide.md b/Django_Iranian_Cities_Pytest_Guide.md index fc3e13f..6a25a00 100644 --- a/Django_Iranian_Cities_Pytest_Guide.md +++ b/Django_Iranian_Cities_Pytest_Guide.md @@ -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 @@ -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 @@ -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. @@ -149,10 +149,10 @@ class TestMyModelAdmin: admin_site = AdminSite() request = HttpRequest() request.user = User.objects.create_superuser('admin', 'admin@example.com', '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) @@ -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. @@ -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. diff --git a/LICENSE b/LICENSE index 0be85c2..667e3f5 100644 --- a/LICENSE +++ b/LICENSE @@ -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 -. \ No newline at end of file +. diff --git a/MANIFEST.in b/MANIFEST.in index c539018..2de2b72 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,2 @@ include iranian_cities/data/*.csv -include README.md \ No newline at end of file +include README.md diff --git a/iranian_cities/checks.py b/iranian_cities/checks.py index d49e639..5137136 100644 --- a/iranian_cities/checks.py +++ b/iranian_cities/checks.py @@ -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 ) diff --git a/iranian_cities/conf.py b/iranian_cities/conf.py index 817c14f..2b0f722 100644 --- a/iranian_cities/conf.py +++ b/iranian_cities/conf.py @@ -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) diff --git a/pyproject.toml b/pyproject.toml index 7e5e95d..033ff72 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -209,7 +209,7 @@ django-settings-module= "kernel.settings" load-plugins = [ "pylint_django", "pylint.extensions.docparams", - + ] good-names = [ "qs", # QuerySet abbreviation diff --git a/setup.cfg b/setup.cfg index 7718e19..eda6e9f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -27,4 +27,4 @@ classifiers = [options] include_package_data = true -python_requires = >=3.8 \ No newline at end of file +python_requires = >=3.8 diff --git a/setup.py b/setup.py index 9f93ad2..ba7bf32 100644 --- a/setup.py +++ b/setup.py @@ -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='mail@sageteam.org', - 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="mail@sageteam.org", + 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", + ], ) diff --git a/tox.ini b/tox.ini index a1de588..f444f96 100644 --- a/tox.ini +++ b/tox.ini @@ -25,4 +25,11 @@ commands = pytest --cov setenv = - DJANGO_SETTINGS_MODULE = kernel.settings \ No newline at end of file + DJANGO_SETTINGS_MODULE = kernel.settings + +[testenv:pre-commit] +description = Run pre-commit hooks +deps = + pre-commit +commands = + pre-commit run --all-files