Skip to content

Commit

Permalink
Merge pull request #1 from Sydney-Informatics-Hub/feature-ci
Browse files Browse the repository at this point in the history
Added CI
  • Loading branch information
spikelynch authored Dec 9, 2024
2 parents f3c1d5f + d1c5bf2 commit 3796e47
Show file tree
Hide file tree
Showing 6 changed files with 206 additions and 6 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: linters

on:
push:
branches:
- main
pull_request:
branches:
- '**'

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Check out source
uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v3
with:
version: "0.5.4"

- name: Set up Python
run: uv python install

- name: Install project
run: uv sync --all-extras --dev

- name: ruff
run: uv run ruff check --output-format=github
30 changes: 30 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: pytest

on:
push:
branches:
- main
pull_request:
branches:
- '**'

jobs:
pytest:
runs-on: ubuntu-latest
steps:
- name: Check out source
uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v3
with:
version: "0.5.4"

- name: Set up Python
run: uv python install

- name: Install project
run: uv sync --all-extras --dev

- name: Pytest
run: uv run pytest
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ dev = [
"pytest-httpserver>=1.1.0",
"pytest>=8.3.4",
"ruff>=0.8.2",
"pre-commit>=4.0.1",
]
6 changes: 3 additions & 3 deletions src/rocrate_abstract/rocrate_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ def add(self, t, i, props):

def all(self):
"""dunno about this"""
return [TinyEntity(self, e) for e in self.graph]
return [Entity(self, e) for e in self.graph]

def get(self, i):
es = [e for e in self.graph if e["@id"] == i]
if es:
return TinyEntity(self, es[0])
return Entity(self, es[0])
else:
return None

Expand All @@ -67,7 +67,7 @@ def write_json(self, crate_dir):
json.dump({"@context": self.context, "@graph": self.graph}, jfh, indent=2)


class TinyEntity:
class Entity:
def __init__(self, crate, ejsonld):
self.crate = crate
self.type = ejsonld["@type"]
Expand Down
6 changes: 3 additions & 3 deletions tests/test_crates.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_crate(tmp_path):
jcrate.write_json(Path(tmp_path))
with open(jsonf, "r") as jfh:
jsonld = json.load(jfh)
jcrate2 = TinyCrate(jsonld=jsonld)
jcrate2 = Crate(jsonld=jsonld)
for i in range(1000):
eid = f"#ds{i:05d}"
ea = jcrate.get(eid)
Expand All @@ -36,7 +36,7 @@ def test_load_file(crates):
cratedir = crates["textfiles"]
with open(Path(cratedir) / "ro-crate-metadata.json", "r") as jfh:
jsonld = json.load(jfh)
crate = TinyCrate(jsonld=jsonld, directory=cratedir)
crate = Crate(jsonld=jsonld, directory=cratedir)
tfile = crate.get("doc001/textfile.txt")
contents = tfile.fetch()
with open(Path(cratedir) / "doc001" / "textfile.txt", "r") as tfh:
Expand All @@ -56,7 +56,7 @@ def test_load_url(crates, httpserver: HTTPServer):
cratedir = crates["textfiles"]
with open(Path(cratedir) / "ro-crate-metadata.json", "r") as jfh:
jsonld = json.load(jfh)
crate = TinyCrate(jsonld=jsonld, directory=cratedir)
crate = Crate(jsonld=jsonld, directory=cratedir)
# add an entity to the crate with the endpoint URL as the id
urlid = httpserver.url_for("/textfileonurl.txt")
crate.add("File", urlid, {"name": "textfileonurl.txt"})
Expand Down
Loading

0 comments on commit 3796e47

Please sign in to comment.