Skip to content

Commit 33ebb2a

Browse files
committed
fix: update release workflow and improve type hints in hypergraph methods
1 parent 11d545f commit 33ebb2a

File tree

4 files changed

+46
-34
lines changed

4 files changed

+46
-34
lines changed

.github/workflows/release.yml

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
types: [published]
66

77
permissions:
8-
contents: read
8+
contents: write # For uploading release assets
99
id-token: write # For trusted publishing to PyPI
1010

1111
jobs:
@@ -28,10 +28,17 @@ jobs:
2828
run: uv python install 3.11
2929

3030
- name: Install dependencies
31-
run: uv sync --group test
31+
run: uv sync --group test --group dev
32+
33+
- name: Run quality checks
34+
run: |
35+
uv run black --check hyperdb/ tests/
36+
uv run isort --check-only hyperdb/ tests/
37+
uv run flake8 hyperdb/ tests/
38+
uv run mypy hyperdb/ --ignore-missing-imports
3239
3340
- name: Run tests
34-
run: uv run pytest tests/ -v
41+
run: uv run pytest tests/ -v --cov=hyperdb --cov-report=xml --cov-report=term
3542

3643
- name: Build package
3744
run: uv build
@@ -40,19 +47,23 @@ jobs:
4047
run: |
4148
uv run pip install twine
4249
uv run twine check dist/*
50+
51+
- name: Create package archive
52+
run: |
53+
cd dist
54+
zip -r ../packages.zip .
55+
cd ..
4356
4457
- name: Publish to PyPI
4558
uses: pypa/gh-action-pypi-publish@release/v1
4659
with:
47-
password: ${{ secrets.PYPI_API_TOKEN }}
4860
skip-existing: true
61+
# Uses trusted publishing with id-token, no password needed
4962

5063
- name: Upload Release Assets
51-
uses: actions/upload-release-asset@v1
52-
env:
53-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
64+
uses: softprops/action-gh-release@v1
5465
with:
55-
upload_url: ${{ github.event.release.upload_url }}
56-
asset_path: dist/
57-
asset_name: packages
58-
asset_content_type: application/zip
66+
files: |
67+
dist/*
68+
packages.zip
69+
token: ${{ secrets.GITHUB_TOKEN }}

hyperdb/base.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,16 @@ def encode_e(self, e_tuple: Union[List, Set, Tuple]) -> Tuple:
9393
raise NotImplementedError
9494

9595
@cached_property
96-
def all_v(self) -> List[str]:
96+
def all_v(self) -> Set[Any]:
9797
r"""
98-
Return a list of all vertices in the hypergraph.
98+
Return a set of all vertices in the hypergraph.
9999
"""
100100
raise NotImplementedError
101101

102102
@cached_property
103-
def all_e(self) -> List[Tuple]:
103+
def all_e(self) -> Set[Tuple]:
104104
r"""
105-
Return a list of all hyperedges in the hypergraph.
105+
Return a set of all hyperedges in the hypergraph.
106106
"""
107107
raise NotImplementedError
108108

@@ -214,7 +214,7 @@ def degree_e(self, e_tuple: Tuple) -> int:
214214
"""
215215
raise NotImplementedError
216216

217-
def nbr_e_of_v(self, v_id: Any) -> list:
217+
def nbr_e_of_v(self, v_id: Any) -> set:
218218
r"""
219219
Return the hyperedge neighbors of the vertex.
220220
@@ -223,7 +223,7 @@ def nbr_e_of_v(self, v_id: Any) -> list:
223223
"""
224224
raise NotImplementedError
225225

226-
def nbr_v_of_e(self, e_tuple: Tuple) -> list:
226+
def nbr_v_of_e(self, e_tuple: Tuple) -> set:
227227
r"""
228228
Return the vertex neighbors of the hyperedge.
229229
@@ -232,12 +232,13 @@ def nbr_v_of_e(self, e_tuple: Tuple) -> list:
232232
"""
233233
raise NotImplementedError
234234

235-
def nbr_v(self, v_id: Any) -> list:
235+
def nbr_v(self, v_id: Any, exclude_self: bool = True) -> set:
236236
r"""
237237
Return the vertex neighbors of the vertex.
238238
239239
Args:
240240
``v_id`` (``Any``): The vertex id.
241+
``exclude_self`` (``bool``): Whether to exclude the vertex itself from neighbors.
241242
"""
242243
raise NotImplementedError
243244

hyperdb/hypergraph.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,18 @@ def encode_e(self, e_tuple: Union[List, Set, Tuple]) -> Tuple:
110110
return tuple(tmp)
111111

112112
@cached_property
113-
def all_v(self) -> List[str]:
113+
def all_v(self) -> Set[Any]:
114114
r"""
115-
Return a list of all vertices in the hypergraph.
115+
Return a set of all vertices in the hypergraph.
116116
"""
117-
return list(self._v_data.keys())
117+
return set(self._v_data.keys())
118118

119119
@cached_property
120-
def all_e(self) -> List[Tuple]:
120+
def all_e(self) -> Set[Tuple]:
121121
r"""
122-
Return a list of all hyperedges in the hypergraph.
122+
Return a set of all hyperedges in the hypergraph.
123123
"""
124-
return list(self._e_data.keys())
124+
return set(self._e_data.keys())
125125

126126
@cached_property
127127
def num_v(self) -> int:
@@ -298,7 +298,7 @@ def degree_e(self, e_tuple: Union[List, Set, Tuple]) -> int:
298298
assert e_tuple in self._e_data, f"The hyperedge {e_tuple} does not exist in the hypergraph."
299299
return len(e_tuple)
300300

301-
def nbr_e_of_v(self, v_id: Any) -> list:
301+
def nbr_e_of_v(self, v_id: Any) -> set:
302302
r"""
303303
Return the incident hyperedges of the vertex.
304304
@@ -307,9 +307,9 @@ def nbr_e_of_v(self, v_id: Any) -> list:
307307
"""
308308
assert isinstance(v_id, Hashable), "The vertex id must be hashable."
309309
assert v_id in self._v_data, f"The vertex {v_id} does not exist in the hypergraph."
310-
return list(self._v_inci[v_id])
310+
return set(self._v_inci[v_id])
311311

312-
def nbr_v_of_e(self, e_tuple: Union[List, Set, Tuple]) -> list:
312+
def nbr_v_of_e(self, e_tuple: Union[List, Set, Tuple]) -> set:
313313
r"""
314314
Return the incident vertices of the hyperedge.
315315
@@ -319,9 +319,9 @@ def nbr_v_of_e(self, e_tuple: Union[List, Set, Tuple]) -> list:
319319
assert isinstance(e_tuple, (list, set, tuple)), "The hyperedge must be a list, set, or tuple of vertex ids."
320320
e_tuple = self.encode_e(e_tuple)
321321
assert e_tuple in self._e_data, f"The hyperedge {e_tuple} does not exist in the hypergraph."
322-
return list(e_tuple)
322+
return set(e_tuple)
323323

324-
def nbr_v(self, v_id: Any, exclude_self=True) -> list:
324+
def nbr_v(self, v_id: Any, exclude_self=True) -> set:
325325
r"""
326326
Return the neighbors of the vertex.
327327
@@ -335,4 +335,4 @@ def nbr_v(self, v_id: Any, exclude_self=True) -> list:
335335
nbrs.update(e_tuple)
336336
if exclude_self:
337337
nbrs.remove(v_id)
338-
return list(nbrs)
338+
return nbrs

tests/test_hypergraph.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ def hg():
2222

2323

2424
def test_all_v(hg):
25-
assert hg.all_v == set([1, 2, 3, 4, 5, 6])
25+
assert hg.all_v == {1, 2, 3, 4, 5, 6}
2626
assert hg.num_v == 6
2727
hg.remove_v(2)
28-
assert hg.all_v == set([1, 3, 4, 5, 6])
28+
assert hg.all_v == {1, 3, 4, 5, 6}
2929
assert hg.num_v == 5
3030

3131

3232
def test_all_e(hg):
33-
assert hg.all_e == set([(1, 2), (1, 3), (2, 3, 4), (1, 3, 4, 5), (4, 5, 6), (1, 5, 6)])
33+
assert hg.all_e == {(1, 2), (1, 3), (1, 3, 4, 5), (1, 5, 6), (2, 3, 4), (4, 5, 6)}
3434
assert hg.num_e == 6
3535
hg.remove_v(2)
36-
assert hg.all_e == set([(1, 3), (3, 4), (1, 3, 4, 5), (4, 5, 6), (1, 5, 6)])
36+
assert hg.all_e == {(1, 3), (1, 3, 4, 5), (1, 5, 6), (3, 4), (4, 5, 6)}
3737
assert hg.num_e == 5
3838

3939

0 commit comments

Comments
 (0)