diff --git a/.github/workflows/ci-copier.yml b/.github/workflows/ci-copier.yml index dcbfe843..6627b872 100644 --- a/.github/workflows/ci-copier.yml +++ b/.github/workflows/ci-copier.yml @@ -84,12 +84,11 @@ jobs: # Replace actions trigger with on: [push] yq eval '.on = ["push"]' -i .github/workflows/ci.yml yq eval '.on = ["push"]' -i .github/workflows/build.yml - git add .github/workflows/ci.yml .github/workflows/build.yml - git commit -m "Replace actions trigger with on: [push]" + git init # create pixi.lock - pixi list --manifest-path pixi.toml --color=always - git add pixi.lock - git commit -m "Create pixi.lock" + pixi lock --manifest-path pixi.toml --color=always + git add . + git commit -m "Initial commit" # Push the generated package's HEAD commit to a `ci/*` branch cid=$(git rev-parse HEAD) git push -f "${GITHUB_SERVER_URL/https:\/\//git@}:$GITHUB_REPOSITORY" $cid:refs/heads/${STEPS_BRANCH_OUTPUTS_NAME} diff --git a/copier.yml b/copier.yml index 467decaa..79cb2d15 100644 --- a/copier.yml +++ b/copier.yml @@ -62,7 +62,3 @@ add_autobump_workflow: type: bool help: Do you want to add a GitHub Workflow to automatically bump `pixi.lock`? default: true - -_tasks: - - '"{{ _copier_python }}" -I -c "import sys; sys.path.insert(0, \"{{ _copier_conf.src_path }}\"); import runpy; - runpy.run_module(\"tasks\", run_name=\"__main__\")"' diff --git a/tasks/__init__.py b/tasks/__init__.py deleted file mode 100644 index 40014a0a..00000000 --- a/tasks/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -# Copyright (c) QuantCo 2023-2024 -# SPDX-License-Identifier: LicenseRef-QuantCo - -from .git_init import GitInitTask - -__all__ = ["GitInitTask"] diff --git a/tasks/__main__.py b/tasks/__main__.py deleted file mode 100644 index 7b2aef55..00000000 --- a/tasks/__main__.py +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright (c) QuantCo 2023-2024 -# SPDX-License-Identifier: LicenseRef-QuantCo - -import logging - -from . import GitInitTask - -tasks = [GitInitTask()] - - -def main(): - logging.basicConfig(level=logging.WARNING) - - for task in tasks: - task.run() - - -if __name__ == "__main__": - main() diff --git a/tasks/git_init.py b/tasks/git_init.py deleted file mode 100644 index 170ea89d..00000000 --- a/tasks/git_init.py +++ /dev/null @@ -1,27 +0,0 @@ -# Copyright (c) QuantCo 2023-2024 -# SPDX-License-Identifier: LicenseRef-QuantCo - -import logging -import os -from subprocess import check_output - - -class GitInitTask: - def run(self): - if not os.path.exists(".git"): - git_version = check_output(["git", "--version"]).decode().split()[2] - git_major, git_minor = (int(v) for v in git_version.split(".")[:2]) - git_too_old = (git_major < 2) or (git_major == 2 and git_minor < 28) - # Warn user about --initial-branch option failing for older versions of git - if git_too_old: - logging.warning( - f"Please update your version of git; found version {git_version} " - "when this copier template requires at least 2.28." - ) - check_output(["git", "init", "."]) - else: - check_output(["git", "init", "--initial-branch=main", "."]) - - check_output(["git", "add", "."]) - check_output(["git", "commit", "-m", "Initial project skeleton"]) - check_output(["git", "tag", "0.0.1"]) diff --git a/template/.github/workflows/build.yml b/template/.github/workflows/build.yml index a68f69e8..81d72db2 100644 --- a/template/.github/workflows/build.yml +++ b/template/.github/workflows/build.yml @@ -18,12 +18,21 @@ jobs: fetch-depth: 0 - name: Set up pixi uses: prefix-dev/setup-pixi@a0af7a228712d6121d37aba47adf55c1332c9c2e # v0.9.4 - with: - environments: build + - name: Derive version + id: version + if: startsWith(github.ref, 'refs/tags/') + shell: bash + run: echo "version=$(git describe --tags --abbrev=0 | sed 's/^v//')" >> $GITHUB_OUTPUT + - name: Replace version + if: startsWith(github.ref, 'refs/tags/') + run: | + sed -i -e "s/0.0.0/${STEPS_VERSION_OUTPUTS_VERSION}/g" pyproject.toml + env: + STEPS_VERSION_OUTPUTS_VERSION: ${{ steps.version.outputs.version }} - name: Build project - run: pixi run -e build build-wheel + run: pixi run build-wheel - name: Check package - run: pixi run -e build check-wheel + run: pixi run check-wheel - name: Upload package uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0 with: diff --git a/template/.github/workflows/ci.yml.jinja b/template/.github/workflows/ci.yml.jinja index fd66ce5a..55e1d8c3 100644 --- a/template/.github/workflows/ci.yml.jinja +++ b/template/.github/workflows/ci.yml.jinja @@ -55,8 +55,6 @@ jobs: uses: prefix-dev/setup-pixi@a0af7a228712d6121d37aba47adf55c1332c9c2e # v0.9.4 with: environments: ${{ matrix.environment }} - - name: Install repository - run: pixi run -e ${{ matrix.environment }} postinstall - name: Run pytest run: pixi run -e ${{ matrix.environment }} test-coverage --color=yes {%- endraw %} diff --git a/template/pixi.toml.jinja b/template/pixi.toml.jinja index 34081260..89de7945 100644 --- a/template/pixi.toml.jinja +++ b/template/pixi.toml.jinja @@ -2,18 +2,22 @@ name = "{{ project_slug }}" channels = ["conda-forge"] platforms = ["osx-arm64", "osx-64", "linux-64", "win-64"] +preview = ["pixi-build"] -[tasks] -postinstall = "pip install --no-build-isolation --no-deps --disable-pip-version-check -e ." +[package] +name = "{{ project_slug }}" +[package.build.backend] +name = "pixi-build-python" +version = "*" +[package.host-dependencies] +python = ">={{ minimal_python_version.replace('py3', '3.') }}" +hatchling = "*" [dependencies] -python = ">={{ minimal_python_version.replace('py3', '3.') }}" -pip = "*" -setuptools = ">=61" -setuptools-scm = "*" +{{ project_slug if "." not in project_slug else ('"' ~ project_slug ~ '"') }} = { path = "." } [feature.test.dependencies] -pytest = ">=6" +pytest = "*" pytest-cov = "*" mypy = "*" [feature.test.tasks] @@ -21,16 +25,16 @@ test = "pytest" test-coverage = "pytest --cov={{ project_slug_snake_case }} --cov-report=xml --cov-report=term-missing" [feature.build.dependencies] +python = "*" +hatchling = "*" python-build = "*" -twine = "*" -wheel = "*" +twine = ">=6" [feature.build.tasks] build-wheel = "python -m build --no-isolation ." check-wheel = "twine check dist/*" [feature.lint.dependencies] lefthook = "*" -insert-license-header = "*" docformatter = "*" ruff = "*" prettier = "*" @@ -55,7 +59,7 @@ python = "3.14.*" {%- endif %} [environments] -default = ["test", "lint"] +default = ["test", "build", "lint"] {%- if minimal_python_version <= "py310" %} py310 = ["py310", "test"] {%- endif %} @@ -71,7 +75,3 @@ py313 = ["py313", "test"] {%- if minimal_python_version <= "py314" %} py314 = ["py314", "test"] {%- endif %} -{%- if build_docs %} -docs = ["docs"] -{%- endif %} -build = ["build"] diff --git a/template/pyproject.toml.jinja b/template/pyproject.toml.jinja index ec7364a3..8fb0514c 100644 --- a/template/pyproject.toml.jinja +++ b/template/pyproject.toml.jinja @@ -1,14 +1,13 @@ [build-system] -requires = ["setuptools", "setuptools-scm", "wheel"] - -[tool.setuptools_scm] -version_scheme = "post-release" +requires = ["hatchling"] +build-backend = "hatchling.build" [project] name = "{{ project_slug }}" description = "{{ project_short_description }}" authors = [{ name = "{{ author_name }}", email = "{{ author_email }}" }] -dynamic = ["version"] +# replaced in CI +version = "0.0.0" classifiers = [ "Programming Language :: Python :: 3", {%- if minimal_python_version <= "py310" %} diff --git a/tests/test_tasks.py b/tests/test_tasks.py deleted file mode 100644 index b722dcf4..00000000 --- a/tests/test_tasks.py +++ /dev/null @@ -1,26 +0,0 @@ -from tasks import GitInitTask - -from .utils import change_directory, git_user - - -def test_git_init(tmp_path): - # Create a file for git to add and commit - (tmp_path / "file").touch() - - task = GitInitTask() - with change_directory(tmp_path): - with git_user(): - task.run() - - assert (tmp_path / ".git").is_dir() - - -def test_git_init_already_exists(tmp_path): - (tmp_path / ".git").mkdir() - - task = GitInitTask() - with change_directory(tmp_path): - with git_user(): - task.run() - - # No asserts. We just want no exceptions