Skip to content

Commit

Permalink
CI: Ensure we run from a built package instead of source (#4719)
Browse files Browse the repository at this point in the history
  • Loading branch information
ClausHolbechArista authored Nov 13, 2024
1 parent 35f3688 commit 6fad7e2
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 14 deletions.
6 changes: 1 addition & 5 deletions .github/requirements-ci.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# Installing PyAVD from source.
# The package path below is relative to the repo root and will only work if the pip install is executed from there.
./python-avd
# The -r path is relative to this file.
-r ../ansible_collections/arista/avd/requirements.txt
# Needed for molecule
jsonschema-rs>=0.24
./python-avd[ansible-collection]
7 changes: 7 additions & 0 deletions .github/workflows/new-cvp-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ on: workflow_dispatch

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}

env:
# Set -vvv is ACTIONS_STEP_DEBUG is set
# Apparently it is set in secrets when running with debug
ANSIBLE_VERBOSITY: ${{ secrets.ACTIONS_STEP_DEBUG && 3 || 0 }}
AVD_NEVER_RUN_FROM_SOURCE: 1

jobs:
# ----------------------------------------------- #
# CV INTEGRATION MOLECULE TEST FOR CV_WORKFLOW #
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/pull-request-management.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ env:
# Set -vvv is ACTIONS_STEP_DEBUG is set
# Apparently it is set in secrets when running with debug
ANSIBLE_VERBOSITY: ${{ secrets.ACTIONS_STEP_DEBUG && 3 || 0 }}
AVD_NEVER_RUN_FROM_SOURCE: 1

jobs:
file-changes:
Expand Down Expand Up @@ -111,7 +112,7 @@ jobs:
python-version: ${{ matrix.python_version }}
- name: 'Install Python requirements'
run: |
pip install -r ansible_collections/arista/avd/requirements-dev.txt -r ansible_collections/arista/avd/requirements.txt --upgrade
pip install -r .github/requirements-ci.txt -r ansible_collections/arista/avd/requirements-dev.txt --upgrade
# ----------------------------------- #
# EOS CLI CONFIG GEN MOLECULE
Expand Down Expand Up @@ -432,7 +433,7 @@ jobs:
3.13
- name: 'Install Python & Ansible requirements'
run: |
pip install -r ansible_collections/arista/avd/requirements-dev.txt -r ansible_collections/arista/avd/requirements.txt --upgrade
pip install -r .github/requirements-ci.txt -r ansible_collections/arista/avd/requirements-dev.txt --upgrade
ansible-galaxy collection install -r ansible_collections/arista/avd/collections.yml
- name: 'Run ansible-test integration test cases'
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Developing with your local Python environment requires you to configure and inst
Recommended steps with Python virtual environment:

1. Create and activate a Python virtual environment.
2. Install Python requirements located in the AVD repository: [requirements-dev.txt](https://github.com/aristanetworks/avd/blob/devel/ansible_collections/arista/avd/requirements-dev.txt) and [requirements.txt](https://github.com/aristanetworks/avd/blob/devel/ansible_collections/arista/avd/requirements.txt).
2. Install Python requirements located in the AVD repository: [requirements-dev.txt](https://github.com/aristanetworks/avd/blob/devel/ansible_collections/arista/avd/requirements-dev.txt).

!!! note
Ensure the virtual environment is located outside of the AVD project directory.
Expand All @@ -72,7 +72,7 @@ source avd-venv/bin/activate
# The installation _must_ be performed from the root of the cloned avd repository.
cd avd
# Requirements files are located in `ansible_collections/arista/avd` of the avd repository.
pip3 install -r ansible_collections/arista/avd/requirements-dev.txt -r ansible_collections/arista/avd/requirements.txt --upgrade
pip3 install -r ansible_collections/arista/avd/requirements-dev.txt --upgrade
```

!!! note
Expand Down
3 changes: 2 additions & 1 deletion ansible_collections/arista/avd/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
from __future__ import annotations

from contextlib import suppress
from os import environ
from pathlib import Path

PYTHON_AVD_PATH = Path(__file__).parents[4] / "python-avd"
RUNNING_FROM_SOURCE_PATH = PYTHON_AVD_PATH / "pyavd/running_from_src.txt"
RUNNING_FROM_SOURCE = RUNNING_FROM_SOURCE_PATH.exists()
RUNNING_FROM_SOURCE = RUNNING_FROM_SOURCE_PATH.exists() and not environ.get("AVD_NEVER_RUN_FROM_SOURCE")

if RUNNING_FROM_SOURCE:
import sys
Expand Down
7 changes: 4 additions & 3 deletions containers/dev/.devcontainer/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ if [ -z "$(command -v ansible)" ]; then
pip install "pyavd[ansible] @ ${PYAVD_INSTALL_LOCATION}"
ansible-galaxy collection install --force ${AVD_INSTALL_PATH}
# otherwise install requirements and collection from container workspace
elif [ -f ${CONTAINER_WSF_AVD_PATH}/requirements.txt ] && [ -f ${CONTAINER_WSF_AVD_PATH}/requirements-dev.txt ] ; then
# use editable install for requirements
pip install -r ${CONTAINER_WSF_AVD_PATH}/requirements-dev.txt -r ${CONTAINER_WSF_AVD_PATH}/requirements.txt
elif [ -f ${CONTAINER_WORKSPACE}/python-avd/pyproject.toml ] && [ -f ${CONTAINER_WSF_AVD_PATH}/requirements-dev.txt ] ; then
# Install pyavd from source and dev requirements from file
pip install ${CONTAINER_WORKSPACE}/python-avd[ansible-collection] -r ${CONTAINER_WSF_AVD_PATH}/requirements-dev.txt
# Install arista.avd collection from source
ansible-galaxy collection install --force ${CONTAINER_WSF_AVD_PATH}
fi

Expand Down
3 changes: 2 additions & 1 deletion python-avd/pyavd/constants.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Copyright (c) 2023-2024 Arista Networks, Inc.
# Use of this source code is governed by the Apache License 2.0
# that can be found in the LICENSE file.
from os import environ
from pathlib import Path

RUNNING_FROM_SRC = Path(__file__).parent.joinpath("running_from_src.txt").exists()
RUNNING_FROM_SRC = Path(__file__).parent.joinpath("running_from_src.txt").exists() and not environ.get("AVD_NEVER_RUN_FROM_SOURCE")
EOS_CLI_CONFIG_GEN_SCHEMA_ID = "eos_cli_config_gen"
EOS_DESIGNS_SCHEMA_ID = "eos_designs"
EOS_CLI_CONFIG_GEN_JINJA2_CONFIG_TEMPLATE = "eos-intended-config.j2"
Expand Down

0 comments on commit 6fad7e2

Please sign in to comment.