pydepinject


Namepydepinject JSON
Version 0.0.2.dev0 PyPI version JSON
download
home_pageNone
SummaryA package to dynamically inject requirements into a virtual environment.
upload_time2024-06-10 08:19:42
maintainerNone
docs_urlNone
authorpydepinject
requires_python>=3.9
licenseMIT
keywords virtualenv requirements dependency management
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Requirement Manager

This project provides a `RequirementManager` (`requires` is an alias) class to manage Python package requirements using virtual environments. It can be used as a decorator or context manager to ensure specific packages are installed and available during the execution of a function or code block.

## Features

- Automatically creates and manages virtual environments.
- Checks if the required packages are already installed.
- Installs packages if they are not already available.
- Supports ephemeral virtual environments that are deleted after use.
- Can be used as a decorator or context manager.

## Installation

`pip install pydepinject`


## Usage

### Decorator

To use the `requires` as a decorator, simply decorate your function with the required packages:

```python
from pydepinject import requires


@requires("requests", "numpy")
def my_function():
    import requests
    import numpy as np
    print(requests.__version__)
    print(np.__version__)

my_function()
```

### Context Manager

You can also use the `requires` as a context manager:

```python
from pydepinject import requires


with requires("requests", "numpy"):
    import requests
    import numpy as np
    print(requests.__version__)
    print(np.__version__)
```

### Virtual Environment with specific name

The `requires` can create a virtual environment with a specific name:

```python
@requires("requests", venv_name="myenv")
def my_function():
    import requests
    print(requests.__version__)


with requires("pylint", venv_name="myenv"):
    import pylint
    print(pylint.__version__)
    import requests  # This is also available here because it was installed in the same virtual environment
    print(requests.__version__)


# The virtual environment name can also be set as PYDEPINJECT_VENV_NAME environment variable
import os
os.environ["PYDEPINJECT_VENV_NAME"] = "myenv"

@requires("requests")
def my_function():
    import requests
    print(requests.__version__)


with requires("pylint"):
    import pylint
    print(pylint.__version__)
    import requests  # This is also available here because it was installed in the same virtual environment
    print(requests.__version__)
```



### Reusable Virtual Environments

The `requires` can create named virtual environments and reuse them across multiple functions or code blocks:

```python
@requires("requests", venv_name="myenv", ephemeral=False)
def my_function():
    import requests
    print(requests.__version__)


with requires("pylint", venv_name="myenv", ephemeral=False):
    import pylint
    print(pylint.__version__)
    import requests  # This is also available here because it was installed in the same virtual environment
    print(requests.__version__)
```

### Managing Virtual Environments

The `requires` can automatically delete ephemeral virtual environments after use. This is useful when you want to ensure that the virtual environment is clean and does not persist after the function or code block completes:

```python
@requires("requests", venv_name="myenv", ephemeral=True)
def my_function():
    import requests
    print(requests.__version__)

my_function()
```

## Logging

The `requires` uses the `logging` module to provide debug information. By default, it logs to the console at the DEBUG level. You can adjust the logging configuration as needed.

## Unit Tests

Unit tests are provided to verify the functionality of the `requires`. The tests use `pytest` and cover various scenarios including decorator usage, context manager usage, ephemeral environments, and more.

### Running Tests

To run the unit tests, ensure you have `pytest` installed, and then execute the following command:

```bash
pytest
```

