pylint-django


Namepylint-django JSON
Version 2.6.1 PyPI version JSON
download
home_pagehttps://github.com/pylint-dev/pylint-django
SummaryA Pylint plugin to help Pylint understand the Django web framework
upload_time2024-10-10 14:46:37
maintainerNone
docs_urlNone
authorCarl Crowder
requires_python<4.0,>=3.9
licenseNone
keywords pylint django plugin
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            pylint-django
=============

.. image:: https://github.com/pylint-dev/pylint-django/actions/workflows/build.yml/badge.svg
    :target: https://github.com/pylint-dev/pylint-django/actions/workflows/build.yml

.. image:: https://coveralls.io/repos/github/pylint-dev/pylint-django/badge.svg?branch=master
     :target: https://coveralls.io/github/pylint-dev/pylint-django?branch=master

.. image:: https://img.shields.io/pypi/v/pylint-django.svg
    :target: https://pypi.python.org/pypi/pylint-django


About
-----

``pylint-django`` is a `Pylint <http://pylint.org>`__ plugin for improving code
analysis when analysing code using Django. It is also used by the
`Prospector <https://github.com/landscapeio/prospector>`__ tool.


Installation
------------

To install::

    pip install pylint-django


**WARNING:** ``pylint-django`` will not install ``Django`` by default because
this causes more trouble than good,
`see discussion <https://github.com/pylint-dev/pylint-django/pull/132>`__. If you wish
to automatically install the latest version of ``Django`` then::

    pip install pylint-django[with-django]

otherwise sort out your testing environment and please **DO NOT** report issues
about missing Django!


Usage
-----


Ensure ``pylint-django`` is installed and on your path. In order to access some
of the internal Django features to improve pylint inspections, you should also
provide a Django settings module appropriate to your project. This can be done
either with an environment variable::

    DJANGO_SETTINGS_MODULE=your.app.settings pylint --load-plugins pylint_django [..other options..] <path_to_your_sources>

Alternatively, this can be passed in as a commandline flag::

    pylint --load-plugins pylint_django --django-settings-module=your.app.settings [..other options..] <path_to_your_sources>

If you do not configure Django, default settings will be used but this will not include, for
example, which applications to include in `INSTALLED_APPS` and so the linting and type inference
will be less accurate. It is recommended to specify a settings module.

Prospector
----------

If you have ``prospector`` installed, then ``pylint-django`` will already be
installed as a dependency, and will be activated automatically if Django is
detected::

    prospector [..other options..]


Features
--------

* Prevents warnings about Django-generated attributes such as
  ``Model.objects`` or ``Views.request``.
