Skip to content

Commit 19a51f7

Browse files
authored
Merge pull request #1 from gem5/tidyups
Tidy up the repo (final pass by Bobby)
2 parents 186bbd6 + 317bb25 commit 19a51f7

23 files changed

+751
-490
lines changed

.funcignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Copyright (c) 2025 The Regents of the University of California
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
14
.git*
25
.vscode
36
__azurite_db*__.json
@@ -7,4 +10,4 @@ local.settings.json
710
test
811
.venv
912
.env
10-
update_filter_view.py
13+
update_filter_view.py

.github/workflows/ci-tests.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
# Copyright (c) 2025 The Regents of the University of California
3+
# SPDX-License-Identifier: BSD-3-Clause
4+
5+
name: CI Tests for Pull Requests
6+
7+
on:
8+
pull_request:
9+
types: [opened, synchronize, ready_for_review]
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
pre-commit:
17+
runs-on: ubuntu-24.04
18+
if: github.event.pull_request.draft == false
19+
steps:
20+
- name: Checkout repo
21+
uses: actions/checkout@v4
22+
23+
- name: Setup Python
24+
uses: actions/setup-python@v5
25+
with:
26+
python-version: '3.10'
27+
28+
- name: Run pre-commit hooks
29+
uses: pre-commit/[email protected]
30+
31+
32+
unit-tests:
33+
runs-on: ubuntu-24.04
34+
35+
if: github.event.pull_request.draft == false
36+
needs: pre-commit
37+
env:
38+
FUNCTIONS_WORKER_RUNTIME: python
39+
MONGO_CONNECTION_STRING: ${{ secrets.MONGO_CONNECTION_STRING }}
40+
AzureWebJobsStorage: UseDevelopmentStorage=true
41+
steps:
42+
- name: Checkout repo
43+
uses: actions/checkout@v4
44+
45+
- name: Setup Python
46+
uses: actions/setup-python@v5
47+
with:
48+
python-version: '3.10'
49+
50+
- name: Install dependencies
51+
run: |
52+
python -m pip install --upgrade pip
53+
if [ -f requirements.txt ];
54+
then
55+
pip install -r requirements.txt
56+
fi
57+
58+
- name: Install Azure Functions Core Tools
59+
run: |
60+
npm install -g azure-functions-core-tools@4 --unsafe-perm true
61+
62+
- name: Start Azure Functions
63+
run: |
64+
# Start Azure Functions in the background
65+
func start --port 7071 --no-build > func.log 2>&1 &
66+
echo $! > func.pid
67+
# Wait for the functions to be ready (adjust time as needed)
68+
sleep 20
69+
70+
- name: Run tests
71+
run: |
72+
python3 -m unittest tests.resources_api_unit_tests -v
73+
- name: Cleanup Azure Functions
74+
if: always()
75+
run: |
76+
kill $(cat func.pid) || true

.github/workflows/deploy-azure.yml

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,50 @@
1+
---
2+
# Copyright (c) 2025 The Regents of the University of California
3+
# SPDX-License-Identifier: BSD-3-Clause
4+
15
name: Deploy Python project to Azure Function App
26

7+
on:
8+
workflow_dispatch: # allows manual triggering of the workflow
9+
310
# on:
411
# push:
512
# branches:
613
# - main # only run on pushes to main
714

815
env:
9-
AZURE_FUNCTIONAPP_NAME: 'gem5-resources-api'
10-
AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # function API code lives in the repo root
11-
PYTHON_VERSION: '3.12'
16+
AZURE_FUNCTIONAPP_NAME: gem5-resources-api
17+
18+
# function API code lives in the repo root
19+
AZURE_FUNCTIONAPP_PACKAGE_PATH: .
20+
PYTHON_VERSION: '3.12'
1221

1322
jobs:
14-
build-and-deploy:
15-
runs-on: ubuntu-latest
16-
steps:
17-
- name: Checkout code
18-
uses: actions/checkout@v3
19-
20-
- name: Set up Python ${{ env.PYTHON_VERSION }}
21-
uses: actions/setup-python@v4
22-
with:
23-
python-version: ${{ env.PYTHON_VERSION }}
24-
25-
- name: Install dependencies into .python_packages
26-
run: |
27-
pushd ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
28-
python -m pip install --upgrade pip
29-
pip install -r requirements.txt --target=".python_packages/lib/site-packages"
30-
popd
31-
32-
- name: Deploy to Azure Functions
33-
uses: Azure/functions-action@v1
34-
with:
35-
app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }}
36-
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
37-
publish-profile: ${{ secrets.AZURE_FUNCTIONAPP_PUBLISH_PROFILE }}
38-
scm-do-build-during-deployment: true
39-
enable-oryx-build: true
23+
build-and-deploy:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Checkout code
27+
uses: actions/checkout@v3
28+
29+
- name: Set up Python ${{ env.PYTHON_VERSION }}
30+
uses: actions/setup-python@v4
31+
with:
32+
python-version: ${{ env.PYTHON_VERSION }}
33+
34+
- name: Install dependencies into .python_packages
35+
run: |
36+
pushd ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
37+
python -m pip install --upgrade pip
38+
pip install -r requirements.txt \
39+
--target=".python_packages/lib/site-packages"
40+
popd
41+
42+
- name: Deploy to Azure Functions
43+
uses: Azure/functions-action@v1
44+
with:
45+
app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }}
46+
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
47+
publish-profile: |
48+
${{ secrets.AZURE_FUNCTIONAPP_PUBLISH_PROFILE }}
49+
scm-do-build-during-deployment: true
50+
enable-oryx-build: true

