Name | flake8-no-pep420 JSON |
Version |
2.9.0
JSON |
| download |
home_page | None |
Summary | A flake8 plugin to ban PEP-420 implicit namespace packages. |
upload_time | 2025-09-08 23:44:12 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.9 |
license | None |
keywords |
flake8
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
================
flake8-no-pep420
================
.. image:: https://img.shields.io/github/actions/workflow/status/adamchainz/flake8-no-pep420/main.yml.svg?branch=main&style=for-the-badge
:target: https://github.com/adamchainz/flake8-no-pep420/actions?workflow=CI
.. image:: https://img.shields.io/pypi/v/flake8-no-pep420.svg?style=for-the-badge
:target: https://pypi.org/project/flake8-no-pep420/
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg?style=for-the-badge
:target: https://github.com/psf/black
.. image:: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white&style=for-the-badge
:target: https://github.com/pre-commit/pre-commit
:alt: pre-commit
A `flake8 <https://flake8.readthedocs.io/en/latest/>`_ plugin to ban `PEP-420 <https://www.python.org/dev/peps/pep-0420/>`__ implicit namespace packages.
----
**Linting a Django project?**
Check out my book `Boost Your Django DX <https://adamchainz.gumroad.com/l/byddx>`__ which covers Flake8 and many other code quality tools.
----
Requirements
============
Python 3.9 to 3.14 supported.
Installation
============
First, install with ``pip``:
.. code-block:: sh
python -m pip install flake8-no-pep420
Second, if you define Flake8’s ``select`` setting, add the ``INP`` prefix to it.
Otherwise, the plugin should be active by default.
Rationale
=========
Implicit namespace packages are directories of Python files without an ``__init__.py``.
They’re valid and importable, but they break some tools:
* unittest test discovery, unless |-s (--start-directory)|__ points to the namespace package.
By extension, this affects Django’s test runner too.
.. |-s (--start-directory)| replace:: ``-s`` (``--start-directory``)
__ https://docs.python.org/3/library/unittest.html#cmdoption-unittest-discover-s
* Coverage.py, unless |report.include_namespace_packages|__ is enabled.
.. |report.include_namespace_packages| replace:: ``report.include_namespace_packages``
__ https://coverage.readthedocs.io/en/latest/config.html#report-include-namespace-packages
* pytest (`Issue #5147 <https://github.com/pytest-dev/pytest/issues/5147>`__)
In most cases, tools fail silently, which can lead to a false sense of security:
* Tests may look legitimate but never run
* Code may be untested but not appear in coverage statistics
PEP-420’s algorithm is non-trivial which is probably why such tools haven’t (yet) implemented it.
Rules
=====
INP001: File is part of an implicit namespace package. Add __init__.py?
-----------------------------------------------------------------------
flake8-no-pep420 will trigger this on the first line of any file that sits in a directory without an ``__init__.py`` file.
Often projects have a few root files *not* in packages, for which an ``__init__.py`` file should not be added.
For example, Django projects normally have a ``manage.py`` file in the root of their repository.
In these cases you can ignore the ``INP001`` error.
It’s possible to use ``# noqa: INP001`` to ignore the error in-line, but this isn’t possible if the first line is a `shebang <https://en.wikipedia.org/wiki/Shebang_(Unix)>`__, such as in Django’s ``manage.py``.
In such cases it’s preferable to use Flake8’s `per-file-ignores option <https://flake8.pycqa.org/en/latest/user/options.html#cmdoption-flake8-per-file-ignores>`__, for example in ``setup.cfg``:
.. code-block:: ini
[flake8]
# ...
per-file-ignores =
manage.py:INP001
Raw data
{
"_id": null,
"home_page": null,
"name": "flake8-no-pep420",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "flake8",
"author": null,
"author_email": "Adam Johnson <me@adamj.eu>",
"download_url": "https://files.pythonhosted.org/packages/ac/e3/5373b9c21537efc9954c5daa924e9b59ff09ead43b5068f2b4b8ea8cde23/flake8_no_pep420-2.9.0.tar.gz",
"platform": null,
"description": "================\nflake8-no-pep420\n================\n\n.. image:: https://img.shields.io/github/actions/workflow/status/adamchainz/flake8-no-pep420/main.yml.svg?branch=main&style=for-the-badge\n :target: https://github.com/adamchainz/flake8-no-pep420/actions?workflow=CI\n\n.. image:: https://img.shields.io/pypi/v/flake8-no-pep420.svg?style=for-the-badge\n :target: https://pypi.org/project/flake8-no-pep420/\n\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg?style=for-the-badge\n :target: https://github.com/psf/black\n\n.. image:: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white&style=for-the-badge\n :target: https://github.com/pre-commit/pre-commit\n :alt: pre-commit\n\nA `flake8 <https://flake8.readthedocs.io/en/latest/>`_ plugin to ban `PEP-420 <https://www.python.org/dev/peps/pep-0420/>`__ implicit namespace packages.\n\n----\n\n**Linting a Django project?**\nCheck out my book `Boost Your Django DX <https://adamchainz.gumroad.com/l/byddx>`__ which covers Flake8 and many other code quality tools.\n\n----\n\nRequirements\n============\n\nPython 3.9 to 3.14 supported.\n\nInstallation\n============\n\nFirst, install with ``pip``:\n\n.. code-block:: sh\n\n python -m pip install flake8-no-pep420\n\nSecond, if you define Flake8\u2019s ``select`` setting, add the ``INP`` prefix to it.\nOtherwise, the plugin should be active by default.\n\nRationale\n=========\n\nImplicit namespace packages are directories of Python files without an ``__init__.py``.\nThey\u2019re valid and importable, but they break some tools:\n\n* unittest test discovery, unless |-s (--start-directory)|__ points to the namespace package.\n By extension, this affects Django\u2019s test runner too.\n\n .. |-s (--start-directory)| replace:: ``-s`` (``--start-directory``)\n __ https://docs.python.org/3/library/unittest.html#cmdoption-unittest-discover-s\n\n* Coverage.py, unless |report.include_namespace_packages|__ is enabled.\n\n .. |report.include_namespace_packages| replace:: ``report.include_namespace_packages``\n __ https://coverage.readthedocs.io/en/latest/config.html#report-include-namespace-packages\n\n* pytest (`Issue #5147 <https://github.com/pytest-dev/pytest/issues/5147>`__)\n\nIn most cases, tools fail silently, which can lead to a false sense of security:\n\n* Tests may look legitimate but never run\n* Code may be untested but not appear in coverage statistics\n\nPEP-420\u2019s algorithm is non-trivial which is probably why such tools haven\u2019t (yet) implemented it.\n\nRules\n=====\n\nINP001: File is part of an implicit namespace package. Add __init__.py?\n-----------------------------------------------------------------------\n\nflake8-no-pep420 will trigger this on the first line of any file that sits in a directory without an ``__init__.py`` file.\n\nOften projects have a few root files *not* in packages, for which an ``__init__.py`` file should not be added.\nFor example, Django projects normally have a ``manage.py`` file in the root of their repository.\nIn these cases you can ignore the ``INP001`` error.\nIt\u2019s possible to use ``# noqa: INP001`` to ignore the error in-line, but this isn\u2019t possible if the first line is a `shebang <https://en.wikipedia.org/wiki/Shebang_(Unix)>`__, such as in Django\u2019s ``manage.py``.\nIn such cases it\u2019s preferable to use Flake8\u2019s `per-file-ignores option <https://flake8.pycqa.org/en/latest/user/options.html#cmdoption-flake8-per-file-ignores>`__, for example in ``setup.cfg``:\n\n.. code-block:: ini\n\n [flake8]\n # ...\n per-file-ignores =\n manage.py:INP001\n",
"bugtrack_url": null,
"license": null,
"summary": "A flake8 plugin to ban PEP-420 implicit namespace packages.",
"version": "2.9.0",
"project_urls": {
"Changelog": "https://github.com/adamchainz/flake8-no-pep420/blob/main/CHANGELOG.rst",
"Funding": "https://adamj.eu/books/",
"Repository": "https://github.com/adamchainz/flake8-no-pep420"
},
"split_keywords": [
"flake8"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "92561f625d8399c3441e2976c8dfde6dd2af2319e216323c07e623e8086e9b65",
"md5": "c903c16433a71addf3d9e1708d613329",
"sha256": "981d5d720dd545662f85625373badd4ca33a4e6484cc5ad976ca17d00dc994de"
},
"downloads": -1,
"filename": "flake8_no_pep420-2.9.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c903c16433a71addf3d9e1708d613329",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 4803,
"upload_time": "2025-09-08T23:44:11",
"upload_time_iso_8601": "2025-09-08T23:44:11.551290Z",
"url": "https://files.pythonhosted.org/packages/92/56/1f625d8399c3441e2976c8dfde6dd2af2319e216323c07e623e8086e9b65/flake8_no_pep420-2.9.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "ace35373b9c21537efc9954c5daa924e9b59ff09ead43b5068f2b4b8ea8cde23",
"md5": "fabd516d1fc0be4dfb75ec4b6d927b55",
"sha256": "5dcd9e23bdd545cb957dd23987d9d227e733d1610717b0e13591262df1a33413"
},
"downloads": -1,
"filename": "flake8_no_pep420-2.9.0.tar.gz",
"has_sig": false,
"md5_digest": "fabd516d1fc0be4dfb75ec4b6d927b55",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 5482,
"upload_time": "2025-09-08T23:44:12",
"upload_time_iso_8601": "2025-09-08T23:44:12.715653Z",
"url": "https://files.pythonhosted.org/packages/ac/e3/5373b9c21537efc9954c5daa924e9b59ff09ead43b5068f2b4b8ea8cde23/flake8_no_pep420-2.9.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-09-08 23:44:12",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "adamchainz",
"github_project": "flake8-no-pep420",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "flake8-no-pep420"
}