Skip to content

Commit

Permalink
✨ feat: add pdm package management and remove poetry
Browse files Browse the repository at this point in the history
  • Loading branch information
jzazo committed Dec 6, 2024
1 parent 91bb6f9 commit d92d7eb
Show file tree
Hide file tree
Showing 34 changed files with 1,793 additions and 2,179 deletions.
2 changes: 0 additions & 2 deletions .azure-pipelines/cg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ schedules:
- main
pool:
vmImage: ubuntu-latest
variables:
EnableDetectorPoetry: true
steps:
- task: ComponentGovernanceComponentDetection@0
inputs:
Expand Down
2 changes: 0 additions & 2 deletions .azure-pipelines/cg.yml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ schedules:
- main
pool:
vmImage: ubuntu-latest
variables:
EnableDetectorPoetry: true
steps:
- task: ComponentGovernanceComponentDetection@0
inputs:
Expand Down
2 changes: 1 addition & 1 deletion .codespellrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ write-changes =
count = true
quiet-level = 3
ignore-words-list = aks,aml,requestors
skip = *.drawio,dist,poetry.lock
skip = *.drawio,dist,pdm.lock
2 changes: 1 addition & 1 deletion .cz.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
name = "cz_gitmoji"
tag_format = "v$version"
version_scheme = "pep440"
version_provider = "poetry"
version_provider = "pep621"
update_changelog_on_bump = true
20 changes: 20 additions & 0 deletions .devcontainer/direnvrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,23 @@ layout_poetry() {
export POETRY_ACTIVE=1
PATH_add "$VENV"
}

layout_pdm() {
PYPROJECT_TOML="${PYPROJECT_TOML:-pyproject.toml}"
if [ ! -f "$PYPROJECT_TOML" ]; then
log_error 'No pyproject.toml found. Use `pdm init` to create one first.'
exit 2
fi

VIRTUAL_ENV=$(pdm venv list | grep "^\*" | awk -F" " '{print $3}')

if [ -z "$VIRTUAL_ENV" ] || [ ! -d "$VIRTUAL_ENV" ]; then
log_status "No virtual environment exists. Executing \`pdm info\` to create one."
pdm info
VIRTUAL_ENV=$(pdm venv list | grep "^\*" | awk -F" " '{print $3}')
fi

export PDM_ACTIVE=1
export VIRTUAL_ENV
PATH_add "$VIRTUAL_ENV/bin"
}
18 changes: 9 additions & 9 deletions .devcontainer/on-create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ pipx ensurepath
echo "UPDATE PIP"
pip3 install -U pip

echo "POETRY INSTALL"
pipx install poetry
poetry completions bash >> ~/.bash_completion
mkdir $ZSH_CUSTOM/plugins/poetry
poetry completions zsh > $ZSH_CUSTOM/plugins/poetry/_poetry
sed -i 's/plugins=(git)/plugins=(git poetry)/' ~/.zshrc
poetry config virtualenvs.in-project true
echo "PDM INSTALL"
pipx install pdm
pdm completion bash > ~/.bash_completion
mkdir $ZSH_CUSTOM/plugins/pdm
pdm completion zsh > ~/.zfunc/_pdm
sed -i 's/plugins=(git)/plugins=(git pdm)/' ~/.zshrc
pdm config virtualenvs.in-project true
direnv allow .
poetry env remove --all
poetry install
pdm env remove --all
pdm install
2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
layout_poetry
layout_pdm

# get path to the root of the project even if deep into the path
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
- name: Install dependencies
run: |
python -m pip install -U pip
pip install -U poetry
poetry install --only docs
pip install -U pdm
pdm install --dev docs
- name: build-docs
run: |
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,29 @@ jobs:
- name: Install dependencies
run: |
python -m pip install -U pip
pip install -U poetry
poetry install
pip install -U pdm
pdm install
- name: ruff-check
run: |
poetry run ruff check --no-fix --output-format=github
pdm run ruff check --no-fix --output-format=github
- name: ruff-format
run: |
poetry run ruff format --check
pdm run ruff format --check
- name: pyright
run: |
poetry run pyright
pdm run pyright
- name: codespell
run: |
poetry run codespell
pdm run codespell
- name: pytest
run: |
poetry run coverage run -m pytest
pdm run coverage run -m pytest
- name: coverage
run: |
poetry run coverage xml -o .tmp/reports/coverage.xml
pdm run coverage xml -o .tmp/reports/coverage.xml
4 changes: 2 additions & 2 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ jobs:
- name: Install dependencies
run: |
python -m pip install -U pip
pip install -U poetry
pip install -U pdm
- name: build-wheel
run: |
poetry build -f wheel
pdm build
- name: upload-artifacts
uses: actions/upload-artifact@v4
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
.coverage
.tmp
.cache
.pdm-python
.pdm.toml

