Skip to content

Commit 621a6aa

Browse files
authored
Merge pull request #141 from technige/1.2-fix-setup
Fix broken setup (on some platforms)
2 parents b2c4358 + d9cb453 commit 621a6aa

File tree

4 files changed

+73
-56
lines changed

4 files changed

+73
-56
lines changed

MANIFEST.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
global-exclude *.class *.pyc *.pyo *.so *.dll __pycache__
12
recursive-include neo4j *.c
2-
recursive-exclude test *
3+
recursive-include neo4j *.pyx
4+
prune test

neo4j/addressing.py

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,34 @@
2020

2121

2222
from collections import namedtuple
23-
from socket import getaddrinfo, gaierror, error as SocketError, \
24-
SOCK_STREAM, IPPROTO_TCP, AF_INET6, inet_aton, inet_pton
23+
from socket import getaddrinfo, gaierror, SOCK_STREAM, IPPROTO_TCP
2524

2625
from neo4j.compat import urlparse
2726
from neo4j.exceptions import AddressError
2827

2928

29+
VALID_IPv4_SEGMENTS = [str(i).encode("latin1") for i in range(0x100)]
30+
VALID_IPv6_SEGMENT_CHARS = b"0123456789abcdef"
31+
32+
33+
def is_ipv4_address(string):
34+
if not isinstance(string, bytes):
35+
string = str(string).encode("latin1")
36+
segments = string.split(b".")
37+
return len(segments) == 4 and all(segment in VALID_IPv4_SEGMENTS for segment in segments)
38+
39+
40+
def is_ipv6_address(string):
41+
if not isinstance(string, bytes):
42+
string = str(string).encode("latin1")
43+
segments = string.lower().split(b":")
44+
return 3 <= len(segments) <= 8 and all(all(c in VALID_IPv6_SEGMENT_CHARS for c in segment) for segment in segments)
45+
46+
47+
def is_ip_address(string):
48+
return is_ipv4_address(string) or is_ipv6_address(string)
49+
50+
3051
IPv4SocketAddress = namedtuple("Address", ["host", "port"])
3152
IPv6SocketAddress = namedtuple("Address", ["host", "port", "flow_info", "scope_id"])
3253

@@ -65,25 +86,3 @@ def resolve(socket_address):
6586
getaddrinfo(socket_address[0], socket_address[1], 0, SOCK_STREAM, IPPROTO_TCP)]
6687
except gaierror:
6788
raise AddressError("Cannot resolve address {!r}".format(socket_address[0]))
68-
69-
70-
def is_ipv4_address(string):
71-
try:
72-
inet_aton(string)
73-
except (OSError, SocketError):
74-
return False
75-
else:
76-
return True
77-
78-
79-
def is_ipv6_address(string):
80-
try:
81-
inet_pton(AF_INET6, string)
82-
except (OSError, SocketError):
83-
return False
84-
else:
85-
return True
86-
87-
88-
def is_ip_address(string):
89-
return is_ipv4_address(string) or is_ipv6_address(string)

neo4j/meta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919
# limitations under the License.
2020

2121

22-
version = "1.2.0rc1"
22+
version = "1.2.0rc2"

setup.py

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
# See the License for the specific language governing permissions and
1919
# limitations under the License.
2020

21-
import os
21+
22+
from __future__ import print_function
23+
24+
from os.path import dirname, join as path_join
2225
try:
2326
from setuptools import setup, Extension
2427
except ImportError:
@@ -30,41 +33,54 @@
3033
from Cython.Build import cythonize
3134
from Cython.Distutils import build_ext
3235
except ImportError:
33-
cmdclass = {}
3436
ext_modules = [
3537
Extension("neo4j.bolt._io", ["neo4j/bolt/_io.c"]),
3638
Extension("neo4j.packstream._packer", ["neo4j/packstream/_packer.c"]),
3739
Extension("neo4j.packstream._unpacker", ["neo4j/packstream/_unpacker.c"]),
3840
]
3941
else:
40-
cmdclass = {'build_ext': build_ext}
4142
ext_modules = cythonize([Extension("*", ["**/*.pyx"])])
4243

44+
classifiers = [
45+
"Intended Audience :: Developers",
46+
"License :: OSI Approved :: Apache Software License",
47+
"Operating System :: OS Independent",
48+
"Topic :: Database",
49+
"Topic :: Software Development",
50+
"Programming Language :: Python :: 2.7",
51+
"Programming Language :: Python :: 3.4",
52+
"Programming Language :: Python :: 3.5",
53+
"Programming Language :: Python :: 3.6",
54+
]
55+
packages = [
56+
"neo4j",
57+
"neo4j.bolt",
58+
"neo4j.compat",
59+
"neo4j.packstream",
60+
"neo4j.v1",
61+
]
62+
package_data = {
63+
"neo4j.bolt": ["*.pyx"],
64+
"neo4j.packstream": ["*.pyx"],
65+
}
66+
setup_args = {
67+
"name": "neo4j-driver",
68+
"version": version,
69+
"description": "Neo4j Bolt driver for Python",
70+
"license": "Apache License, Version 2.0",
71+
"long_description": open(path_join(dirname(__file__), "README.rst")).read(),
72+
"author": "Neo Technology",
73+
"author_email": "drivers@neo4j.com",
74+
"keywords": "neo4j graph database",
75+
"url": "https://github.com/neo4j/neo4j-python-driver",
76+
"classifiers": classifiers,
77+
"packages": packages,
78+
"ext_modules": ext_modules,
79+
}
4380

44-
# Used for reading the README into long_description below.
45-
def read(fname):
46-
return open(os.path.join(os.path.dirname(__file__), fname)).read()
47-
48-
49-
setup(name="neo4j-driver",
50-
version=version,
51-
description="Neo4j Bolt driver for Python",
52-
license="Apache License, Version 2.0",
53-
long_description=read("README.rst"),
54-
author="Neo Technology",
55-
author_email="drivers@neo4j.com",
56-
keywords="neo4j graph database",
57-
url="https://github.com/neo4j/neo4j-python-driver",
58-
classifiers=[
59-
"Intended Audience :: Developers",
60-
"License :: OSI Approved :: Apache Software License",
61-
"Operating System :: OS Independent",
62-
"Topic :: Database",
63-
"Topic :: Software Development",
64-
"Programming Language :: Python :: 2.7",
65-
"Programming Language :: Python :: 3.4",
66-
"Programming Language :: Python :: 3.5",
67-
"Programming Language :: Python :: 3.6",
68-
],
69-
packages=["neo4j", "neo4j.bolt", "neo4j.compat", "neo4j.packstream", "neo4j.v1"],
70-
ext_modules=ext_modules)
81+
try:
82+
setup(**setup_args)
83+
except SystemExit:
84+
print("Compilation failed, falling back to pure Python.")
85+
del setup_args["ext_modules"]
86+
setup(**setup_args)

0 commit comments

Comments
 (0)