Skip to content

Commit

Permalink
Migrate to pyproject.toml (#25)
Browse files Browse the repository at this point in the history
* initial commit

* lint cleanup

* workflow cleanup

* disable 3.12

* fix lint

* lock `torch` in workflow
  • Loading branch information
aMahanna authored Nov 15, 2023
1 parent dbee0fc commit ce6e1d1
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 103 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python: ["3.8", "3.9", "3.10", "3.11"]
python: ["3.8", "3.9", "3.10", "3.11"] # "3.12"
name: Python ${{ matrix.python }}
steps:
- uses: actions/checkout@v4
Expand All @@ -32,7 +32,7 @@ jobs:

- name: Install packages
run: |
pip install torch
pip install torch==2.1.0
pip install torch-scatter torch-sparse -f https://data.pyg.org/whl/torch-$(python -c 'import torch; print(torch.__version__.split("+")[0])')+cpu.html
pip install -e .[dev]
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ jobs:
run: gitchangelog ${{env.VERSION}} > CHANGELOG.md

- name: Make commit for auto-generated changelog
uses: EndBug/add-and-commit@v7
uses: EndBug/add-and-commit@v9
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
add: "CHANGELOG.md"
branch: actions/changelog
new_branch: actions/changelog
message: "!gitchangelog"

- name: Create pull request for the auto generated changelog
Expand Down
18 changes: 8 additions & 10 deletions adbpyg_adapter/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,8 @@ def arangodb_graph_to_pyg(
:raise adbpyg_adapter.exceptions.ADBMetagraphError: If invalid metagraph.
"""
graph = self.__db.graph(name)
v_cols: Set[str] = graph.vertex_collections() # type: ignore
edge_definitions: List[Json] = graph.edge_definitions() # type: ignore
v_cols: Set[str] = graph.vertex_collections()
edge_definitions: List[Json] = graph.edge_definitions()
e_cols: Set[str] = {c["edge_collection"] for c in edge_definitions}

return self.arangodb_collections_to_pyg(
Expand Down Expand Up @@ -731,12 +731,12 @@ def get_aql_return_value(
)
"""

col_size: int = self.__db.collection(col).count() # type: ignore
col_size: int = self.__db.collection(col).count()

with get_export_spinner_progress(f"ADB Export: '{col}' ({col_size})") as p:
p.add_task(col)

cursor: Cursor = self.__db.aql.execute( # type: ignore
cursor: Cursor = self.__db.aql.execute(
f"FOR doc IN @@col RETURN {get_aql_return_value(meta)}",
bind_vars={"@col": col},
**{**adb_export_kwargs, **{"stream": True}},
Expand Down Expand Up @@ -785,7 +785,7 @@ def __process_adb_cursor(
with Live(Group(progress)):
i = 0
while not cursor.empty():
cursor_batch = len(cursor.batch()) # type: ignore
cursor_batch = len(cursor.batch())
df = DataFrame([cursor.pop() for _ in range(cursor_batch)])

i = process_adb_df(i, df, col, adb_map, meta, preserve_key, **kwargs)
Expand Down Expand Up @@ -1180,7 +1180,7 @@ def __create_adb_graph(
edge_definitions = self.__etypes_to_edefinitions(edge_types)
orphan_collections = self.__ntypes_to_ocollections(node_types, edge_types)

return self.__db.create_graph( # type: ignore[return-value]
return self.__db.create_graph(
name,
edge_definitions,
orphan_collections,
Expand Down Expand Up @@ -1239,8 +1239,7 @@ def __process_pyg_node_batch(

# 3. Apply the ArangoDB Node Controller (if provided)
if is_custom_controller:
f = lambda n: self.__cntrl._prepare_pyg_node(n, n_type)
df = df.apply(f, axis=1)
df = df.apply(lambda n: self.__cntrl._prepare_pyg_node(n, n_type), axis=1)

return df

Expand Down Expand Up @@ -1313,8 +1312,7 @@ def __process_pyg_edge_batch(

# 5. Apply the ArangoDB Edge Controller (if provided)
if is_custom_controller:
f = lambda e: self.__cntrl._prepare_pyg_edge(e, e_type)
df = df.apply(f, axis=1)
df = df.apply(lambda e: self.__cntrl._prepare_pyg_edge(e, e_type), axis=1)

return df

Expand Down
4 changes: 1 addition & 3 deletions adbpyg_adapter/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
logger.addHandler(handler)


def get_export_spinner_progress(
text: str,
) -> Progress:
def get_export_spinner_progress(text: str) -> Progress:
return Progress(
TextColumn(text),
SpinnerColumn("aesthetic", "#5BC0DE"),
Expand Down
89 changes: 82 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,92 @@
[build-system]
requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2", "wheel"]
requires = ["setuptools>=45", "wheel", "setuptools_scm"]
build-backend = "setuptools.build_meta"

[tool.coverage.run]
omit = [
"adbpyg_adapter/version.py",
"setup.py",
[tool.setuptools_scm]
normalize = true

[project]
name = "adbpyg_adapter"
description = "Convert ArangoDB graphs to PyG & vice-versa."
keywords = ["arangodb", "pyg", "pytorch", "pytorch geometric", "adapter"]
readme = "README.md"
dynamic = ["version"]
license = {file = "LICENSE"}
requires-python = ">=3.8"

authors = [{name = "Anthony Mahanna", email = "[email protected]"}]

classifiers = [
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
# "Programming Language :: Python :: 3.12",
"Topic :: Utilities",
"Typing :: Typed",
]

dependencies = [
"requests>=2.27.1",
"rich>=12.5.1",
"pandas>=1.3.5",
"python-arango~=7.6",
"torch>=1.12.0",
"torch-sparse>=0.6.14",
"torch-scatter>=2.0.9",
"torch-geometric>=2.0.4",
"setuptools>=45"
]

[project.optional-dependencies]
dev = [
"black==23.3.0",
"flake8==6.0.0",
"Flake8-pyproject",
"isort==5.12.0",
"mypy==1.4.1",
"pytest>=6.0.0",
"pytest-cov>=2.0.0",
"coveralls>=3.3.1",
"types-setuptools>=57.4.9",
"types-requests>=2.27.11",
"networkx>=2.5.1",
]

[project.urls]
"Homepage" = "https://github.com/arangoml/pyg-adapter"

[tool.setuptools]
packages = ["adbpyg_adapter"]

[tool.pytest.ini_options]
addopts = "-s -vv"
minversion = "6.0"
testpaths = ["tests"]

[tool.setuptools_scm]
write_to = "adbpyg_adapter/version.py"
[tool.coverage.report]
omit = ["*tests*"]

[tool.coverage.run]
omit = ["*tests*"]

[tool.isort]
profile = "black"

[tool.flake8]
max-line-length = 88
extend-ignore = ["E203", "W503", "E251"]
exclude = [".git", ".idea", ".*_cache", "dist", "venv"]

[tool.mypy]
strict = true
ignore_missing_imports = true
implicit_reexport = true
scripts_are_modules = true
follow_imports = "skip"
disallow_subclassing_any = false
disallow_untyped_decorators = false
12 changes: 0 additions & 12 deletions setup.cfg

This file was deleted.

55 changes: 1 addition & 54 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,56 +1,3 @@
from setuptools import setup

with open("./README.md") as fp:
long_description = fp.read()

setup(
name="adbpyg_adapter",
author="Anthony Mahanna",
author_email="[email protected]",
description="Convert ArangoDB graphs to PyG & vice-versa.",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/arangoml/pyg-adapter",
keywords=["arangodb", "pyg", "pytorch", "pytorch geometric", "adapter"],
packages=["adbpyg_adapter"],
include_package_data=True,
python_requires=">=3.8",
license="Apache Software License",
install_requires=[
"requests>=2.27.1",
"rich>=12.5.1",
"pandas>=1.3.5",
"python-arango~=7.6",
"torch>=1.12.0",
"torch-sparse>=0.6.14",
"torch-scatter>=2.0.9",
"torch-geometric>=2.0.4",
"setuptools>=45",
],
extras_require={
"dev": [
"black==23.3.0",
"flake8==6.0.0",
"isort==5.12.0",
"mypy==1.4.1",
"pytest>=6.0.0",
"pytest-cov>=2.0.0",
"coveralls>=3.3.1",
"types-setuptools>=57.4.9",
"types-requests>=2.27.11",
"networkx>=2.5.1",
],
},
classifiers=[
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Utilities",
"Typing :: Typed",
],
)
setup()
26 changes: 13 additions & 13 deletions tests/test_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ class Bad_ADBPyG_Controller:
pass

with pytest.raises(TypeError):
ADBPyG_Adapter(bad_db) # type: ignore
ADBPyG_Adapter(bad_db)

with pytest.raises(TypeError):
ADBPyG_Adapter(db, Bad_ADBPyG_Controller()) # type: ignore
ADBPyG_Adapter(db, Bad_ADBPyG_Controller()) # type:ignore[arg-type]


@pytest.mark.parametrize(
Expand Down Expand Up @@ -395,11 +395,11 @@ def test_pyg_to_arangodb_with_controller() -> None:

ADBPyG_Adapter(db, Custom_ADBPyG_Controller()).pyg_to_arangodb(name, data)

for doc in db.collection(f"{name}_N"): # type: ignore
for doc in db.collection(f"{name}_N"):
assert "foo" in doc
assert doc["foo"] == "bar"

for edge in db.collection(f"{name}_E"): # type: ignore
for edge in db.collection(f"{name}_E"):
assert "bar" in edge
assert edge["bar"] == "foo"

Expand Down Expand Up @@ -649,8 +649,8 @@ def test_adb_graph_to_pyg(
pyg_g_new = adapter.arangodb_graph_to_pyg(name)

graph = db.graph(name)
v_cols: Set[str] = graph.vertex_collections() # type: ignore
edge_definitions: List[Json] = graph.edge_definitions() # type: ignore
v_cols: Set[str] = graph.vertex_collections()
edge_definitions: List[Json] = graph.edge_definitions()
e_cols: Set[str] = {c["edge_collection"] for c in edge_definitions}

# Manually set the number of nodes (since nodes are feature-less)
Expand Down Expand Up @@ -683,8 +683,8 @@ def test_adb_graph_to_pyg_to_arangodb_with_missing_document_and_strict(
ADBPyG_Adapter(db).pyg_to_arangodb(name, data)

graph = db.graph(name)
v_cols: Set[str] = graph.vertex_collections() # type: ignore
edge_definitions: List[Json] = graph.edge_definitions() # type: ignore
v_cols: Set[str] = graph.vertex_collections()
edge_definitions: List[Json] = graph.edge_definitions()
e_cols: Set[str] = {c["edge_collection"] for c in edge_definitions}

for v_col in v_cols:
Expand Down Expand Up @@ -713,8 +713,8 @@ def test_adb_graph_to_pyg_to_arangodb_with_missing_document_and_permissive(
ADBPyG_Adapter(db).pyg_to_arangodb(name, data)

graph = db.graph(name)
v_cols: Set[str] = graph.vertex_collections() # type: ignore
edge_definitions: List[Json] = graph.edge_definitions() # type: ignore
v_cols: Set[str] = graph.vertex_collections()
edge_definitions: List[Json] = graph.edge_definitions()
e_cols: Set[str] = {c["edge_collection"] for c in edge_definitions}

for v_col in v_cols:
Expand All @@ -728,7 +728,7 @@ def test_adb_graph_to_pyg_to_arangodb_with_missing_document_and_permissive(

data = adapter.arangodb_to_pyg(name, metagraph=metagraph, strict=False)

collection_count: int = db.collection(list(e_cols)[0]).count() # type: ignore
collection_count: int = db.collection(list(e_cols)[0]).count()
assert len(data.edge_index[0]) < collection_count

db.delete_graph(name, drop_collections=True)
Expand Down Expand Up @@ -799,8 +799,8 @@ def test_full_cycle_homogeneous_with_preserve_adb_keys() -> None:
pyg_g = adbpyg_adapter.arangodb_graph_to_pyg(name, preserve_adb_keys=True)

graph = db.graph(name)
v_cols: Set[str] = graph.vertex_collections() # type: ignore
edge_definitions: List[Json] = graph.edge_definitions() # type: ignore
v_cols: Set[str] = graph.vertex_collections()
edge_definitions: List[Json] = graph.edge_definitions()
e_cols: Set[str] = {c["edge_collection"] for c in edge_definitions}

metagraph: ADBMetagraph = {
Expand Down

0 comments on commit ce6e1d1

Please sign in to comment.