pip-lock


Namepip-lock JSON
Version 2.10.0 PyPI version JSON
download
home_pagehttps://github.com/adamchainz/pip-lock
SummaryCheck for differences between requirements.txt files and your environment.
upload_time2023-06-13 18:07:24
maintainer
docs_urlNone
authorAaron Kirkbride, Adam Johnson, et al.
requires_python>=3.7
licenseMIT
keywords pip requirements
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ========
pip-lock
========

.. image:: https://img.shields.io/github/actions/workflow/status/adamchainz/pip-lock/main.yml?branch=main&style=for-the-badge
   :target: https://github.com/adamchainz/pip-lock/actions?workflow=CI

.. image:: https://img.shields.io/pypi/v/pip-lock.svg?style=for-the-badge
   :target: https://pypi.org/project/pip-lock/

.. 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

Check for differences between requirements.txt files and the current environment.

Installation
============

Install with ``python -m pip install pip-lock``.

Python 3.7 to 3.12 supported.

----

**Working on a Django project?**
Check out my book `Boost Your Django DX <https://adamchainz.gumroad.com/l/byddx>`__ which covers many ways to improve your development experience.

----

Example usage
=============

Call ``pip_lock.check_requirements()`` at your application startup to verify that the current virtual environment matches your requirements file.
This gives instant feedback to developers changing branches etc. who would otherwise experience unexpected behaviour or errors due to out of sync requirements.

In a Django project, it makes sense to add the check inside the ``manage.py`` file, which is the project’s main entrypoint.
You can add a call to ``pip_lock.check_requirements()`` after the first import of Django.
For example:

.. code-block:: python

    #!/usr/bin/env python
    import os
    import sys
    from pathlib import Path


    def main():
        os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.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

        try:
            import pip_lock
        except ImportError:
            raise ImportError(
                "Couldn't import pip-lock. Are you on the right virtualenv and up "
                + "to date?"
            )

        requirements_path = str(Path(__file__).parent / "requirements.txt")
        pip_lock.check_requirements(
            requirements_path,
            post_text="\nRun the following:\n\npython -m pip install -r requirements.txt\n",
        )

        execute_from_command_line(sys.argv)


    if __name__ == "__main__":
        main()

API
===

``check_requirements(requirements_file_path: str, post_text: str='') -> None``
------------------------------------------------------------------------------

Exit with exit code 1 and output to stderr if there are mismatches between the environment and requirements file.

``requirements_file_path`` is the path to the ``requirements.txt`` file - we recommend using an absolute file path.

``post_text`` is optional text which is displayed after the stderr message. This can be used to display instructions
on how to update the requirements.

Example:

.. code-block:: python

    check_requirements(
        "requirements.txt",
        post_text="\nRun the following on your host machine: \n\n    vagrant provision\n",
    )

.. code-block:: bash

    There are requirement mismatches with requirements.txt:
        * Package Django has version 1.9.10 but you have version 1.9.0 installed.
        * Package requests has version 2.11.1 but you have version 2.11.0 installed.
        * Package requests-oauthlib is in requirements.txt but not in virtualenv

    Run the following on your host machine:

        vagrant provision

``get_mismatches(requirements_file_path: str) -> dict[str, tuple[str, str | None]]``
------------------------------------------------------------------------------------

Return a dictionary of package names to tuples of ``(expected_version, actual_version)`` for mismatched packages.

``requirements_file_path`` is the path to the ``requirements.txt`` file - we recommend using an absolute file path.

Example:

