Skip to content

Commit c8c7c61

Browse files
committed
Add proxies with deprecation warning for internal modules
1 parent 4075ed5 commit c8c7c61

34 files changed

+690
-142
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@
104104
deprecated without replacement. They are internal functions.
105105
- Importing `neo4j.packstream` has been deprecated. It's internal and should not
106106
be used by client code.
107+
- Importing `neo4j.routing` has been deprecated. It's internal and should not
108+
be used by client code.
109+
- Importing `neo4j.config` has been deprecated. It's internal and should not
110+
be used by client code.
111+
- `neoj4.Config`, `neoj4.PoolConfig`, `neoj4.SessionConfig`, and
112+
`neoj4.WorkspaceConfig` have been deprecated without replacement. They are
113+
internal classes.
107114
- Importing `neo4j.meta` has been deprecated. It's internal and should not
108115
be used by client code. `ExperimantalWarning` should be imported directly from
109116
`neo4j`. `neo4j.meta.version` is exposed through `neo4j.__vesrion__`

neo4j/__init__.py

Lines changed: 79 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -16,60 +16,7 @@
1616
# limitations under the License.
1717

1818

19-
__all__ = [
20-
"__version__",
21-
"Address",
22-
"AsyncBoltDriver",
23-
"AsyncDriver",
24-
"AsyncGraphDatabase",
25-
"AsyncManagedTransaction",
26-
"AsyncNeo4jDriver",
27-
"AsyncResult",
28-
"AsyncSession",
29-
"AsyncTransaction",
30-
"Auth",
31-
"AuthToken",
32-
"basic_auth",
33-
"bearer_auth",
34-
"BoltDriver",
35-
"Bookmark",
36-
"Bookmarks",
37-
"Config",
38-
"custom_auth",
39-
"DEFAULT_DATABASE",
40-
"Driver",
41-
"ExperimentalWarning",
42-
"get_user_agent",
43-
"GraphDatabase",
44-
"IPv4Address",
45-
"IPv6Address",
46-
"kerberos_auth",
47-
"ManagedTransaction",
48-
"Neo4jDriver",
49-
"PoolConfig",
50-
"Query",
51-
"READ_ACCESS",
52-
"Record",
53-
"Result",
54-
"ResultSummary",
55-
"ServerInfo",
56-
"Session",
57-
"SessionConfig",
58-
"SummaryCounters",
59-
"Transaction",
60-
"TRUST_ALL_CERTIFICATES",
61-
"TRUST_SYSTEM_CA_SIGNED_CERTIFICATES",
62-
"TrustAll",
63-
"TrustCustomCAs",
64-
"TrustSystemCAs",
65-
"unit_of_work",
66-
"Version",
67-
"WorkspaceConfig",
68-
"WRITE_ACCESS",
69-
]
70-
71-
72-
from logging import getLogger
19+
from logging import getLogger as _getLogger
7320

7421
from ._async.driver import (
7522
AsyncBoltDriver,
@@ -84,13 +31,13 @@
8431
AsyncTransaction,
8532
)
8633
from ._conf import (
87-
Config,
88-
PoolConfig,
89-
SessionConfig,
34+
Config as _Config,
35+
PoolConfig as _PoolConfig,
36+
SessionConfig as _SessionConfig,
9037
TrustAll,
9138
TrustCustomCAs,
9239
TrustSystemCAs,
93-
WorkspaceConfig,
40+
WorkspaceConfig as _WorkspaceConfig,
9441
)
9542
from ._data import Record
9643
from ._meta import (
@@ -143,4 +90,77 @@
14390
)
14491

14592

146-
log = getLogger("neo4j")
93+
__all__ = [
94+
"__version__",
95+
"Address",
96+
"AsyncBoltDriver",
97+
"AsyncDriver",
98+
"AsyncGraphDatabase",
99+
"AsyncManagedTransaction",
100+
"AsyncNeo4jDriver",
101+
"AsyncResult",
102+
"AsyncSession",
103+
"AsyncTransaction",
104+
"Auth",
105+
"AuthToken",
106+
"basic_auth",
107+
"bearer_auth",
108+
"BoltDriver",
109+
"Bookmark",
110+
"Bookmarks",
111+
"Config",
112+
"custom_auth",
113+
"DEFAULT_DATABASE",
114+
"Driver",
115+
"ExperimentalWarning",
116+
"get_user_agent",
117+
"GraphDatabase",
118+
"IPv4Address",
119+
"IPv6Address",
120+
"kerberos_auth",
121+
"ManagedTransaction",
122+
"Neo4jDriver",
123+
"PoolConfig",
124+
"Query",
125+
"READ_ACCESS",
126+
"Record",
127+
"Result",
128+
"ResultSummary",
129+
"ServerInfo",
130+
"Session",
131+
"SessionConfig",
132+
"SummaryCounters",
133+
"Transaction",
134+
"TRUST_ALL_CERTIFICATES",
135+
"TRUST_SYSTEM_CA_SIGNED_CERTIFICATES",
136+
"TrustAll",
137+
"TrustCustomCAs",
138+
"TrustSystemCAs",
139+
"unit_of_work",
140+
"Version",
141+
"WorkspaceConfig",
142+
"WRITE_ACCESS",
143+
]
144+
145+
146+
_log = _getLogger("neo4j")
147+
148+
149+
def __getattr__(name):
150+
# TODO 6.0 - remove this
151+
if name in (
152+
"log", "Config", "PoolConfig", "SessionConfig", "WorkspaceConfig"
153+
):
154+
from ._meta import deprecation_warn
155+
deprecation_warn(
156+
"Importing {} from neo4j is deprecated without replacement. It's "
157+
"internal and will be removed in a future version."
158+
.format(name),
159+
stack_level=2
160+
)
161+
return globals()[f"_{name}"]
162+
raise AttributeError(f"module {__name__} has no attribute {name}")
163+
164+
165+
def __dir__():
166+
return __all__

