# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
---
- name: Install system requirements
  apt:
    name:
      - gunicorn
      - python3.10-venv
      - python3.10-dev
      - build-essential
    state: present

- name: Create virtual environment
  command: "python3.10 -m venv {{ graphql_dir }}/venv"
  args:
    creates: "{{ graphql_dir }}/venv/bin/python"
  register: venv_created
  changed_when: venv_created.rc == 0

- name: Ensure pip is installed in the virtualenv
  command: "{{ graphql_dir }}/venv/bin/python -m ensurepip --upgrade"
  args:
    creates: "{{ graphql_dir }}/venv/bin/pip"

- name: Ensure pip is upgraded
  pip:
    name: pip
    virtualenv: "{{ graphql_dir }}/venv"
    state: latest

- name: Install Python dependencies
  pip:
    requirements: "{{ graphql_dir }}/requirements.txt"
    virtualenv: "{{ graphql_dir }}/venv"
    extra_args: --no-cache-dir
