Skip to content

Commit 0a1d752

Browse files
committed
Modernize packaging
* Introducing `pyproject.toml` https://peps.python.org/pep-0621/ * Migrate from flat-layout to src-layout * Deprecate legacy package name `neo4j-driver` in favor of `neo4j` + warn about it
1 parent 29f9415 commit 0a1d752

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+261
-143
lines changed

.coveragerc

-19
This file was deleted.

.pre-commit-config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ repos:
3333
name: unasync
3434
entry: bin/make-unasync
3535
language: system
36-
files: "^(neo4j/_async|tests/(unit|integration)/async_|testkitbackend/_async)/.*"
36+
files: "^(src/neo4j/_async|tests/(unit|integration)/async_|testkitbackend/_async)/.*"
3737
- id: mypy
3838
name: mypy static type check
3939
entry: mypy
40-
args: [ --show-error-codes, neo4j, tests, testkitbackend ]
40+
args: [ --show-error-codes, src, tests, testkitbackend ]
4141
'types_or': [ python, pyi ]
4242
language: system
4343
pass_filenames: false

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Remember that many community members have become regular contributors and some a
5454
## Specifically for this project:
5555

5656
All code in `_sync` or `sync` folders is auto-generated. Don't change it, but
57-
install the pre-commit hooks as described below insted. They will take care of
57+
install the pre-commit hooks as described below instead. They will take care of
5858
updating the code if necessary.
5959

6060
Setting up the development environment:

MANIFEST.in

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
global-exclude *.class *.pyc *.pyo *.so *.dll __pycache__
2-
prune tests
1+
include NOTICE* src/**/py.typed
2+
global-exclude *.class *.py[cod] *.so *.dll __pycache__
3+
prune test*

README.rst

+8
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ To install the latest stable version, use:
3232
pip install neo4j
3333
3434
35+
.. TODO: 7.0 - remove this note
36+
37+
.. note::
38+
39+
`neo4j-driver` is the old name for this package. It is now deprecated and
40+
and will receive no further updates starting with 6.0.0.
41+
42+
3543
Quick Example
3644
=============
3745

bin/dist-functions

+39-17
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,41 @@
22
set -e
33

44
ROOT=$(dirname "$0")/..
5+
SRC="${ROOT}/src"
56
DIST="${ROOT}/dist"
67

78
function get_package
89
{
10+
cd "${SRC}"
911
python -c "from neo4j._meta import package; print(package)"
12+
cd - > /dev/null
1013
}
1114

1215
function set_package
1316
{
14-
sed -i 's/^package = .*/package = "'$1'"/g' neo4j/_meta.py
17+
sed -i 's/^package = .*/package = "'$1'"/g' "${SRC}/neo4j/_meta.py"
1518
}
1619

1720
function get_version
1821
{
22+
cd "${SRC}"
1923
python -c "from neo4j._meta import version; print(version)"
24+
cd - > /dev/null
2025
}
2126

2227
function set_version
2328
{
24-
sed -i 's/^version = .*/version = "'$1'"/g' neo4j/_meta.py
29+
sed -i 's/^version = .*/version = "'$1'"/g' "${SRC}/neo4j/_meta.py"
30+
}
31+
32+
function get_deprecated {
33+
cd "${SRC}"
34+
python -c "from neo4j._meta import deprecated_package; print(deprecated_package)"
35+
cd - > /dev/null
36+
}
37+
38+
function set_deprecated {
39+
sed -i 's/^deprecated_package = .*/deprecated_package = '$1'/g' "${SRC}/neo4j/_meta.py"
2540
}
2641

