Skip to content

Commit f0ed26f

Browse files
committed
Add "build-dev" action
1 parent 67eb996 commit f0ed26f

File tree

5 files changed

+89
-9
lines changed

5 files changed

+89
-9
lines changed

.github/workflows/build-dev.yml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# MIT licensed
2+
name: openMINDS_Python_dev_build_pipeline
3+
4+
on:
5+
push:
6+
branches:
7+
- pipeline
8+
workflow_dispatch: # This triggers the workflow when a webhook is received
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
python-version: ["3.8", "3.12"]
16+
steps:
17+
18+
- name: Checkout Repository
19+
uses: actions/checkout@v4
20+
21+
- name: Set up Python ${{ matrix.python-version }}
22+
uses: actions/setup-python@v5
23+
with:
24+
python-version: ${{ matrix.python-version }}
25+
26+
- name: Run build
27+
run: |
28+
pip install -r requirements.txt
29+
python build.py --branch=development
30+
31+
- name: Test built package
32+
run: |
33+
pip install pytest
34+
pip install ./target
35+
pytest -v pipeline/tests
36+
37+
- name: Checkout development branch
38+
uses: actions/checkout@v4
39+
with:
40+
ref: development
41+
path: development
42+
token: ${{ secrets.GITHUB_TOKEN }}
43+
if: ${{ matrix.python-version == 3.12 }}
44+
45+
- name: Push to development
46+
if: ${{ matrix.python-version == 3.12 }}
47+
run: |
48+
cp -R target/* development
49+
cd development
50+
rm -rf build openMINDS.egg-info
51+
git config --global user.email "openminds@ebrains.eu"
52+
git config --global user.name "openMINDS pipeline"
53+
if [[ $(git add . --dry-run | wc -l) -gt 0 ]]; then
54+
git add .
55+
git commit -m "build triggered by ${{ github.event_name }}"
56+
git push -f
57+
else
58+
echo "Nothing to commit"
59+
fi

.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
target
22
__pycache__
3-
test_tmp
3+
test_tmp
4+
dist
5+
*.egg-info
6+
*.orig
7+
.coverage

build.py

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import argparse
12
from collections import defaultdict
23
import json
34
import os.path
@@ -11,20 +12,25 @@
1112
from pipeline.translator import PythonBuilder
1213
from pipeline.utils import clone_sources, SchemaLoader, InstanceLoader
1314

15+
1416
include_instances = True # to speed up the build during development, set this to False
1517

16-
print("*********************************************************")
17-
print(f"Triggering the generation of Python package for openMINDS")
18-
print("*********************************************************")
18+
parser = argparse.ArgumentParser(prog=sys.argv[0], description="Generate Python package for openMINDS")
19+
parser.add_argument('--branch', help="The branch to build from ('main' or 'development')", default="main")
20+
args = parser.parse_args()
21+
22+
print("*******************************************************************************")
23+
print(f"Triggering the generation of Python package for openMINDS, from the {args.branch} branch")
24+
print("*******************************************************************************")
1925

2026
# Step 0 - read code for additional methods
2127
additional_methods = {}
2228
with open("pipeline/src/additional_methods/by_name.py.txt") as fp:
2329
code = fp.read()
2430
additional_methods["by_name"] = code
2531

26-
# Step 1 - clone central repository in main branch to get the latest sources
27-
clone_sources()
32+
# Step 1 - clone central repository in main or development branch to get the latest sources
33+
clone_sources(args.branch)
2834
schema_loader = SchemaLoader()
2935
instance_loader = InstanceLoader()
3036
if os.path.exists("target"):
@@ -105,8 +111,11 @@
105111
autoescape=select_autoescape()
106112
)
107113
context = {
108-
"version": "0.2.3",
114+
"version": "0.3.0",
109115
}
116+
if args.branch == "development":
117+
context["version"] += ".dev"
118+
110119
with open("target/pyproject.toml", "w") as fp:
111120
contents = env.get_template("pipeline/src/pyproject_template.toml.txt").render(context)
112121
fp.write(contents)

pipeline/translator.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def get_type(property):
9595
"iri": "IRI",
9696
"email": "str", # todo: add an Email class for validation?
9797
"ECMA262": "str", # ...
98+
"boolean": "bool"
9899
}
99100
if "_linkedTypes" in property:
100101
types = []
@@ -165,7 +166,11 @@ def filter_instance(instance):
165166
for iri, property in self._schema_payload["properties"].items():
166167
allow_multiple = property.get("type", "") == "array"
167168
if allow_multiple:
168-
property_name = property['namePlural']
169+
if "namePlural" in property:
170+
property_name = property['namePlural']
171+
else:
172+
print(f"Missing plural name for '{property['name']}'")
173+
property_name = property['name'] + "s"
169174
else:
170175
property_name = property['name']
171176
pythonic_name = generate_python_name(property_name)

pipeline/utils.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,21 @@
66
from git import Repo, GitCommandError
77

88

9-
def clone_sources():
9+
def clone_sources(branch="main"):
1010
if os.path.exists("_sources"):
1111
shutil.rmtree("_sources")
1212
Repo.clone_from(
1313
"https://github.com/openMetadataInitiative/openMINDS.git",
1414
to_path="_sources/schemas",
1515
depth=1,
16+
branch=branch,
17+
single_branch=True
1618
)
1719
Repo.clone_from(
1820
"https://github.com/openMetadataInitiative/openMINDS_instances.git",
1921
to_path="_sources/instances",
2022
depth=1,
23+
single_branch=True
2124
)
2225

2326

0 commit comments

Comments
 (0)