nightscout / trio-docs

GNU Affero General Public License v3.0
9 stars 12 forks source link

🔧 Add direct dependencies file: requirements.in #73

Open ebouchut opened 4 days ago

ebouchut commented 4 days ago

Here is a proposal to make it easier to create and add dependencies, and to be alerted to security issues in the packages we use.

Why?

The goal is:

Today, when using a single file with all dependencies (requirements.txt), I find it difficult to spot the direct dependencies (sphinx, sphinx-copybutton, sphinx-rtd-theme, myst-parser) in an ocean of indirect dependencies. So, I suggest using 2 files.

How?

pip-compile reads a source file requirements.in to generate a requirements.txt with all the dependencies. It resolves and pins the dependencies to the ad-hoc version, ensuring reproducibility. It only focuses on dependencies declared in the source file.

pip freeze uses all packages installed in the virtual environment.

Install

We need to install pip-tools first to use pip-compile:

python -m pip install pip-tools

Usage

Using pip-compile:

pip-compile
python -m pip install -r requirements.txt

pip-compile only looks at the source file (requirements/in), whereas pip freeze looks at what is currently installed in the virtual environment.

Previously, with pip:

# Assuming the `venv` virtual environment has already been created and activated
# python -m venv venv
# source venv/bin/activate

# Remove all installed dependencies/packages
python -m pip freeze --exclude-editable | xargs python -m pip  uninstall -y

# Install the project's packages listed in `requirements.in`
python -m pip install -r requirements.in

# List the pinned project packages (name + version) in `requirements.txt`
python -m pip freeze > requirements.txt

# Install dependencies
python -m pip install -r requirements.txt
ebouchut commented 4 days ago

EDIT: moved to PR description.