diff --git a/.circleci/config.yml b/.circleci/config.yml index 2b6fb324..8d16aa0d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,5 +1,11 @@ version: 2.1 +orbs: + ocean: dwave/ocean@1.3 + +environment: + PIP_PROGRESS_BAR: 'off' + jobs: test-linux: parameters: @@ -8,56 +14,25 @@ jobs: dimod-version: type: string - docker: - - image: circleci/python:<< parameters.python-version >> + executor: + name: ocean/python + python-version: << parameters.python-version >> steps: - checkout - - restore_cache: &restore-cache-env - key: v1-dependencies-{{ checksum "requirements.txt" }}-{{ checksum "tests/requirements.txt" }}-{{ .Environment.CIRCLE_JOB }} + - ocean/pip-install: + requirements: requirements.txt tests/requirements.txt - - run: &create-virtualenv - name: Create virtual environment - command: | - python -m venv env - - - run: &install-requirements - name: Install requirements - command: | - . env/bin/activate - pip install -U pip - pip install -r requirements.txt -r tests/requirements.txt - pip install wheel twine - - - run: - name: Install appropriate dimod version - command: | - . env/bin/activate - if [[ "<< parameters.dimod-version >>" ]]; then - pip install 'dimod<< parameters.dimod-version >>' - else - pip uninstall dimod -y - fi - - - save_cache: &save-cache-env - key: v1-dependencies-{{ checksum "requirements.txt" }}-{{ checksum "tests/requirements.txt" }}-{{ .Environment.CIRCLE_JOB }} - paths: - - env - - - run: &build-package - name: Build package - command: env/bin/python setup.py sdist bdist_wheel - - - run: &install-package - name: Install package - command: env/bin/pip install . + - ocean/pip-install: + cache: false + packages: . dimod<< parameters.dimod-version >> - run: &run-python-tests name: Run Python tests command: env/bin/coverage run -m unittest discover - - run: &upload-python-code-coverage + - run: name: Upload code coverage command: | . env/bin/activate @@ -76,83 +51,31 @@ jobs: steps: - checkout - # install `python-version` and cache it - - run: &brew-install-pyenv - name: Install pyenv - command: HOMEBREW_NO_AUTO_UPDATE=1 brew install pyenv - - - restore_cache: &restore-cache-pyenv - keys: - - v1-pyenv-{{ .Environment.CIRCLE_JOB }}-xcode-<< parameters.xcode >> - - - when: - # backport https://github.com/python/cpython/pull/21113 to support macOS 11 when building py36 - # see also: https://github.com/pyenv/pyenv/issues/1737. - condition: - matches: - pattern: "^3\\.6.*$" - value: << parameters.python-version >> - steps: - - run: - name: Install Python 3.6 with a patch for macOS 11 - command: | - curl -LO https://github.com/python/cpython/commit/8ea6353.patch - pyenv install << parameters.python-version>> -s -p < 8ea6353.patch - - - run: &pyenv-install-python - name: Install python - command: pyenv install << parameters.python-version >> -s - - - run: &pyenv-set-system-python - name: Set system python - command: | - echo -e '\n\n# Initialize pyenv' >> ~/.bash_profile - echo 'eval "$(pyenv init --path 2>/dev/null || true)"' >> ~/.bash_profile - echo 'eval "$(pyenv init -)"' >> ~/.bash_profile - pyenv global << parameters.python-version >> - - - save_cache: &save-cache-pyenv - key: v1-pyenv-{{ .Environment.CIRCLE_JOB }}-xcode-<< parameters.xcode >> - paths: - - ~/.pyenv - - # install dependencies and cache them - - restore_cache: *restore-cache-env + - ocean/brew-install-pyenv - - run: *create-virtualenv + - ocean/pyenv-install-python: + python-version: << parameters.python-version >> + cache-key-prefix: << parameters.xcode >> - - run: *install-requirements + - ocean/pip-install: + requirements: requirements.txt tests/requirements.txt - - save_cache: *save-cache-env - - - run: *install-package + - ocean/pip-install: + cache: false + packages: . - run: *run-python-tests test-docs: - docker: - - image: circleci/python:3.7 + executor: + name: ocean/python + python-version: "3.7" steps: - checkout - - restore_cache: - key: v1-dependencies-{{ checksum "requirements.txt" }}-{{ checksum "tests/requirements.txt" }}-{{ checksum "docs/requirements.txt" }}-{{ .Environment.CIRCLE_JOB }} - - - run: *create-virtualenv - - - run: *install-requirements - - - run: - name: Install docs requirements - command: env/bin/pip install -r docs/requirements.txt - - - save_cache: - key: v1-dependencies-{{ checksum "requirements.txt" }}-{{ checksum "tests/requirements.txt" }}-{{ checksum "docs/requirements.txt" }}-{{ .Environment.CIRCLE_JOB }} - paths: - - env - - - run: *install-package + - ocean/pip-install: + requirements: requirements.txt tests/requirements.txt docs/requirements.txt - run: name: Build docs @@ -175,29 +98,28 @@ jobs: . env/bin/activate make -C docs/ linkcheck - pypi-deploy: - docker: - - image: circleci/python:3.9 + build-dist: + executor: + name: ocean/python + python-version: "3.9" steps: - checkout - - restore_cache: *restore-cache-env - - - run: *create-virtualenv - - - run: *install-requirements + - ocean/pip-install: + requirements: requirements.txt + packages: wheel + cache: false - - save_cache: *save-cache-env - - - run: *build-package + - ocean/build-dist: + dist-type: sdist bdist_wheel - store_artifacts: - path: ./dist + path: dist - - run: - name: Upload package to PyPI - command: env/bin/twine upload -u "$PYPI_USERNAME" -p "$PYPI_PASSWORD" --skip-existing ./dist/* + - persist_to_workspace: + root: dist + paths: . workflows: @@ -224,10 +146,20 @@ workflows: xcode: ["13.2.0"] - test-docs + - build-dist deploy: jobs: - - pypi-deploy: + - build-dist: + filters: + tags: + only: /^[0-9]+(\.[0-9]+)*((\.dev|rc)([0-9]+)?)?$/ + branches: + ignore: /.*/ + + - ocean/pypi-deploy: + requires: + - build-dist filters: tags: only: /^[0-9]+(\.[0-9]+)*((\.dev|rc)([0-9]+)?)?$/