Skip to content

Commit

Permalink
Switch from pdm to poetry
Browse files Browse the repository at this point in the history
Signed-off-by: Fabrice Normandin <[email protected]>
  • Loading branch information
lebrice committed Jul 4, 2024
1 parent d5281e1 commit d2ac00d
Show file tree
Hide file tree
Showing 7 changed files with 4,152 additions and 103 deletions.
32 changes: 17 additions & 15 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"image": "mcr.microsoft.com/devcontainers/python:1-3.12-bullseye",
// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
"ghcr.io/devcontainers-contrib/features/pdm:2": {},
"ghcr.io/devcontainers-contrib/features/poetry:2": {"version": "1.8.3"},
"ghcr.io/devcontainers-contrib/features/pre-commit:2": {},
"ghcr.io/devcontainers-contrib/features/apt-get-packages": {
"packages": "vim"
Expand Down Expand Up @@ -65,11 +65,9 @@
},
"mounts": [
// https://code.visualstudio.com/remote/advancedcontainers/add-local-file-mount
// Mount a directory which will contain the pdm installation cache (shared with the host machine).
// This will use $SCRATCH/.cache/pdm, otherwise
// Mount a directory which will contain the poetry installation cache (shared with the host machine).
// Mount a "$SCRATCH" directory in the host to ~/scratch in the container.
"source=${localEnv:SCRATCH},target=/home/vscode/scratch,type=bind,consistency=cached",
"source=${localEnv:SCRATCH}/.cache/pdm,target=/home/vscode/.pdm_install_cache,type=bind,consistency=cached",
// Mount a /network to match the /network directory on the host.
// FIXME: This assumes that either the NETWORK_DIR environment variable is set on the host, or
// that the /network directory exists.
Expand All @@ -78,7 +76,12 @@
// note: there's also a SLURM_TMPDIR env variable set to /tmp/slurm_tmpdir in the container.
// NOTE: this assumes that either $SLURM_TMPDIR is set on the host machine (e.g. a compute node)
// or that `/tmp/slurm_tmpdir` exists on the host machine.
"source=${localEnv:SLURM_TMPDIR:/tmp/slurm_tmpdir},target=/tmp,type=bind,consistency=cached"
"source=${localEnv:SLURM_TMPDIR:/tmp/slurm_tmpdir},target=/tmp,type=bind,consistency=cached",
// NOTE: Mounting the hosts's ~/.cache/pypoetry dir to ~/.poetry_cache in the container because
// it causes issues to try to map it to ~/.cache/pypoetry directly (since ~/.cache doesn't
// exist initially, it seems to cause some permission issues?). Later below we
// `mkdir -p ~/.cache` and make a symlink to from ~/.cache/pypoetry to ~/.poetry_cache.
"source=${localEnv:SCRATCH}/.cache/pypoetry,target=/home/vscode/.poetry_cache,type=bind,consistency=cached",
],
"runArgs": [
"--gpus",
Expand All @@ -88,27 +91,26 @@
// create the pdm cache dir on the host machine if it doesn exist yet so the mount above
// doesn't fail.
"initializeCommand": {
"create pdm install cache": "mkdir -p ${SCRATCH?need the SCRATCH environment variable to be set.}/.cache/pdm", // todo: put this on $SCRATCH on the host (e.g. compute node)
// Create the dirs so the mount above doesn't fail.
"create the poetry install cache dir if needed": "mkdir -p ${SCRATCH?need the SCRATCH environment variable to be set.}/.cache/pypoetry", // todo: put this on $SCRATCH on the host (e.g. compute node)
"create fake SLURM_TMPDIR": "mkdir -p ${SLURM_TMPDIR:-/tmp/slurm_tmpdir}" // this is fine on compute nodes
},
// NOTE: Getting some permission issues with the .cache dir if mounting .cache/pdm to
// .cache/pdm in the container. Therefore, here I'm making a symlink from ~/.cache/pdm to
// ~/.pdm_install_cache so the ~/.cache directory is writeable by the container.
// NOTE: Getting some permission issues with the .cache dir if mounting .cache/pypoetry to
// .cache/pypoetry in the container. Therefore, here I'm making a symlink from ~/.cache/pypoetry to
// ~/.poetry_cache so the ~/.cache directory is writeable by the container.
"onCreateCommand": {
"setup_pdm_install_cache": "mkdir -p ~/.cache && ln -s /home/vscode/.pdm_install_cache /home/vscode/.cache/pdm",
"setup_pdm_install_cache": "mkdir -p ~/.cache && ln -s /home/vscode/.poetry_install_cache /home/vscode/.cache/pypoetry",
"pre-commit": "pre-commit install --install-hooks",
"setup_pdm_config": "pdm config install.cache true && pdm config venv.with_pip true && pdm config venv.in_project false"
"setup_pdm_config": "poetry config cache-dir /home/vscode/.poetry_cache && poetry config virtualenvs.in-project false "
},
"updateContentCommand": {
"pdm_install": "pdm install"
"pdm_install": "poetry install"
},

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "pip3 install --user -r requirements.txt",
"postCreateCommand": {
// NOTE: This sets up the python interpreter correctly, but the shell doesn't show the
// environment name, which isn't a big deal.
"setup_venv_shell": "pdm venv activate >> ~/.bash_aliases && chmod +x ~/.bash_aliases",
"setup_venv_shell": "echo \"source `poetry env info --path`/bin/activate\" >> ~/.bash_aliases && chmod +x ~/.bash_aliases",
// "pdm-pep-582": "pdm --pep582 >> ~/.bash_profile",
// "pdm": "pdm config install.cache false && pdm config venv.in_project false && pdm install",
// "pre-commit": "pre-commit install --install-hooks"
Expand Down
18 changes: 11 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,18 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- run: pip install pdm
cache: poetry
- run: pip install poetry
- name: Install dependencies
run: pdm install
run: poetry install
- name: Test with pytest (very fast)
env:
JAX_PLATFORMS: cpu
run: pdm run pytest -v --shorter-than=1.0 --cov=project --cov-report=xml --cov-append
run: poetry run pytest -v --shorter-than=1.0 --cov=project --cov-report=xml --cov-append
- name: Test with pytest (fast)
env:
JAX_PLATFORMS: cpu
run: pdm run pytest -v --cov=project --cov-report=xml --cov-append
run: poetry run pytest -v --cov=project --cov-report=xml --cov-append

- name: Store coverage report as an artifact
uses: actions/upload-artifact@v4
Expand All @@ -74,12 +75,15 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- run: pip install pdm
cache: poetry
- name: Install poetry
run: pip install poetry
- name: Install dependencies
run: pdm config install.cache true && pdm install
run: poetry install

- name: Test with pytest
run: pdm run pytest -v --cov=project --cov-report=xml --cov-append
shell: poetry run
run: pytest -v --cov=project --cov-report=xml --cov-append

# TODO: this is taking too long to run, and is failing consistently. Need to debug this before making it part of the CI again.
# - name: Test with pytest (only slow tests)
Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,17 @@ jobs:
name: Deploy docs
runs-on: ubuntu-latest
steps:
- name: Checkout main
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.12
cache: poetry
- name: Install poetry
run: pip install poetry
- name: Install dependencies
run: poetry install

- name: Deploy docs
uses: mhausenblas/[email protected]
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ repos:
require_serial: true

# Dependency management
- repo: https://github.com/pdm-project/pdm
rev: 2.12.4
- repo: https://github.com/python-poetry/poetry
rev: 1.8.3
hooks:
- id: pdm-lock-check
- id: poetry-check
require_serial: true


Expand Down
Loading

0 comments on commit d2ac00d

Please sign in to comment.