diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..21b87f5 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,72 @@ +name: Deploy Main +on: + release: + types: [published] +jobs: + deploy-pypi: + runs-on: ubuntu-latest + environment: deployment + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + + - name: Install Python + uses: actions/setup-python@v3 + with: + python-version: "3.8" + + - name: Install Twine + run: sudo pip install twine + + - name: Create the distribution + run: | + git fetch --prune --unshallow --tags + sudo python setup.py sdist bdist_wheel + - name: Push to PyPI + run: sudo twine upload -u ${{ secrets.PYPI_USERNAME }} -p ${{ secrets.PYPI_PASSWORD }} dist/* + + deploy-conda: + runs-on: ubuntu-latest + environment: deployment +# sets default shell to remove need for source to run the conda shell + defaults: + run: + shell: bash -l {0} + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + + - name: Install Python + uses: actions/setup-python@v3 + with: + python-version: "3.8" + + - name: Install Miniconda + uses: conda-incubator/setup-miniconda@v2 + with: + auto-activate-base: true + activate-environment: "" + miniconda-version: "latest" + + - name: Install the Conda Dependencies + run: | + conda config --set always_yes yes --set auto_update_conda false + conda update conda + conda install conda-build + +# echo yes before login to prevent anaconda bug breaking automation +# git tags MUST be fetched otherwise output will be blank +# bash variables cannot be used in github actions, must use actions specific syntax and methods + - name: Build the Anaconda Package + id: condabuild + run: | + conda install anaconda-client + conda config --set anaconda_upload no + echo yes | anaconda login --username ${{ secrets.ANACONDA_CLOUD_USERNAME }} --password ${{ secrets.ANACONDA_CLOUD_PASSWORD }} + git fetch --prune --unshallow --tags + VERSION_FROM_GIT_TAG=$(git tag --list "v*[0-9]" --sort=version:refname | tail -1 | cut -c 2-) conda build . -c pytorch -c stanfordcvxgrp -c conda-forge --numpy 1.22.2 + echo '::set-output name=gitversion::$(git tag --list "v*[0-9]" --sort=version:refname | tail -1 | cut -c 2-)' + - name: Upload the Anaconda Package + id: condaload + run: | + anaconda upload -u stanfordcvxgrp /usr/share/miniconda3/conda-bld/noarch/sure-cr-${{ steps.condabuild.outputs.gitversion }}-*.tar.bz2 \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..4cbfe9d --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,87 @@ +name: Main Test +on: + pull_request: + push: + branches: + - main +jobs: + run-tests: + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + + - name: Install Python + uses: actions/setup-python@v3 + + - name: Install Dependencies + run: | + git fetch --prune --unshallow --tags + sudo $pythonLocation/bin/python3 -m pip install -r requirements.txt + sudo $pythonLocation/bin/python3 -m pip install setuptools --upgrade + sudo $pythonLocation/bin/python3 -m pip install pytest + sudo $pythonLocation/bin/python3 -m pip install -e . +# Uncomment and modify once tests have been added to the repo +# - name: Run Unit Tests +# run: | +# sudo $pythonLocation/bin/python3 -m pytest --import-mode=append tests/test_cg.py +# sudo $pythonLocation/bin/python3 -m pytest --import-mode=append tests/ + + test-build-pypi: + needs: run-tests + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + + - name: Install Python + uses: actions/setup-python@v3 + with: + python-version: "3.8" + + - name: Install Twine + run: sudo pip install twine + + - name: Create the distribution + run: | + git fetch --prune --unshallow --tags + sudo python setup.py sdist bdist_wheel + test-build-conda: + needs: run-tests + runs-on: ubuntu-latest +# sets default shell to remove need for source to run the conda shell + defaults: + run: + shell: bash -l {0} + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + + - name: Install Python + uses: actions/setup-python@v3 + with: + python-version: "3.8" + + - name: Install Miniconda + uses: conda-incubator/setup-miniconda@v2 + with: + auto-activate-base: true + activate-environment: "" + miniconda-version: "latest" + + - name: Install the Conda Dependencies + run: | + conda config --set always_yes yes --set auto_update_conda false + conda update conda + conda install conda-build + +# echo yes before login to prevent anaconda bug breaking automation +# git tags MUST be fetched otherwise output will be blank +# bash variables cannot be used in github actions, must use actions specific syntax and methods + - name: Build the Anaconda Package + id: condabuild + run: | + conda install anaconda-client + conda config --set anaconda_upload no + git fetch --prune --unshallow --tags + VERSION_FROM_GIT_TAG=$(git tag --list "v*[0-9]" --sort=version:refname | tail -1 | cut -c 2-) conda build . -c pytorch -c stanfordcvxgrp -c conda-forge --numpy 1.22.2 \ No newline at end of file diff --git a/conda_recipe/meta.yaml b/conda_recipe/meta.yaml new file mode 100644 index 0000000..dc702ba --- /dev/null +++ b/conda_recipe/meta.yaml @@ -0,0 +1,46 @@ +{% set name = "SURE-CR" %} + +package: + name: "{{ name|lower }}" + version: {{ environ.get('VERSION_FROM_GIT_TAG') }} + +source: + git_url: https://github.com/cvxgrp/SURE-CR + +build: + noarch: python + number: 0 + script: "{{ PYTHON }} -m pip install . --ignore-installed -vv " + +requirements: + host: + - pip + - python >=3.6 + - numpy >=1.17.5 + - scipy + - pytorch + - cvxpy + - torch-linops + + run: + - pip + - python >=3.6 + - numpy >=1.17.5 + - scipy + - pytorch + - cvxpy + - torch-linops + +about: + home: https://github.com/cvxgrp/SURE-CR + license: APACHEv2 + license_family: Apache + license_file: + summary: This package enables tractable evaluation of Stein's Unbiased Risk Estimate on convexly regularized estimators. + doc_url: + dev_url: + +extra: + recipe-maintainers: + - PTNobel + - Thistleman \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..9a3511e --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools >= 18.0", "wheel"] +build-backend = "setuptools.build_meta" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..9cbc1a0 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +numpy>=1.17.5 +scipy +torch +cvxpy +cvxpylayers +torch-linops \ No newline at end of file diff --git a/setup.py b/setup.py index d579f3a..c449d16 100644 --- a/setup.py +++ b/setup.py @@ -1,12 +1,28 @@ #!/usr/bin/python -from setuptools import setup +import subprocess +from setuptools import setup, find_packages with open("README.md", "r") as fh: long_description = fh.read() +# get all the git tags from the cmd line that follow our versioning pattern +git_tags = subprocess.Popen( + ["git", "tag", "--list", "v*[0-9]", "--sort=version:refname"], + stdout=subprocess.PIPE, +) +tags = git_tags.stdout.read() +git_tags.stdout.close() +tags = tags.decode("utf-8").split("\n") +tags.sort() + +# PEP 440 won't accept the v in front, so here we remove it, strip the new line and decode the byte stream +VERSION_FROM_GIT_TAG = tags[-1][1:] + setup( name="surecr", + version=VERSION_FROM_GIT_TAG, # Required setup_requires=["setuptools>=18.0"], + packages=find_packages(exclude=["notebooks"]), # Required install_requires=[ "numpy >= 1.17.5", "scipy", @@ -15,6 +31,9 @@ "cvxpylayers", "torch-linops", ], + description="This package enables tractable evaluation of Stein's Unbiased Risk Estimate on convexly regularized estimators.", + long_description=long_description, + long_description_content_type="text/markdown", url="https://github.com/cvxgrp/SURE-CR", classifiers=[ "Programming Language :: Python :: 3",