-
Notifications
You must be signed in to change notification settings - Fork 23
101 lines (95 loc) · 3.46 KB
/
base-python-package.yml
File metadata and controls
101 lines (95 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: "[Base] Python Package"
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
paths:
- 'base/**'
- '.github/workflows/base-python-package.yml'
jobs:
linting:
strategy:
matrix:
python-version: [3.13]
os: [ubuntu-latest]
runs-on: ${{matrix.os}}
defaults:
run:
shell: bash -l {0}
steps:
- uses: actions/checkout@v2
- name: Set up conda environment
uses: conda-incubator/setup-miniconda@v3
with:
python-version: ${{ matrix.python-version }}
environment-file: base/environment.yml
activate-environment: pyk
auto-activate: false
miniforge-version: "latest"
architecture: ${{ contains(matrix.os, 'arm') && 'arm64' || 'x64' }}
conda-remove-defaults: true
- name: Install flake8
run: conda install -c conda-forge flake8=7.3.0
- name: Lint with flake8
working-directory: base
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# flake8 options are defined in setup.cfg
flake8 . --count --statistics
formatting:
strategy:
matrix:
python-version: [3.13]
os: [ubuntu-latest]
runs-on: ${{matrix.os}}
defaults:
run:
shell: bash -l {0}
steps:
- uses: actions/checkout@v2
- name: Set up conda environment
uses: conda-incubator/setup-miniconda@v3
with:
python-version: ${{ matrix.python-version }}
environment-file: base/environment.yml
activate-environment: pyk
auto-activate: false
miniforge-version: "latest"
architecture: ${{ contains(matrix.os, 'arm') && 'arm64' || 'x64' }}
conda-remove-defaults: true
- name: Install black and clang-format
run: |
conda install -c conda-forge black=25.12.0
sudo apt-get update
sudo apt-get install -y software-properties-common wget gnupg
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
DISTRIB_CODENAME=$(lsb_release -sc)
echo "deb http://apt.llvm.org/${DISTRIB_CODENAME}/ llvm-toolchain-${DISTRIB_CODENAME}-16 main" | sudo tee /etc/apt/sources.list.d/llvm-16.list
if sudo apt-get update 2>&1 | grep -q "llvm-toolchain-${DISTRIB_CODENAME}-16"; then
echo "LLVM repository added successfully"
fi
if sudo apt-get install -y clang-format-16 2>/dev/null; then
echo "Installed clang-format-16"
echo "CLANG_FORMAT=clang-format-16" >> $GITHUB_ENV
fi
- name: black format
working-directory: base
run: |
black --diff --check .
- name: clang-format
working-directory: base
run: |
set +e
FILES=$(find include src examples -type f | egrep '\.hpp$|\.cpp$|\.cpp\.in$')
FORMAT_OUT=$($CLANG_FORMAT -output-replacements-xml ${FILES})
RET=$(echo ${FORMAT_OUT} | grep -c '<replacement ')
if [ "${RET}" -ne 0 ]; then
echo -e "\nError! Code not formatted. Detected ${RET} lines\n"
$CLANG_FORMAT -i ${FILES}
git diff
exit ${RET}
fi