From 7a31d2d087a782a387b140a385f879ca7866a196 Mon Sep 17 00:00:00 2001 From: Albert DeFusco Date: Tue, 30 Jan 2024 13:18:41 -0600 Subject: [PATCH 01/15] support pydantic 2 using the v1 fallback for now --- environment.yml | 12 +++++++++--- etc/test-environment.yml | 3 +-- pyproject.toml | 2 +- src/conda_project/project.py | 8 +++++++- src/conda_project/project_file.py | 9 ++++++++- 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/environment.yml b/environment.yml index debf36ba..78c883f2 100644 --- a/environment.yml +++ b/environment.yml @@ -1,5 +1,4 @@ channels: - - defaults - conda-forge dependencies: - python=3.8 @@ -10,9 +9,16 @@ dependencies: - pytest-cov - pytest-mock - pre-commit - - conda-lock>=1.2 + - conda-lock>=2.2 - pydantic - ruamel.yaml - - setuptools-scm + - setuptools-scm>=6.2 + - shellingham + - python-dotenv + - lockfile + - pexpect - fsspec - python-libarchive-c + - pip + - pip: + - -e . diff --git a/etc/test-environment.yml b/etc/test-environment.yml index 7880d9b5..983e4d81 100644 --- a/etc/test-environment.yml +++ b/etc/test-environment.yml @@ -1,9 +1,8 @@ name: test-conda-project channels: - - defaults - conda-forge dependencies: - - conda-lock>=2.1.1 + - conda-lock>=2.2 - pexpect - lockfile - ruamel.yaml diff --git a/pyproject.toml b/pyproject.toml index 0b49cb65..ab2d55ee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,7 +31,7 @@ classifiers = [ "Topic :: Utilities", ] dependencies = [ - "conda-lock >=1.2", + "conda-lock >=2.2", "lockfile", "pexpect", "ruamel.yaml", diff --git a/src/conda_project/project.py b/src/conda_project/project.py index e1a565c1..a06c4fde 100644 --- a/src/conda_project/project.py +++ b/src/conda_project/project.py @@ -30,7 +30,13 @@ render_lockfile_for_platform, ) from fsspec.core import split_protocol -from pydantic import BaseModel, create_model + +try: + # Version 2 provides a v1 API + from pydantic.v1 import BaseModel, create_model +except ImportError: + from pydantic import BaseModel # type: ignore + from pydantic import create_model # type: ignore from .conda import ( CONDA_EXE, diff --git a/src/conda_project/project_file.py b/src/conda_project/project_file.py index 210c6fec..4b3c0fc7 100644 --- a/src/conda_project/project_file.py +++ b/src/conda_project/project_file.py @@ -9,9 +9,16 @@ from conda_lock._vendor.conda.models.match_spec import MatchSpec from pkg_resources import Requirement -from pydantic import BaseModel, ValidationError, validator from ruamel.yaml import YAML +try: + # Version 2 provides a v1 API + from pydantic.v1 import BaseModel, ValidationError, validator +except ImportError: + from pydantic import BaseModel # type: ignore + from pydantic import ValidationError # type: ignore + from pydantic import validator # type: ignore + from .exceptions import CondaProjectError PROJECT_YAML_FILENAMES = ("conda-project.yml", "conda-project.yaml") From fb1db617dce146571c526cd54891886934f92d66 Mon Sep 17 00:00:00 2001 From: Albert DeFusco Date: Thu, 1 Feb 2024 14:31:18 -0600 Subject: [PATCH 02/15] missed one --- tests/test_project_file.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/test_project_file.py b/tests/test_project_file.py index 516bd947..73a895ff 100644 --- a/tests/test_project_file.py +++ b/tests/test_project_file.py @@ -7,7 +7,12 @@ from typing import Dict, List, Optional, Union import pytest -from pydantic import ValidationError + +try: + # Version 2 provides a v1 API + from pydantic.v1 import ValidationError +except ImportError: + from pydantic import ValidationError # type: ignore from conda_project.exceptions import CondaProjectError from conda_project.project_file import ( From 8bf1ffb03859227b5eacb46c1c25fdd695905455 Mon Sep 17 00:00:00 2001 From: Albert DeFusco Date: Fri, 2 Feb 2024 11:30:18 -0600 Subject: [PATCH 03/15] switch libmamba install order --- .github/workflows/main.yaml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 03671ebb..25045f37 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -81,14 +81,6 @@ jobs: shell: bash run: | ./conda.exe create -p $HOME/miniconda conda=${{ matrix.conda-version }} python=${{ matrix.python-version }} - - name: Update with test dependencies - shell: bash - run: | - if [ $RUNNER_OS == 'Windows' ]; then - source $HOME/miniconda/Scripts/activate root && conda env update -f etc/test-environment.yml -p $HOME/miniconda && $HOME/miniconda/Scripts/pip install --no-deps . - else - source $HOME/miniconda/bin/activate root && conda env update -f etc/test-environment.yml -p $HOME/miniconda && $HOME/miniconda/bin/pip install --no-deps . - fi - name: Install Libmamba shell: bash run: | @@ -101,6 +93,14 @@ jobs: conda install conda-libmamba-solver -p $HOME/miniconda fi fi + - name: Update with test dependencies + shell: bash + run: | + if [ $RUNNER_OS == 'Windows' ]; then + source $HOME/miniconda/Scripts/activate root && conda env update -f etc/test-environment.yml -p $HOME/miniconda && $HOME/miniconda/Scripts/pip install --no-deps . + else + source $HOME/miniconda/bin/activate root && conda env update -f etc/test-environment.yml -p $HOME/miniconda && $HOME/miniconda/bin/pip install --no-deps . + fi - name: py.test shell: bash env: From 7efab6fd23d85576fbb3fab770101561201dd8dd Mon Sep 17 00:00:00 2001 From: Albert DeFusco Date: Fri, 2 Feb 2024 16:02:05 -0600 Subject: [PATCH 04/15] get version into CI/CD build --- conda.recipe/meta.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conda.recipe/meta.yaml b/conda.recipe/meta.yaml index 4463e231..07264a3c 100644 --- a/conda.recipe/meta.yaml +++ b/conda.recipe/meta.yaml @@ -12,7 +12,7 @@ source: path: .. build: - script: {{ PYTHON }} -m pip install . -vv + script: SETUPTOOLS_SCM_PRETEND_VERSION={{version}} {{ PYTHON }} -m pip install . -vv noarch: python entry_points: {% for name, reference in project['scripts'].items() %} From f8f0b58011ec9f65dadcd917da65dca63094f90b Mon Sep 17 00:00:00 2001 From: Albert DeFusco Date: Fri, 2 Feb 2024 16:13:32 -0600 Subject: [PATCH 05/15] version assert in conda.recipe --- conda.recipe/meta.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conda.recipe/meta.yaml b/conda.recipe/meta.yaml index 07264a3c..fbf8a891 100644 --- a/conda.recipe/meta.yaml +++ b/conda.recipe/meta.yaml @@ -42,7 +42,7 @@ test: commands: - conda-project --help - conda-project --version - - python -c "import conda_project; ver = conda_project.__version__; assert ver != '0.0.0' and ver != 'unknown'" + - python -c "from conda_project import __version__; assert __version__ == \"{{ version }}\"" about: home: {{ project['urls']['repository'] }} From 905b23e1e627e5dbf7bb0c38eaeafd5eb9c1ec17 Mon Sep 17 00:00:00 2001 From: Albert DeFusco Date: Fri, 2 Feb 2024 21:39:54 -0600 Subject: [PATCH 06/15] switch to hatch --- conda.recipe/meta.yaml | 7 +++++-- pyproject.toml | 19 +++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/conda.recipe/meta.yaml b/conda.recipe/meta.yaml index fbf8a891..bc553406 100644 --- a/conda.recipe/meta.yaml +++ b/conda.recipe/meta.yaml @@ -23,10 +23,12 @@ requirements: host: - python {{ project['requires-python'] }} - pip - - setuptools + {% for dep in pyproject['build-system']['requires'] %} + - {{ dep.lower() }} + {% endfor %} run: - python {{ project['requires-python'] }} - - conda-lock >=1.2 + - conda-lock >=2.2 - lockfile - pexpect - ruamel.yaml @@ -39,6 +41,7 @@ requirements: test: imports: - conda_project + - from conda_project import CondaProject commands: - conda-project --help - conda-project --version diff --git a/pyproject.toml b/pyproject.toml index ab2d55ee..c8fa41d2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [build-system] -requires = ["setuptools>=42", "wheel", "setuptools-scm[toml]>=6.2"] -build-backend = "setuptools.build_meta" +build-backend = "hatchling.build" +requires = ["hatchling", "hatch-vcs>=0.3", "setuptools-scm>=7.1"] [project] name = "conda-project" @@ -42,9 +42,20 @@ dependencies = [ "libarchive-c" ] -[tool.setuptools_scm] +[tool.hatch.version] +source = "vcs" + +[tool.hatch.build.hooks.vcs] +version-file = "src/conda_project/_version.py" + +[tool.hatch.version.raw-options] version_scheme = "post-release" -write_to = "src/conda_project/_version.py" + +[tool.hatch.build.targets.sdist] +include = [ + "/src/conda_project", + "/pyproject.toml" +] [project.optional-dependencies] docs = [ From ec68a2cc424579ecdf88b1751bc6245049d477c4 Mon Sep 17 00:00:00 2001 From: Albert DeFusco Date: Sat, 3 Feb 2024 08:50:08 -0600 Subject: [PATCH 07/15] conda-forge --- .github/workflows/main.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 25045f37..c11ee42a 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -38,7 +38,7 @@ jobs: - name: conda Build shell: bash -l {0} run: | - VERSION=`python -m setuptools_scm` conda build conda.recipe + VERSION=`python -m setuptools_scm` conda build -c conda-forge conda.recipe mv $CONDA_PREFIX/conda-bld . - name: Upload the build artifact uses: actions/upload-artifact@v3 From 4103d757ad66c45ea511c14d5cea7a64e1e6ad92 Mon Sep 17 00:00:00 2001 From: Albert DeFusco Date: Sat, 3 Feb 2024 08:57:40 -0600 Subject: [PATCH 08/15] so close --- conda.recipe/meta.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/conda.recipe/meta.yaml b/conda.recipe/meta.yaml index bc553406..cefc30a3 100644 --- a/conda.recipe/meta.yaml +++ b/conda.recipe/meta.yaml @@ -41,7 +41,6 @@ requirements: test: imports: - conda_project - - from conda_project import CondaProject commands: - conda-project --help - conda-project --version From f8a8aee06ff6513c4f2031bedf2e5eec1a33da7f Mon Sep 17 00:00:00 2001 From: Albert DeFusco Date: Sat, 3 Feb 2024 10:26:16 -0600 Subject: [PATCH 09/15] Update meta.yaml --- conda.recipe/meta.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conda.recipe/meta.yaml b/conda.recipe/meta.yaml index cefc30a3..41998452 100644 --- a/conda.recipe/meta.yaml +++ b/conda.recipe/meta.yaml @@ -42,8 +42,8 @@ test: imports: - conda_project commands: - - conda-project --help - - conda-project --version + # conda-project --help + # conda-project --version - python -c "from conda_project import __version__; assert __version__ == \"{{ version }}\"" about: From 9d9b4b0555da23cfa7bb0ebb4eb00899799267a8 Mon Sep 17 00:00:00 2001 From: Albert DeFusco Date: Sat, 3 Feb 2024 11:29:35 -0600 Subject: [PATCH 10/15] Update main.yaml --- .github/workflows/main.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index c11ee42a..5f8c5fed 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -38,7 +38,7 @@ jobs: - name: conda Build shell: bash -l {0} run: | - VERSION=`python -m setuptools_scm` conda build -c conda-forge conda.recipe + VERSION=`hatch version` conda build -c conda-forge conda.recipe mv $CONDA_PREFIX/conda-bld . - name: Upload the build artifact uses: actions/upload-artifact@v3 From 9bedf60fa08ea1ba0397e46c6b79ecab3f53b8a3 Mon Sep 17 00:00:00 2001 From: Albert DeFusco Date: Sat, 3 Feb 2024 11:31:10 -0600 Subject: [PATCH 11/15] Almost there --- etc/build-environment.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/etc/build-environment.yml b/etc/build-environment.yml index 337d4873..cf0056fc 100644 --- a/etc/build-environment.yml +++ b/etc/build-environment.yml @@ -3,4 +3,7 @@ dependencies: - conda - conda-build - conda-verify + - hatch + - hatchling + - hatch-vcs - setuptools-scm From 1f235b562e0cdb7a61de052b0c7c9dcec86f1f0b Mon Sep 17 00:00:00 2001 From: Albert DeFusco Date: Sat, 3 Feb 2024 13:23:42 -0600 Subject: [PATCH 12/15] =?UTF-8?q?One=20more=20=F0=9F=A4=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- etc/build-environment.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/etc/build-environment.yml b/etc/build-environment.yml index cf0056fc..37c5e484 100644 --- a/etc/build-environment.yml +++ b/etc/build-environment.yml @@ -1,4 +1,7 @@ name: build-conda-project +channels: + - defaults + - conda-forge dependencies: - conda - conda-build From 1ea596249c2fc7044edf63ffe54a95caa77f3d09 Mon Sep 17 00:00:00 2001 From: Albert DeFusco Date: Sat, 3 Feb 2024 17:34:58 -0600 Subject: [PATCH 13/15] packaging updates * try to fix conda-build step exit 1 * add pypi publish --- .github/workflows/main.yaml | 58 +++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 5f8c5fed..f4f198a2 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -21,8 +21,8 @@ on: jobs: - package: - name: Build package + conda-package: + name: Build Conda package runs-on: "ubuntu-latest" steps: - uses: actions/checkout@v3 @@ -38,13 +38,37 @@ jobs: - name: conda Build shell: bash -l {0} run: | - VERSION=`hatch version` conda build -c conda-forge conda.recipe - mv $CONDA_PREFIX/conda-bld . + VERSION=`hatch version` conda build -c conda-forge --output-directory conda-build conda.recipe - name: Upload the build artifact uses: actions/upload-artifact@v3 with: name: package-${{ github.sha }} - path: conda-bld + path: conda-build + + build-wheel: + name: Build the wheel + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + with: + fetch-depth: 0 + - name: Setup Python + uses: actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236 # v4 + with: + python-version: "3.10" + - name: Install build dependencies + run: pip install build + - name: Build the package + run: python -m build + - name: Upload the build artifact + uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3 + with: + name: wheel-${{ github.sha }} + path: dist/*.whl + if-no-files-found: error + retention-days: 7 + test: name: Test (conda ${{ matrix.conda-version }}, Python ${{ matrix.python-version }}, ${{ matrix.os }}) runs-on: ${{ matrix.os }} @@ -154,6 +178,30 @@ jobs: uses: glassechidna/artifact-cleaner@master with: minimumAge: 86400 + + publish-to-pypi: + name: Build & publish to PyPI + if: github.event_name == 'push' && github.event_name == 'release' && github.event.action == 'created' + runs-on: ubuntu-latest + needs: [check] + steps: + - name: Checkout + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + - name: Setup Python + uses: actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236 # v4 + - name: Download the build artifacts + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3 + with: + name: wheel-${{ github.sha }} + path: ~/dist + - name: Install build dependencies + run: pip install twine + - name: Upload to PyPI with twine + run: python -m twine upload ~/dist/* + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN}} + # This check job runs to ensure all tests have passed, such that we can use it as a "wildcard" for branch # protection to ensure all tests pass before a PR can be merged. check: From f47eda078a8d4da341f251092113cb607eaff55c Mon Sep 17 00:00:00 2001 From: Albert DeFusco Date: Sat, 3 Feb 2024 17:37:58 -0600 Subject: [PATCH 14/15] =?UTF-8?q?=F0=9F=98=94=20so=20close?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/main.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index f4f198a2..809607f3 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -38,7 +38,7 @@ jobs: - name: conda Build shell: bash -l {0} run: | - VERSION=`hatch version` conda build -c conda-forge --output-directory conda-build conda.recipe + VERSION=`hatch version` conda build -c conda-forge --output-folder conda-build conda.recipe - name: Upload the build artifact uses: actions/upload-artifact@v3 with: From 3d2e1747239ef98ae3656e15077f949704355167 Mon Sep 17 00:00:00 2001 From: Albert DeFusco Date: Sat, 3 Feb 2024 19:02:00 -0600 Subject: [PATCH 15/15] maybe without setupminiconda --- .github/workflows/main.yaml | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 809607f3..ddfc2375 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -28,16 +28,13 @@ jobs: - uses: actions/checkout@v3 with: fetch-depth: 0 - - uses: conda-incubator/setup-miniconda@v2 - with: - miniconda-version: "latest" - activate-environment: build-conda-token - environment-file: etc/build-environment.yml - python-version: 3.8 - auto-activate-base: false + - name: Create build environment + run: | + source $CONDA/bin/activate + conda env create -f etc/build-environment.yml - name: conda Build - shell: bash -l {0} run: | + source $CONDA/bin/activate && conda activate build-conda-project VERSION=`hatch version` conda build -c conda-forge --output-folder conda-build conda.recipe - name: Upload the build artifact uses: actions/upload-artifact@v3