Skip to content

Commit 6202d53

Browse files
authored
Merge pull request #74 from adamnsch/user-agent
Set explicit user agent in default constructor
2 parents a2db6d7 + 5d5b03c commit 6202d53

File tree

5 files changed

+24
-12
lines changed

5 files changed

+24
-12
lines changed

graphdatascience/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from .graph_data_science import GraphDataScience
22
from .query_runner.query_runner import QueryRunner
3+
from .version import __version__
34

4-
__all__ = ["GraphDataScience", "QueryRunner"]
5+
__all__ = ["GraphDataScience", "QueryRunner", "__version__"]

graphdatascience/graph_data_science.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from .error.uncallable_namespace import UncallableNamespace
88
from .query_runner.neo4j_query_runner import Neo4jQueryRunner
99
from .query_runner.query_runner import QueryResult, QueryRunner
10+
from .version import __version__
1011

1112
GDS = TypeVar("GDS", bound="GraphDataScience")
1213

@@ -18,20 +19,23 @@ def __init__(
1819
self, endpoint: Union[str, QueryRunner], auth: Any = None, aura_ds: bool = False
1920
):
2021
if isinstance(endpoint, str):
21-
self._config = {}
22+
self._config: Dict[str, Any] = {
23+
"user_agent": f"neo4j-graphdatascience-v{__version__}"
24+
}
25+
2226
if aura_ds:
2327
protocol = endpoint.split(":")[0]
2428
if not protocol == self._AURA_DS_PROTOCOL:
2529
raise ValueError(
26-
f"AuraDS requires using the 'neo4j+s' protocol (provided protocol was '{protocol}')"
30+
f"AuraDS requires using the '{self._AURA_DS_PROTOCOL}' protocol ('{protocol}' was provided)"
2731
)
28-
self._config = {
29-
"max_connection_lifetime": 60 * 8, # 8 minutes
30-
"keep_alive": True,
31-
"max_connection_pool_size": 50,
32-
}
32+
33+
self._config["max_connection_lifetime"] = 60 * 8 # 8 minutes
34+
self._config["keep_alive"] = True
35+
self._config["max_connection_pool_size"] = 50
3336

3437
driver = GraphDatabase.driver(endpoint, auth=auth, **self._config)
38+
3539
self._query_runner = self.create_neo4j_query_runner(driver)
3640
else:
3741
self._query_runner = endpoint

graphdatascience/tests/integration/test_database_ops.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from graphdatascience.graph_data_science import GraphDataScience
55
from graphdatascience.query_runner.neo4j_query_runner import Neo4jQueryRunner
66
from graphdatascience.tests.integration.conftest import AUTH, URI
7+
from graphdatascience.version import __version__
78

89
GRAPH_NAME = "g"
910

@@ -34,28 +35,29 @@ def test_from_neo4j_driver(neo4j_driver: Driver) -> None:
3435
def test_from_neo4j_credentials() -> None:
3536
gds = GraphDataScience(URI, auth=AUTH)
3637
assert len(gds.list()) > 10
38+
assert gds.driver_config()["user_agent"] == f"neo4j-graphdatascience-v{__version__}"
3739

3840

3941
def test_aurads_rejects_bolt() -> None:
4042
with pytest.raises(
4143
ValueError,
42-
match=r"AuraDS requires using the 'neo4j\+s' protocol \(provided protocol was 'bolt'\)",
44+
match=r"AuraDS requires using the 'neo4j\+s' protocol \('bolt' was provided\)",
4345
):
4446
GraphDataScience("bolt://localhost:7687", auth=AUTH, aura_ds=True)
4547

4648

4749
def test_aurads_rejects_neo4j() -> None:
4850
with pytest.raises(
4951
ValueError,
50-
match=r"AuraDS requires using the 'neo4j\+s' protocol \(provided protocol was 'neo4j'\)",
52+
match=r"AuraDS requires using the 'neo4j\+s' protocol \('neo4j' was provided\)",
5153
):
5254
GraphDataScience("neo4j://localhost:7687", auth=AUTH, aura_ds=True)
5355

5456

5557
def test_aurads_rejects_neo4j_ssc() -> None:
5658
with pytest.raises(
5759
ValueError,
58-
match=r"AuraDS requires using the 'neo4j\+s' protocol \(provided protocol was 'neo4j\+ssc'\)",
60+
match=r"AuraDS requires using the 'neo4j\+s' protocol \('neo4j\+ssc' was provided\)",
5961
):
6062
GraphDataScience("neo4j+ssc://localhost:7687", auth=AUTH, aura_ds=True)
6163

@@ -66,6 +68,7 @@ def test_aurads_accepts_neo4j_s() -> None:
6668
assert gds.driver_config()["keep_alive"]
6769
assert gds.driver_config()["max_connection_lifetime"] == 60 * 8
6870
assert gds.driver_config()["max_connection_pool_size"] == 50
71+
assert gds.driver_config()["user_agent"] == f"neo4j-graphdatascience-v{__version__}"
6972

7073

7174
def test_run_cypher(gds: GraphDataScience) -> None:

graphdatascience/version.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "0.1.0"

setup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
with open("requirements/base.txt", "r", encoding="utf-8") as f:
77
reqs = f.read().splitlines()
88

9+
with open("graphdatascience/version.py") as f:
10+
version = f.readline().strip().split()[-1][1:-1]
11+
912
classifiers = [
1013
"Intended Audience :: Developers",
1114
"Intended Audience :: Science/Research",
@@ -26,7 +29,7 @@
2629

2730
setuptools.setup(
2831
name="graphdatascience",
29-
version="0.1.0",
32+
version=version,
3033
author="Neo4j",
3134
author_email="team-gds@neo4j.org",
3235
description="A Python client for the Neo4j Graph Data Science (GDS) library",

0 commit comments

Comments
 (0)