2742
function check_file
@@ -40,54 +55,61 @@ function check_file
4055
function set_metadata_and_setup
4156
{
4257
PACKAGE="$1"; shift
58+
DEPRECATED="$1"; shift
4359
VERSION="$1"; shift
4460

45-
cd ${ROOT}
61+
cd "${ROOT}"
4662

4763
# Capture original package metadata
4864
ORIGINAL_PACKAGE=$(get_package)
4965
ORIGINAL_VERSION=$(get_version)
50-
echo "Source code originally configured for package ${ORIGINAL_PACKAGE}/${ORIGINAL_VERSION}"
66+
ORIGINAL_DEPRECATED=$(get_deprecated)
67+
echo "Source code originally configured for package ${ORIGINAL_PACKAGE}/${ORIGINAL_VERSION}/deprecated=${ORIGINAL_DEPRECATED}"
5168
echo "----------------------------------------"
52-
grep "package\s\+=" neo4j/_meta.py
53-
grep "version\s\+=" neo4j/_meta.py
69+
grep "package\s\+=" "${SRC}/neo4j/_meta.py"
70+
grep "version\s\+=" "${SRC}/neo4j/_meta.py"
71+
grep "deprecated_package\s\+=" "${SRC}/neo4j/_meta.py"
5472
echo "----------------------------------------"
5573

5674
function cleanup() {
5775
# Reset to original package metadata
5876
set_package "${ORIGINAL_PACKAGE}"
5977
set_version "${ORIGINAL_VERSION}"
60-
echo "Source code reconfigured back to original package ${ORIGINAL_PACKAGE}/${ORIGINAL_VERSION}"
78+
set_deprecated "${ORIGINAL_DEPRECATED}"
79+
echo "Source code reconfigured back to original package ${ORIGINAL_PACKAGE}/${ORIGINAL_VERSION}/deprecated=${ORIGINAL_DEPRECATED}"
6180
echo "----------------------------------------"
62-
grep "package\s\+=" neo4j/_meta.py
63-
grep "version\s\+=" neo4j/_meta.py
81+
grep "package\s\+=" "${SRC}/neo4j/_meta.py"
82+
grep "version\s\+=" "${SRC}/neo4j/_meta.py"
83+
grep "deprecated_package\s\+=" "${SRC}/neo4j/_meta.py"
6484
echo "----------------------------------------"
6585
}
6686
trap cleanup EXIT
6787

6888
# Temporarily override package metadata
6989
set_package "${PACKAGE}"
7090
set_version "${VERSION}"
71-
echo "Source code reconfigured for package ${PACKAGE}/${VERSION}"
91+
set_deprecated "${DEPRECATED}"
92+
echo "Source code reconfigured for package ${PACKAGE}/${VERSION}/deprecated=${DEPRECATED}"
7293
echo "----------------------------------------"
73-
grep "package\s\+=" neo4j/_meta.py
74-
grep "version\s\+=" neo4j/_meta.py
94+
grep "package\s\+=" "${SRC}/neo4j/_meta.py"
95+
grep "version\s\+=" "${SRC}/neo4j/_meta.py"
96+
grep "deprecated_package\s\+=" "${SRC}/neo4j/_meta.py"
7597
echo "----------------------------------------"
7698

7799
# Create source distribution
78100
find . -name *.pyc -delete
79-
rm -rf ${ROOT}/*.egg-info 2> /dev/null
101+
rm -rf "${SRC}/*.egg-info" 2> /dev/null
80102
python setup.py $*
81103
check_file "${DIST}/${PACKAGE}-${VERSION}.tar.gz"
82104

83-
trap - EXIT
84-
cleanup
105+
trap - EXIT
106+
cleanup
85107
}
86108

87109
function setup
88110
{
89111
ARGS="$*"
90112
rm -rf ${DIST} 2> /dev/null
91-
set_metadata_and_setup "neo4j-driver" ${ARGS} # Legacy package; can be removed in 2.0
92-
set_metadata_and_setup "neo4j" ${ARGS}
113+
set_metadata_and_setup "neo4j-driver" "True" ${ARGS} # Legacy package; can be removed in 2.0
114+
set_metadata_and_setup "neo4j" "False" ${ARGS}
93115
}

bin/make-unasync

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ import unasync
3232

3333

3434
ROOT_DIR = Path(__file__).parents[1].absolute()
35-
ASYNC_DIR = ROOT_DIR / "neo4j" / "_async"
36-
SYNC_DIR = ROOT_DIR / "neo4j" / "_sync"
35+
ASYNC_DIR = ROOT_DIR / "src" / "neo4j" / "_async"
36+
SYNC_DIR = ROOT_DIR / "src" / "neo4j" / "_sync"
3737
ASYNC_UNIT_TEST_DIR = ROOT_DIR / "tests" / "unit" / "async_"
3838
SYNC_UNIT_TEST_DIR = ROOT_DIR / "tests" / "unit" / "sync"
3939
ASYNC_INTEGRATION_TEST_DIR = ROOT_DIR / "tests" / "integration" / "async_"

pyproject.toml

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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+
[project]
19+
name = "neo4j"
20+
description = "Neo4j Bolt driver for Python"
21+
license = {text = "Apache License, Version 2.0"}
22+
#TODO: 6.0 - static readme
23+
#readme = "README.rst"
24+
authors = [
25+
{name = "Neo4j, Inc.", email = "[email protected]"},
26+
]
27+
dependencies = ["pytz"]
28+
requires-python = ">=3.7"
29+
keywords = ["neo4j", "graph", "database"]
30+
classifiers = [
31+
"Intended Audience :: Developers",
32+
"License :: OSI Approved :: Apache Software License",
33+
"Operating System :: OS Independent",
34+
"Topic :: Database",
35+
"Topic :: Software Development",
36+
"Programming Language :: Python :: 3.7",
37+
"Programming Language :: Python :: 3.8",
38+
"Programming Language :: Python :: 3.9",
39+
"Programming Language :: Python :: 3.10",
40+
"Programming Language :: Python :: 3.11",
41+
]
42+
dynamic = ["version", "readme"]
43+
44+
[project.urls]
45+
Homepage = "https://github.com/neo4j/neo4j-python-driver"
46+
47+
[project.optional-dependencies]
48+
pandas = ["pandas>=1.0.0"]
49+
50+
[build-system]
51+
requires = ["setuptools~=65.6", "tomlkit~=0.11.6"]
52+
build-backend = "setuptools.build_meta"
53+
54+
# still in beta
55+
#[tool.setuptools.dynamic]
56+
#version = {attr = "neo4j._meta.version"}
57+
58+
59+
[tool.coverage]
60+
show_missing = true
61+
62+
[tool.coverage.run]
63+
branch = true
64+
omit = [
65+
".*/*",
66+
"tests/*",
67+
"src/neo4j/meta.py",
68+
"*virtualenv*",
69+
"*venv*",
70+
]
71+
72+
[tool.coverage.report]
73+
exclude_lines = [
74+
"pragma: no cover",
75+
"def __repr__",
76+
"if self.debug:",
77+
"raise NotImplementedError",
78+
"if __name__ == .__main__.:",
79+
"except ImportError",
80+
]
81+
82+
83+
[tool.isort]
84+
combine_as_imports = true
85+
ensure_newline_before_comments = true
86+
force_grid_wrap = 2
87+
# breaks order of relative imports
88+
# https://github.com/PyCQA/isort/issues/1944
89+
#force_sort_within_sections = true
90+
include_trailing_comma = true
91+
# currently broken
92+
# https://github.com/PyCQA/isort/issues/1855
93+
#lines_before_imports = 2
94+
lines_after_imports = 2
95+
lines_between_sections = 1
96+
multi_line_output = 3
97+
order_by_type = false
98+
remove_redundant_aliases = true
99+
use_parentheses = true
100+
101+
102+
[tool.pytest.ini_options]
103+
mock_use_standalone_module = true
104+
asyncio_mode = "auto"
105+
106+
107+
[tool.mypy]
108+
109+
[[tool.mypy.overrides]]
110+
module = "pandas.*"
111+
ignore_missing_imports = true

requirements-dev.txt

+20-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
1+
# the driver itself
2+
-e .
3+
14
# auto-generate sync driver from async code
25
unasync>=0.5.0
6+
# pre-commit hooks and tools
37
pre-commit>=2.15.0
48
isort>=5.10.0
59
mypy>=0.971
610
typing-extensions>=4.3.0
711
types-pytz>=2022.1.2
812

9-
# needed for running tests
10-
-r tests/requirements.txt
13+
# for packaging
14+
setuptools~=65.6
15+
# TODO: 6.0 - can be removed once `setup.py` is simplified
16+
tomlkit~=0.11.6
1117

12-
# production dependencies
13-
-r requirements.txt
18+
# needed for running tests
19+
coverage[toml]>=5.5
20+
mock>=4.0.3
21+
pandas>=1.0.0
22+
pytest>=6.2.5
23+
pytest-asyncio>=0.16.0
24+
pytest-benchmark>=3.4.1
25+
pytest-cov>=3.0.0
26+
pytest-mock>=3.6.1
27+
teamcity-messages>=1.29
28+
tox>=3.27.1
29+
tox-factor>=0.1.2

setup.cfg

-26
This file was deleted.

0 commit comments

Comments
 (0)