## License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pydepinject",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "virtualenv, requirements, dependency management",
    "author": "pydepinject",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/19/54/3e52dd26c66d1e828192e5d35fbb1764d0bd97bc056c26f7ea05b5e9b1ce/pydepinject-0.0.2.dev0.tar.gz",
    "platform": null,
    "description": "# Requirement Manager\n\nThis project provides a `RequirementManager` (`requires` is an alias) class to manage Python package requirements using virtual environments. It can be used as a decorator or context manager to ensure specific packages are installed and available during the execution of a function or code block.\n\n## Features\n\n- Automatically creates and manages virtual environments.\n- Checks if the required packages are already installed.\n- Installs packages if they are not already available.\n- Supports ephemeral virtual environments that are deleted after use.\n- Can be used as a decorator or context manager.\n\n## Installation\n\n`pip install pydepinject`\n\n\n## Usage\n\n### Decorator\n\nTo use the `requires` as a decorator, simply decorate your function with the required packages:\n\n```python\nfrom pydepinject import requires\n\n\n@requires(\"requests\", \"numpy\")\ndef my_function():\n    import requests\n    import numpy as np\n    print(requests.__version__)\n    print(np.__version__)\n\nmy_function()\n```\n\n### Context Manager\n\nYou can also use the `requires` as a context manager:\n\n```python\nfrom pydepinject import requires\n\n\nwith requires(\"requests\", \"numpy\"):\n    import requests\n    import numpy as np\n    print(requests.__version__)\n    print(np.__version__)\n```\n\n### Virtual Environment with specific name\n\nThe `requires` can create a virtual environment with a specific name:\n\n```python\n@requires(\"requests\", venv_name=\"myenv\")\ndef my_function():\n    import requests\n    print(requests.__version__)\n\n\nwith requires(\"pylint\", venv_name=\"myenv\"):\n    import pylint\n    print(pylint.__version__)\n    import requests  # This is also available here because it was installed in the same virtual environment\n    print(requests.__version__)\n\n\n# The virtual environment name can also be set as PYDEPINJECT_VENV_NAME environment variable\nimport os\nos.environ[\"PYDEPINJECT_VENV_NAME\"] = \"myenv\"\n\n@requires(\"requests\")\ndef my_function():\n    import requests\n    print(requests.__version__)\n\n\nwith requires(\"pylint\"):\n    import pylint\n    print(pylint.__version__)\n    import requests  # This is also available here because it was installed in the same virtual environment\n    print(requests.__version__)\n```\n\n\n\n### Reusable Virtual Environments\n\nThe `requires` can create named virtual environments and reuse them across multiple functions or code blocks:\n\n```python\n@requires(\"requests\", venv_name=\"myenv\", ephemeral=False)\ndef my_function():\n    import requests\n    print(requests.__version__)\n\n\nwith requires(\"pylint\", venv_name=\"myenv\", ephemeral=False):\n    import pylint\n    print(pylint.__version__)\n    import requests  # This is also available here because it was installed in the same virtual environment\n    print(requests.__version__)\n```\n\n### Managing Virtual Environments\n\nThe `requires` can automatically delete ephemeral virtual environments after use. This is useful when you want to ensure that the virtual environment is clean and does not persist after the function or code block completes:\n\n```python\n@requires(\"requests\", venv_name=\"myenv\", ephemeral=True)\ndef my_function():\n    import requests\n    print(requests.__version__)\n\nmy_function()\n```\n\n## Logging\n\nThe `requires` uses the `logging` module to provide debug information. By default, it logs to the console at the DEBUG level. You can adjust the logging configuration as needed.\n\n## Unit Tests\n\nUnit tests are provided to verify the functionality of the `requires`. The tests use `pytest` and cover various scenarios including decorator usage, context manager usage, ephemeral environments, and more.\n\n### Running Tests\n\nTo run the unit tests, ensure you have `pytest` installed, and then execute the following command:\n\n```bash\npytest\n```\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A package to dynamically inject requirements into a virtual environment.",
    "version": "0.0.2.dev0",
    "project_urls": {
        "documentation": "https://github.com/pydepinject/pydepinject",
        "homepage": "https://github.com/pydepinject/pydepinject",
        "repository": "https://github.com/pydepinject/pydepinject"
    },
    "split_keywords": [
        "virtualenv",
        " requirements",
        " dependency management"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ba14d135353e9ce18c1121904e10359881d91e607a181bdb7d02694fcbcd4349",
                "md5": "6d080c51f1c8ddf74b3f521cea4af847",
                "sha256": "1564342c74797c50aae1bb2b07a64d328948d6972b041b5391e2eac9602bab05"
            },
            "downloads": -1,
            "filename": "pydepinject-0.0.2.dev0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6d080c51f1c8ddf74b3f521cea4af847",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 7423,
            "upload_time": "2024-06-10T08:19:41",
            "upload_time_iso_8601": "2024-06-10T08:19:41.754862Z",
            "url": "https://files.pythonhosted.org/packages/ba/14/d135353e9ce18c1121904e10359881d91e607a181bdb7d02694fcbcd4349/pydepinject-0.0.2.dev0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "19543e52dd26c66d1e828192e5d35fbb1764d0bd97bc056c26f7ea05b5e9b1ce",
                "md5": "f5003e1f42cd169bcc4811a9bfa60643",
                "sha256": "dd925395f0b4b3c9cf8529ca720f8e9c27248ba67dbfc3efb9e51479280b6cbf"
            },
            "downloads": -1,
            "filename": "pydepinject-0.0.2.dev0.tar.gz",
            "has_sig": false,
            "md5_digest": "f5003e1f42cd169bcc4811a9bfa60643",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 10742,
            "upload_time": "2024-06-10T08:19:42",
            "upload_time_iso_8601": "2024-06-10T08:19:42.869860Z",
            "url": "https://files.pythonhosted.org/packages/19/54/3e52dd26c66d1e828192e5d35fbb1764d0bd97bc056c26f7ea05b5e9b1ce/pydepinject-0.0.2.dev0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-10 08:19:42",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pydepinject",
    "github_project": "pydepinject",
    "github_not_found": true,
    "lcname": "pydepinject"
}
        
Elapsed time: 0.61871s