neo4j/_async/driver.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ def driver(cls, uri, *, auth=None, **config):
139139
"Creating a direct driver (`bolt://` scheme) with routing "
140140
"context (URI parameters) is deprecated. They will be "
141141
"ignored. This will raise an error in a future release. "
142-
'Given URI "{}"'.format(uri)
142+
'Given URI "{}"'.format(uri),
143+
stack_level=2
143144
)
144145
# TODO: 6.0 - raise instead of warning
145146
# raise ValueError(

neo4j/_codec/hydration/_common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818

1919
from ...graph import Graph
20-
from ...packstream import Structure
20+
from ..packstream import Structure
2121

2222

2323
class GraphHydrator:

neo4j/_sync/driver.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ def driver(cls, uri, *, auth=None, **config):
139139
"Creating a direct driver (`bolt://` scheme) with routing "
140140
"context (URI parameters) is deprecated. They will be "
141141
"ignored. This will raise an error in a future release. "
142-
'Given URI "{}"'.format(uri)
142+
'Given URI "{}"'.format(uri),
143+
stack_level=2
143144
)
144145
# TODO: 6.0 - raise instead of warning
145146
# raise ValueError(

neo4j/api.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ def custom_auth(principal, credentials, realm, scheme, **parameters):
165165
return Auth(scheme, principal, credentials, realm, **parameters)
166166

167167

168+
# TODO 6.0 - remove this class
168169
class Bookmark:
169170
"""A Bookmark object contains an immutable list of bookmark string values.
170171
@@ -271,6 +272,10 @@ def from_raw_values(cls, values):
271272
if not isinstance(value, str):
272273
raise TypeError("Raw bookmark values must be str. "
273274
"Found {}".format(type(value)))
275+
try:
276+
value.encode("ascii")
277+
except UnicodeEncodeError as e:
278+
raise ValueError(f"The value {value} is not ASCII") from e
274279
bookmarks.append(value)
275280
obj._raw_values = frozenset(bookmarks)
276281
return obj

neo4j/conf.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Copyright (c) "Neo4j"
2+
# Neo4j Sweden AB [https://neo4j.com]
3+
#
4+
# This file is part of Neo4j.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# https://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
# TODO: 6.0 - remove this file
19+
20+
21+
from ._conf import (
22+
Config,
23+
ConfigType,
24+
DeprecatedAlias,
25+
DeprecatedAlternative,
26+
iter_items,
27+
PoolConfig,
28+
RoutingConfig,
29+
SessionConfig,
30+
TransactionConfig,
31+
WorkspaceConfig,
32+
)
33+
from ._meta import deprecation_warn as _deprecation_warn
34+
35+
36+
__all__ = [
37+
"Config",
38+
"ConfigType",
39+
"DeprecatedAlias",
40+
"DeprecatedAlternative",
41+
"iter_items",
42+
"PoolConfig",
43+
"RoutingConfig",
44+
"SessionConfig",
45+
"TransactionConfig",
46+
"WorkspaceConfig",
47+
]
48+
49+
_deprecation_warn(
50+
"The module 'neo4j.conf' was made internal and will "
51+
"no longer be available for import in future versions.",
52+
stack_level=2
53+
)

neo4j/data.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright (c) "Neo4j"
2+
# Neo4j Sweden AB [https://neo4j.com]
3+
#
4+
# This file is part of Neo4j.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# https://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
# TODO: 6.0 - remove this file
19+
20+
21+
from ._data import (
22+
DataTransformer,
23+
Record,
24+
RecordExporter,
25+
RecordTableRowExporter,
26+
)
27+
from ._meta import deprecation_warn
28+
29+
30+
map_type = type(map(str, range(0)))
31+
32+
__all__ = [
33+
"map_type",
34+
"Record",
35+
"DataTransformer",
36+
"RecordExporter",
37+
"RecordTableRowExporter",
38+
]
39+
40+
deprecation_warn(
41+
"The module 'neo4j.data' was made internal and will "
42+
"no longer be available for import in future versions. "
43+
"`neo4j.data.Record` should be imported directly from `neo4j`.",
44+
stack_level=2
45+
)

neo4j/graph/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
from collections.abc import Mapping
3333

34-
from ..meta import (
34+
from .._meta import (
3535
deprecated,
3636
deprecation_warn,
3737
)

neo4j/meta.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright (c) "Neo4j"
2+
# Neo4j Sweden AB [https://neo4j.com]
3+
#
4+
# This file is part of Neo4j.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# https://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
# TODO: 6.0 - remove this file
19+
20+
21+
from ._meta import (
22+
deprecated,
23+
deprecation_warn,
24+
experimental,
25+
ExperimentalWarning,
26+
get_user_agent,
27+
package,
28+
version,
29+
)
30+
31+
32+
__all__ = [
33+
"package",
34+
"version",
35+
"get_user_agent",
36+
"deprecation_warn",
37+
"deprecated",
38+
"ExperimentalWarning",
39+
"experimental",
40+
]
41+
42+
deprecation_warn(
43+
"The module 'neo4j.meta' was made internal and will "
44+
"no longer be available for import in future versions."
45+
"`ExperimentalWarning` can be imported from `neo4j` directly and "
46+
"`neo4j.meta.version` is exposed as `neo4j.__version__`.",
47+
stack_level=2
48+
)

0 commit comments

Comments
 (0)