Skip to content

Commit

Permalink
Upgraded imports, preparing for oarepo 12 (#3)
Browse files Browse the repository at this point in the history
* Upgraded imports, preparing for oarepo 12

* creating venv
  • Loading branch information
mesemus authored Oct 31, 2023
1 parent 8a1098c commit 2873576
Show file tree
Hide file tree
Showing 12 changed files with 181 additions and 138 deletions.
78 changes: 78 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Build and test

on:
workflow_call:
inputs:
oarepo:
description: OARepo version (11, 12, ...)
required: true
default: 11
type: string

env:
OAREPO_VERSION: ${{ github.event.inputs.oarepo }}

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.9", "3.10" ]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Cache pip
uses: actions/cache@v3
with:
# This path is specific to Ubuntu
path: ~/.cache/pip
# Look to see if there is a cache hit for the corresponding requirements file
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
${{ runner.os }}-
- name: Configure sysctl limits
run: |
sudo swapoff -a
sudo sysctl -w vm.swappiness=1
sudo sysctl -w fs.file-max=262144
sudo sysctl -w vm.max_map_count=262144
- name: Runs Opensearch
uses: ankane/setup-opensearch@v1
with:
plugins: analysis-icu

- name: Start Redis
uses: supercharge/[email protected]
with:
redis-version: ${{ matrix.redis-version }}

- name: Run tests
run: |
./run-tests.sh
- name: Build package to publish
run: |
.venv-builder/bin/python setup.py sdist bdist_wheel
- name: Freeze packages
run: |
.venv-builder/bin/pip freeze > requirements.txt
.venv-tests/bin/pip freeze >>requirements.txt
- name: Archive production artifacts
uses: actions/upload-artifact@v3
with:
name: dist
path: dist

- name: Archive production artifacts
uses: actions/upload-artifact@v3
with:
name: requirements.txt
path: requirements.txt
96 changes: 0 additions & 96 deletions .github/workflows/main.yml

This file was deleted.

15 changes: 15 additions & 0 deletions .github/workflows/manual.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Dispatch

on:
workflow_dispatch:
inputs:
oarepo:
description: OARepo version (11, 12, ...)
required: true
default: 11

jobs:
build:
uses: ./.github/workflows/build.yaml
with:
oarepo: ${{ github.event.inputs.oarepo }}
36 changes: 36 additions & 0 deletions .github/workflows/push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Build, test and publish

on: push

permissions:
id-token: write
contents: read

jobs:
build:
uses: ./.github/workflows/build.yaml
with:
oarepo: 11

publish:
runs-on: ubuntu-latest
needs: build
steps:
- name: Use built artifacts
uses: actions/download-artifact@v3
with:
name: dist
path: dist

- name: List files
run: |
ls -la
ls -la dist
- name: Publish package
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip_existing: true
user: __token__
password: ${{ secrets.PYPI_PASSWORD }}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ __pycache__/
.Python
env/
venv/
.venv/
.venv*/
.model_venv/
build/
develop-eggs/
Expand Down Expand Up @@ -91,3 +91,5 @@ dist/
.model_venv
/tests/test
/thesis/

build-tests/thesis
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ def finish(self, **extra_kwargs):
)

def _get_output_module(self):
return f'{self.current_model.definition["tests"]["module"]}.conftest'
return f'{self.current_model.definition["tests"]["module"]}.conftest'
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,16 @@ def before_model_prepare(self, datatype, *, context, **kwargs):
return
files_field = set_default(datatype, "files-field", {})
if datatype.root.profile == "draft_files":
record_class = datatype.definition["record"]["class"]
files_field.setdefault("file-class", base_name(record_class))
files_field.setdefault("file-class", datatype.definition["record"]["class"])
files_field.setdefault("field-args", ["store=False", "delete=False"])
files_field.setdefault(
"imports",
[
{
"import": "invenio_records_resources.records.systemfields.FilesField"
},
{"import": record_class},
],
)
# files_field.setdefault(
# "imports",
# [
# {
# "import": "invenio_records_resources.records.systemfields.FilesField"
# },
# ],
# )

if datatype.root.profile == "files":
files_field.setdefault(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from oarepo_model_builder.datatypes import (
DataType,
DataTypeComponent,
Import,
ModelDataType,
Section,
)
from oarepo_model_builder.utils.python_name import Import
from oarepo_model_builder.datatypes.components import DefaultsModelComponent
from oarepo_model_builder.datatypes.components.model.utils import set_default
from oarepo_model_builder.datatypes.model import Link
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,8 @@ def before_model_prepare(self, datatype, *, context, **kwargs):
append_array(
datatype,
"service-config",
"imports",
{
"import": "invenio_drafts_resources.services.records.components.DraftFilesComponent"
},
)
append_array(
datatype, "service-config", "components", "DraftFilesComponent"
"components",
"invenio_drafts_resources.services.records.components.DraftFilesComponent",
)
service = set_default(datatype, "service", {})
service.setdefault(
Expand Down
35 changes: 35 additions & 0 deletions run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
set -e

OAREPO_VERSION=${OAREPO_VERSION:-11}
OAREPO_VERSION_MAX=$((OAREPO_VERSION+1))

BUILDER_VENV=".venv-builder"
if test -d $BUILDER_VENV ; then
rm -rf $BUILDER_VENV
fi

python3 -m venv $BUILDER_VENV
. $BUILDER_VENV/bin/activate
pip install -U setuptools pip wheel
pip install -e .


MODEL="thesis"
VENV=".venv-tests"

if test -d ./build-tests/$MODEL; then
rm -rf ./build-tests/$MODEL
fi

if test -d ./$VENV; then
rm -rf ./$VENV
fi

oarepo-compile-model ./build-tests/$MODEL.yaml --output-directory ./build-tests/$MODEL -vvv
python3 -m venv $VENV
. $VENV/bin/activate
pip install -U setuptools pip wheel
pip install "oarepo>=$OAREPO_VERSION,<$OAREPO_VERSION_MAX"
pip install "./build-tests/${MODEL}[tests]"
pytest build-tests/$MODEL/tests
20 changes: 0 additions & 20 deletions run_tests.sh

This file was deleted.

2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = oarepo-model-builder-drafts-files
version = 4.0.4
version = 4.0.5
description =
authors = Ronald Krist <[email protected]>
readme = README.md
Expand Down

0 comments on commit 2873576

Please sign in to comment.