* Prevents warnings when using ``ForeignKey`` attributes ("Instance of
  ForeignKey has no <x> member").
* Fixes pylint's knowledge of the types of Model and Form field attributes
* Validates ``Model.__unicode__`` methods.
* ``Meta`` informational classes on forms and models do not generate errors.
* Flags dangerous use of the exclude attribute in ModelForm.Meta.
* Uses Django's internal machinery to try and resolve models referenced as
  strings in ForeignKey fields. That relies on ``django.setup()`` which needs
  the appropriate project settings defined!


Additional plugins
------------------

``pylint_django.checkers.migrations`` looks for migrations which:

- add new model fields and these fields have a default value. According to
  `Django docs <https://docs.djangoproject.com/en/2.0/topics/migrations/#postgresql>`_
  this may have performance penalties especially on large tables. The preferred way
  is to add a new DB column with ``null=True`` because it will be created instantly
  and then possibly populate the table with the desired default values.
  Only the last migration from a sub-directory will be examined;
- are ``migrations.RunPython()`` without a reverse callable - these will result in
  non reversible data migrations;


This plugin is disabled by default! To enable it::

    pylint --load-plugins pylint_django --load-plugins pylint_django.checkers.migrations


Contributing
------------

Please feel free to add your name to the ``CONTRIBUTORS.rst`` file if you want to
be credited when pull requests get merged. You can also add to the
``CHANGELOG.rst`` file if you wish, although we'll also do that when merging.


Tests
-----

The structure of the test package follows that from pylint itself.

It is fairly simple: create a module starting with ``func_`` followed by
a test name, and insert into it some code. The tests will run pylint
against these modules. If the idea is that no messages now occur, then
that is fine, just check to see if it works by running ``scripts/test.sh``.

Any command line argument passed to ``scripts/test.sh`` will be passed to the internal invocation of ``pytest``.
For example if you want to debug the tests you can execute ``scripts/test.sh --capture=no``.
A specific test case can be run by filtering based on the file name of the test case ``./scripts/test.sh -k 'func_noerror_views'``.

Ideally, add some pylint error suppression messages to the file to prevent
spurious warnings, since these are all tiny little modules not designed to
do anything so there's no need to be perfect.

It is possible to make tests with expected error output, for example, if
adding a new message or simply accepting that pylint is supposed to warn.
A ``test_file_name.txt`` file contains a list of expected error messages in the
format
``error-type:line number:class name or empty:1st line of detailed error text:confidence or empty``.


License
-------

``pylint-django`` is available under the GPLv2 license.


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/pylint-dev/pylint-django",
    "name": "pylint-django",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": "pylint, django, plugin",
    "author": "Carl Crowder",
    "author_email": "git@carlcrowder.com",
    "download_url": "https://files.pythonhosted.org/packages/40/d3/42f88e7549c6d69d9642e7f2de7a1a4a3d45fd352a8ca049c554a3feaba0/pylint-django-2.6.1.tar.gz",
    "platform": null,
    "description": "pylint-django\n=============\n\n.. image:: https://github.com/pylint-dev/pylint-django/actions/workflows/build.yml/badge.svg\n    :target: https://github.com/pylint-dev/pylint-django/actions/workflows/build.yml\n\n.. image:: https://coveralls.io/repos/github/pylint-dev/pylint-django/badge.svg?branch=master\n     :target: https://coveralls.io/github/pylint-dev/pylint-django?branch=master\n\n.. image:: https://img.shields.io/pypi/v/pylint-django.svg\n    :target: https://pypi.python.org/pypi/pylint-django\n\n\nAbout\n-----\n\n``pylint-django`` is a `Pylint <http://pylint.org>`__ plugin for improving code\nanalysis when analysing code using Django. It is also used by the\n`Prospector <https://github.com/landscapeio/prospector>`__ tool.\n\n\nInstallation\n------------\n\nTo install::\n\n    pip install pylint-django\n\n\n**WARNING:** ``pylint-django`` will not install ``Django`` by default because\nthis causes more trouble than good,\n`see discussion <https://github.com/pylint-dev/pylint-django/pull/132>`__. If you wish\nto automatically install the latest version of ``Django`` then::\n\n    pip install pylint-django[with-django]\n\notherwise sort out your testing environment and please **DO NOT** report issues\nabout missing Django!\n\n\nUsage\n-----\n\n\nEnsure ``pylint-django`` is installed and on your path. In order to access some\nof the internal Django features to improve pylint inspections, you should also\nprovide a Django settings module appropriate to your project. This can be done\neither with an environment variable::\n\n    DJANGO_SETTINGS_MODULE=your.app.settings pylint --load-plugins pylint_django [..other options..] <path_to_your_sources>\n\nAlternatively, this can be passed in as a commandline flag::\n\n    pylint --load-plugins pylint_django --django-settings-module=your.app.settings [..other options..] <path_to_your_sources>\n\nIf you do not configure Django, default settings will be used but this will not include, for\nexample, which applications to include in `INSTALLED_APPS` and so the linting and type inference\nwill be less accurate. It is recommended to specify a settings module.\n\nProspector\n----------\n\nIf you have ``prospector`` installed, then ``pylint-django`` will already be\ninstalled as a dependency, and will be activated automatically if Django is\ndetected::\n\n    prospector [..other options..]\n\n\nFeatures\n--------\n\n* Prevents warnings about Django-generated attributes such as\n  ``Model.objects`` or ``Views.request``.\n* Prevents warnings when using ``ForeignKey`` attributes (\"Instance of\n  ForeignKey has no <x> member\").\n* Fixes pylint's knowledge of the types of Model and Form field attributes\n* Validates ``Model.__unicode__`` methods.\n* ``Meta`` informational classes on forms and models do not generate errors.\n* Flags dangerous use of the exclude attribute in ModelForm.Meta.\n* Uses Django's internal machinery to try and resolve models referenced as\n  strings in ForeignKey fields. That relies on ``django.setup()`` which needs\n  the appropriate project settings defined!\n\n\nAdditional plugins\n------------------\n\n``pylint_django.checkers.migrations`` looks for migrations which:\n\n- add new model fields and these fields have a default value. According to\n  `Django docs <https://docs.djangoproject.com/en/2.0/topics/migrations/#postgresql>`_\n  this may have performance penalties especially on large tables. The preferred way\n  is to add a new DB column with ``null=True`` because it will be created instantly\n  and then possibly populate the table with the desired default values.\n  Only the last migration from a sub-directory will be examined;\n- are ``migrations.RunPython()`` without a reverse callable - these will result in\n  non reversible data migrations;\n\n\nThis plugin is disabled by default! To enable it::\n\n    pylint --load-plugins pylint_django --load-plugins pylint_django.checkers.migrations\n\n\nContributing\n------------\n\nPlease feel free to add your name to the ``CONTRIBUTORS.rst`` file if you want to\nbe credited when pull requests get merged. You can also add to the\n``CHANGELOG.rst`` file if you wish, although we'll also do that when merging.\n\n\nTests\n-----\n\nThe structure of the test package follows that from pylint itself.\n\nIt is fairly simple: create a module starting with ``func_`` followed by\na test name, and insert into it some code. The tests will run pylint\nagainst these modules. If the idea is that no messages now occur, then\nthat is fine, just check to see if it works by running ``scripts/test.sh``.\n\nAny command line argument passed to ``scripts/test.sh`` will be passed to the internal invocation of ``pytest``.\nFor example if you want to debug the tests you can execute ``scripts/test.sh --capture=no``.\nA specific test case can be run by filtering based on the file name of the test case ``./scripts/test.sh -k 'func_noerror_views'``.\n\nIdeally, add some pylint error suppression messages to the file to prevent\nspurious warnings, since these are all tiny little modules not designed to\ndo anything so there's no need to be perfect.\n\nIt is possible to make tests with expected error output, for example, if\nadding a new message or simply accepting that pylint is supposed to warn.\nA ``test_file_name.txt`` file contains a list of expected error messages in the\nformat\n``error-type:line number:class name or empty:1st line of detailed error text:confidence or empty``.\n\n\nLicense\n-------\n\n``pylint-django`` is available under the GPLv2 license.\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A Pylint plugin to help Pylint understand the Django web framework",
    "version": "2.6.1",
    "project_urls": {
        "Homepage": "https://github.com/pylint-dev/pylint-django",
        "Repository": "https://github.com/pylint-dev/pylint-django"
    },
    "split_keywords": [
        "pylint",
        " django",
        " plugin"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1b8288b58feecce482e76e4ec4a45e44ed28075fddd82530d071d89466e83529",
                "md5": "a5f8f73b920a695e5195a4e62caecf62",
                "sha256": "359f68fe8c810ee6bc8e1ab4c83c19b15a43b234a24b08978f47a23462b5ce28"
            },
            "downloads": -1,
            "filename": "pylint_django-2.6.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a5f8f73b920a695e5195a4e62caecf62",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 42858,
            "upload_time": "2024-10-10T14:46:36",
            "upload_time_iso_8601": "2024-10-10T14:46:36.236910Z",
            "url": "https://files.pythonhosted.org/packages/1b/82/88b58feecce482e76e4ec4a45e44ed28075fddd82530d071d89466e83529/pylint_django-2.6.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "40d342f88e7549c6d69d9642e7f2de7a1a4a3d45fd352a8ca049c554a3feaba0",
                "md5": "1b8dcfb2708dbf9a1690f56de41bc350",
                "sha256": "19e8c85a8573a04e3de7be2ba91e9a7c818ebf05e1b617be2bbae67a906b725f"
            },
            "downloads": -1,
            "filename": "pylint-django-2.6.1.tar.gz",
            "has_sig": false,
            "md5_digest": "1b8dcfb2708dbf9a1690f56de41bc350",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 31970,
            "upload_time": "2024-10-10T14:46:37",
            "upload_time_iso_8601": "2024-10-10T14:46:37.931290Z",
            "url": "https://files.pythonhosted.org/packages/40/d3/42f88e7549c6d69d9642e7f2de7a1a4a3d45fd352a8ca049c554a3feaba0/pylint-django-2.6.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-10 14:46:37",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pylint-dev",
    "github_project": "pylint-django",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "tox": true,
    "lcname": "pylint-django"
}
        
Elapsed time: 0.31314s