Python Depencencies Check it is a module that automatically check if the dependencies used in the code appear in the environment file (conda.yaml
or requirements.txt
) but forgot to add manually to these files.
In this way, the files with the dependencies are always aligned with the dependencies you are using in the code.
Note
Works for conda virtual environments and with conda.yaml
and requirements.txt
files.
It looks in your code to see what libraries you are using, discards internal python libraries and is left with only the libraries that need to be installed. These are the ones we need to add in the dependency files.
Once you have these libraries, take the version you are using in your conda environment and add it to the dependency file if it is not already added.
It only needs 2 parameters, the file you want to check and the conda environment you use for that project.
Warning
It does not remove unused libraries from your dependency file. It only adds libraries that are not in your dependency file.
For convenience, add it as a hook to your .pre-commit-config.yaml, or if you don't have one, create a new one with this hook.
Note
Use of requirements.txt or conda.yaml:
args: ['--env-file', 'requirements.txt', '--env-name', '<env_nzme>']
args: ['--env-file', 'conda.yaml', '--env-name', '<env_name>']
# .pre-commit-config.yaml
repos:
- repo: https://github.com/jorgenusan/pydepcheck.git
rev: v0.1.3
hooks:
- id: pydepcheck
args: ['--env-file', 'requirements.txt', '--env-name', 'pydepcheck']
With this configuration, every commit you make will check that all dependencies are added.
- pre-commit
- Python 3.8+
-
Conda env
conda create -n pydepcheck python=3.9 -y conda activate pydepcheck
-
install the repository
python setup.py install
-
Execute pydepcheck
python pydepcheck/main.py --env_file [file.txt/file.yaml] --env_name pydepcheck