**/*.pyc
**/*.egg-info
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ repos:
name: Run codespell to check for common misspellings in files
language: python
types: [text]
exclude: "poetry.lock|CHANGELOG.md"
exclude: "pdm.lock|CHANGELOG.md"
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ RUN apt-get -qq update && \
rm -rf /var/lib/apt/lists/* && \
rm -rf /tmp/*

RUN pipx install poetry && \
RUN pipx install pdm && \
rm -rf ~/.cache

RUN mkdir -p $PROJECT_PATH/src/cookie && \
touch $PROJECT_PATH/src/cookie/__init__.py && \
touch $PROJECT_PATH/README.md

COPY pyproject.toml poetry.lock $PROJECT_PATH/
COPY pyproject.toml pdm.lock $PROJECT_PATH/

RUN poetry install --only main && \
RUN pdm install --prod && \
rm -rf /root/.cache

COPY src $PROJECT_PATH/src
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Cookie-doh is a repository template for creating single Python package projects

* :seedling: Improve your development workflow, validity and readability of code for individual & collaborative projects!

* :scroll: Uses [poetry](https://python-poetry.org/) for dependency management, virtual environments and packaging, i.e., code is readily importable!
* :scroll: Uses [pdm](https://pdm-project.org/) for dependency management, virtual environments and packaging, i.e., code is readily importable!

* :tropical_drink: Takes less than a minute to create a fully pre-configured project!

Expand All @@ -36,7 +36,7 @@ copier copy gh:microsoft/cookie-doh <new-repo-folder>
and answer the questions to create your new project.

Minimum required system dependencies are [python >= 3.10](https://www.python.org/) and
[poetry](https://python-poetry.org/docs/#installation).
[PDM](https://pdm-project.org/en/latest/#installation).


## :notebook_with_decorative_cover: Documentation
Expand Down Expand Up @@ -77,7 +77,7 @@ and/or [PyCharm](https://www.jetbrains.com/help/pycharm/connect-to-devcontainer.
## :computer: Local development

The only required system dependencies are [python >= 3.10](https://www.python.org/) and
[poetry](https://python-poetry.org/).
[PDM](https://pdm-project.org/).
However, we recommend installing some extra dependencies to improve the development experience.

:point_right: Follow [instructions](https://microsoft.github.io/cookie-doh/dev_setup)
Expand All @@ -88,7 +88,7 @@ to set up your local environment.

Cookie-doh uses and generates projects with the following tools to help the development experience:

* [Poetry](https://python-poetry.org/) for dependency management, virtual environments and
* [PDM](https://pdm-project.org/) for dependency management, virtual environments and
packaging, i.e., makes your code readily importable!
* [ruff](https://github.com/astral-sh/ruff) for formatting and linting: helps you write clean and uniform code for better consistency (and it's fast!).
* [pytest](https://docs.pytest.org/en/stable/) for testing: ensures your code is working as expected!
Expand Down
2 changes: 1 addition & 1 deletion bin/build-docs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
set -e

rm -rf dist/site
poetry run mkdocs build --site-dir=dist/site
pdm run mkdocs build --site-dir=dist/site
10 changes: 5 additions & 5 deletions bin/check-all
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ pre-commit run --all

echo
echo "RUNNING RUFF CHECK"
poetry run ruff check
pdm run ruff check

echo
echo "RUNNING RUFF FORMAT"
poetry run ruff format
pdm run ruff format

echo
echo "RUNNING PYRIGHT"
poetry run pyright
pdm run pyright

echo
echo "RUNNING CODESPELL"
poetry run codespell
pdm run codespell

echo
echo "RUNNING PYTEST AND COVERAGE"
poetry run coverage run -m pytest
pdm run coverage run -m pytest

echo
echo "BUILDING DOCS"
Expand Down
2 changes: 1 addition & 1 deletion bin/serve-docs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
set -e

poetry run mkdocs serve
pdm run mkdocs serve
10 changes: 5 additions & 5 deletions copier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ _subdirectory: template
_exclude:
- CHANGELOG.md
- cookie-doh.code-workspace
- poetry.lock
- pdm.lock
- copier.yaml
- copier.yml
- .git
Expand All @@ -83,7 +83,7 @@ _message_after_copy: |
Your project "{{ project_name }}" has been created successfully! 🎉
Required dependencies:
* Make sure you have `python >= 3.10` and `poetry` installed.
* Make sure you have `python >= 3.10` and `pdm` installed.
* Instructions: https://microsoft.github.io/cookie-doh/dev_setup
* You can also install optional tools like `direnv` and `pre-commit` following the link above
if needed for your project.
Expand Down Expand Up @@ -113,10 +113,10 @@ _message_after_copy: |
{% endif -%}
3. Add project dependencies to `pyproject.toml` and install them with Poetry:
3. Add project dependencies to `pyproject.toml` and install them with PDM:
$ poetry add <new-dependencies> # optional
$ poetry install
$ pdm add <new-dependencies> # optional
$ pdm install
4. Add the project outputs, configure pre-commit and commit your changes:
Expand Down
8 changes: 4 additions & 4 deletions docs/dev_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Check the [minimum required dependencies](#minimum-required-dependencies) and in
### Minimum required dependencies:

* [python >= 3.10](https://www.python.org/downloads/): we recommend installing python via [pyenv](#pyenv).
* [poetry](https://python-poetry.org/docs/#installation): we recommend installing [poetry](#poetry) with [pipx](#pipx).
* [PDM](https://pdm-project.org/en/latest/#installation): we recommend installing [PDM](#pdm) with [pipx](#pipx).


### [Direnv](https://direnv.net/)
Expand All @@ -30,7 +30,7 @@ echo 'eval "$(direnv hook bash)"' >> ~/.bashrc # if you use bash
echo 'eval "$(direnv hook zsh)"' >> ~/.zshrc # if you use zsh
eval "$(direnv hook bash)" # add to current shell

# Add poetry support to direnv
# Add PDM support to direnv
mkdir -p ~/.config/direnv/
cp .devcontainer/direnvrc ~/.config/direnv/direnvrc
```
Expand Down Expand Up @@ -92,11 +92,11 @@ pipx ensurepath
```


### [Poetry](https://python-poetry.org/)
### [PDM](https://pdm-project.org/)
To manage package dependencies and virtual environments.

```bash
pipx install poetry
pipx install pdm
```


Expand Down
6 changes: 3 additions & 3 deletions docs/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

Required dependencies:

* Make sure you have `python >= 3.10` and `poetry` installed.
* Make sure you have `python >= 3.10` and `PDM` installed.
* Instructions: https://microsoft.github.io/cookie-doh/dev_setup
* You can also install optional tools like `direnv` and `pre-commit` following the link above
if needed for your project.
Expand Down Expand Up @@ -45,8 +45,8 @@ Once you've created your new repository, the creation process will tell you to:
3. Install dependencies:
```bash
poetry add <dependencies>
poetry install
pdm add <dependencies>
pdm install
```
4. Commit the initial files:
Expand Down
6 changes: 3 additions & 3 deletions docs/getting_started.md.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ and the corresponding line in the `docs/.pages` file from your project.

Required dependencies:

* Make sure you have `python >= 3.10` and `poetry` installed.
* Make sure you have `python >= 3.10` and `pdm` installed.
* Instructions: https://microsoft.github.io/cookie-doh/dev_setup
* You can also install optional tools like `direnv` and `pre-commit` following the link above
if needed for your project.
Expand Down Expand Up @@ -40,8 +40,8 @@ Once you've created your new repository, the creation process will tell you to:
```
3. Install dependencies:
```bash
poetry add <dependencies>
poetry install
pdm add <dependencies>
pdm install
```
4. Commit the initial files:
```bash
Expand Down
12 changes: 6 additions & 6 deletions docs/repo_structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ by opening your project's folder.
This will set up VSCode with convenient settings and recommended extensions.
* Put your python code in `src/{{project_name}}`, tests in `test/test_{{project_name}}`,
and markdown documentation in `docs`.
* When you run `poetry install` it will install the `src` package in editable mode, so every package
* When you run `pdm install` it will install the `src` package in editable mode, so every package
and module you add will be available to import locally in your project.
* Add new dependencies to `pyproject.toml` and run `poetry install` to install them or
run `poetry add <package>` to add a new dependency. Run `poetry update` to update all dependencies.
Poetry will create a `.venv` folder with a virtual environment inside your project (configurable
with `poetry.toml`).
* To run tests, use `poetry run pytest`, or if you use [_direnv_](https://github.com/direnv/direnv)
* Add new dependencies to `pyproject.toml` and run `pdm install` to install them or
run `pdm add <package>` to add a new dependency. Run `pdm update` to update all dependencies.
PDM will create a `.venv` folder with a virtual environment inside your project (configurable
with `pdm.toml`).
* To run tests, use `pdm run pytest`, or if you use [_direnv_](https://github.com/direnv/direnv)
and have [enabled](dev_setup.md#direnv) it, simply run `pytest`.
* You will only get the `docs` folder if you enabled documentation builds in the _copier_ prompts.
Add your markdown documentation to the `docs` folder and run `bin/serve-docs` to see a live preview
Expand Down
Loading

0 comments on commit d92d7eb

Please sign in to comment.