-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
validator using pypi's rocrate #38
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest using the more modern |
||
for name in files: | ||
if not name.endswith('.eln'): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of checking with a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or directly search the *.eln files with path.glob(...) method |
||
continue | ||
fileName = os.path.join(root, name) | ||
print(f'\n\nTry to parse: {fileName}') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd write: "Trying to parse" instead of "Try to parse" |
||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of tracking exit code with
success
var, simply do asys.exit(1)
in theexcept
block, and otherwise asys.exit(0)
for the happy path.