Skip to content

Commit

Permalink
Move from poetry to hatch to manage the environment (Fixes #9)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericof committed Apr 25, 2024
1 parent a48cb3a commit b1f1079
Show file tree
Hide file tree
Showing 35 changed files with 294 additions and 1,086 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Changelog check
on:
pull_request:
types: [assigned, opened, synchronize, reopened, labeled, unlabeled]
branches:
- main

env:
PYTHON_VERSION: 3.11

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
# Fetch all history
fetch-depth: '0'

- name: Install hatch
run: pipx install hatch

- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: 'pip'

- name: "Install Environment"
run: hatch env create

- name: Check for presence of a Change Log fragment (only pull requests)
run: |
git fetch --no-tags origin ${BASE_BRANCH}
towncrier check
env:
BASE_BRANCH: ${{ github.base_ref }}
if: github.event_name == 'pull_request'
24 changes: 12 additions & 12 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,36 @@ jobs:
- name: Checkout codebase
uses: actions/checkout@v4

- name: Install poetry
run: pipx install poetry
- name: Install hatch
run: pipx install hatch

- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: 'poetry'
cache: 'pip'

- name: "Install Packages"
run: poetry install
- name: "Install Environment"
run: hatch env create

- name: "Run checks"
run: poetry run pre-commit run -a
run: hatch run check

test:
runs-on: ubuntu-latest
steps:
- name: Checkout codebase
uses: actions/checkout@v4

- name: Install poetry
run: pipx install poetry
- name: Install hatch
run: pipx install hatch

- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: 'poetry'
cache: 'pip'

- name: "Install Packages"
run: poetry install
- name: "Install Environment"
run: hatch env create

- name: "Test Codebase"
run: poetry run pytest --cov --cov-config=pyproject.toml --cov-report=xml
run: hatch run tests
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@ repos:
- id: codespell
additional_dependencies:
- tomli
- repo: https://github.com/regebro/pyroma
rev: "4.2"
hooks:
- id: pyroma
args: ["-d", "--min=10", "."]
10 changes: 10 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Changelog

<!--
You should *NOT* be adding new change log entries to this file.
You should create a file in the news directory instead.
For helpful instructions, please see:
https://github.com/plone/plone.releaser/blob/master/ADD-A-NEWS-ITEM.rst
-->

<!-- towncrier release notes start -->
9 changes: 9 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License

Copyright (c) 2024-present Plone Foundation <board@plone.org>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
44 changes: 16 additions & 28 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,41 +42,29 @@ all: help
help: ## This help message
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.PHONY: clean
clean: ## Clean up the environment
@echo "🚀 Cleanup the current environment"
@rm -rf .pytest_cache .ruff_cache .coverage coverage.xml .tox .venv

.PHONY: install
install: ## Install the poetry environment and install the pre-commit hooks
@echo "🚀 Creating virtual environment using pyenv and poetry"
@poetry install
if [ -d $(GIT_FOLDER) ]; then poetry run pre-commit install; else echo "$(RED) Not installing pre-commit$(RESET)";fi
@poetry shell
install: ## Install the default environment
@echo "🚀 Creating virtual environment using hatch"
@pipx install hatch
@hatch env create
if [ -d $(GIT_FOLDER) ]; then hatch run pre-commit install; else echo "$(RED) Not installing pre-commit$(RESET)";fi

.PHONY: check
check: ## Run code quality tools.
@echo "🚀 Checking Poetry lock file consistency with 'pyproject.toml': Running poetry lock --check"
@poetry lock --check
@echo "🚀 Linting code: Running pre-commit"
@poetry run pre-commit run -a
@hatch run check

.PHONY: test
test: ## Test the code with pytest
@echo "🚀 Testing code: Running pytest"
@poetry run pytest --cov --cov-config=pyproject.toml --cov-report=xml

.PHONY: build
build: clean-build ## Build wheel file using poetry
@echo "🚀 Creating wheel file"
@poetry build

.PHONY: clean-build
clean-build: ## clean build artifacts
@rm -rf dist

.PHONY: publish
publish: ## publish a release to pypi.
@echo "🚀 Publishing: Dry run."
@poetry config pypi-token.pypi $(PYPI_TOKEN)
@poetry publish --dry-run
@echo "🚀 Publishing."
@poetry publish
@hatch run test

.PHONY: build-and-publish
build-and-publish: build publish ## Build and publish.
.PHONY: release
release: ## Release the package to pypi.org
@echo "🚀 Release package"
@hatch run fullrelease
3 changes: 3 additions & 0 deletions cookieplone/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
# SPDX-FileCopyrightText: 2024-present Plone Foundation <board@plone.org>
#
# SPDX-License-Identifier: MIT
__version__ = "0.4.1"
3 changes: 3 additions & 0 deletions cookieplone/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# SPDX-FileCopyrightText: 2024-present Plone Foundation <board@plone.org>
#
# SPDX-License-Identifier: MIT
"""Allow cookieplone to be executable through `python -m cookieplone`."""

from cookieplone.cli import main
Expand Down
3 changes: 3 additions & 0 deletions cookieplone/cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# SPDX-FileCopyrightText: 2024-present Plone Foundation <board@plone.org>
#
# SPDX-License-Identifier: MIT
"""Main `cookieplone` CLI."""

import os
Expand Down
3 changes: 3 additions & 0 deletions cookieplone/data.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# SPDX-FileCopyrightText: 2024-present Plone Foundation <board@plone.org>
#
# SPDX-License-Identifier: MIT
from collections.abc import Callable
from dataclasses import dataclass
from pathlib import Path
Expand Down
3 changes: 3 additions & 0 deletions cookieplone/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# SPDX-FileCopyrightText: 2024-present Plone Foundation <board@plone.org>
#
# SPDX-License-Identifier: MIT
class CookieploneException(Exception):
"""Cookieplone base exception."""

Expand Down
3 changes: 3 additions & 0 deletions cookieplone/filters/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# SPDX-FileCopyrightText: 2024-present Plone Foundation <board@plone.org>
#
# SPDX-License-Identifier: MIT
import os

from cookiecutter.utils import simple_filter
Expand Down
3 changes: 3 additions & 0 deletions cookieplone/generator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# SPDX-FileCopyrightText: 2024-present Plone Foundation <board@plone.org>
#
# SPDX-License-Identifier: MIT
import json
from collections import OrderedDict
from pathlib import Path
Expand Down
3 changes: 3 additions & 0 deletions cookieplone/repository.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# SPDX-FileCopyrightText: 2024-present Plone Foundation <board@plone.org>
#
# SPDX-License-Identifier: MIT
import json
from pathlib import Path

Expand Down
3 changes: 3 additions & 0 deletions cookieplone/settings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# SPDX-FileCopyrightText: 2024-present Plone Foundation <board@plone.org>
#
# SPDX-License-Identifier: MIT
PLONE_MIN_VERSION = "6"

SUPPORTED_PYTHON_VERSIONS = [
Expand Down
3 changes: 3 additions & 0 deletions cookieplone/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# SPDX-FileCopyrightText: 2024-present Plone Foundation <board@plone.org>
#
# SPDX-License-Identifier: MIT
from cookiecutter.utils import rmtree

__all__ = ["rmtree"]
3 changes: 3 additions & 0 deletions cookieplone/utils/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# SPDX-FileCopyrightText: 2024-present Plone Foundation <board@plone.org>
#
# SPDX-License-Identifier: MIT
import re
import subprocess
import sys
Expand Down
3 changes: 3 additions & 0 deletions cookieplone/utils/console.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# SPDX-FileCopyrightText: 2024-present Plone Foundation <board@plone.org>
#
# SPDX-License-Identifier: MIT
import os
from textwrap import dedent

Expand Down
3 changes: 3 additions & 0 deletions cookieplone/utils/containers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# SPDX-FileCopyrightText: 2024-present Plone Foundation <board@plone.org>
#
# SPDX-License-Identifier: MIT
REGISTRIES = {"docker_hub": "", "github": "ghcr.io/", "gitlab": "registry.gitlab.com/"}


Expand Down
3 changes: 3 additions & 0 deletions cookieplone/utils/files.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# SPDX-FileCopyrightText: 2024-present Plone Foundation <board@plone.org>
#
# SPDX-License-Identifier: MIT
from pathlib import Path

from cookiecutter.utils import rmtree
Expand Down
3 changes: 3 additions & 0 deletions cookieplone/utils/git.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# SPDX-FileCopyrightText: 2024-present Plone Foundation <board@plone.org>
#
# SPDX-License-Identifier: MIT
from pathlib import Path

from git import Commit, Repo
Expand Down
3 changes: 3 additions & 0 deletions cookieplone/utils/internal.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# SPDX-FileCopyrightText: 2024-present Plone Foundation <board@plone.org>
#
# SPDX-License-Identifier: MIT
import sys
from datetime import datetime
from pathlib import Path
Expand Down
3 changes: 3 additions & 0 deletions cookieplone/utils/sanity.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# SPDX-FileCopyrightText: 2024-present Plone Foundation <board@plone.org>
#
# SPDX-License-Identifier: MIT
from cookieplone import data


Expand Down
3 changes: 3 additions & 0 deletions cookieplone/utils/validators.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# SPDX-FileCopyrightText: 2024-present Plone Foundation <board@plone.org>
#
# SPDX-License-Identifier: MIT
import re
from typing import Any
from urllib.parse import urlparse
Expand Down
3 changes: 3 additions & 0 deletions cookieplone/utils/versions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# SPDX-FileCopyrightText: 2024-present Plone Foundation <board@plone.org>
#
# SPDX-License-Identifier: MIT
import requests
from packaging.version import Version

Expand Down
15 changes: 15 additions & 0 deletions news/.changelog_template.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% if sections[""] %}
{% for category, val in definitions.items() if category in sections[""] %}

### {{ definitions[category]['name'] }}

{% for text, values in sections[""][category].items() %}
- {{ text }} {{ values|join(', ') }}
{% endfor %}

{% endfor %}
{% else %}
No significant changes.


{% endif %}
1 change: 1 addition & 0 deletions news/9.internal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Move from poetry to hatch to manage the environment [@ericof]
Loading

0 comments on commit b1f1079

Please sign in to comment.