Skip to content

Commit

Permalink
Merge pull request #38 from TheELNConsortium/sb_github_actions
Browse files Browse the repository at this point in the history
validator using pypi's rocrate
  • Loading branch information
SteffenBrinckmann authored Nov 3, 2023
2 parents 55f1103 + 4b936cd commit 8b9c223
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/validator_pypi_rocrate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: pypi_rocrate
# Validate if rocrate of pypi can open and parse it
# https://pypi.org/project/rocrate/

on: [ push ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.10" ]
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install rocrate
- name: validate
run: |
import os
import sys
import tempfile
from pathlib import Path
from zipfile import ZIP_DEFLATED
from zipfile import Path as ZPath
from zipfile import ZipFile
from rocrate.rocrate import ROCrate
from rocrate.model.entity import Entity
from rocrate.model.contextentity import ContextEntity
success = 0
for root, _, files in os.walk(".", topdown=False):
for name in files:
if not name.endswith('.eln'):
continue
fileName = os.path.join(root, name)
print(f'\n\nTry to parse: {fileName}')
with ZipFile(fileName, 'r', compression=ZIP_DEFLATED) as elnFile:
p = ZPath(elnFile)
dirName = sorted(p.iterdir())[0]
try:
dirpath = Path(tempfile.mkdtemp())
elnFile.extractall(dirpath)
temppath= dirpath.joinpath(dirName.name)
crate = ROCrate(temppath)
for e in crate.get_entities():
print(f' {e.id}: {e.type}')
except Exception:
print(" ***** ERROR: Could not parse content of this file!! *****")
success = 1
sys.exit(success)
shell: python

0 comments on commit 8b9c223

Please sign in to comment.