Skip to content

Commit

Permalink
feat: Support using venvs instead of pypackages
Browse files Browse the repository at this point in the history
Handle creation of multiple venvs with Makefile and `setup.sh`.

Related to pawamoy/pdm-multirun#10: pawamoy/pdm-multirun#10
Co-authored-by: Timothée Mazzucotelli <pawamoy@pm.me>
  • Loading branch information
laenan8466 committed Dec 1, 2023
1 parent cbcc75d commit 23f0d3e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
19 changes: 15 additions & 4 deletions docs/work.md
Expand Up @@ -229,14 +229,25 @@ The first thing you should run when entering your repository is:
make setup
```

If you don't have the `make` command,
you can use `bash scripts/setup.sh` directly,
or even just `pdm install`
if you don't plan on using multiple Python versions.

This will install the project's dependencies in `__pypackages__`:
one folder per chosen Python version.
The chosen Python versions are defined in the Makefile.
If you would like to use *virtual environments (venvs)* instead,
set the PDM configuration item `python.use_venv` to true:

If you don't have the `make` command,
you can use `bash scripts/setup.sh` instead,
or even just `pdm install`
if you don't plan on using multiple Python versions.
```bash
pdm config --local python.use_venv
```

Remove the `--local` flag to enable using venvs for all your local projects.

When venvs are enabled, the setup script will create named venvs (`name=3.xx`)
in your `venv.location` directory (PDM configuration).

Now you can start writing and editing code in `src/your_package`.

Expand Down
1 change: 1 addition & 0 deletions project/Makefile.jinja
Expand Up @@ -2,6 +2,7 @@
SHELL := bash
DUTY := $(if $(VIRTUAL_ENV),,pdm run) duty
export PDM_MULTIRUN_VERSIONS ?= 3.8 3.9 3.10 3.11 3.12
export PDM_MULTIRUN_USE_VENVS ?= $(if $(shell pdm config python.use_venv | grep True),1,0)

args = $(foreach a,$($(subst -,_,$1)_args),$(if $(value $a),$a="$($a)"))
check_quality_args = files
Expand Down
7 changes: 7 additions & 0 deletions project/scripts/setup.sh
Expand Up @@ -12,6 +12,13 @@ if ! pdm self list 2>/dev/null | grep -q pdm-multirun; then
fi

if [ -n "${PDM_MULTIRUN_VERSIONS}" ]; then
if [ "${PDM_MULTIRUN_USE_VENVS}" -eq "1" ]; then
for version in ${PDM_MULTIRUN_VERSIONS}; do
if ! pdm venv --path "${version}" &>/dev/null; then
pdm venv create --name "${version}" "${version}"
fi
done
fi
pdm multirun -v pdm install -G:all
else
pdm install -G:all
Expand Down

0 comments on commit 23f0d3e

Please sign in to comment.