virtualenv-cache


Namevirtualenv-cache JSON
Version 0.0.2 PyPI version JSON
download
home_page
SummaryManage a cache of Python environments
upload_time2023-08-30 17:00:40
maintainer
docs_urlNone
author
requires_python>=3.6
licenseBSD-3-Clause
keywords packaging pip-tools cache dependencies virtual environment poetry pdm pipfile
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            virtualenv-cache
----------------

Manage a cache of virtual environments based on changes in requirements files.

An example usage of this tool might be a CI system that executes a testsuite.
If there are no changes in requirements, a cached virtual environment already
available in the CI might be used. This environment can have all the
dependencies already installed to speed up CI jobs.

If a new virtual environment is created, this virtual environment can be added
to the cache to speed up next CI jobs.

This tool automatically manages the cache, lifetime of cache entries, and
additional cache parameters based on the supplied configuration file.

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

You can install `the latest version from PyPI <https://pypi.org/project/virtualenv-cache>`__:

.. code-block:: console

  pip install virtualenv-cache

If you wish to run the latest version from `the Git repository <https://github.com/fridex/virtualenv-cache>`__:

.. code-block:: console

  pip install git+https://github.com/fridex/virtualenv-cache@latest

Usage
=====

First, there needs to be generated a configuration file:

.. code-block:: console

  virtualenv-cache init

The command above will create a configuration file in the current directory (by
default) called ``.virtualenv_cache.toml``. Check its configuration options as
described below to match your desired behavior. This file has be generated per
project that should be using the cache and should be part of the project code
base - e.g. committed to the Git repository so that it can be used on a clone.

Next, your configuration in a CI can look similar to the code snipped bellow:

.. code-block::

  cd project-root/
  virtualenv-cache restore
  [ $? -eq 1 ] && ( python3 -m venv .venv && source .venv/bin/activate && pip install -r requirements.txt && virtualenv-cache store )

The code snipped above will try to restore a virtual environment from cache.
If there is no matching cached virtual environment, the ``restore`` command
exists with exit code of 1 indicating cache miss. In that case, the virtual
environment can be created and prepared for the next runs which will result in
a cache hit (unless there is a change in requirements files which results in a
new virtual environment creation that will get cached again). Just make sure
you keep all the requirements installed in your virtual environment and have
them stated in ``requirements_lock_paths``.

Configuration file
==================

The configuration file can be generated using ``virtualenv-cache init``. An
example of such configuration file:

.. code-block:: toml

  [virtualenv-cache]
  cache_size = 25
  cache_path = "${HOME}/.virtualenv-cache/my-project/cache/"
  virtualenv_path = ".venv"
  requirements_lock_paths = [
      "requirements.txt",
      "requirements-dev.txt",
      "requirements-typing.txt"
  ]

``cache_size``
##############

The number of virtual environments cached. If the ``cache_size`` is reached,
the cache is trimmed based on use of virtual environments - only the most used
virtual environments based on datetime are kept in the cache.

``cache_path``
##############

A path where cached virtual environments should be stored. If you use
``virtualenv-cache`` to manage cache for multiple projects, make sure you
define different ``cache_path`` for each of them.

The path configuration value can state environment variables which get
expanded.

``virtualenv_path``
###################

A path where the virtual environment is created for the project. This path is
used to copy the virtual environment into the cache or restored from the cache.

The path configuration value can state environment variables which get
expanded.

``requirements_lock_paths``
###########################

A list of requirements files that affect installed dependencies in the virtual
environment. There can be stated lock files, such as ``requirements.txt`` as
produced by `pip-tools <https://pypi.org/project/pip-tools/>`__, a
``poetry.lock`` file as produced by `Poetry <https://python-poetry.org/>`__, a
`pdm.lock <https://pdm.fming.dev/>`__ file as produced by `PDM
<https://pdm.fming.dev/>`__, or a ``Pipfile.lock`` as produced by `Pipenv
<https://github.com/pypa/pipenv>`__.

Note there are internally computed hashes of these files on their content
without taking into account semantics. That means any change, even a new line,
added to the file affects a new cache entry creation. Generally, this does not
create any issues as the old cache entries will get removed over time based on
the ``cache_size`` configuration option. This also mean that you can add any
other file which content potentially affects virtual environment to this
listing.

Commands
========

The tool can be run with the following sub-commands:

