Skip to content

Commit f722f65

Browse files
authored
Materialize optional Rust extension in metadata (#993)
1 parent 656c796 commit f722f65

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

src/neo4j/_codec/packstream/__init__.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@
1414
# limitations under the License.
1515

1616

17-
from ._common import Structure
17+
from ._common import (
18+
RUST_AVAILABLE,
19+
Structure,
20+
)
1821

1922

2023
__all__ = [
2124
"Structure",
25+
"RUST_AVAILABLE",
2226
]

src/neo4j/_codec/packstream/_common.py

+2
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@
1616

1717
try:
1818
from ._rust import Structure
19+
RUST_AVAILABLE = True
1920
except ImportError:
2021
from ._python import Structure
22+
RUST_AVAILABLE = False

src/neo4j/_meta.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
from inspect import isclass
2626
from warnings import warn
2727

28+
from ._codec.packstream import RUST_AVAILABLE
29+
2830

2931
if t.TYPE_CHECKING:
3032
_FuncT = t.TypeVar("_FuncT", bound=t.Callable)
@@ -40,13 +42,17 @@ def _compute_bolt_agent() -> t.Dict[str, str]:
4042
def format_version_info(version_info):
4143
return "{}.{}.{}-{}-{}".format(*version_info)
4244

45+
language = "Python"
46+
if RUST_AVAILABLE:
47+
language += "-Rust"
48+
4349
return {
4450
"product": f"neo4j-python/{version}",
4551
"platform":
4652
f"{platform.system() or 'Unknown'} "
4753
f"{platform.release() or 'unknown'}; "
4854
f"{platform.machine() or 'unknown'}",
49-
"language": f"Python/{format_version_info(sys.version_info)}",
55+
"language": f"{language}/{format_version_info(sys.version_info)}",
5056
"language_details":
5157
f"{platform.python_implementation()}; "
5258
f"{format_version_info(sys.implementation.version)} "
@@ -59,9 +65,9 @@ def format_version_info(version_info):
5965

6066

6167
def _compute_user_agent() -> str:
62-
template = "neo4j-python/{} Python/{}.{}.{}-{}-{} ({})"
63-
fields = (version,) + tuple(sys.version_info) + (sys.platform,)
64-
return template.format(*fields)
68+
return (f'{BOLT_AGENT_DICT["product"]} '
69+
f'{BOLT_AGENT_DICT["language"]} '
70+
f'({sys.platform})')
6571

6672

6773
USER_AGENT = _compute_user_agent()

0 commit comments

Comments
 (0)