.. code-block:: pycon

    >>> get_mismatches("requirements.txt")
    {'django': ('1.10.2', '1.9.0'), 'requests': ('2.11.1', '2.9.2'), 'request-oauthlib': ('0.7.0', None)}

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/adamchainz/pip-lock",
    "name": "pip-lock",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "pip,requirements",
    "author": "Aaron Kirkbride, Adam Johnson, et al.",
    "author_email": "me@adamj.eu",
    "download_url": "https://files.pythonhosted.org/packages/2b/f6/727aa8f3131f1460f0524f86d7f25fb3cc99778667625efc9384c1760539/pip_lock-2.10.0.tar.gz",
    "platform": null,
    "description": "========\npip-lock\n========\n\n.. image:: https://img.shields.io/github/actions/workflow/status/adamchainz/pip-lock/main.yml?branch=main&style=for-the-badge\n   :target: https://github.com/adamchainz/pip-lock/actions?workflow=CI\n\n.. image:: https://img.shields.io/pypi/v/pip-lock.svg?style=for-the-badge\n   :target: https://pypi.org/project/pip-lock/\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\nCheck for differences between requirements.txt files and the current environment.\n\nInstallation\n============\n\nInstall with ``python -m pip install pip-lock``.\n\nPython 3.7 to 3.12 supported.\n\n----\n\n**Working on a Django project?**\nCheck out my book `Boost Your Django DX <https://adamchainz.gumroad.com/l/byddx>`__ which covers many ways to improve your development experience.\n\n----\n\nExample usage\n=============\n\nCall ``pip_lock.check_requirements()`` at your application startup to verify that the current virtual environment matches your requirements file.\nThis gives instant feedback to developers changing branches etc. who would otherwise experience unexpected behaviour or errors due to out of sync requirements.\n\nIn a Django project, it makes sense to add the check inside the ``manage.py`` file, which is the project\u2019s main entrypoint.\nYou can add a call to ``pip_lock.check_requirements()`` after the first import of Django.\nFor example:\n\n.. code-block:: python\n\n    #!/usr/bin/env python\n    import os\n    import sys\n    from pathlib import Path\n\n\n    def main():\n        os.environ.setdefault(\"DJANGO_SETTINGS_MODULE\", \"example.settings\")\n\n        try:\n            from django.core.management import execute_from_command_line\n        except ImportError as exc:\n            raise ImportError(\n                \"Couldn't import Django. Are you sure it's installed and \"\n                \"available on your PYTHONPATH environment variable? Did you \"\n                \"forget to activate a virtual environment?\"\n            ) from exc\n\n        try:\n            import pip_lock\n        except ImportError:\n            raise ImportError(\n                \"Couldn't import pip-lock. Are you on the right virtualenv and up \"\n                + \"to date?\"\n            )\n\n        requirements_path = str(Path(__file__).parent / \"requirements.txt\")\n        pip_lock.check_requirements(\n            requirements_path,\n            post_text=\"\\nRun the following:\\n\\npython -m pip install -r requirements.txt\\n\",\n        )\n\n        execute_from_command_line(sys.argv)\n\n\n    if __name__ == \"__main__\":\n        main()\n\nAPI\n===\n\n``check_requirements(requirements_file_path: str, post_text: str='') -> None``\n------------------------------------------------------------------------------\n\nExit with exit code 1 and output to stderr if there are mismatches between the environment and requirements file.\n\n``requirements_file_path`` is the path to the ``requirements.txt`` file - we recommend using an absolute file path.\n\n``post_text`` is optional text which is displayed after the stderr message. This can be used to display instructions\non how to update the requirements.\n\nExample:\n\n.. code-block:: python\n\n    check_requirements(\n        \"requirements.txt\",\n        post_text=\"\\nRun the following on your host machine: \\n\\n    vagrant provision\\n\",\n    )\n\n.. code-block:: bash\n\n    There are requirement mismatches with requirements.txt:\n        * Package Django has version 1.9.10 but you have version 1.9.0 installed.\n        * Package requests has version 2.11.1 but you have version 2.11.0 installed.\n        * Package requests-oauthlib is in requirements.txt but not in virtualenv\n\n    Run the following on your host machine:\n\n        vagrant provision\n\n``get_mismatches(requirements_file_path: str) -> dict[str, tuple[str, str | None]]``\n------------------------------------------------------------------------------------\n\nReturn a dictionary of package names to tuples of ``(expected_version, actual_version)`` for mismatched packages.\n\n``requirements_file_path`` is the path to the ``requirements.txt`` file - we recommend using an absolute file path.\n\nExample:\n\n.. code-block:: pycon\n\n    >>> get_mismatches(\"requirements.txt\")\n    {'django': ('1.10.2', '1.9.0'), 'requests': ('2.11.1', '2.9.2'), 'request-oauthlib': ('0.7.0', None)}\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Check for differences between requirements.txt files and your environment.",
    "version": "2.10.0",
    "project_urls": {
        "Changelog": "https://github.com/adamchainz/pip-lock/blob/main/CHANGELOG.rst",
        "Homepage": "https://github.com/adamchainz/pip-lock",
        "Mastodon": "https://fosstodon.org/@adamchainz",
        "Twitter": "https://twitter.com/adamchainz"
    },
    "split_keywords": [
        "pip",
        "requirements"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "78f74d9643b22b72b8617e6cf1d62d12de5566ec52d61e1ad40f10bbc8c079a8",
                "md5": "c2ff6d226b20b1292ca90feb952892bc",
                "sha256": "f48c06911f631b9576dde3d8723d5d3a4ce403aa4b599a2d9ca116f36fb9e71f"
            },
            "downloads": -1,
            "filename": "pip_lock-2.10.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c2ff6d226b20b1292ca90feb952892bc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 5441,
            "upload_time": "2023-06-13T18:07:23",
            "upload_time_iso_8601": "2023-06-13T18:07:23.282059Z",
            "url": "https://files.pythonhosted.org/packages/78/f7/4d9643b22b72b8617e6cf1d62d12de5566ec52d61e1ad40f10bbc8c079a8/pip_lock-2.10.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2bf6727aa8f3131f1460f0524f86d7f25fb3cc99778667625efc9384c1760539",
                "md5": "69aff5d085e7cbaab51ea726990aad00",
                "sha256": "4380809d5bf0672deff8c70ad13f0891ad23c7512cd3980d71dcb80fa5bb3ff5"
            },
            "downloads": -1,
            "filename": "pip_lock-2.10.0.tar.gz",
            "has_sig": false,
            "md5_digest": "69aff5d085e7cbaab51ea726990aad00",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 8610,
            "upload_time": "2023-06-13T18:07:24",
            "upload_time_iso_8601": "2023-06-13T18:07:24.600760Z",
            "url": "https://files.pythonhosted.org/packages/2b/f6/727aa8f3131f1460f0524f86d7f25fb3cc99778667625efc9384c1760539/pip_lock-2.10.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-13 18:07:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "adamchainz",
    "github_project": "pip-lock",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "pip-lock"
}
        
Elapsed time: 0.07918s