https://github.com/maxblee/force_deps
A small package for enforcing package requirements at the class- or function-level.
https://github.com/maxblee/force_deps
Last synced: 12 months ago
JSON representation
A small package for enforcing package requirements at the class- or function-level.
- Host: GitHub
- URL: https://github.com/maxblee/force_deps
- Owner: maxblee
- License: mit
- Created: 2019-09-18T06:22:15.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-09-18T08:26:13.000Z (almost 7 years ago)
- Last Synced: 2025-06-13T08:05:55.074Z (about 1 year ago)
- Language: Python
- Size: 32.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
force-dependencies
===============================
version number: "0.1.0"
author: Max Lee
[](https://travis-ci.org/maxblee/force_deps) [](https://coveralls.io/github/maxblee/force_deps?branch=master)
Overview
--------
`force-dependencies` is a small package for enforcing package requirements at the class- or function-level.
Simply use:
```python
from force_deps import requires, requires_any, requires_all
@requires("sqlalchemy")
class SQLHandler(object):
def __init__(self):
pass
db = SQLHandler()
Traceback (most recent call last):
...
ImportError: You must import `sqlalchemy` in order to run `SQLHandler`
```
to require users to have a package installed in order to use your class or function,
```python
@requires_any(["sqlalchemy", "sqlite3"])
...
```
to require that users have at least one of a number of packages installed, or
```python
@requires_all(["sqlalchemy", "pandas"])
...
```
to require that users have all of a number of packages installed in order to use a class or function.
Finally, you can combine the decorators together in pretty much any way you please:
```python
@requires_any(["sqlalchemy", "sqlite3"])
@requires("pandas")
...
```
Installation / Usage
--------------------
This library requires Python>=3.5. You should be able to extend its compatibility by removing the dependencies
on Python's `typing` libraries.
To install use pip:
$ pip install force_deps
Or clone the repo:
```shell
$ git clone https://github.com/maxblee/force_deps.git
$ python setup.py install
```
Project template based off [this minimal Python cookiecutter template](https://github.com/wdm0006/cookiecutter-pipproject).