# Python CircleCI 2.1 configuration file
version: 2.1

defaults: &defaults
  working_directory: ~/repo

read_cache: &read_cache
  keys:
  - v1-dependencies-{{ checksum "poetry.lock" }}
  - v1-dependencies-

store_cache: &store_cache
  paths:
  - ./repo
  key: v1-dependencies-{{ checksum "poetry.lock" }}

run_tests: &run_tests
  name: run tests
  command: poetry run pytest

install_deps: &install_deps
  name: install dependencies
  command: poetry install --no-root

jobs:
  py35:
    <<: *defaults
    docker:
    - image: cimg/python:3.5.10
    steps:
    - checkout
    - restore_cache: *read_cache
    - run: *install_deps
    - save_cache: *store_cache
    - run: *run_tests
  py36:
    <<: *defaults
    docker:
    - image: cimg/python:3.6.15
    steps:
    - checkout
    - restore_cache: *read_cache
    - run: *install_deps
    - save_cache: *store_cache
    - run: *run_tests
  py37:
    <<: *defaults
    docker:
    - image: cimg/python:3.7.13
    steps:
    - checkout
    - restore_cache: *read_cache
    - run: *install_deps
    - save_cache: *store_cache
    - run: *run_tests
  py38:
    <<: *defaults
    docker:
      - image: cimg/python:3.8.13
    steps:
      - checkout
      - restore_cache: *read_cache
      - run: *install_deps
      - save_cache: *store_cache
      - run: *run_tests
  py39:
    <<: *defaults
    docker:
      - image: cimg/python:3.9.13
    steps:
      - checkout
      - restore_cache: *read_cache
      - run: *install_deps
      - save_cache: *store_cache
      - run: *run_tests
  py310:
    <<: *defaults
    docker:
      - image: cimg/python:3.10.5
    steps:
      - checkout
      - restore_cache: *read_cache
      - run: *install_deps
      - save_cache: *store_cache
      - run: *run_tests
  pypy38:
    docker:
    - image: pypy:3.8-7.3.9
    <<: *defaults
    steps:
    - checkout
    - restore_cache: *read_cache
    - run:
        name: install dependencies
        command: pip install pytest
    - save_cache: *store_cache
    - run:
        name: run tests
        command: pytest
  pypy39:
    docker:
      - image: pypy:3.9-7.3.9
    <<: *defaults
    steps:
      - checkout
      - restore_cache: *read_cache
      - run:
          name: install dependencies
          command: pip install pytest
      - save_cache: *store_cache
      - run:
          name: run tests
          command: pytest
  flake8:
    docker:
      - image: cimg/python:3.8.13
    <<: *defaults
    steps:
    - checkout
    - restore_cache: *read_cache
    - run: *install_deps
    - save_cache: *store_cache
    - run:
        name: run flake8
        command: poetry run flake8
  docs:
    docker:
      - image: cimg/python:3.8.13
    <<: *defaults
    steps:
    - checkout
    - restore_cache: *read_cache
    - run: *install_deps
    - run:
        name: Install Sphinx
        command: |
          sudo apt update
          sudo apt install -y python3-sphinx python3-sphinx-rtd-theme
    - save_cache: *store_cache
    - run:
        name: run doctest
        command: sphinx-build -aEW -b html -d docs/_build/doctrees docs docs/_build/html

workflows:
  version: 2
  linters:
    jobs:
      - flake8
  unit-tests:
    jobs:
      - py35
      - py36
      - py37
      - py38
      - py39
      - py310
      - pypy38
      - pypy39
  release-dry-run:
    jobs:
      - docs