.github/workflows/pr-unittest.yml

Lines changed: 0 additions & 41 deletions
This file was deleted.

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Copyright (c) 2025 The Regents of the University of California
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
14
# Byte-compiled / optimized / DLL files
25
__pycache__/
36
*.py[cod]
@@ -132,4 +135,4 @@ local.settings.json
132135
__blobstorage__
133136
__queuestorage__
134137
__azurite_db*__.json
135-
.python_packages
138+
.python_packages

.pre-commit-config.yaml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
# Copyright (c) 2025 The Regents of the University of California
3+
# SPDX-License-Identifier: BSD-3-Clause
4+
5+
minimum_pre_commit_version: '2.18'
6+
7+
default_language_version:
8+
python: python3
9+
10+
default_stages: [pre-commit]
11+
12+
repos:
13+
- repo: https://github.com/pre-commit/pre-commit-hooks
14+
rev: v5.0.0
15+
hooks:
16+
- id: trailing-whitespace
17+
- id: end-of-file-fixer
18+
- id: check-json
19+
- id: check-yaml
20+
- id: check-added-large-files
21+
- id: mixed-line-ending
22+
args: [--fix=lf]
23+
- id: check-ast
24+
- id: check-case-conflict
25+
- id: check-merge-conflict
26+
- id: check-symlinks
27+
- id: destroyed-symlinks
28+
- id: requirements-txt-fixer
29+
- repo: https://github.com/PyCQA/isort
30+
rev: 6.0.1
31+
hooks:
32+
- id: isort
33+
- repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
34+
rev: 0.2.3
35+
hooks:
36+
- id: yamlfmt
37+
- repo: https://github.com/psf/black
38+
rev: 25.1.0
39+
hooks:
40+
- id: black
41+
- repo: https://github.com/asottile/pyupgrade
42+
rev: v3.19.1
43+
hooks:
44+
- id: pyupgrade
45+
# Python 3.10 is the earliest version supported.
46+
# We therefore conform to the standards compatible with 3.10+.
47+
args: [--py310-plus]

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
2626
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
2727
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2828
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,14 @@ gem5-resources-api/
232232
Start the Azure Function locally. By default, the development server starts at `http://localhost:7071`. Use func start `--port <port>` to run on a different port:
233233

234234
```bash
235-
func start
235+
func start
236236
```
237237

238238
Expected output:
239239

240240
```bash
241241
Functions:
242-
get_resources_by_batch: [GET] http://localhost:7071/api/resources/find-resources-in-batch
242+
get_resources_by_batch: [GET] http://localhost:7071/api/resources/find-resources-in-batch
243243
search_resources: [GET] http://localhost:7071/api/resources/search
244244
get_filters: [GET] http://localhost:7071/api/resources/filters
245245
get_dependent_workloads: [GET] http://localhost:7071/api/resources/get-dependent-workloads
@@ -322,7 +322,7 @@ This repository has github actions set up that will re deploy the functions once
322322
Each new endpoint file must be manually imported and registered in function_app.py using the pattern shown below.
323323

324324
1. **Create Function Module**:
325-
325+
326326
```python
327327
# functions/new_endpoint.py
328328
def register_function(app, collection):

function_app.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
# SPDX-License-Identifier: BSD-3-Clause
21
# Copyright (c) 2025 The Regents of the University of California
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
34

45
import azure.functions as func
5-
import logging
6-
from shared.database import initialize_database
6+
77
from functions import (
8+
get_dependent_workloads,
9+
get_filters,
810
get_resources_by_batch,
911
search_resources,
10-
get_filters,
11-
get_dependent_workloads
1212
)
13+
from shared.database import initialize_database
1314

1415
# Initialize the function app
1516
app = func.FunctionApp()
@@ -21,4 +22,4 @@
2122
get_resources_by_batch.register_function(app, collection)
2223
search_resources.register_function(app, collection)
2324
get_filters.register_function(app, collection, db["filter_values"])
24-
get_dependent_workloads.register_function(app, collection)
25+
get_dependent_workloads.register_function(app, collection)

functions/__init__.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1+
# Copyright (c) 2025 The Regents of the University of California
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
14
# Make this directory a package
2-
from . import get_resources_by_batch
3-
from . import search_resources
4-
from . import get_filters
5-
from . import get_dependent_workloads
5+
from . import (
6+
get_dependent_workloads,
7+
get_filters,
8+
get_resources_by_batch,
9+
search_resources,
10+
)
611

712
__all__ = [
8-
'get_resources_by_batch',
9-
'search_resources',
10-
'get_filters',
11-
'get_dependent_workloads'
12-
]
13+
"get_resources_by_batch",
14+
"search_resources",
15+
"get_filters",
16+
"get_dependent_workloads",
17+
]

0 commit comments

Comments
 (0)