From 9c4adb69b2f744b3a30877a87aacc5242ccfc854 Mon Sep 17 00:00:00 2001 From: Giovanni Bussi Date: Mon, 20 May 2024 16:18:10 +0200 Subject: [PATCH] added conda workflow - install and run tests using conda - no deployment yet --- .github/workflows/python-package.yml | 56 ++++++++++++++++++++++++++++ conda/conda_build_config.yaml | 8 ++++ conda/meta.yaml.in | 39 +++++++++++++++++++ make_conda_recipe.py | 41 ++++++++++++++++++++ 4 files changed, 144 insertions(+) create mode 100644 conda/conda_build_config.yaml create mode 100644 conda/meta.yaml.in create mode 100644 make_conda_recipe.py diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index c30be39..7fe7cee 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -59,3 +59,59 @@ jobs: python setup.py sdist python -m twine upload -u __token__ -p "$MDREFINE_PYPI" dist/MDRefine-*.tar.gz + + conda: + + strategy: + matrix: + os: [ubuntu-latest, macos-12, macos-14] + + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v4 + - name: Install conda + run: | + curl -LO https://raw.githubusercontent.com/GiovanniBussi/conda-ci/master/conda-ci + source ./conda-ci install + source ./conda-ci install-conda-build + - name: Build + run: | + source activate base + python make_conda_recipe.py + export CPU_COUNT=2 + conda-build -c conda-forge conda + rm -fr MDRefine # make sure this is not imported by mistake in tests + - name: Test 3.9 + run: | + source activate base + conda create -n py39 -c conda-forge -c local python=3.9 MDRefine pytest + source activate py39 + pytest -v + - name: Test 3.10 + run: | + source activate base + conda create -n py310 -c conda-forge -c local python=3.10 MDRefine pytest + source activate py310 + pytest -v + - name: Test 3.11 + run: | + source activate base + conda create -n py311 -c conda-forge -c local python=3.11 MDRefine pytest + source activate py311 + pytest -v + - name: Test 3.12 + run: | + source activate base + conda create -n py312 -c conda-forge -c local python=3.12 MDRefine pytest + source activate py312 + pytest -v + - name: Deploy conda + if: ${{ matrix.os == 'ubuntu-latest' && startsWith(github.ref, 'refs/tags/') }} + #env: + # CONDA_UPLOAD_TOKEN: ${{ secrets.CONDA_UPLOAD_TOKEN }} + run: | + #TODO + #source activate base + #anaconda -t $CONDA_UPLOAD_TOKEN upload -u bussilab -l main $CONDA_PREFIX/conda-bld/*/py-bussilab*.tar.bz2 --force + diff --git a/conda/conda_build_config.yaml b/conda/conda_build_config.yaml new file mode 100644 index 0000000..53ef61b --- /dev/null +++ b/conda/conda_build_config.yaml @@ -0,0 +1,8 @@ +CONDA_BUILD_SYSROOT: + - /opt/MacOSX10.13.sdk # [osx and x86_64] + - /opt/MacOSX11.0.sdk # [osx and arm64] +python: + - "3.12" + - "3.11" + - "3.10" + - "3.9" diff --git a/conda/meta.yaml.in b/conda/meta.yaml.in new file mode 100644 index 0000000..6b91a1f --- /dev/null +++ b/conda/meta.yaml.in @@ -0,0 +1,39 @@ +package: + name: mdrefine + version: __VERSION__ + +source: + path: .. + +build: + number: 0 + noarch: python + script: "{{ PYTHON }} -m pip install . --no-deps -vv" + +requirements: + host: + - python >=3.9 + - pip + run: + __REQUIRED__ + - python >=3.9 + +test: + imports: + - MDRefine + #commands: + # - bussilab check --import + +about: + home: https://github.com/bussilab/MDRefine + license: LGPL-2.1 + license_family: GPL + summary: '__SUMMARY__' + description: | + __DESCRIPTION__ + #doc_url: https://bussilab.github.io/doc-py-bussilab + #dev_url: https://github.com/bussilab/py-bussilab + +extra: + recipe-maintainers: + - GiovanniBussi diff --git a/make_conda_recipe.py b/make_conda_recipe.py new file mode 100644 index 0000000..acd935c --- /dev/null +++ b/make_conda_recipe.py @@ -0,0 +1,41 @@ +import ast +import re +from MDRefine import _required_ +from MDRefine import __version__ + +def readme(): + with open('README.md') as f: + return f.read() + +def description(): + from MDRefine import __doc__ as doc + return doc.partition('\n')[0] + +with open('conda/meta.yaml.in') as f: + recipe=f.read() + +recipe=re.sub("__VERSION__",__version__,recipe) + +match=re.search("( *)(__REQUIRED__)",recipe) + +requirements="" + +for r in ast.literal_eval(str(_required_)): + requirements+=match.group(1)+"- " + r+"\n" + +recipe=re.sub("( *)(__REQUIRED__)\n",requirements,recipe) + +recipe=re.sub("__SUMMARY__",description(),recipe) + +match=re.search("( *)(__DESCRIPTION__)",recipe) + +description="" + +for r in readme().split("\n"): + description+=match.group(1)+r+"\n" + +recipe=re.sub("( *)(__DESCRIPTION__)",description,recipe) + +with open('conda/meta.yaml',"w") as f: + f.write(recipe) +