From f50c9f5e783f5d3b371408bfc25469a337c8a217 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Wed, 13 Aug 2025 00:44:24 +0530 Subject: [PATCH 01/60] Reset django project --- .gitignore | 2 - .isort.cfg | 3 - .pylintrc | 625 ---------------------- .vscode/settings.json | 22 - README.md | 239 +-------- django_starter/db.sqlite3 | 0 django_starter/django_starter/__init__.py | 0 django_starter/django_starter/asgi.py | 16 - django_starter/django_starter/settings.py | 124 ----- django_starter/django_starter/urls.py | 21 - django_starter/django_starter/wsgi.py | 16 - django_starter/manage.py | 22 - mypy.ini | 6 - requirements.txt | 7 - 14 files changed, 3 insertions(+), 1100 deletions(-) delete mode 100644 .gitignore delete mode 100644 .isort.cfg delete mode 100644 .pylintrc delete mode 100644 .vscode/settings.json delete mode 100644 django_starter/db.sqlite3 delete mode 100644 django_starter/django_starter/__init__.py delete mode 100644 django_starter/django_starter/asgi.py delete mode 100644 django_starter/django_starter/settings.py delete mode 100644 django_starter/django_starter/urls.py delete mode 100644 django_starter/django_starter/wsgi.py delete mode 100644 django_starter/manage.py delete mode 100644 mypy.ini delete mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 033df5f..0000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.venv -__pycache__ diff --git a/.isort.cfg b/.isort.cfg deleted file mode 100644 index c31706b..0000000 --- a/.isort.cfg +++ /dev/null @@ -1,3 +0,0 @@ -[settings] -verbose = true -skip_glob = **/migrations/* \ No newline at end of file diff --git a/.pylintrc b/.pylintrc deleted file mode 100644 index de881a9..0000000 --- a/.pylintrc +++ /dev/null @@ -1,625 +0,0 @@ -[MAIN] - -# Analyse import fallback blocks. This can be used to support both Python 2 and -# 3 compatible code, which means that the block might have code that exists -# only in one or another interpreter, leading to false positives when analysed. -analyse-fallback-blocks=no - -# Load and enable all available extensions. Use --list-extensions to see a list -# all available extensions. -#enable-all-extensions= - -# In error mode, messages with a category besides ERROR or FATAL are -# suppressed, and no reports are done by default. Error mode is compatible with -# disabling specific errors. -#errors-only= - -# Always return a 0 (non-error) status code, even if lint errors are found. -# This is primarily useful in continuous integration scripts. -#exit-zero= - -# A comma-separated list of package or module names from where C extensions may -# be loaded. Extensions are loading into the active Python interpreter and may -# run arbitrary code. -extension-pkg-allow-list= - -# A comma-separated list of package or module names from where C extensions may -# be loaded. Extensions are loading into the active Python interpreter and may -# run arbitrary code. (This is an alternative name to extension-pkg-allow-list -# for backward compatibility.) -extension-pkg-whitelist= - -# Return non-zero exit code if any of these messages/categories are detected, -# even if score is above --fail-under value. Syntax same as enable. Messages -# specified are enabled, while categories only check already-enabled messages. -fail-on= - -# Specify a score threshold under which the program will exit with error. -fail-under=10 - -# Interpret the stdin as a python script, whose filename needs to be passed as -# the module_or_package argument. -#from-stdin= - -# Files or directories to be skipped. They should be base names, not paths. -ignore=CVS - -# Add files or directories matching the regular expressions patterns to the -# ignore-list. The regex matches against paths and can be in Posix or Windows -# format. Because '\' represents the directory delimiter on Windows systems, it -# can't be used as an escape character. -ignore-paths= - -# Files or directories matching the regular expression patterns are skipped. -# The regex matches against base names, not paths. The default value ignores -# Emacs file locks -ignore-patterns=^\.# - -# List of module names for which member attributes should not be checked -# (useful for modules/projects where namespaces are manipulated during runtime -# and thus existing member attributes cannot be deduced by static analysis). It -# supports qualified module names, as well as Unix pattern matching. -ignored-modules= - -# Python code to execute, usually for sys.path manipulation such as -# pygtk.require(). -#init-hook= - -# Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the -# number of processors available to use, and will cap the count on Windows to -# avoid hangs. -jobs=1 - -# Control the amount of potential inferred values when inferring a single -# object. This can help the performance when dealing with large functions or -# complex, nested conditions. -limit-inference-results=100 - -# List of plugins (as comma separated values of python module names) to load, -# usually to register additional checkers. -load-plugins=pylint_django - -# Pickle collected data for later comparisons. -persistent=yes - -# Minimum Python version to use for version dependent checks. Will default to -# the version used to run pylint. -py-version=3.10 - -# Discover python modules and packages in the file system subtree. -recursive=no - -# When enabled, pylint would attempt to guess common misconfiguration and emit -# user-friendly hints instead of false-positive error messages. -suggestion-mode=yes - -# Allow loading of arbitrary C extensions. Extensions are imported into the -# active Python interpreter and may run arbitrary code. -unsafe-load-any-extension=no - -# In verbose mode, extra non-checker-related info will be displayed. -#verbose= - - -[BASIC] - -# Naming style matching correct argument names. -argument-naming-style=snake_case - -# Regular expression matching correct argument names. Overrides argument- -# naming-style. If left empty, argument names will be checked with the set -# naming style. -#argument-rgx= - -# Naming style matching correct attribute names. -attr-naming-style=snake_case - -# Regular expression matching correct attribute names. Overrides attr-naming- -# style. If left empty, attribute names will be checked with the set naming -# style. -#attr-rgx= - -# Bad variable names which should always be refused, separated by a comma. -bad-names=foo, - bar, - baz, - toto, - tutu, - tata - -# Bad variable names regexes, separated by a comma. If names match any regex, -# they will always be refused -bad-names-rgxs= - -# Naming style matching correct class attribute names. -class-attribute-naming-style=any - -# Regular expression matching correct class attribute names. Overrides class- -# attribute-naming-style. If left empty, class attribute names will be checked -# with the set naming style. -#class-attribute-rgx= - -# Naming style matching correct class constant names. -class-const-naming-style=UPPER_CASE - -# Regular expression matching correct class constant names. Overrides class- -# const-naming-style. If left empty, class constant names will be checked with -# the set naming style. -#class-const-rgx= - -# Naming style matching correct class names. -class-naming-style=PascalCase - -# Regular expression matching correct class names. Overrides class-naming- -# style. If left empty, class names will be checked with the set naming style. -#class-rgx= - -# Naming style matching correct constant names. -const-naming-style=UPPER_CASE - -# Regular expression matching correct constant names. Overrides const-naming- -# style. If left empty, constant names will be checked with the set naming -# style. -#const-rgx= - -# Minimum line length for functions/classes that require docstrings, shorter -# ones are exempt. -docstring-min-length=-1 - -# Naming style matching correct function names. -function-naming-style=snake_case - -# Regular expression matching correct function names. Overrides function- -# naming-style. If left empty, function names will be checked with the set -# naming style. -#function-rgx= - -# Good variable names which should always be accepted, separated by a comma. -good-names=i, - j, - k, - ex, - Run, - _ - -# Good variable names regexes, separated by a comma. If names match any regex, -# they will always be accepted -good-names-rgxs= - -# Include a hint for the correct naming format with invalid-name. -include-naming-hint=no - -# Naming style matching correct inline iteration names. -inlinevar-naming-style=any - -# Regular expression matching correct inline iteration names. Overrides -# inlinevar-naming-style. If left empty, inline iteration names will be checked -# with the set naming style. -#inlinevar-rgx= - -# Naming style matching correct method names. -method-naming-style=snake_case - -# Regular expression matching correct method names. Overrides method-naming- -# style. If left empty, method names will be checked with the set naming style. -#method-rgx= - -# Naming style matching correct module names. -module-naming-style=snake_case - -# Regular expression matching correct module names. Overrides module-naming- -# style. If left empty, module names will be checked with the set naming style. -#module-rgx= - -# Colon-delimited sets of names that determine each other's naming style when -# the name regexes allow several styles. -name-group= - -# Regular expression which should only match function or class names that do -# not require a docstring. -no-docstring-rgx=^_ - -# List of decorators that produce properties, such as abc.abstractproperty. Add -# to this list to register other decorators that produce valid properties. -# These decorators are taken in consideration only for invalid-name. -property-classes=abc.abstractproperty - -# Regular expression matching correct type variable names. If left empty, type -# variable names will be checked with the set naming style. -#typevar-rgx= - -# Naming style matching correct variable names. -variable-naming-style=snake_case - -# Regular expression matching correct variable names. Overrides variable- -# naming-style. If left empty, variable names will be checked with the set -# naming style. -#variable-rgx= - - -[CLASSES] - -# Warn about protected attribute access inside special methods -check-protected-access-in-special-methods=no - -# List of method names used to declare (i.e. assign) instance attributes. -defining-attr-methods=__init__, - __new__, - setUp, - __post_init__ - -# List of member names, which should be excluded from the protected access -# warning. -exclude-protected=_asdict, - _fields, - _replace, - _source, - _make - -# List of valid names for the first argument in a class method. -valid-classmethod-first-arg=cls - -# List of valid names for the first argument in a metaclass class method. -valid-metaclass-classmethod-first-arg=cls - - -[DESIGN] - -# List of regular expressions of class ancestor names to ignore when counting -# public methods (see R0903) -exclude-too-few-public-methods= - -# List of qualified class names to ignore when counting class parents (see -# R0901) -ignored-parents= - -# Maximum number of arguments for function / method. -max-args=5 - -# Maximum number of attributes for a class (see R0902). -max-attributes=7 - -# Maximum number of boolean expressions in an if statement (see R0916). -max-bool-expr=5 - -# Maximum number of branch for function / method body. -max-branches=12 - -# Maximum number of locals for function / method body. -max-locals=15 - -# Maximum number of parents for a class (see R0901). -max-parents=7 - -# Maximum number of public methods for a class (see R0904). -max-public-methods=20 - -# Maximum number of return / yield for function / method body. -max-returns=6 - -# Maximum number of statements in function / method body. -max-statements=50 - -# Minimum number of public methods for a class (see R0903). -min-public-methods=2 - - -[EXCEPTIONS] - -# Exceptions that will emit a warning when caught. -overgeneral-exceptions=BaseException, - Exception - - -[FORMAT] - -# Expected format of line ending, e.g. empty (any line ending), LF or CRLF. -expected-line-ending-format= - -# Regexp for a line that is allowed to be longer than the limit. -ignore-long-lines=^\s*(# )??$ - -# Number of spaces of indent required inside a hanging or continued line. -indent-after-paren=4 - -# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 -# tab). -indent-string=' ' - -# Maximum number of characters on a single line. -max-line-length=100 - -# Maximum number of lines in a module. -max-module-lines=1000 - -# Allow the body of a class to be on the same line as the declaration if body -# contains single statement. -single-line-class-stmt=no - -# Allow the body of an if to be on the same line as the test if there is no -# else. -single-line-if-stmt=no - - -[IMPORTS] - -# List of modules that can be imported at any level, not just the top level -# one. -allow-any-import-level= - -# Allow wildcard imports from modules that define __all__. -allow-wildcard-with-all=no - -# Deprecated modules which should not be used, separated by a comma. -deprecated-modules= - -# Output a graph (.gv or any supported image format) of external dependencies -# to the given file (report RP0402 must not be disabled). -ext-import-graph= - -# Output a graph (.gv or any supported image format) of all (i.e. internal and -# external) dependencies to the given file (report RP0402 must not be -# disabled). -import-graph= - -# Output a graph (.gv or any supported image format) of internal dependencies -# to the given file (report RP0402 must not be disabled). -int-import-graph= - -# Force import order to recognize a module as part of the standard -# compatibility libraries. -known-standard-library= - -# Force import order to recognize a module as part of a third party library. -known-third-party=enchant - -# Couples of modules and preferred modules, separated by a comma. -preferred-modules= - - -[LOGGING] - -# The type of string formatting that logging methods do. `old` means using % -# formatting, `new` is for `{}` formatting. -logging-format-style=old - -# Logging modules to check that the string format arguments are in logging -# function parameter format. -logging-modules=logging - - -[MESSAGES CONTROL] - -# Only show warnings with the listed confidence levels. Leave empty to show -# all. Valid levels: HIGH, CONTROL_FLOW, INFERENCE, INFERENCE_FAILURE, -# UNDEFINED. -confidence=HIGH, - CONTROL_FLOW, - INFERENCE, - INFERENCE_FAILURE, - UNDEFINED - -# Disable the message, report, category or checker with the given id(s). You -# can either give multiple identifiers separated by comma (,) or put this -# option multiple times (only on the command line, not in the configuration -# file where it should appear only once). You can also use "--disable=all" to -# disable everything first and then re-enable specific checks. For example, if -# you want to run only the similarities checker, you can use "--disable=all -# --enable=similarities". If you want to run only the classes checker, but have -# no Warning level messages displayed, use "--disable=all --enable=classes -# --disable=W". -disable=raw-checker-failed, - bad-inline-option, - locally-disabled, - file-ignored, - suppressed-message, - useless-suppression, - deprecated-pragma, - use-symbolic-message-instead, - import-outside-toplevel - - -# Enable the message, report, category or checker with the given id(s). You can -# either give multiple identifier separated by comma (,) or put this option -# multiple time (only on the command line, not in the configuration file where -# it should appear only once). See also the "--disable" option for examples. -enable=c-extension-no-member - - -[METHOD_ARGS] - -# List of qualified names (i.e., library.method) which require a timeout -# parameter e.g. 'requests.api.get,requests.api.post' -timeout-methods=requests.api.delete,requests.api.get,requests.api.head,requests.api.options,requests.api.patch,requests.api.post,requests.api.put,requests.api.request - - -[MISCELLANEOUS] - -# List of note tags to take in consideration, separated by a comma. -notes=FIXME, - XXX, - TODO - -# Regular expression of note tags to take in consideration. -notes-rgx= - - -[REFACTORING] - -# Maximum number of nested blocks for function / method body -max-nested-blocks=5 - -# Complete name of functions that never returns. When checking for -# inconsistent-return-statements if a never returning function is called then -# it will be considered as an explicit return statement and no message will be -# printed. -never-returning-functions=sys.exit,argparse.parse_error - - -[REPORTS] - -# Python expression which should return a score less than or equal to 10. You -# have access to the variables 'fatal', 'error', 'warning', 'refactor', -# 'convention', and 'info' which contain the number of messages in each -# category, as well as 'statement' which is the total number of statements -# analyzed. This score is used by the global evaluation report (RP0004). -evaluation=max(0, 0 if fatal else 10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)) - -# Template used to display messages. This is a python new-style format string -# used to format the message information. See doc for all details. -msg-template= - -# Set the output format. Available formats are text, parseable, colorized, json -# and msvs (visual studio). You can also give a reporter class, e.g. -# mypackage.mymodule.MyReporterClass. -#output-format= - -# Tells whether to display a full report or only the messages. -reports=no - -# Activate the evaluation score. -score=yes - - -[SIMILARITIES] - -# Comments are removed from the similarity computation -ignore-comments=yes - -# Docstrings are removed from the similarity computation -ignore-docstrings=yes - -# Imports are removed from the similarity computation -ignore-imports=yes - -# Signatures are removed from the similarity computation -ignore-signatures=yes - -# Minimum lines number of a similarity. -min-similarity-lines=4 - - -[SPELLING] - -# Limits count of emitted suggestions for spelling mistakes. -max-spelling-suggestions=4 - -# Spelling dictionary name. Available dictionaries: none. To make it work, -# install the 'python-enchant' package. -spelling-dict= - -# List of comma separated words that should be considered directives if they -# appear at the beginning of a comment and should not be checked. -spelling-ignore-comment-directives=fmt: on,fmt: off,noqa:,noqa,nosec,isort:skip,mypy: - -# List of comma separated words that should not be checked. -spelling-ignore-words= - -# A path to a file that contains the private dictionary; one word per line. -spelling-private-dict-file= - -# Tells whether to store unknown words to the private dictionary (see the -# --spelling-private-dict-file option) instead of raising a message. -spelling-store-unknown-words=no - - -[STRING] - -# This flag controls whether inconsistent-quotes generates a warning when the -# character used as a quote delimiter is used inconsistently within a module. -check-quote-consistency=no - -# This flag controls whether the implicit-str-concat should generate a warning -# on implicit string concatenation in sequences defined over several lines. -check-str-concat-over-line-jumps=no - - -[TYPECHECK] - -# List of decorators that produce context managers, such as -# contextlib.contextmanager. Add to this list to register other decorators that -# produce valid context managers. -contextmanager-decorators=contextlib.contextmanager - -# List of members which are set dynamically and missed by pylint inference -# system, and so shouldn't trigger E1101 when accessed. Python regular -# expressions are accepted. -generated-members= - -# Tells whether to warn about missing members when the owner of the attribute -# is inferred to be None. -ignore-none=yes - -# This flag controls whether pylint should warn about no-member and similar -# checks whenever an opaque object is returned when inferring. The inference -# can return multiple potential results while evaluating a Python object, but -# some branches might not be evaluated, which results in partial inference. In -# that case, it might be useful to still emit no-member and other checks for -# the rest of the inferred objects. -ignore-on-opaque-inference=yes - -# List of symbolic message names to ignore for Mixin members. -ignored-checks-for-mixins=no-member, - not-async-context-manager, - not-context-manager, - attribute-defined-outside-init - -# List of class names for which member attributes should not be checked (useful -# for classes with dynamically set attributes). This supports the use of -# qualified names. -ignored-classes=optparse.Values,thread._local,_thread._local,argparse.Namespace - -# Show a hint with possible names when a member name was not found. The aspect -# of finding the hint is based on edit distance. -missing-member-hint=yes - -# The minimum edit distance a name should have in order to be considered a -# similar match for a missing member name. -missing-member-hint-distance=1 - -# The total number of similar names that should be taken in consideration when -# showing a hint for a missing member. -missing-member-max-choices=1 - -# Regex pattern to define which classes are considered mixins. -mixin-class-rgx=.*[Mm]ixin - -# List of decorators that change the signature of a decorated function. -signature-mutators= - - -[VARIABLES] - -# List of additional names supposed to be defined in builtins. Remember that -# you should avoid defining new builtins when possible. -additional-builtins= - -# Tells whether unused global variables should be treated as a violation. -allow-global-unused-variables=yes - -# List of names allowed to shadow builtins -allowed-redefined-builtins= - -# List of strings which can identify a callback function by name. A callback -# name must start or end with one of those strings. -callbacks=cb_, - _cb - -# A regular expression matching the name of dummy variables (i.e. expected to -# not be used). -dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_ - -# Argument names that match this expression will be ignored. -ignored-argument-names=_.*|^ignored_|^unused_ - -# Tells whether we should check for unused import in __init__ files. -init-import=no - -# List of qualified module names which can have objects that can redefine -# builtins. -redefining-builtins-modules=six.moves,past.builtins,future.builtins,builtins,io - - -# pylint_django configuration -[pylint-django] -django-settings-module=django_starter.settings \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 8923697..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "editor.formatOnSave": true, - "editor.codeActionsOnSave": { - "source.fixAll": true, - "source.organizeImports": true, - }, - "isort.args": [ - "skip_glob", - "*/migrations/*", - ], - "[python]": { - "editor.defaultFormatter": "ms-python.black-formatter" - }, - "python.linting.enabled": true, - "python.linting.pylintEnabled": true, - "python.linting.pylintArgs": [ - "--load-plugins", - "pylint_django", - "django-settings-module=django_starter.settings", - ], - "python.linting.mypyEnabled": true, -} diff --git a/README.md b/README.md index d3dec14..1929514 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ## Django Starter Project -Create Virtual Environment +1. Create Virtual Environment - if windows @@ -14,7 +14,7 @@ Create Virtual Environment python3 -m venv .venv ``` -Activate Virtual Environment +2. Activate Virtual Environment - if windows @@ -28,241 +28,8 @@ Activate Virtual Environment source .venv/bin/activate ``` -- if you want to deactivate +- Note:- if you want to deactivate ```bash deactivate ``` - -Install Django - -```bash -pip install django -``` - -Create Django Project - -```bash -django-admin startproject -``` - -Run Django Project - -```bash -python manage.py runserver -``` - -Setup Pylint - -- Reference Links - - - [pylint](https://github.com/PyCQA/pylint/) - - - [pylint-django](https://github.com/PyCQA/pylint-django/) - - - Blog: [How to setup pylint for django project](https://dkolodzey.medium.com/pylint-django-with-github-actions-2e3ef05dd34a) - -- Install pylint for code analysis and linting - - ```bash - pip install pylint - ``` - -- Install pylint-django pylint plugin - - ```bash - pip install pylint-django - ``` - -- Create pylint config file if you want to customize - - ```bash - pylint --generate-rcfile > .pylintrc - ``` - - - -- Add pylint_django in load-plugins to pylint config file - - ```text - [MASTER] - load-plugins=pylint_django - ``` - -- Add django settings module in pylint config file - - ```text - [pylint-django] - django-settings-module=.settings - ``` - -- Run pylint - - ```bash - pylint **/*.py - ``` - -- NOTE: if you not want to create pylint config file, you can run pylint with - -```bash -pylint --load-plugins=pylint_django --django-settings-module=.settings **/*.py -``` - -TODO - Fix this is not working - -- If you are using vscode, you can install pylint extension and it will automatically run pylint on save. for that you need to add this in settings.json - - ```json - { - { - "python.linting.enabled": true, - "python.linting.pylintEnabled": true, - "python.linting.pylintArgs": [ - "--load-plugins", - "pylint_django", - "--django-settings-module=.settings" - ] - } - ``` - - [Setup Reference Links](https://dkolodzey.medium.com/pylint-for-django-in-vscode-f3fadb8462d) - -Setup Black for code formatting - -- Reference Links - - - [black](https://black.readthedocs.io/en/stable/) - - [Blog Link](https://ctrlzblog.com/how-to-set-up-black-to-automatically-format-your-django-project/) - -- Install black - - ```bash - pip install black - ``` - -- Run black - - ```bash - black . - ``` - -- Check black formatting - - ```bash - black --check . - ``` - -- If you are using vscode - - - Install VS Code Extension `ms-python.black-formatter` - - - add this in settings.json - ```json - { - "editor.formatOnSave": true, - "python.formatting.provider": "black" - } - ``` - -Setup mypy for static type checking - -- Reference Links - - - [mypy](https://mypy.readthedocs.io/en/stable/) - - [django-stubs github repo](https://github.com/typeddjango/django-stubs) - -- Install mypy - - ```bash - pip install mypy - ``` - -- Install django-stubs for django type checking - - ```bash - pip install django-stubs - ``` - -- Note this is not required in current case, but if you are using django models, you need to install django-stubs - - - [mypy config docs](https://mypy.readthedocs.io/en/latest/config_file.html) - - [Stack Overflow Reference](https://stackoverflow.com/questions/59031982/type-annotations-for-django-models) - - - Add django-stubs in plugins in mypy config file `mypy.ini` - - ```text - [mypy] - plugins = mypy_django_plugin.main - ``` - - - Add django settings module in mypy config file `mypy.ini` - ```text - [mypy.plugins.django-stubs] - django_settings_module = .settings - ``` - -- Run mypy - - ```bash - mypy . - - ``` - -- If you are using vscode, you need to add this in settings.json - - ```json - { - "python.linting.mypyEnabled": true, - "python.linting.mypyArgs": ["--strict"] - } - ``` - -- [Reference Blog](https://dev.to/jodaut/python-type-checking-with-visual-studio-code-46a7) - -Setup isort for sorting imports - -- Reference Links - - - [isort](https://pycqa.github.io/isort/) - - [github wiki](https://github.com/PyCQA/isort/wiki/isort-Settings) - -- Install isort - - ```bash - pip install isort - ``` - -- Run isort - - ```bash - isort . - ``` - -- Check isort - - ```bash - isort --check . - ``` - -- If want to customize isort, you can create isort config file `isort.cfg` - - ```text - [settings] - verbose = true - skip_glob = **/migrations/*.py - ``` - -- NOTE: supported options are [here](https://pycqa.github.io/isort/docs/configuration/options.html) - -- If you are using vscode, you need to add this in settings.json - - ```json - { - "editor.codeActionsOnSave": { - "source.organizeImports": true - }, - "isort.args": ["skip_glob", "*/migrations/*"] - } - ``` diff --git a/django_starter/db.sqlite3 b/django_starter/db.sqlite3 deleted file mode 100644 index e69de29..0000000 diff --git a/django_starter/django_starter/__init__.py b/django_starter/django_starter/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/django_starter/django_starter/asgi.py b/django_starter/django_starter/asgi.py deleted file mode 100644 index 263c45a..0000000 --- a/django_starter/django_starter/asgi.py +++ /dev/null @@ -1,16 +0,0 @@ -""" -ASGI config for django_starter project. - -It exposes the ASGI callable as a module-level variable named ``application``. - -For more information on this file, see -https://docs.djangoproject.com/en/4.1/howto/deployment/asgi/ -""" - -import os - -from django.core.asgi import get_asgi_application - -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_starter.settings") - -application = get_asgi_application() diff --git a/django_starter/django_starter/settings.py b/django_starter/django_starter/settings.py deleted file mode 100644 index ac26394..0000000 --- a/django_starter/django_starter/settings.py +++ /dev/null @@ -1,124 +0,0 @@ -""" -Django settings for django_starter project. - -Generated by 'django-admin startproject' using Django 4.1.4. - -For more information on this file, see -https://docs.djangoproject.com/en/4.1/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/4.1/ref/settings/ -""" - -from pathlib import Path -from typing import List - -# Build paths inside the project like this: BASE_DIR / 'subdir'. -BASE_DIR = Path(__file__).resolve().parent.parent - - -# Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/ - -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = "django-insecure-122)h3o=1ewbz!3)e^b1n3h*i*on3(-v$%8**r&n--0t2sijcn" - -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True - -ALLOWED_HOSTS: List[str] = [] - - -# Application definition - -INSTALLED_APPS = [ - "django.contrib.admin", - "django.contrib.auth", - "django.contrib.contenttypes", - "django.contrib.sessions", - "django.contrib.messages", - "django.contrib.staticfiles", -] - -MIDDLEWARE = [ - "django.middleware.security.SecurityMiddleware", - "django.contrib.sessions.middleware.SessionMiddleware", - "django.middleware.common.CommonMiddleware", - "django.middleware.csrf.CsrfViewMiddleware", - "django.contrib.auth.middleware.AuthenticationMiddleware", - "django.contrib.messages.middleware.MessageMiddleware", - "django.middleware.clickjacking.XFrameOptionsMiddleware", -] - -ROOT_URLCONF = "django_starter.urls" - -TEMPLATES = [ - { - "BACKEND": "django.template.backends.django.DjangoTemplates", - "DIRS": [], - "APP_DIRS": True, - "OPTIONS": { - "context_processors": [ - "django.template.context_processors.debug", - "django.template.context_processors.request", - "django.contrib.auth.context_processors.auth", - "django.contrib.messages.context_processors.messages", - ], - }, - }, -] - -WSGI_APPLICATION = "django_starter.wsgi.application" - - -# Database -# https://docs.djangoproject.com/en/4.1/ref/settings/#databases - -DATABASES = { - "default": { - "ENGINE": "django.db.backends.sqlite3", - "NAME": BASE_DIR / "db.sqlite3", - } -} - - -# Password validation -# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators - -AUTH_PASSWORD_VALIDATORS = [ - { - "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", - }, - { - "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", - }, - { - "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", - }, - { - "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", - }, -] - - -# Internationalization -# https://docs.djangoproject.com/en/4.1/topics/i18n/ - -LANGUAGE_CODE = "en-us" - -TIME_ZONE = "UTC" - -USE_I18N = True - -USE_TZ = True - - -# Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/4.1/howto/static-files/ - -STATIC_URL = "static/" - -# Default primary key field type -# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field - -DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" diff --git a/django_starter/django_starter/urls.py b/django_starter/django_starter/urls.py deleted file mode 100644 index 1a80484..0000000 --- a/django_starter/django_starter/urls.py +++ /dev/null @@ -1,21 +0,0 @@ -"""django_starter URL Configuration - -The `urlpatterns` list routes URLs to views. For more information please see: - https://docs.djangoproject.com/en/4.1/topics/http/urls/ -Examples: -Function views - 1. Add an import: from my_app import views - 2. Add a URL to urlpatterns: path('', views.home, name='home') -Class-based views - 1. Add an import: from other_app.views import Home - 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') -Including another URLconf - 1. Import the include() function: from django.urls import include, path - 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) -""" -from django.contrib import admin -from django.urls import include, path - -urlpatterns = [ - path("admin/", admin.site.urls), -] diff --git a/django_starter/django_starter/wsgi.py b/django_starter/django_starter/wsgi.py deleted file mode 100644 index 158b332..0000000 --- a/django_starter/django_starter/wsgi.py +++ /dev/null @@ -1,16 +0,0 @@ -""" -WSGI config for django_starter project. - -It exposes the WSGI callable as a module-level variable named ``application``. - -For more information on this file, see -https://docs.djangoproject.com/en/4.1/howto/deployment/wsgi/ -""" - -import os - -from django.core.wsgi import get_wsgi_application - -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_starter.settings") - -application = get_wsgi_application() diff --git a/django_starter/manage.py b/django_starter/manage.py deleted file mode 100644 index ea424a9..0000000 --- a/django_starter/manage.py +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env python -"""Django's command-line utility for administrative tasks.""" -import os -import sys - - -def main(): - """Run administrative tasks.""" - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_starter.settings") - try: - from django.core.management import execute_from_command_line - except ImportError as exc: - raise ImportError( - "Couldn't import Django. Are you sure it's installed and " - "available on your PYTHONPATH environment variable? Did you " - "forget to activate a virtual environment?" - ) from exc - execute_from_command_line(sys.argv) - - -if __name__ == "__main__": - main() diff --git a/mypy.ini b/mypy.ini deleted file mode 100644 index 81de0b4..0000000 --- a/mypy.ini +++ /dev/null @@ -1,6 +0,0 @@ -[mypy] -mypy_path = ./django_starter -plugins = mypy_django_plugin.main - -[mypy.plugins.django-stubs] -django_settings_module = "django_starter.settings" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 332d1f4..0000000 --- a/requirements.txt +++ /dev/null @@ -1,7 +0,0 @@ -black==22.12.0 -Django==4.1.4 -django-stubs==1.13.1 -isort==5.11.3 -mypy==0.991 -pylint==2.15.9 -pylint-django==2.5.3 \ No newline at end of file From 09636c959530819ca731d02f64d3325dc87dcefa Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Wed, 13 Aug 2025 01:11:14 +0530 Subject: [PATCH 02/60] Add git ignore file --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1d17dae --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.venv From a30e854ece034f38df923d883668f9f2efd2fcc6 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Thu, 14 Aug 2025 12:34:28 +0530 Subject: [PATCH 03/60] Install Django project --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 1929514..d749e62 100644 --- a/README.md +++ b/README.md @@ -33,3 +33,9 @@ ```bash deactivate ``` + +3. Install django package + + ```sh + pip install django + ``` From 3320a6b1093e271c62b5e11a3831914a2c1c8560 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Thu, 14 Aug 2025 12:38:13 +0530 Subject: [PATCH 04/60] Add installed Django package to requirements file --- README.md | 12 ++++++++++-- requirements.txt | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 requirements.txt diff --git a/README.md b/README.md index d749e62..7f58ec3 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,16 @@ deactivate ``` -3. Install django package +3. Setup Django project with app + +- Install Django package + + ```sh + pip install Django + ``` + +- Add installed Django package to requirements file ```sh - pip install django + pip freeze | grep Django > requirements.txt ``` diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..0729064 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +Django==5.2.4 From 72ae8f156e954c7d2d48ae045ba7af6d5fc12bf8 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Thu, 14 Aug 2025 12:42:00 +0530 Subject: [PATCH 05/60] Start django project `backend` --- README.md | 6 +++ backend/__init__.py | 0 backend/asgi.py | 16 ++++++ backend/settings.py | 122 ++++++++++++++++++++++++++++++++++++++++++++ backend/urls.py | 23 +++++++++ backend/wsgi.py | 16 ++++++ manage.py | 22 ++++++++ 7 files changed, 205 insertions(+) create mode 100644 backend/__init__.py create mode 100644 backend/asgi.py create mode 100644 backend/settings.py create mode 100644 backend/urls.py create mode 100644 backend/wsgi.py create mode 100755 manage.py diff --git a/README.md b/README.md index 7f58ec3..925ffea 100644 --- a/README.md +++ b/README.md @@ -47,3 +47,9 @@ ```sh pip freeze | grep Django > requirements.txt ``` + +- Start Django project + + ```sh + django-admin startproject . + ``` diff --git a/backend/__init__.py b/backend/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/asgi.py b/backend/asgi.py new file mode 100644 index 0000000..ecaff6f --- /dev/null +++ b/backend/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for backend project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "backend.settings") + +application = get_asgi_application() diff --git a/backend/settings.py b/backend/settings.py new file mode 100644 index 0000000..402f94b --- /dev/null +++ b/backend/settings.py @@ -0,0 +1,122 @@ +""" +Django settings for backend project. + +Generated by 'django-admin startproject' using Django 5.2.4. + +For more information on this file, see +https://docs.djangoproject.com/en/5.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/5.2/ref/settings/ +""" + +from pathlib import Path + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = "django-insecure-2l@ji^toi5&60%f!if3-9bkx1y(f)f+*1vs0(q3l2y1-&i4jv%" + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + "django.contrib.admin", + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", + "django.contrib.messages", + "django.contrib.staticfiles", +] + +MIDDLEWARE = [ + "django.middleware.security.SecurityMiddleware", + "django.contrib.sessions.middleware.SessionMiddleware", + "django.middleware.common.CommonMiddleware", + "django.middleware.csrf.CsrfViewMiddleware", + "django.contrib.auth.middleware.AuthenticationMiddleware", + "django.contrib.messages.middleware.MessageMiddleware", + "django.middleware.clickjacking.XFrameOptionsMiddleware", +] + +ROOT_URLCONF = "backend.urls" + +TEMPLATES = [ + { + "BACKEND": "django.template.backends.django.DjangoTemplates", + "DIRS": [], + "APP_DIRS": True, + "OPTIONS": { + "context_processors": [ + "django.template.context_processors.request", + "django.contrib.auth.context_processors.auth", + "django.contrib.messages.context_processors.messages", + ], + }, + }, +] + +WSGI_APPLICATION = "backend.wsgi.application" + + +# Database +# https://docs.djangoproject.com/en/5.2/ref/settings/#databases + +DATABASES = { + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": BASE_DIR / "db.sqlite3", + } +} + + +# Password validation +# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/5.2/topics/i18n/ + +LANGUAGE_CODE = "en-us" + +TIME_ZONE = "UTC" + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/5.2/howto/static-files/ + +STATIC_URL = "static/" + +# Default primary key field type +# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" diff --git a/backend/urls.py b/backend/urls.py new file mode 100644 index 0000000..ec9924b --- /dev/null +++ b/backend/urls.py @@ -0,0 +1,23 @@ +""" +URL configuration for backend project. + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/5.2/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" + +from django.contrib import admin +from django.urls import path + +urlpatterns = [ + path("admin/", admin.site.urls), +] diff --git a/backend/wsgi.py b/backend/wsgi.py new file mode 100644 index 0000000..2e99f5a --- /dev/null +++ b/backend/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for backend project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "backend.settings") + +application = get_wsgi_application() diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..1917e46 --- /dev/null +++ b/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "backend.settings") + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == "__main__": + main() From 78cc5232bd9ab78597304eba1a48a57c0ad9a962 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Thu, 14 Aug 2025 13:08:12 +0530 Subject: [PATCH 06/60] Start django app core --- core/__init__.py | 0 core/admin.py | 3 +++ core/apps.py | 6 ++++++ core/migrations/__init__.py | 0 core/models.py | 3 +++ core/tests.py | 3 +++ core/views.py | 3 +++ 7 files changed, 18 insertions(+) create mode 100644 core/__init__.py create mode 100644 core/admin.py create mode 100644 core/apps.py create mode 100644 core/migrations/__init__.py create mode 100644 core/models.py create mode 100644 core/tests.py create mode 100644 core/views.py diff --git a/core/__init__.py b/core/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/core/admin.py b/core/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/core/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/core/apps.py b/core/apps.py new file mode 100644 index 0000000..c0ce093 --- /dev/null +++ b/core/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class CoreConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "core" diff --git a/core/migrations/__init__.py b/core/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/core/models.py b/core/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/core/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/core/tests.py b/core/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/core/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/core/views.py b/core/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/core/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. From 0d97ae8f0aa5358ab3073fc7d344620ba99da1c6 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Thu, 14 Aug 2025 13:10:39 +0530 Subject: [PATCH 07/60] Install django app in project setting --- backend/settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/settings.py b/backend/settings.py index 402f94b..9c8d7ac 100644 --- a/backend/settings.py +++ b/backend/settings.py @@ -37,6 +37,7 @@ "django.contrib.sessions", "django.contrib.messages", "django.contrib.staticfiles", + 'core', ] MIDDLEWARE = [ From f8d32b64d95d0dc64b6f7bab92ec7a5ed5c66e54 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Thu, 14 Aug 2025 13:12:24 +0530 Subject: [PATCH 08/60] Add Djnago app setup instructions --- README.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 925ffea..e8ad59e 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ deactivate ``` -3. Setup Django project with app +3. Setup Django project - Install Django package @@ -53,3 +53,20 @@ ```sh django-admin startproject . ``` + +4. Setup Django app + +- Start Django app + + ```sh + python3 manage.py startapp + ``` + +- Install Django app in project setting + + ```python + INSTALLED_APPS = [ + ..., + '', + ] + ``` From 5e058d701dc47a987541707eba824d7f1ca4e1e8 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Thu, 14 Aug 2025 13:22:36 +0530 Subject: [PATCH 09/60] Add students model --- core/models.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/models.py b/core/models.py index 71a8362..5454764 100644 --- a/core/models.py +++ b/core/models.py @@ -1,3 +1,9 @@ from django.db import models # Create your models here. + +class Student(models.Model): + """Student Model""" + + first_name = models.CharField(max_length=30) + last_name = models.CharField(max_length=30) \ No newline at end of file From 48ea96d7a8d45d4d953aab2aa25978bbc92ed954 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Thu, 14 Aug 2025 13:24:26 +0530 Subject: [PATCH 10/60] Add student model str method --- core/models.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/models.py b/core/models.py index 5454764..7f9e7c4 100644 --- a/core/models.py +++ b/core/models.py @@ -6,4 +6,9 @@ class Student(models.Model): """Student Model""" first_name = models.CharField(max_length=30) - last_name = models.CharField(max_length=30) \ No newline at end of file + last_name = models.CharField(max_length=30) + + def __str__(self): + """Student string representation""" + + return f"{self.first_name} {self.last_name}" \ No newline at end of file From 204e9baf225ad7c36e5e30a317c33a8184c97d1c Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Thu, 14 Aug 2025 13:29:04 +0530 Subject: [PATCH 11/60] Generate migration file for django model --- core/migrations/0001_initial.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 core/migrations/0001_initial.py diff --git a/core/migrations/0001_initial.py b/core/migrations/0001_initial.py new file mode 100644 index 0000000..2df654b --- /dev/null +++ b/core/migrations/0001_initial.py @@ -0,0 +1,29 @@ +# Generated by Django 5.2.4 on 2025-08-14 07:55 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [] + + operations = [ + migrations.CreateModel( + name="Student", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("first_name", models.CharField(max_length=30)), + ("last_name", models.CharField(max_length=30)), + ], + ), + ] From e05c2c4657b5a2b040a023a9f8f86b546e910f7a Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Thu, 14 Aug 2025 13:29:45 +0530 Subject: [PATCH 12/60] Add pycache and sqlite3 files in gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 1d17dae..0905b23 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ .venv +__pycache__/ +*sqlite3 From aedc92ce2f40532ebf48fdbf1178b8798b5e8152 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Thu, 14 Aug 2025 13:30:22 +0530 Subject: [PATCH 13/60] Add instructions for model setup --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index e8ad59e..b90cd0b 100644 --- a/README.md +++ b/README.md @@ -70,3 +70,17 @@ '', ] ``` + +5. Setup Django Model + +- Generate migration file for model + + ```sh + python3 manage.py makemigrations + ``` + +- Apply migration + + ```sh + python3 manage.py migrate + ``` \ No newline at end of file From cb381be144dbef4f116c9f40743bde662450e41f Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Thu, 14 Aug 2025 13:44:27 +0530 Subject: [PATCH 14/60] Add unit test for model --- core/tests.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/core/tests.py b/core/tests.py index 7ce503c..151090a 100644 --- a/core/tests.py +++ b/core/tests.py @@ -1,3 +1,23 @@ from django.test import TestCase +from .models import Student +from datetime import date # Create your tests here. + +class StudentModelTest(TestCase): + def setUp(self): + self.student = Student.objects.create( + first_name="John", + last_name="Doe", + ) + + def test_student_creation(self): + """Test that a student instance is created correctly.""" + + self.assertEqual(self.student.first_name, "John") + self.assertEqual(self.student.last_name, "Doe") + + def test_str_method(self): + """Test the __str__ method of the Student model.""" + + self.assertEqual(str(self.student), "John Doe") \ No newline at end of file From 873ad2cafd1274f5042975605c32cc810526eadd Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Thu, 14 Aug 2025 13:45:52 +0530 Subject: [PATCH 15/60] Add instructions to run unit tests --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index b90cd0b..55c1064 100644 --- a/README.md +++ b/README.md @@ -83,4 +83,10 @@ ```sh python3 manage.py migrate + ``` + +6. Run unit tests + + ```sh + python3 manage.py test ``` \ No newline at end of file From b286082682090afa7771b85d11c64b9f0069ac6e Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Fri, 15 Aug 2025 17:44:03 +0530 Subject: [PATCH 16/60] Add drf package in requirements file --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 0729064..938261d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ Django==5.2.4 +djangorestframework==3.16.0 From 132cf5573bec00788e7db56c5f80983490d25aeb Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Fri, 15 Aug 2025 17:45:39 +0530 Subject: [PATCH 17/60] Install DRF in project setting --- backend/settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/settings.py b/backend/settings.py index 9c8d7ac..e4697f3 100644 --- a/backend/settings.py +++ b/backend/settings.py @@ -37,6 +37,7 @@ "django.contrib.sessions", "django.contrib.messages", "django.contrib.staticfiles", + 'rest_framework', 'core', ] From 690de7cd96fa8a7e4881046f5119fe4bf3405bd8 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Fri, 15 Aug 2025 17:48:55 +0530 Subject: [PATCH 18/60] Add DRF setup instructions in readme file --- README.md | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 55c1064..1549a52 100644 --- a/README.md +++ b/README.md @@ -89,4 +89,27 @@ ```sh python3 manage.py test - ``` \ No newline at end of file + ``` + +7. Setup DRF(Django Rest Framework) + +- Install DRF package + + ```sh + pip install djangorestframework + ``` + +- Add installed DRF package to requirements file + + ```sh + pip freeze | grep djangorestframework >> requirements.txt + ``` + +- Install DRF app in project setting + + ```python + INSTALLED_APPS = [ + ..., + 'rest_framework', + ] + ``` From d57c9a9a8514d761e877d9789e1d3c97cc965cb7 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Fri, 15 Aug 2025 18:01:10 +0530 Subject: [PATCH 19/60] Add coverage package in requirements file --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 938261d..f5a2929 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ Django==5.2.4 djangorestframework==3.16.0 +coverage==7.9.2 From 18eab77c2f194c38e529202621430c220f416d0a Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Fri, 15 Aug 2025 18:02:11 +0530 Subject: [PATCH 20/60] add coverage files in gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 0905b23..51fcfd1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ .venv __pycache__/ *sqlite3 +.coverage +htmlcov From 9b2278cf17cae15c0a98d71af7a2f00e183fadb3 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Fri, 15 Aug 2025 18:05:13 +0530 Subject: [PATCH 21/60] Add coverage setup instructions in readme file --- README.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/README.md b/README.md index 1549a52..2656163 100644 --- a/README.md +++ b/README.md @@ -113,3 +113,35 @@ 'rest_framework', ] ``` + +8. Setup Test Coverage + +- Install Coverage package + + ```sh + pip install coverage + ``` + +- Add installed Coverage package to requirements file + + ```sh + pip freeze | grep coverage >> requirements.txt + ``` + +- Run tests with coverage + + ```sh + coverage run manage.py test + ``` + +- See coverage report on terminal + + ```sh + coverage report + ``` + +- Generate HTML report + + ```sh + coverage html + ``` From cd9779ae887bbc9db688e6273091889aca649b54 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Fri, 15 Aug 2025 18:17:35 +0530 Subject: [PATCH 22/60] Add mypy package in requirements file --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index f5a2929..a80cbfa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ Django==5.2.4 djangorestframework==3.16.0 coverage==7.9.2 +mypy==1.17.0 From 99acf89ed5990ce187c226757abc1d3c3b2641f1 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Fri, 15 Aug 2025 18:39:45 +0530 Subject: [PATCH 23/60] Add django stubs package in requirements file --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index a80cbfa..0f22b79 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ Django==5.2.4 djangorestframework==3.16.0 coverage==7.9.2 mypy==1.17.0 +django-stubs==5.2.2 From 7fc32c59aadca754797c879bea491ab06708e012 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Fri, 15 Aug 2025 18:46:04 +0530 Subject: [PATCH 24/60] Add djangorestframework-stubs package in requirements file --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 0f22b79..f8c6523 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,4 @@ djangorestframework==3.16.0 coverage==7.9.2 mypy==1.17.0 django-stubs==5.2.2 +djangorestframework-stubs==3.16.1 From 53937ce8e5fa1a86b154a945a1f5f563ac4aba9a Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Fri, 15 Aug 2025 19:05:07 +0530 Subject: [PATCH 25/60] Add mypy config file --- mypy.ini | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 mypy.ini diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 0000000..2693036 --- /dev/null +++ b/mypy.ini @@ -0,0 +1,6 @@ +[mypy] +plugins = mypy_django_plugin.main +exclude = migrations|tests + +[mypy.plugins.django-stubs] +django_settings_module = "backend.settings" From b96a3bff4c35cfb60d6098dae51a3fcb978e1b84 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Fri, 15 Aug 2025 19:07:58 +0530 Subject: [PATCH 26/60] Add instructions to setup mypy --- README.md | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/README.md b/README.md index 2656163..3714ee1 100644 --- a/README.md +++ b/README.md @@ -145,3 +145,60 @@ ```sh coverage html ``` + +9. Setup MyPy + +- Install MyPy package + + ```sh + pip install mypy + ``` + +- Add installed mypy package to requirements file + + ```sh + pip freeze | grep mypy== >> requirements.txt + ``` + +- Install django stubs package + + ```sh + pip install django-stubs + ``` + +- Add installed django stubs package to requirements file + + ```sh + pip freeze | grep django-stubs== >> requirements.txt + ``` + +- Install drf stubs package + + ```sh + pip install djangorestframework-stubs + ``` + +- Add installed drf stubs package to requirements file + + ```sh + pip freeze | grep djangorestframework-stubs >> requirements.txt + ``` + +- Add MyPy config file `mypy.init` + + ```init + [mypy] + plugins = mypy_django_plugin.main + exclude = migrations|tests + + [mypy.plugins.django-stubs] + django_settings_module = ".settings" + ``` + +- Note:- config file [doc](https://mypy.readthedocs.io/en/latest/config_file.html) + +- Run mypy type checking + + ```sh + mypy . + ``` From 1a5b1973bbacccc4ec85bed7dc93d7af048a0987 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Fri, 15 Aug 2025 19:08:49 +0530 Subject: [PATCH 27/60] Fix mypy warning --- backend/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/settings.py b/backend/settings.py index e4697f3..a369797 100644 --- a/backend/settings.py +++ b/backend/settings.py @@ -25,7 +25,7 @@ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = [] +ALLOWED_HOSTSS: list[str] = [] # Application definition From f88a2b40275d4b4c8deed61e75e1070c364032f8 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Fri, 15 Aug 2025 19:15:56 +0530 Subject: [PATCH 28/60] Add black package in requirements file --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index f8c6523..5b89757 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ coverage==7.9.2 mypy==1.17.0 django-stubs==5.2.2 djangorestframework-stubs==3.16.1 +black==25.1.0 From d0921ba265b473fc58abfc3b40368703c8492a50 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Fri, 15 Aug 2025 19:20:53 +0530 Subject: [PATCH 29/60] Add black config --- pyproject.toml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..5bbddd5 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,2 @@ +[tool.black] +force-exclude = "/migrations/" From 26415ddebd8b66cf9655d574c1a93ce27298fcad Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Fri, 15 Aug 2025 19:22:24 +0530 Subject: [PATCH 30/60] Add vscode setting to format code on save using black --- .vscode/setting.json | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .vscode/setting.json diff --git a/.vscode/setting.json b/.vscode/setting.json new file mode 100644 index 0000000..390a413 --- /dev/null +++ b/.vscode/setting.json @@ -0,0 +1,12 @@ +{ + "editor.formatOnSave": true, + "editor.codeActionsOnSave": { + "source.fixAll": "explicit" + }, + "editor.rulers": [ + 100 + ], + "[python]": { + "editor.defaultFormatter": "ms-python.black-formatter" + } +} \ No newline at end of file From a0e8f887f51e8b6007c82892960369f6e0e8ffb5 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Fri, 15 Aug 2025 22:37:24 +0530 Subject: [PATCH 31/60] Fix formmating --- backend/settings.py | 4 ++-- core/models.py | 5 +++-- core/tests.py | 7 ++++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/backend/settings.py b/backend/settings.py index a369797..ee1598e 100644 --- a/backend/settings.py +++ b/backend/settings.py @@ -37,8 +37,8 @@ "django.contrib.sessions", "django.contrib.messages", "django.contrib.staticfiles", - 'rest_framework', - 'core', + "rest_framework", + "core", ] MIDDLEWARE = [ diff --git a/core/models.py b/core/models.py index 7f9e7c4..5466fff 100644 --- a/core/models.py +++ b/core/models.py @@ -2,6 +2,7 @@ # Create your models here. + class Student(models.Model): """Student Model""" @@ -10,5 +11,5 @@ class Student(models.Model): def __str__(self): """Student string representation""" - - return f"{self.first_name} {self.last_name}" \ No newline at end of file + + return f"{self.first_name} {self.last_name}" diff --git a/core/tests.py b/core/tests.py index 151090a..9040659 100644 --- a/core/tests.py +++ b/core/tests.py @@ -4,6 +4,7 @@ # Create your tests here. + class StudentModelTest(TestCase): def setUp(self): self.student = Student.objects.create( @@ -16,8 +17,8 @@ def test_student_creation(self): self.assertEqual(self.student.first_name, "John") self.assertEqual(self.student.last_name, "Doe") - + def test_str_method(self): """Test the __str__ method of the Student model.""" - - self.assertEqual(str(self.student), "John Doe") \ No newline at end of file + + self.assertEqual(str(self.student), "John Doe") From b267838d2d60eb60e9b610a440f549bd2d50c863 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Fri, 15 Aug 2025 22:37:47 +0530 Subject: [PATCH 32/60] Add instructions to setup black --- README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/README.md b/README.md index 3714ee1..01387b5 100644 --- a/README.md +++ b/README.md @@ -202,3 +202,30 @@ ```sh mypy . ``` + +10. Setup black + +- Install black package + + ```sh + pip install black + ``` + +- Add installed black package to requirements file + + ```sh + pip freeze | grep black >> requirements.txt + ``` + +- Add black config in `puproject.toml` file + + ```toml + [tool.black] + force-exclude = "/migrations/" + ``` + +- Fix formatting using black + + ```sh + black . + ``` \ No newline at end of file From 02a9595534349d0617fbbce5604a096145be0266 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Fri, 15 Aug 2025 22:39:26 +0530 Subject: [PATCH 33/60] Add black official doc --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 01387b5..6ea91ea 100644 --- a/README.md +++ b/README.md @@ -224,8 +224,10 @@ force-exclude = "/migrations/" ``` +- Note:- black official [doc](https://black.readthedocs.io/en/stable/getting_started.html) + - Fix formatting using black ```sh black . - ``` \ No newline at end of file + ``` From 9cad6fdaa0c215ab24593b4bce100d1a84f3c1b0 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Fri, 15 Aug 2025 23:01:04 +0530 Subject: [PATCH 34/60] Add isort package in requirements file --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 5b89757..4342b23 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,3 +5,4 @@ mypy==1.17.0 django-stubs==5.2.2 djangorestframework-stubs==3.16.1 black==25.1.0 +isort==6.0.1 From a9f07cd27cd29ca6f043c5d1a1c0f9761a682c4e Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Fri, 15 Aug 2025 23:01:10 +0530 Subject: [PATCH 35/60] Add isort config --- isort.cfg | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 isort.cfg diff --git a/isort.cfg b/isort.cfg new file mode 100644 index 0000000..b678189 --- /dev/null +++ b/isort.cfg @@ -0,0 +1,4 @@ +[settings] +profile = black +verbose = true +skip_glob = **/migrations/*.py From e11e3622a32daa74b33e1166ebff97df49e23dbe Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Sat, 16 Aug 2025 12:39:12 +0530 Subject: [PATCH 36/60] Configure vs code for isort --- .vscode/setting.json | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.vscode/setting.json b/.vscode/setting.json index 390a413..54f9617 100644 --- a/.vscode/setting.json +++ b/.vscode/setting.json @@ -1,12 +1,19 @@ { "editor.formatOnSave": true, "editor.codeActionsOnSave": { - "source.fixAll": "explicit" + "source.fixAll": "explicit", + "source.organizeImports": "explicit" }, "editor.rulers": [ 100 ], "[python]": { "editor.defaultFormatter": "ms-python.black-formatter" - } + }, + "isort.args":[ + "--profile", + "black", + "--skip-glob", + "*/migrations/*" + ] } \ No newline at end of file From 4779e44d822f40a57806e3faec0aafbcc9b07c09 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Sat, 16 Aug 2025 12:39:54 +0530 Subject: [PATCH 37/60] Add instructions to setup isort --- README.md | 74 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 64 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 6ea91ea..1780d58 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ 4. Setup Django app -- Start Django app +- Start Django app ```sh python3 manage.py startapp @@ -87,9 +87,9 @@ 6. Run unit tests - ```sh - python3 manage.py test - ``` +```sh +python3 manage.py test +``` 7. Setup DRF(Django Rest Framework) @@ -102,7 +102,7 @@ - Add installed DRF package to requirements file ```sh - pip freeze | grep djangorestframework >> requirements.txt + pip freeze | grep djangorestframework >> requirements.txt ``` - Install DRF app in project setting @@ -125,7 +125,7 @@ - Add installed Coverage package to requirements file ```sh - pip freeze | grep coverage >> requirements.txt + pip freeze | grep coverage >> requirements.txt ``` - Run tests with coverage @@ -157,7 +157,7 @@ - Add installed mypy package to requirements file ```sh - pip freeze | grep mypy== >> requirements.txt + pip freeze | grep mypy== >> requirements.txt ``` - Install django stubs package @@ -169,7 +169,7 @@ - Add installed django stubs package to requirements file ```sh - pip freeze | grep django-stubs== >> requirements.txt + pip freeze | grep django-stubs== >> requirements.txt ``` - Install drf stubs package @@ -181,7 +181,7 @@ - Add installed drf stubs package to requirements file ```sh - pip freeze | grep djangorestframework-stubs >> requirements.txt + pip freeze | grep djangorestframework-stubs >> requirements.txt ``` - Add MyPy config file `mypy.init` @@ -214,7 +214,7 @@ - Add installed black package to requirements file ```sh - pip freeze | grep black >> requirements.txt + pip freeze | grep black >> requirements.txt ``` - Add black config in `puproject.toml` file @@ -226,8 +226,62 @@ - Note:- black official [doc](https://black.readthedocs.io/en/stable/getting_started.html) +- Install VS Code Black extension [`ms-python.black-formatter`](https://marketplace.visualstudio.com/items?itemName=ms-python.black-formatter) + +- Configure VS Code python default formatter to black in `.vscode/settings.json` file + + ```json + { + "[python]": { + "editor.defaultFormatter": "ms-python.black-formatter" + } + } + ``` + - Fix formatting using black ```sh black . ``` + +11. Setup isort + +- Install isort package + + ```sh + pip install isort + ``` + +- Add installed isort package to requirements file + + ```sh + pip freeze | grep isort >> requirements.txt + ``` + +- Add MyPy config file `isort.cfg` + + ```cfg + [settings] + profile = black + verbose = true + skip_glob = **/migrations/*.py + ``` + +- Install VS Code Black extension [`ms-python.isort`](https://marketplace.visualstudio.com/items?itemName=ms-python.isort) + +- Configure VS Code to organize python imports using isort in `.vscode/settings.json` + + ```json + { + "editor.codeActionsOnSave": { + "source.organizeImports": "explicit" + }, + "isort.args": ["--profile", "black", "--skip-glob", "*/migrations/*"] + } + ``` + +- Sort imports using isort + + ```sh + isort . + ``` From ea2a07482453340e4676eb8abcda0bcc31a71dd4 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Sat, 16 Aug 2025 12:40:13 +0530 Subject: [PATCH 38/60] Fix isort warning --- core/tests.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/tests.py b/core/tests.py index 9040659..9ed09c0 100644 --- a/core/tests.py +++ b/core/tests.py @@ -1,6 +1,8 @@ +from datetime import date + from django.test import TestCase + from .models import Student -from datetime import date # Create your tests here. From b6b4c2958ded0d0950aae05b30aa15724c362dfb Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Sat, 16 Aug 2025 17:54:11 +0530 Subject: [PATCH 39/60] Add pylint package in requirements file --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 4342b23..7732812 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,3 +6,4 @@ django-stubs==5.2.2 djangorestframework-stubs==3.16.1 black==25.1.0 isort==6.0.1 +pylint==3.3.7 From 134c3feeceea33663afb871ff9a8eabc493f115d Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Sat, 16 Aug 2025 17:54:19 +0530 Subject: [PATCH 40/60] Add pylint-django package in requirements file --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 7732812..0767be6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,3 +7,4 @@ djangorestframework-stubs==3.16.1 black==25.1.0 isort==6.0.1 pylint==3.3.7 +pylint-django==2.6.1 From 82b9e1bb7db0ca1e6074e640f61559c4dcea8270 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Sat, 16 Aug 2025 18:00:25 +0530 Subject: [PATCH 41/60] Add pylint config file --- .pylintrc | 643 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 643 insertions(+) create mode 100644 .pylintrc diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..cd7939a --- /dev/null +++ b/.pylintrc @@ -0,0 +1,643 @@ +[MAIN] + +# Analyse import fallback blocks. This can be used to support both Python 2 and +# 3 compatible code, which means that the block might have code that exists +# only in one or another interpreter, leading to false positives when analysed. +analyse-fallback-blocks=no + +# Clear in-memory caches upon conclusion of linting. Useful if running pylint +# in a server-like mode. +clear-cache-post-run=no + +# Load and enable all available extensions. Use --list-extensions to see a list +# all available extensions. +#enable-all-extensions= + +# In error mode, messages with a category besides ERROR or FATAL are +# suppressed, and no reports are done by default. Error mode is compatible with +# disabling specific errors. +#errors-only= + +# Always return a 0 (non-error) status code, even if lint errors are found. +# This is primarily useful in continuous integration scripts. +#exit-zero= + +# A comma-separated list of package or module names from where C extensions may +# be loaded. Extensions are loading into the active Python interpreter and may +# run arbitrary code. +extension-pkg-allow-list= + +# A comma-separated list of package or module names from where C extensions may +# be loaded. Extensions are loading into the active Python interpreter and may +# run arbitrary code. (This is an alternative name to extension-pkg-allow-list +# for backward compatibility.) +extension-pkg-whitelist= + +# Return non-zero exit code if any of these messages/categories are detected, +# even if score is above --fail-under value. Syntax same as enable. Messages +# specified are enabled, while categories only check already-enabled messages. +fail-on= + +# Specify a score threshold under which the program will exit with error. +fail-under=10 + +# Interpret the stdin as a python script, whose filename needs to be passed as +# the module_or_package argument. +#from-stdin= + +# Files or directories to be skipped. They should be base names, not paths. +ignore=CVS + +# Add files or directories matching the regular expressions patterns to the +# ignore-list. The regex matches against paths and can be in Posix or Windows +# format. Because '\\' represents the directory delimiter on Windows systems, +# it can't be used as an escape character. +ignore-paths=.*/migrations + +# Files or directories matching the regular expression patterns are skipped. +# The regex matches against base names, not paths. The default value ignores +# Emacs file locks +ignore-patterns=^\.# + +# List of module names for which member attributes should not be checked +# (useful for modules/projects where namespaces are manipulated during runtime +# and thus existing member attributes cannot be deduced by static analysis). It +# supports qualified module names, as well as Unix pattern matching. +ignored-modules= + +# Python code to execute, usually for sys.path manipulation such as +# pygtk.require(). +#init-hook= + +# Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the +# number of processors available to use, and will cap the count on Windows to +# avoid hangs. +jobs=1 + +# Control the amount of potential inferred values when inferring a single +# object. This can help the performance when dealing with large functions or +# complex, nested conditions. +limit-inference-results=100 + +# List of plugins (as comma separated values of python module names) to load, +# usually to register additional checkers. +load-plugins=pylint_django + +# Pickle collected data for later comparisons. +persistent=yes + +# Minimum Python version to use for version dependent checks. Will default to +# the version used to run pylint. +py-version=3.10 + +# Discover python modules and packages in the file system subtree. +recursive=no + +# Add paths to the list of the source roots. Supports globbing patterns. The +# source root is an absolute path or a path relative to the current working +# directory used to determine a package namespace for modules located under the +# source root. +source-roots= + +# When enabled, pylint would attempt to guess common misconfiguration and emit +# user-friendly hints instead of false-positive error messages. +suggestion-mode=yes + +# Allow loading of arbitrary C extensions. Extensions are imported into the +# active Python interpreter and may run arbitrary code. +unsafe-load-any-extension=no + +# In verbose mode, extra non-checker-related info will be displayed. +#verbose= + + +[BASIC] + +# Naming style matching correct argument names. +argument-naming-style=snake_case + +# Regular expression matching correct argument names. Overrides argument- +# naming-style. If left empty, argument names will be checked with the set +# naming style. +#argument-rgx= + +# Naming style matching correct attribute names. +attr-naming-style=snake_case + +# Regular expression matching correct attribute names. Overrides attr-naming- +# style. If left empty, attribute names will be checked with the set naming +# style. +#attr-rgx= + +# Bad variable names which should always be refused, separated by a comma. +bad-names=foo, + bar, + baz, + toto, + tutu, + tata + +# Bad variable names regexes, separated by a comma. If names match any regex, +# they will always be refused +bad-names-rgxs= + +# Naming style matching correct class attribute names. +class-attribute-naming-style=any + +# Regular expression matching correct class attribute names. Overrides class- +# attribute-naming-style. If left empty, class attribute names will be checked +# with the set naming style. +#class-attribute-rgx= + +# Naming style matching correct class constant names. +class-const-naming-style=UPPER_CASE + +# Regular expression matching correct class constant names. Overrides class- +# const-naming-style. If left empty, class constant names will be checked with +# the set naming style. +#class-const-rgx= + +# Naming style matching correct class names. +class-naming-style=PascalCase + +# Regular expression matching correct class names. Overrides class-naming- +# style. If left empty, class names will be checked with the set naming style. +#class-rgx= + +# Naming style matching correct constant names. +const-naming-style=UPPER_CASE + +# Regular expression matching correct constant names. Overrides const-naming- +# style. If left empty, constant names will be checked with the set naming +# style. +#const-rgx= + +# Minimum line length for functions/classes that require docstrings, shorter +# ones are exempt. +docstring-min-length=-1 + +# Naming style matching correct function names. +function-naming-style=snake_case + +# Regular expression matching correct function names. Overrides function- +# naming-style. If left empty, function names will be checked with the set +# naming style. +#function-rgx= + +# Good variable names which should always be accepted, separated by a comma. +good-names=i, + j, + k, + ex, + Run, + _ + +# Good variable names regexes, separated by a comma. If names match any regex, +# they will always be accepted +good-names-rgxs= + +# Include a hint for the correct naming format with invalid-name. +include-naming-hint=no + +# Naming style matching correct inline iteration names. +inlinevar-naming-style=any + +# Regular expression matching correct inline iteration names. Overrides +# inlinevar-naming-style. If left empty, inline iteration names will be checked +# with the set naming style. +#inlinevar-rgx= + +# Naming style matching correct method names. +method-naming-style=snake_case + +# Regular expression matching correct method names. Overrides method-naming- +# style. If left empty, method names will be checked with the set naming style. +#method-rgx= + +# Naming style matching correct module names. +module-naming-style=snake_case + +# Regular expression matching correct module names. Overrides module-naming- +# style. If left empty, module names will be checked with the set naming style. +#module-rgx= + +# Colon-delimited sets of names that determine each other's naming style when +# the name regexes allow several styles. +name-group= + +# Regular expression which should only match function or class names that do +# not require a docstring. +no-docstring-rgx=^_ + +# List of decorators that produce properties, such as abc.abstractproperty. Add +# to this list to register other decorators that produce valid properties. +# These decorators are taken in consideration only for invalid-name. +property-classes=abc.abstractproperty + +# Regular expression matching correct type alias names. If left empty, type +# alias names will be checked with the set naming style. +#typealias-rgx= + +# Regular expression matching correct type variable names. If left empty, type +# variable names will be checked with the set naming style. +#typevar-rgx= + +# Naming style matching correct variable names. +variable-naming-style=snake_case + +# Regular expression matching correct variable names. Overrides variable- +# naming-style. If left empty, variable names will be checked with the set +# naming style. +#variable-rgx= + + +[CLASSES] + +# Warn about protected attribute access inside special methods +check-protected-access-in-special-methods=no + +# List of method names used to declare (i.e. assign) instance attributes. +defining-attr-methods=__init__, + __new__, + setUp, + asyncSetUp, + __post_init__ + +# List of member names, which should be excluded from the protected access +# warning. +exclude-protected=_asdict,_fields,_replace,_source,_make,os._exit + +# List of valid names for the first argument in a class method. +valid-classmethod-first-arg=cls + +# List of valid names for the first argument in a metaclass class method. +valid-metaclass-classmethod-first-arg=mcs + + +[DESIGN] + +# List of regular expressions of class ancestor names to ignore when counting +# public methods (see R0903) +exclude-too-few-public-methods= + +# List of qualified class names to ignore when counting class parents (see +# R0901) +ignored-parents= + +# Maximum number of arguments for function / method. +max-args=5 + +# Maximum number of attributes for a class (see R0902). +max-attributes=7 + +# Maximum number of boolean expressions in an if statement (see R0916). +max-bool-expr=5 + +# Maximum number of branch for function / method body. +max-branches=12 + +# Maximum number of locals for function / method body. +max-locals=15 + +# Maximum number of parents for a class (see R0901). +max-parents=7 + +# Maximum number of public methods for a class (see R0904). +max-public-methods=20 + +# Maximum number of return / yield for function / method body. +max-returns=6 + +# Maximum number of statements in function / method body. +max-statements=50 + +# Minimum number of public methods for a class (see R0903). +min-public-methods=2 + + +[EXCEPTIONS] + +# Exceptions that will emit a warning when caught. +overgeneral-exceptions=builtins.BaseException,builtins.Exception + + +[FORMAT] + +# Expected format of line ending, e.g. empty (any line ending), LF or CRLF. +expected-line-ending-format= + +# Regexp for a line that is allowed to be longer than the limit. +ignore-long-lines=^\s*(# )??$ + +# Number of spaces of indent required inside a hanging or continued line. +indent-after-paren=4 + +# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 +# tab). +indent-string=' ' + +# Maximum number of characters on a single line. +max-line-length=100 + +# Maximum number of lines in a module. +max-module-lines=1000 + +# Allow the body of a class to be on the same line as the declaration if body +# contains single statement. +single-line-class-stmt=no + +# Allow the body of an if to be on the same line as the test if there is no +# else. +single-line-if-stmt=no + + +[IMPORTS] + +# List of modules that can be imported at any level, not just the top level +# one. +allow-any-import-level= + +# Allow explicit reexports by alias from a package __init__. +allow-reexport-from-package=no + +# Allow wildcard imports from modules that define __all__. +allow-wildcard-with-all=no + +# Deprecated modules which should not be used, separated by a comma. +deprecated-modules= + +# Output a graph (.gv or any supported image format) of external dependencies +# to the given file (report RP0402 must not be disabled). +ext-import-graph= + +# Output a graph (.gv or any supported image format) of all (i.e. internal and +# external) dependencies to the given file (report RP0402 must not be +# disabled). +import-graph= + +# Output a graph (.gv or any supported image format) of internal dependencies +# to the given file (report RP0402 must not be disabled). +int-import-graph= + +# Force import order to recognize a module as part of the standard +# compatibility libraries. +known-standard-library= + +# Force import order to recognize a module as part of a third party library. +known-third-party=enchant + +# Couples of modules and preferred modules, separated by a comma. +preferred-modules= + + +[LOGGING] + +# The type of string formatting that logging methods do. `old` means using % +# formatting, `new` is for `{}` formatting. +logging-format-style=old + +# Logging modules to check that the string format arguments are in logging +# function parameter format. +logging-modules=logging + + +[MESSAGES CONTROL] + +# Only show warnings with the listed confidence levels. Leave empty to show +# all. Valid levels: HIGH, CONTROL_FLOW, INFERENCE, INFERENCE_FAILURE, +# UNDEFINED. +confidence=HIGH, + CONTROL_FLOW, + INFERENCE, + INFERENCE_FAILURE, + UNDEFINED + +# Disable the message, report, category or checker with the given id(s). You +# can either give multiple identifiers separated by comma (,) or put this +# option multiple times (only on the command line, not in the configuration +# file where it should appear only once). You can also use "--disable=all" to +# disable everything first and then re-enable specific checks. For example, if +# you want to run only the similarities checker, you can use "--disable=all +# --enable=similarities". If you want to run only the classes checker, but have +# no Warning level messages displayed, use "--disable=all --enable=classes +# --disable=W". +disable=raw-checker-failed, + bad-inline-option, + locally-disabled, + file-ignored, + suppressed-message, + useless-suppression, + deprecated-pragma, + use-symbolic-message-instead, + use-implicit-booleaness-not-comparison-to-string, + use-implicit-booleaness-not-comparison-to-zero, + missing-module-docstring, + import-outside-toplevel, + fixme + + +# Enable the message, report, category or checker with the given id(s). You can +# either give multiple identifier separated by comma (,) or put this option +# multiple time (only on the command line, not in the configuration file where +# it should appear only once). See also the "--disable" option for examples. +enable= + + +[METHOD_ARGS] + +# List of qualified names (i.e., library.method) which require a timeout +# parameter e.g. 'requests.api.get,requests.api.post' +timeout-methods=requests.api.delete,requests.api.get,requests.api.head,requests.api.options,requests.api.patch,requests.api.post,requests.api.put,requests.api.request + + +[MISCELLANEOUS] + +# List of note tags to take in consideration, separated by a comma. +notes=FIXME, + XXX, + TODO + +# Regular expression of note tags to take in consideration. +notes-rgx= + + +[REFACTORING] + +# Maximum number of nested blocks for function / method body +max-nested-blocks=5 + +# Complete name of functions that never returns. When checking for +# inconsistent-return-statements if a never returning function is called then +# it will be considered as an explicit return statement and no message will be +# printed. +never-returning-functions=sys.exit,argparse.parse_error + + +[REPORTS] + +# Python expression which should return a score less than or equal to 10. You +# have access to the variables 'fatal', 'error', 'warning', 'refactor', +# 'convention', and 'info' which contain the number of messages in each +# category, as well as 'statement' which is the total number of statements +# analyzed. This score is used by the global evaluation report (RP0004). +evaluation=max(0, 0 if fatal else 10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)) + +# Template used to display messages. This is a python new-style format string +# used to format the message information. See doc for all details. +msg-template= + +# Set the output format. Available formats are: text, parseable, colorized, +# json2 (improved json format), json (old json format) and msvs (visual +# studio). You can also give a reporter class, e.g. +# mypackage.mymodule.MyReporterClass. +#output-format= + +# Tells whether to display a full report or only the messages. +reports=no + +# Activate the evaluation score. +score=yes + + +[SIMILARITIES] + +# Comments are removed from the similarity computation +ignore-comments=yes + +# Docstrings are removed from the similarity computation +ignore-docstrings=yes + +# Imports are removed from the similarity computation +ignore-imports=yes + +# Signatures are removed from the similarity computation +ignore-signatures=yes + +# Minimum lines number of a similarity. +min-similarity-lines=4 + + +[SPELLING] + +# Limits count of emitted suggestions for spelling mistakes. +max-spelling-suggestions=4 + +# Spelling dictionary name. No available dictionaries : You need to install +# both the python package and the system dependency for enchant to work. +spelling-dict= + +# List of comma separated words that should be considered directives if they +# appear at the beginning of a comment and should not be checked. +spelling-ignore-comment-directives=fmt: on,fmt: off,noqa:,noqa,nosec,isort:skip,mypy: + +# List of comma separated words that should not be checked. +spelling-ignore-words= + +# A path to a file that contains the private dictionary; one word per line. +spelling-private-dict-file= + +# Tells whether to store unknown words to the private dictionary (see the +# --spelling-private-dict-file option) instead of raising a message. +spelling-store-unknown-words=no + + +[STRING] + +# This flag controls whether inconsistent-quotes generates a warning when the +# character used as a quote delimiter is used inconsistently within a module. +check-quote-consistency=no + +# This flag controls whether the implicit-str-concat should generate a warning +# on implicit string concatenation in sequences defined over several lines. +check-str-concat-over-line-jumps=no + + +[TYPECHECK] + +# List of decorators that produce context managers, such as +# contextlib.contextmanager. Add to this list to register other decorators that +# produce valid context managers. +contextmanager-decorators=contextlib.contextmanager + +# List of members which are set dynamically and missed by pylint inference +# system, and so shouldn't trigger E1101 when accessed. Python regular +# expressions are accepted. +generated-members= + +# Tells whether to warn about missing members when the owner of the attribute +# is inferred to be None. +ignore-none=yes + +# This flag controls whether pylint should warn about no-member and similar +# checks whenever an opaque object is returned when inferring. The inference +# can return multiple potential results while evaluating a Python object, but +# some branches might not be evaluated, which results in partial inference. In +# that case, it might be useful to still emit no-member and other checks for +# the rest of the inferred objects. +ignore-on-opaque-inference=yes + +# List of symbolic message names to ignore for Mixin members. +ignored-checks-for-mixins=no-member, + not-async-context-manager, + not-context-manager, + attribute-defined-outside-init + +# List of class names for which member attributes should not be checked (useful +# for classes with dynamically set attributes). This supports the use of +# qualified names. +ignored-classes=optparse.Values,thread._local,_thread._local,argparse.Namespace + +# Show a hint with possible names when a member name was not found. The aspect +# of finding the hint is based on edit distance. +missing-member-hint=yes + +# The minimum edit distance a name should have in order to be considered a +# similar match for a missing member name. +missing-member-hint-distance=1 + +# The total number of similar names that should be taken in consideration when +# showing a hint for a missing member. +missing-member-max-choices=1 + +# Regex pattern to define which classes are considered mixins. +mixin-class-rgx=.*[Mm]ixin + +# List of decorators that change the signature of a decorated function. +signature-mutators= + + +[VARIABLES] + +# List of additional names supposed to be defined in builtins. Remember that +# you should avoid defining new builtins when possible. +additional-builtins= + +# Tells whether unused global variables should be treated as a violation. +allow-global-unused-variables=yes + +# List of names allowed to shadow builtins +allowed-redefined-builtins= + +# List of strings which can identify a callback function by name. A callback +# name must start or end with one of those strings. +callbacks=cb_, + _cb + +# A regular expression matching the name of dummy variables (i.e. expected to +# not be used). +dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_ + +# Argument names that match this expression will be ignored. +ignored-argument-names=_.*|^ignored_|^unused_ + +# Tells whether we should check for unused import in __init__ files. +init-import=no + +# List of qualified module names which can have objects that can redefine +# builtins. +redefining-builtins-modules=six.moves,past.builtins,future.builtins,builtins,io + + +# pylint_django configuration +[pylint-django] +django-settings-module=backend.settings From 352967efe0bcd7e30ebdb7e933fab5d2856a38c4 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Sat, 16 Aug 2025 18:24:01 +0530 Subject: [PATCH 42/60] Add instructions to setup pylint --- README.md | 689 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 686 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1780d58..98f440d 100644 --- a/README.md +++ b/README.md @@ -192,7 +192,7 @@ python3 manage.py test exclude = migrations|tests [mypy.plugins.django-stubs] - django_settings_module = ".settings" + django_settings_module = ".settings" ``` - Note:- config file [doc](https://mypy.readthedocs.io/en/latest/config_file.html) @@ -258,7 +258,7 @@ python3 manage.py test pip freeze | grep isort >> requirements.txt ``` -- Add MyPy config file `isort.cfg` +- Add isort config file `isort.cfg` ```cfg [settings] @@ -267,13 +267,14 @@ python3 manage.py test skip_glob = **/migrations/*.py ``` -- Install VS Code Black extension [`ms-python.isort`](https://marketplace.visualstudio.com/items?itemName=ms-python.isort) +- Install VS Code isort extension [`ms-python.isort`](https://marketplace.visualstudio.com/items?itemName=ms-python.isort) - Configure VS Code to organize python imports using isort in `.vscode/settings.json` ```json { "editor.codeActionsOnSave": { + "source.unusedImports": "explicit", "source.organizeImports": "explicit" }, "isort.args": ["--profile", "black", "--skip-glob", "*/migrations/*"] @@ -285,3 +286,685 @@ python3 manage.py test ```sh isort . ``` + +12. Setup pylint + +- Install pylint package + + ```sh + pip install pylint + ``` + +- Add installed pylint package to requirements file + + ```sh + pip freeze | grep pylint== >> requirements.txt + ``` + +- Install pylint-django package + + ```sh + pip install pylint-django + ``` + +- Add installed pylint-django package to requirements file + + ```sh + pip freeze | grep pylint-django >> requirements.txt + ``` + +- Add pylint config file `.pylintrc` + + ```pylintrc + [MAIN] + + # Analyse import fallback blocks. This can be used to support both Python 2 and + # 3 compatible code, which means that the block might have code that exists + # only in one or another interpreter, leading to false positives when analysed. + analyse-fallback-blocks=no + + # Clear in-memory caches upon conclusion of linting. Useful if running pylint + # in a server-like mode. + clear-cache-post-run=no + + # Load and enable all available extensions. Use --list-extensions to see a list + # all available extensions. + #enable-all-extensions= + + # In error mode, messages with a category besides ERROR or FATAL are + # suppressed, and no reports are done by default. Error mode is compatible with + # disabling specific errors. + #errors-only= + + # Always return a 0 (non-error) status code, even if lint errors are found. + # This is primarily useful in continuous integration scripts. + #exit-zero= + + # A comma-separated list of package or module names from where C extensions may + # be loaded. Extensions are loading into the active Python interpreter and may + # run arbitrary code. + extension-pkg-allow-list= + + # A comma-separated list of package or module names from where C extensions may + # be loaded. Extensions are loading into the active Python interpreter and may + # run arbitrary code. (This is an alternative name to extension-pkg-allow-list + # for backward compatibility.) + extension-pkg-whitelist= + + # Return non-zero exit code if any of these messages/categories are detected, + # even if score is above --fail-under value. Syntax same as enable. Messages + # specified are enabled, while categories only check already-enabled messages. + fail-on= + + # Specify a score threshold under which the program will exit with error. + fail-under=10 + + # Interpret the stdin as a python script, whose filename needs to be passed as + # the module_or_package argument. + #from-stdin= + + # Files or directories to be skipped. They should be base names, not paths. + ignore=CVS + + # Add files or directories matching the regular expressions patterns to the + # ignore-list. The regex matches against paths and can be in Posix or Windows + # format. Because '\\' represents the directory delimiter on Windows systems, + # it can't be used as an escape character. + ignore-paths=.*/migrations + + # Files or directories matching the regular expression patterns are skipped. + # The regex matches against base names, not paths. The default value ignores + # Emacs file locks + ignore-patterns=^\.# + + # List of module names for which member attributes should not be checked + # (useful for modules/projects where namespaces are manipulated during runtime + # and thus existing member attributes cannot be deduced by static analysis). It + # supports qualified module names, as well as Unix pattern matching. + ignored-modules= + + # Python code to execute, usually for sys.path manipulation such as + # pygtk.require(). + #init-hook= + + # Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the + # number of processors available to use, and will cap the count on Windows to + # avoid hangs. + jobs=1 + + # Control the amount of potential inferred values when inferring a single + # object. This can help the performance when dealing with large functions or + # complex, nested conditions. + limit-inference-results=100 + + # List of plugins (as comma separated values of python module names) to load, + # usually to register additional checkers. + load-plugins=pylint_django + + # Pickle collected data for later comparisons. + persistent=yes + + # Minimum Python version to use for version dependent checks. Will default to + # the version used to run pylint. + py-version=3.10 + + # Discover python modules and packages in the file system subtree. + recursive=no + + # Add paths to the list of the source roots. Supports globbing patterns. The + # source root is an absolute path or a path relative to the current working + # directory used to determine a package namespace for modules located under the + # source root. + source-roots= + + # When enabled, pylint would attempt to guess common misconfiguration and emit + # user-friendly hints instead of false-positive error messages. + suggestion-mode=yes + + # Allow loading of arbitrary C extensions. Extensions are imported into the + # active Python interpreter and may run arbitrary code. + unsafe-load-any-extension=no + + # In verbose mode, extra non-checker-related info will be displayed. + #verbose= + + + [BASIC] + + # Naming style matching correct argument names. + argument-naming-style=snake_case + + # Regular expression matching correct argument names. Overrides argument- + # naming-style. If left empty, argument names will be checked with the set + # naming style. + #argument-rgx= + + # Naming style matching correct attribute names. + attr-naming-style=snake_case + + # Regular expression matching correct attribute names. Overrides attr-naming- + # style. If left empty, attribute names will be checked with the set naming + # style. + #attr-rgx= + + # Bad variable names which should always be refused, separated by a comma. + bad-names=foo, + bar, + baz, + toto, + tutu, + tata + + # Bad variable names regexes, separated by a comma. If names match any regex, + # they will always be refused + bad-names-rgxs= + + # Naming style matching correct class attribute names. + class-attribute-naming-style=any + + # Regular expression matching correct class attribute names. Overrides class- + # attribute-naming-style. If left empty, class attribute names will be checked + # with the set naming style. + #class-attribute-rgx= + + # Naming style matching correct class constant names. + class-const-naming-style=UPPER_CASE + + # Regular expression matching correct class constant names. Overrides class- + # const-naming-style. If left empty, class constant names will be checked with + # the set naming style. + #class-const-rgx= + + # Naming style matching correct class names. + class-naming-style=PascalCase + + # Regular expression matching correct class names. Overrides class-naming- + # style. If left empty, class names will be checked with the set naming style. + #class-rgx= + + # Naming style matching correct constant names. + const-naming-style=UPPER_CASE + + # Regular expression matching correct constant names. Overrides const-naming- + # style. If left empty, constant names will be checked with the set naming + # style. + #const-rgx= + + # Minimum line length for functions/classes that require docstrings, shorter + # ones are exempt. + docstring-min-length=-1 + + # Naming style matching correct function names. + function-naming-style=snake_case + + # Regular expression matching correct function names. Overrides function- + # naming-style. If left empty, function names will be checked with the set + # naming style. + #function-rgx= + + # Good variable names which should always be accepted, separated by a comma. + good-names=i, + j, + k, + ex, + Run, + _ + + # Good variable names regexes, separated by a comma. If names match any regex, + # they will always be accepted + good-names-rgxs= + + # Include a hint for the correct naming format with invalid-name. + include-naming-hint=no + + # Naming style matching correct inline iteration names. + inlinevar-naming-style=any + + # Regular expression matching correct inline iteration names. Overrides + # inlinevar-naming-style. If left empty, inline iteration names will be checked + # with the set naming style. + #inlinevar-rgx= + + # Naming style matching correct method names. + method-naming-style=snake_case + + # Regular expression matching correct method names. Overrides method-naming- + # style. If left empty, method names will be checked with the set naming style. + #method-rgx= + + # Naming style matching correct module names. + module-naming-style=snake_case + + # Regular expression matching correct module names. Overrides module-naming- + # style. If left empty, module names will be checked with the set naming style. + #module-rgx= + + # Colon-delimited sets of names that determine each other's naming style when + # the name regexes allow several styles. + name-group= + + # Regular expression which should only match function or class names that do + # not require a docstring. + no-docstring-rgx=^_ + + # List of decorators that produce properties, such as abc.abstractproperty. Add + # to this list to register other decorators that produce valid properties. + # These decorators are taken in consideration only for invalid-name. + property-classes=abc.abstractproperty + + # Regular expression matching correct type alias names. If left empty, type + # alias names will be checked with the set naming style. + #typealias-rgx= + + # Regular expression matching correct type variable names. If left empty, type + # variable names will be checked with the set naming style. + #typevar-rgx= + + # Naming style matching correct variable names. + variable-naming-style=snake_case + + # Regular expression matching correct variable names. Overrides variable- + # naming-style. If left empty, variable names will be checked with the set + # naming style. + #variable-rgx= + + + [CLASSES] + + # Warn about protected attribute access inside special methods + check-protected-access-in-special-methods=no + + # List of method names used to declare (i.e. assign) instance attributes. + defining-attr-methods=__init__, + __new__, + setUp, + asyncSetUp, + __post_init__ + + # List of member names, which should be excluded from the protected access + # warning. + exclude-protected=_asdict,_fields,_replace,_source,_make,os._exit + + # List of valid names for the first argument in a class method. + valid-classmethod-first-arg=cls + + # List of valid names for the first argument in a metaclass class method. + valid-metaclass-classmethod-first-arg=mcs + + + [DESIGN] + + # List of regular expressions of class ancestor names to ignore when counting + # public methods (see R0903) + exclude-too-few-public-methods= + + # List of qualified class names to ignore when counting class parents (see + # R0901) + ignored-parents= + + # Maximum number of arguments for function / method. + max-args=5 + + # Maximum number of attributes for a class (see R0902). + max-attributes=7 + + # Maximum number of boolean expressions in an if statement (see R0916). + max-bool-expr=5 + + # Maximum number of branch for function / method body. + max-branches=12 + + # Maximum number of locals for function / method body. + max-locals=15 + + # Maximum number of parents for a class (see R0901). + max-parents=7 + + # Maximum number of public methods for a class (see R0904). + max-public-methods=20 + + # Maximum number of return / yield for function / method body. + max-returns=6 + + # Maximum number of statements in function / method body. + max-statements=50 + + # Minimum number of public methods for a class (see R0903). + min-public-methods=2 + + + [EXCEPTIONS] + + # Exceptions that will emit a warning when caught. + overgeneral-exceptions=builtins.BaseException,builtins.Exception + + + [FORMAT] + + # Expected format of line ending, e.g. empty (any line ending), LF or CRLF. + expected-line-ending-format= + + # Regexp for a line that is allowed to be longer than the limit. + ignore-long-lines=^\s*(# )??$ + + # Number of spaces of indent required inside a hanging or continued line. + indent-after-paren=4 + + # String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 + # tab). + indent-string=' ' + + # Maximum number of characters on a single line. + max-line-length=100 + + # Maximum number of lines in a module. + max-module-lines=1000 + + # Allow the body of a class to be on the same line as the declaration if body + # contains single statement. + single-line-class-stmt=no + + # Allow the body of an if to be on the same line as the test if there is no + # else. + single-line-if-stmt=no + + + [IMPORTS] + + # List of modules that can be imported at any level, not just the top level + # one. + allow-any-import-level= + + # Allow explicit reexports by alias from a package __init__. + allow-reexport-from-package=no + + # Allow wildcard imports from modules that define __all__. + allow-wildcard-with-all=no + + # Deprecated modules which should not be used, separated by a comma. + deprecated-modules= + + # Output a graph (.gv or any supported image format) of external dependencies + # to the given file (report RP0402 must not be disabled). + ext-import-graph= + + # Output a graph (.gv or any supported image format) of all (i.e. internal and + # external) dependencies to the given file (report RP0402 must not be + # disabled). + import-graph= + + # Output a graph (.gv or any supported image format) of internal dependencies + # to the given file (report RP0402 must not be disabled). + int-import-graph= + + # Force import order to recognize a module as part of the standard + # compatibility libraries. + known-standard-library= + + # Force import order to recognize a module as part of a third party library. + known-third-party=enchant + + # Couples of modules and preferred modules, separated by a comma. + preferred-modules= + + + [LOGGING] + + # The type of string formatting that logging methods do. `old` means using % + # formatting, `new` is for `{}` formatting. + logging-format-style=old + + # Logging modules to check that the string format arguments are in logging + # function parameter format. + logging-modules=logging + + + [MESSAGES CONTROL] + + # Only show warnings with the listed confidence levels. Leave empty to show + # all. Valid levels: HIGH, CONTROL_FLOW, INFERENCE, INFERENCE_FAILURE, + # UNDEFINED. + confidence=HIGH, + CONTROL_FLOW, + INFERENCE, + INFERENCE_FAILURE, + UNDEFINED + + # Disable the message, report, category or checker with the given id(s). You + # can either give multiple identifiers separated by comma (,) or put this + # option multiple times (only on the command line, not in the configuration + # file where it should appear only once). You can also use "--disable=all" to + # disable everything first and then re-enable specific checks. For example, if + # you want to run only the similarities checker, you can use "--disable=all + # --enable=similarities". If you want to run only the classes checker, but have + # no Warning level messages displayed, use "--disable=all --enable=classes + # --disable=W". + disable=raw-checker-failed, + bad-inline-option, + locally-disabled, + file-ignored, + suppressed-message, + useless-suppression, + deprecated-pragma, + use-symbolic-message-instead, + use-implicit-booleaness-not-comparison-to-string, + use-implicit-booleaness-not-comparison-to-zero, + missing-module-docstring, + import-outside-toplevel, + fixme + + + # Enable the message, report, category or checker with the given id(s). You can + # either give multiple identifier separated by comma (,) or put this option + # multiple time (only on the command line, not in the configuration file where + # it should appear only once). See also the "--disable" option for examples. + enable= + + + [METHOD_ARGS] + + # List of qualified names (i.e., library.method) which require a timeout + # parameter e.g. 'requests.api.get,requests.api.post' + timeout-methods=requests.api.delete,requests.api.get,requests.api.head,requests.api.options,requests.api.patch,requests.api.post,requests.api.put,requests.api.request + + + [MISCELLANEOUS] + + # List of note tags to take in consideration, separated by a comma. + notes=FIXME, + XXX, + TODO + + # Regular expression of note tags to take in consideration. + notes-rgx= + + + [REFACTORING] + + # Maximum number of nested blocks for function / method body + max-nested-blocks=5 + + # Complete name of functions that never returns. When checking for + # inconsistent-return-statements if a never returning function is called then + # it will be considered as an explicit return statement and no message will be + # printed. + never-returning-functions=sys.exit,argparse.parse_error + + + [REPORTS] + + # Python expression which should return a score less than or equal to 10. You + # have access to the variables 'fatal', 'error', 'warning', 'refactor', + # 'convention', and 'info' which contain the number of messages in each + # category, as well as 'statement' which is the total number of statements + # analyzed. This score is used by the global evaluation report (RP0004). + evaluation=max(0, 0 if fatal else 10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)) + + # Template used to display messages. This is a python new-style format string + # used to format the message information. See doc for all details. + msg-template= + + # Set the output format. Available formats are: text, parseable, colorized, + # json2 (improved json format), json (old json format) and msvs (visual + # studio). You can also give a reporter class, e.g. + # mypackage.mymodule.MyReporterClass. + #output-format= + + # Tells whether to display a full report or only the messages. + reports=no + + # Activate the evaluation score. + score=yes + + + [SIMILARITIES] + + # Comments are removed from the similarity computation + ignore-comments=yes + + # Docstrings are removed from the similarity computation + ignore-docstrings=yes + + # Imports are removed from the similarity computation + ignore-imports=yes + + # Signatures are removed from the similarity computation + ignore-signatures=yes + + # Minimum lines number of a similarity. + min-similarity-lines=4 + + + [SPELLING] + + # Limits count of emitted suggestions for spelling mistakes. + max-spelling-suggestions=4 + + # Spelling dictionary name. No available dictionaries : You need to install + # both the python package and the system dependency for enchant to work. + spelling-dict= + + # List of comma separated words that should be considered directives if they + # appear at the beginning of a comment and should not be checked. + spelling-ignore-comment-directives=fmt: on,fmt: off,noqa:,noqa,nosec,isort:skip,mypy: + + # List of comma separated words that should not be checked. + spelling-ignore-words= + + # A path to a file that contains the private dictionary; one word per line. + spelling-private-dict-file= + + # Tells whether to store unknown words to the private dictionary (see the + # --spelling-private-dict-file option) instead of raising a message. + spelling-store-unknown-words=no + + + [STRING] + + # This flag controls whether inconsistent-quotes generates a warning when the + # character used as a quote delimiter is used inconsistently within a module. + check-quote-consistency=no + + # This flag controls whether the implicit-str-concat should generate a warning + # on implicit string concatenation in sequences defined over several lines. + check-str-concat-over-line-jumps=no + + + [TYPECHECK] + + # List of decorators that produce context managers, such as + # contextlib.contextmanager. Add to this list to register other decorators that + # produce valid context managers. + contextmanager-decorators=contextlib.contextmanager + + # List of members which are set dynamically and missed by pylint inference + # system, and so shouldn't trigger E1101 when accessed. Python regular + # expressions are accepted. + generated-members= + + # Tells whether to warn about missing members when the owner of the attribute + # is inferred to be None. + ignore-none=yes + + # This flag controls whether pylint should warn about no-member and similar + # checks whenever an opaque object is returned when inferring. The inference + # can return multiple potential results while evaluating a Python object, but + # some branches might not be evaluated, which results in partial inference. In + # that case, it might be useful to still emit no-member and other checks for + # the rest of the inferred objects. + ignore-on-opaque-inference=yes + + # List of symbolic message names to ignore for Mixin members. + ignored-checks-for-mixins=no-member, + not-async-context-manager, + not-context-manager, + attribute-defined-outside-init + + # List of class names for which member attributes should not be checked (useful + # for classes with dynamically set attributes). This supports the use of + # qualified names. + ignored-classes=optparse.Values,thread._local,_thread._local,argparse.Namespace + + # Show a hint with possible names when a member name was not found. The aspect + # of finding the hint is based on edit distance. + missing-member-hint=yes + + # The minimum edit distance a name should have in order to be considered a + # similar match for a missing member name. + missing-member-hint-distance=1 + + # The total number of similar names that should be taken in consideration when + # showing a hint for a missing member. + missing-member-max-choices=1 + + # Regex pattern to define which classes are considered mixins. + mixin-class-rgx=.*[Mm]ixin + + # List of decorators that change the signature of a decorated function. + signature-mutators= + + + [VARIABLES] + + # List of additional names supposed to be defined in builtins. Remember that + # you should avoid defining new builtins when possible. + additional-builtins= + + # Tells whether unused global variables should be treated as a violation. + allow-global-unused-variables=yes + + # List of names allowed to shadow builtins + allowed-redefined-builtins= + + # List of strings which can identify a callback function by name. A callback + # name must start or end with one of those strings. + callbacks=cb_, + _cb + + # A regular expression matching the name of dummy variables (i.e. expected to + # not be used). + dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_ + + # Argument names that match this expression will be ignored. + ignored-argument-names=_.*|^ignored_|^unused_ + + # Tells whether we should check for unused import in __init__ files. + init-import=no + + # List of qualified module names which can have objects that can redefine + # builtins. + redefining-builtins-modules=six.moves,past.builtins,future.builtins,builtins,io + + + # pylint_django configuration + [pylint-django] + django-settings-module=.settings + ``` + +- Run pylint for code quality checks + + ```sh + pylint **/*.py + ``` + +- Install VS Code pylint extension [`ms-python.pylint`](https://marketplace.visualstudio.com/items?itemName=ms-python.pylint) From ed0ae85afbd0ca1392c090de1ec3cf2b0c71a50e Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Sat, 16 Aug 2025 18:24:24 +0530 Subject: [PATCH 43/60] Fix pylint warning --- core/admin.py | 3 --- core/apps.py | 2 ++ core/tests.py | 4 ++-- core/views.py | 3 --- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/core/admin.py b/core/admin.py index 8c38f3f..e69de29 100644 --- a/core/admin.py +++ b/core/admin.py @@ -1,3 +0,0 @@ -from django.contrib import admin - -# Register your models here. diff --git a/core/apps.py b/core/apps.py index c0ce093..cd57cce 100644 --- a/core/apps.py +++ b/core/apps.py @@ -2,5 +2,7 @@ class CoreConfig(AppConfig): + """Core app config""" + default_auto_field = "django.db.models.BigAutoField" name = "core" diff --git a/core/tests.py b/core/tests.py index 9ed09c0..55f4993 100644 --- a/core/tests.py +++ b/core/tests.py @@ -1,5 +1,3 @@ -from datetime import date - from django.test import TestCase from .models import Student @@ -8,6 +6,8 @@ class StudentModelTest(TestCase): + """Student model test""" + def setUp(self): self.student = Student.objects.create( first_name="John", diff --git a/core/views.py b/core/views.py index 91ea44a..e69de29 100644 --- a/core/views.py +++ b/core/views.py @@ -1,3 +0,0 @@ -from django.shortcuts import render - -# Create your views here. From ad183677e26fd2400a3f48b905a2632f77f076cc Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Sat, 16 Aug 2025 22:45:02 +0530 Subject: [PATCH 44/60] Add pre commit package in requirements file --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 0767be6..80b0424 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,3 +8,4 @@ black==25.1.0 isort==6.0.1 pylint==3.3.7 pylint-django==2.6.1 +pre_commit==4.2.0 From 139249c2ee99bf0887482641ec9d83405872e641 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Sat, 16 Aug 2025 22:45:41 +0530 Subject: [PATCH 45/60] Add pre commit config file --- .pre-commit-config.yaml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..0ee24b4 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,7 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.3.0 + hooks: + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace From 77bf4c6da13767933397747641544b729c291e25 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Sat, 16 Aug 2025 22:59:35 +0530 Subject: [PATCH 46/60] Add black pre commit --- .pre-commit-config.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0ee24b4..d44e099 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,3 +5,9 @@ repos: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace + + - repo: https://github.com/psf/black + rev: 25.1.0 + hooks: + - id: black + name: black to format python code From 2bb4de1a217a5b434875d8913c6a83c12710a9a5 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Sat, 16 Aug 2025 23:00:32 +0530 Subject: [PATCH 47/60] Add isort pre commit --- .pre-commit-config.yaml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d44e099..55fcfc9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,3 +11,15 @@ repos: hooks: - id: black name: black to format python code + + - repo: https://github.com/pycqa/isort + rev: 6.0.1 + hooks: + - id: isort + name: isort to sort imports + args: + - --profile + - black + - --verbose + - --skip-glob + - "**/migrations/*.py" From eb4d5d1b2e379fb69d73f73ddb40bdf04e043ecf Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Sat, 16 Aug 2025 23:02:16 +0530 Subject: [PATCH 48/60] Add mypy pre commit --- .pre-commit-config.yaml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 55fcfc9..bafc934 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -23,3 +23,15 @@ repos: - --verbose - --skip-glob - "**/migrations/*.py" + + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.17.0 + hooks: + - id: mypy + name: mypy to check types + additional_dependencies: + - django-jazzmin==3.0.1 + - django-stubs==5.2.2 + - djangorestframework==3.16.0 + - djangorestframework-stubs==3.16.1 + args: ["--config-file=mypy.ini"] From 70499d29fa7904de73df0ac65db50eb7105fc6e9 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Sat, 16 Aug 2025 23:02:44 +0530 Subject: [PATCH 49/60] Add pylint pre commit --- .pre-commit-config.yaml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bafc934..375c4f9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -35,3 +35,18 @@ repos: - djangorestframework==3.16.0 - djangorestframework-stubs==3.16.1 args: ["--config-file=mypy.ini"] + + - repo: https://github.com/pycqa/pylint + rev: v3.3.7 + hooks: + - id: pylint + name: pylint to check code quality + entry: pylint + language: python + types: [python] + args: ["--rcfile=.pylintrc"] + additional_dependencies: + - django-jazzmin==3.0.1 + - Django==5.2.4 + - pylint-django==2.6.1 + - djangorestframework==3.16.0 From 98f56027862dfa9072b5b21f00b4a4548353db68 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Sat, 16 Aug 2025 23:08:24 +0530 Subject: [PATCH 50/60] Add instructions to setup pre commit --- README.md | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/README.md b/README.md index 98f440d..b4ed866 100644 --- a/README.md +++ b/README.md @@ -968,3 +968,108 @@ python3 manage.py test ``` - Install VS Code pylint extension [`ms-python.pylint`](https://marketplace.visualstudio.com/items?itemName=ms-python.pylint) + +13. Setup pre commit + +- Install pre commit package + + ```sh + pip install pre_commit + ``` + +- Add installed pre commit package to requirements file + + ```sh + pip freeze | grep pre_commit >> requirements.txt + ``` + +- Add pre commit config file `.pre-commit-config.yaml` + + ```yaml + repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.3.0 + hooks: + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + ``` + +- Add pre commit config for black in `.pre-commit-config.yaml` + + ```yaml + repos: + - repo: https://github.com/psf/black + rev: 25.1.0 + hooks: + - id: black + name: black to format python code + ``` + +- Add pre commit config for isort in `.pre-commit-config.yaml` + + ```yaml + repos: + - repo: https://github.com/pycqa/isort + rev: 6.0.1 + hooks: + - id: isort + name: isort to sort imports + args: + - --profile + - black + - --verbose + - --skip-glob + - "**/migrations/*.py" + ``` + +- Add pre commit config for mypy in `.pre-commit-config.yaml` + + ```yaml + repos: + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.17.0 + hooks: + - id: mypy + name: mypy to check types + additional_dependencies: + - django-jazzmin==3.0.1 + - django-stubs==5.2.2 + - djangorestframework==3.16.0 + - djangorestframework-stubs==3.16.1 + args: ["--config-file=mypy.ini"] + ``` + +- Add pre commit config for pylint in `.pre-commit-config.yaml` + + ```yaml + repos: + - repo: https://github.com/pycqa/pylint + rev: v3.3.7 + hooks: + - id: pylint + name: pylint to check code quality + entry: pylint + language: python + types: [python] + args: ["--rcfile=.pylintrc"] + additional_dependencies: + - django-jazzmin==3.0.1 + - Django==5.2.4 + - pylint-django==2.6.1 + - djangorestframework==3.16.0 + ``` + +- Install pre commit dependencies + + ```sh + pre-commit install + ``` + +- Run pre-commit hooks manually + + ```sh + pre-commit run --all-files + ``` + +- Note:- pre commit official [doc](https://pre-commit.com/) From 163ab1c942b30d4d4a7af4746d38544684348ef1 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Sat, 16 Aug 2025 23:08:44 +0530 Subject: [PATCH 51/60] Fix pre commit hook warnings --- .pylintrc | 2 +- .vscode/setting.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.pylintrc b/.pylintrc index cd7939a..2a296a9 100644 --- a/.pylintrc +++ b/.pylintrc @@ -46,7 +46,7 @@ fail-under=10 #from-stdin= # Files or directories to be skipped. They should be base names, not paths. -ignore=CVS +ignore=CVS # Add files or directories matching the regular expressions patterns to the # ignore-list. The regex matches against paths and can be in Posix or Windows diff --git a/.vscode/setting.json b/.vscode/setting.json index 54f9617..8758f96 100644 --- a/.vscode/setting.json +++ b/.vscode/setting.json @@ -16,4 +16,4 @@ "--skip-glob", "*/migrations/*" ] -} \ No newline at end of file +} From 017e516b479431e3be500a470b367cc239f0dd4d Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Sat, 16 Aug 2025 23:18:08 +0530 Subject: [PATCH 52/60] Add pre push hook bash file --- .githooks/pre-push | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .githooks/pre-push diff --git a/.githooks/pre-push b/.githooks/pre-push new file mode 100644 index 0000000..a51cddc --- /dev/null +++ b/.githooks/pre-push @@ -0,0 +1,19 @@ +#!/bin/bash + +echo "Running tests with coverage..." + +coverage run manage.py test +status=$? + +if [ $status -ne 0 ]; then + echo "โŒ Tests failed. Push aborted." + exit 1 +fi + +coverage report --fail-under=85 # set your threshold +if [ $? -ne 0 ]; then + echo "โŒ Coverage is below threshold. Push aborted." + exit 1 +fi + +echo "โœ… Tests passed and coverage is acceptable. Proceeding with push." From beaaddfd32deaaac1d75a056c786df708d33a2c1 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Sat, 16 Aug 2025 23:18:59 +0530 Subject: [PATCH 53/60] Add instructions to setup pre push hook --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index b4ed866..79f0bfe 100644 --- a/README.md +++ b/README.md @@ -1073,3 +1073,17 @@ python3 manage.py test ``` - Note:- pre commit official [doc](https://pre-commit.com/) + +14. Setup pre push hook + +- for linux or macos + + ```sh + cp .githooks/pre-push .git/hooks/pre-push && chmod +x .git/hooks/pre-push + ``` + +- for windowns + + ```sh + copy .githooks\pre-push .git\hooks\pre-push + ``` From 4c3292bb6a8614e49a70a681b63901a2f918216c Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Sat, 16 Aug 2025 23:37:45 +0530 Subject: [PATCH 54/60] Add manage py path in env --- .env | 1 + 1 file changed, 1 insertion(+) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 0000000..6c2eaba --- /dev/null +++ b/.env @@ -0,0 +1 @@ +MANAGE_PY_PATH=manage.py From 4817c912a579a9e83910cf869f9ed26de163ad9a Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Sat, 16 Aug 2025 23:38:10 +0530 Subject: [PATCH 55/60] Add VS Code config for python test runner --- .vscode/setting.json | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/.vscode/setting.json b/.vscode/setting.json index 8758f96..40beac9 100644 --- a/.vscode/setting.json +++ b/.vscode/setting.json @@ -1,19 +1,15 @@ { - "editor.formatOnSave": true, - "editor.codeActionsOnSave": { - "source.fixAll": "explicit", - "source.organizeImports": "explicit" - }, - "editor.rulers": [ - 100 - ], - "[python]": { - "editor.defaultFormatter": "ms-python.black-formatter" - }, - "isort.args":[ - "--profile", - "black", - "--skip-glob", - "*/migrations/*" - ] + "editor.formatOnSave": true, + "editor.codeActionsOnSave": { + "source.fixAll": "explicit", + "source.organizeImports": "explicit" + }, + "editor.rulers": [100], + "[python]": { + "editor.defaultFormatter": "ms-python.black-formatter" + }, + "isort.args": ["--profile", "black", "--skip-glob", "*/migrations/*"], + "python.testing.unittestEnabled": true, + "python.testing.pytestEnabled": false, + "python.testing.unittestArgs": ["-p", "*test*.py"] } From 9fb5a7882b7468e019c924c3a21a6f82623f79f8 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Sat, 16 Aug 2025 23:39:37 +0530 Subject: [PATCH 56/60] Add instructions to setup vs code test runner --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index 79f0bfe..6d8a9e4 100644 --- a/README.md +++ b/README.md @@ -1087,3 +1087,21 @@ python3 manage.py test ```sh copy .githooks\pre-push .git\hooks\pre-push ``` + +15. Setup VS Code test runner + +- Add manage.py path variable in `.env` file + + ```env + MANAGE_PY_PATH=manage.py + ``` + +- Configure VS Code to for test runner in `.vscode/settings.json` + + ```json + { + "python.testing.unittestEnabled": true, + "python.testing.pytestEnabled": false, + "python.testing.unittestArgs": ["-p", "*test*.py"] + } + ``` From ee5b5fa7fddc8e7e800bc5398761dd421650afa1 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Sat, 16 Aug 2025 23:47:04 +0530 Subject: [PATCH 57/60] Add recommended extensions file --- .vscode/extensions.json | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .vscode/extensions.json diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..60a76d6 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,15 @@ +{ + "recommendations": [ + "ms-python.python", + "esbenp.prettier-vscode", + "ms-python.black-formatter", + "ms-python.isort", + "ms-python.mypy-type-checker", + "batisteo.vscode-django", + "ms-python.pylint", + "ms-python.debugpy", + "ms-python.vscode-pylance", + "yy0931.vscode-sqlite3-editor", + "streetsidesoftware.code-spell-checker" + ] +} From d23a676bc62be01f92c63c6e49e421b7c2713ad3 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Sat, 16 Aug 2025 23:48:23 +0530 Subject: [PATCH 58/60] Add instructions to install recommended VS Code extensions --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 6d8a9e4..1d081cb 100644 --- a/README.md +++ b/README.md @@ -1105,3 +1105,11 @@ python3 manage.py test "python.testing.unittestArgs": ["-p", "*test*.py"] } ``` + +16. Install recommended VS Code extensions + +- Open the extensions sidebar in VS Code `ctrl+shift+x` or `cmd+shift+x` + +- Type @recommended in the search bar + +- Install the recommended extensions From 6bb4bad292bd506fa4bab6108ffa58fb75b23c1b Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Sat, 16 Aug 2025 23:53:37 +0530 Subject: [PATCH 59/60] Add basic check workflow --- .github/workflows/basic-checks.yaml | 42 +++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .github/workflows/basic-checks.yaml diff --git a/.github/workflows/basic-checks.yaml b/.github/workflows/basic-checks.yaml new file mode 100644 index 0000000..cef4d8b --- /dev/null +++ b/.github/workflows/basic-checks.yaml @@ -0,0 +1,42 @@ +name: ๐Ÿšฆ Basic Checks + +on: + push: + branches: + - main + pull_request: + +jobs: + quality-checks: + name: Quality Checks + runs-on: ubuntu-latest + + steps: + - name: ๐Ÿ“ฅ Checkout code + uses: actions/checkout@v4 + + - name: ๐Ÿ Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: ๐Ÿ“ฆ Install dependencies + run: pip install -r requirements.txt + + - name: ๐ŸŽจ Run black (formatting) + run: black --check . + + - name: ๐Ÿงน Run isort (import sorting) + run: isort --check-only . + + - name: ๐Ÿง Run mypy (type checking) + run: mypy . + + - name: ๐Ÿ” Run pylint (linting) + run: pylint **/*.py + + - name: ๐Ÿงช Run tests with coverage + run: coverage run manage.py test + + - name: ๐Ÿ“Š Generate coverage report (fail if <85%) + run: coverage report --fail-under=85 From f872a12fa13d23a30dd80b00344a27275fa408ed Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Sun, 17 Aug 2025 20:53:59 +0530 Subject: [PATCH 60/60] Fix vscode settings file --- .vscode/{setting.json => settings.json} | 4 ++++ 1 file changed, 4 insertions(+) rename .vscode/{setting.json => settings.json} (80%) diff --git a/.vscode/setting.json b/.vscode/settings.json similarity index 80% rename from .vscode/setting.json rename to .vscode/settings.json index 40beac9..5cf0c19 100644 --- a/.vscode/setting.json +++ b/.vscode/settings.json @@ -2,9 +2,13 @@ "editor.formatOnSave": true, "editor.codeActionsOnSave": { "source.fixAll": "explicit", + "source.unusedImports": "explicit", "source.organizeImports": "explicit" }, "editor.rulers": [100], + "[json]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, "[python]": { "editor.defaultFormatter": "ms-python.black-formatter" },