* ``virtualenv-cache store`` - store the curent virtual environment into the cache
* ``virtualenv-cache restore`` - restore the matching virtual environment from the cache
* ``virtualenv-cache init`` - initialize the configuration file
* ``virtualenv-cache list`` - list entries in the cache with their additional
  metadata, such as the last access time
* ``virtualenv-cache erase`` - drop all cached virtual environments

See ``--help`` for more information and options available.

Additional notes
================

All the CLI parameters can be supplied as environment variables:

* ``VIRTUALENV_CACHE_CONFIG_PATH`` - a path to the ``virtualenv-cache`` configuration file
* ``VIRTUALENV_CACHE_FORMAT`` - format used to print output to terminal
* ``VIRTUALENV_CACHE_WORK_DIR`` - a working directory for the CLI


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "virtualenv-cache",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "packaging,pip-tools,cache,dependencies,virtual environment,poetry,pdm,pipfile",
    "author": "",
    "author_email": "Fridolin Pokorny <fridolin.pokorny@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/45/3b/6d5e680540b70b661821d00c805ac08d70aa119264eef379f79bbe41446e/virtualenv-cache-0.0.2.tar.gz",
    "platform": null,
    "description": "virtualenv-cache\n----------------\n\nManage a cache of virtual environments based on changes in requirements files.\n\nAn example usage of this tool might be a CI system that executes a testsuite.\nIf there are no changes in requirements, a cached virtual environment already\navailable in the CI might be used. This environment can have all the\ndependencies already installed to speed up CI jobs.\n\nIf a new virtual environment is created, this virtual environment can be added\nto the cache to speed up next CI jobs.\n\nThis tool automatically manages the cache, lifetime of cache entries, and\nadditional cache parameters based on the supplied configuration file.\n\nInstallation\n============\n\nYou can install `the latest version from PyPI <https://pypi.org/project/virtualenv-cache>`__:\n\n.. code-block:: console\n\n  pip install virtualenv-cache\n\nIf you wish to run the latest version from `the Git repository <https://github.com/fridex/virtualenv-cache>`__:\n\n.. code-block:: console\n\n  pip install git+https://github.com/fridex/virtualenv-cache@latest\n\nUsage\n=====\n\nFirst, there needs to be generated a configuration file:\n\n.. code-block:: console\n\n  virtualenv-cache init\n\nThe command above will create a configuration file in the current directory (by\ndefault) called ``.virtualenv_cache.toml``. Check its configuration options as\ndescribed below to match your desired behavior. This file has be generated per\nproject that should be using the cache and should be part of the project code\nbase - e.g. committed to the Git repository so that it can be used on a clone.\n\nNext, your configuration in a CI can look similar to the code snipped bellow:\n\n.. code-block::\n\n  cd project-root/\n  virtualenv-cache restore\n  [ $? -eq 1 ] && ( python3 -m venv .venv && source .venv/bin/activate && pip install -r requirements.txt && virtualenv-cache store )\n\nThe code snipped above will try to restore a virtual environment from cache.\nIf there is no matching cached virtual environment, the ``restore`` command\nexists with exit code of 1 indicating cache miss. In that case, the virtual\nenvironment can be created and prepared for the next runs which will result in\na cache hit (unless there is a change in requirements files which results in a\nnew virtual environment creation that will get cached again). Just make sure\nyou keep all the requirements installed in your virtual environment and have\nthem stated in ``requirements_lock_paths``.\n\nConfiguration file\n==================\n\nThe configuration file can be generated using ``virtualenv-cache init``. An\nexample of such configuration file:\n\n.. code-block:: toml\n\n  [virtualenv-cache]\n  cache_size = 25\n  cache_path = \"${HOME}/.virtualenv-cache/my-project/cache/\"\n  virtualenv_path = \".venv\"\n  requirements_lock_paths = [\n      \"requirements.txt\",\n      \"requirements-dev.txt\",\n      \"requirements-typing.txt\"\n  ]\n\n``cache_size``\n##############\n\nThe number of virtual environments cached. If the ``cache_size`` is reached,\nthe cache is trimmed based on use of virtual environments - only the most used\nvirtual environments based on datetime are kept in the cache.\n\n``cache_path``\n##############\n\nA path where cached virtual environments should be stored. If you use\n``virtualenv-cache`` to manage cache for multiple projects, make sure you\ndefine different ``cache_path`` for each of them.\n\nThe path configuration value can state environment variables which get\nexpanded.\n\n``virtualenv_path``\n###################\n\nA path where the virtual environment is created for the project. This path is\nused to copy the virtual environment into the cache or restored from the cache.\n\nThe path configuration value can state environment variables which get\nexpanded.\n\n``requirements_lock_paths``\n###########################\n\nA list of requirements files that affect installed dependencies in the virtual\nenvironment. There can be stated lock files, such as ``requirements.txt`` as\nproduced by `pip-tools <https://pypi.org/project/pip-tools/>`__, a\n``poetry.lock`` file as produced by `Poetry <https://python-poetry.org/>`__, a\n`pdm.lock <https://pdm.fming.dev/>`__ file as produced by `PDM\n<https://pdm.fming.dev/>`__, or a ``Pipfile.lock`` as produced by `Pipenv\n<https://github.com/pypa/pipenv>`__.\n\nNote there are internally computed hashes of these files on their content\nwithout taking into account semantics. That means any change, even a new line,\nadded to the file affects a new cache entry creation. Generally, this does not\ncreate any issues as the old cache entries will get removed over time based on\nthe ``cache_size`` configuration option. This also mean that you can add any\nother file which content potentially affects virtual environment to this\nlisting.\n\nCommands\n========\n\nThe tool can be run with the following sub-commands:\n\n* ``virtualenv-cache store`` - store the curent virtual environment into the cache\n* ``virtualenv-cache restore`` - restore the matching virtual environment from the cache\n* ``virtualenv-cache init`` - initialize the configuration file\n* ``virtualenv-cache list`` - list entries in the cache with their additional\n  metadata, such as the last access time\n* ``virtualenv-cache erase`` - drop all cached virtual environments\n\nSee ``--help`` for more information and options available.\n\nAdditional notes\n================\n\nAll the CLI parameters can be supplied as environment variables:\n\n* ``VIRTUALENV_CACHE_CONFIG_PATH`` - a path to the ``virtualenv-cache`` configuration file\n* ``VIRTUALENV_CACHE_FORMAT`` - format used to print output to terminal\n* ``VIRTUALENV_CACHE_WORK_DIR`` - a working directory for the CLI\n\n",
    "bugtrack_url": null,
    "license": "BSD-3-Clause",
    "summary": "Manage a cache of Python environments",
    "version": "0.0.2",
    "project_urls": {
        "homepage": "https://github.com/fridex/virtualenv-cache"
    },
    "split_keywords": [
        "packaging",
        "pip-tools",
        "cache",
        "dependencies",
        "virtual environment",
        "poetry",
        "pdm",
        "pipfile"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "53248f187cf1d101048a3b78f783a8ca24e397d0b29f2f862c46db4262241c44",
                "md5": "119b5c25042137f428288541830eb7b0",
                "sha256": "ba3472638969b27b4b8068c78a186fd118fd7c9d09e80e5fe5636d2a8086a424"
            },
            "downloads": -1,
            "filename": "virtualenv_cache-0.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "119b5c25042137f428288541830eb7b0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 22394,
            "upload_time": "2023-08-30T17:00:38",
            "upload_time_iso_8601": "2023-08-30T17:00:38.189859Z",
            "url": "https://files.pythonhosted.org/packages/53/24/8f187cf1d101048a3b78f783a8ca24e397d0b29f2f862c46db4262241c44/virtualenv_cache-0.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "453b6d5e680540b70b661821d00c805ac08d70aa119264eef379f79bbe41446e",
                "md5": "2f2002ee8d19b9546dc063859b32fc82",
                "sha256": "ea8467854e1659b8eebc7b9d51181dd26bcb6819c532d2d18b69dfffd0b4117e"
            },
            "downloads": -1,
            "filename": "virtualenv-cache-0.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "2f2002ee8d19b9546dc063859b32fc82",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 28876,
            "upload_time": "2023-08-30T17:00:40",
            "upload_time_iso_8601": "2023-08-30T17:00:40.769818Z",
            "url": "https://files.pythonhosted.org/packages/45/3b/6d5e680540b70b661821d00c805ac08d70aa119264eef379f79bbe41446e/virtualenv-cache-0.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-30 17:00:40",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "fridex",
    "github_project": "virtualenv-cache",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "virtualenv-cache"
}
        
Elapsed time: 0.10904s