Skip to content

Commit 015e7d0

Browse files
committed
Sandbox: Reduce footprint of Buildout
- The sandbox setup is now based on vanilla Python and virtualenv. - A convenient bootstrap script is provided, which can be used like `source bootstrap.sh`. - The test runner has not been changed, it is still `zope.testrunner`. - The command line invocation interface `./bin/test` has not been changed. - Buildout is now only used for downloading the CrateDB tarball using `hexagonit.recipe.download`. References: - #428 - crate-workbench/test-buildout-python310#1
1 parent 6930e52 commit 015e7d0

File tree

14 files changed

+180
-170
lines changed

14 files changed

+180
-170
lines changed

.github/workflows/nightly.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ jobs:
2828
with:
2929
python-version: ${{ matrix.python-version }}
3030

31-
- name: Install dependencies
31+
- name: Propagate matrix information
3232
run: |
33+
source bootstrap.sh
3334
./devtools/setup_ci.sh --cratedb-version=${{ matrix.cratedb-version }} --sqlalchemy-version=${{ matrix.sqla-version }}
3435
3536
- name: Invoke tests
3637
run: |
37-
bin/flake8
38-
bin/coverage run bin/test -vv1
38+
source bootstrap.sh
39+
flake8 src bin
40+
coverage run bin/test -vv1

.github/workflows/tests.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,17 @@ jobs:
3535
brew install gnu-getopt
3636
echo "/usr/local/opt/gnu-getopt/bin" >> $GITHUB_PATH
3737
38-
- name: Install dependencies
38+
- name: Propagate matrix information
3939
run: |
40+
source bootstrap.sh
4041
./devtools/setup_ci.sh --cratedb-version=${{ matrix.cratedb-version }} --sqlalchemy-version=${{ matrix.sqla-version }}
4142
4243
- name: Invoke tests
4344
run: |
44-
bin/flake8
45-
bin/coverage run bin/test -vv1
46-
bin/coverage xml
45+
source bootstrap.sh
46+
flake8 src bin
47+
coverage run bin/test -vv1
48+
coverage xml
4749
4850
# https://github.com/codecov/codecov-action
4951
- name: Upload coverage results to Codecov

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ coverage.xml
66
.tox/
77
*.DS_Store
88
*.pyc
9-
bin/
9+
bin/*
10+
!bin/test
11+
!bin/sphinx
1012
build/
1113
crate-python.iml
1214
crate.egg-info

DEVELOP.rst

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,22 @@ Developer guide
55
Setup
66
=====
77

8-
This project uses buildout_ to set up the development environment.
8+
To start things off, bootstrap the sandbox environment::
99

10-
To start things off, create a Python virtualenv and install buildout::
10+
source bootstrap.sh
1111

12-
python3 -m venv .venv
13-
source .venv/bin/activate
12+
This command should automatically install all prerequisites for the development
13+
sandbox and drop you into the virtualenv, ready for invoking further commands.
1414

15-
# Workaround for Python 3.5
16-
python -m pip install --upgrade "setuptools>=31,<51"
17-
18-
pip install zc.buildout==2.13.4
19-
20-
Then, run::
21-
22-
buildout -N
2315

2416
Running tests
2517
=============
2618

2719
All tests will be invoked using the Python interpreter that was used when
28-
creating the Python virtualenv. The test runner is zope.testrunner_.
20+
creating the Python virtualenv. The test runner is `zope.testrunner`_.
21+
22+
Some examples are outlined below. In order to learn about more details,
23+
see, for example, `useful command-line options for zope-testrunner`_.
2924

3025
Run all tests::
3126

@@ -41,18 +36,18 @@ Ignore specific test directories::
4136

4237
./bin/test -vvvv --ignore_dir=testing
4338

44-
You can run the tests against multiple Python interpreters with tox_::
39+
You can run the tests against multiple Python interpreters with `tox`_::
4540

46-
./bin/tox
41+
tox
4742

4843
To do this, you will need the respective Python interpreter versions available
4944
on your ``$PATH``.
5045

5146
To run against a single interpreter, you can also invoke::
5247

53-
./bin/tox -e py37
48+
tox -e py37
5449

55-
*Note*: before running the tests, make sure to stop all CrateDB instances which
50+
*Note*: Before running the tests, make sure to stop all CrateDB instances which
5651
are listening on the default CrateDB transport port to avoid side effects with
5752
the test layer.
5853

@@ -121,5 +116,6 @@ nothing special you need to do to get the live docs to update.
121116
.. _Sphinx: http://sphinx-doc.org/
122117
.. _tox: http://testrun.org/tox/latest/
123118
.. _twine: https://pypi.python.org/pypi/twine
124-
.. _zope.testrunner: https://pypi.python.org/pypi/zope.testrunner/4.4.1
119+
.. _useful command-line options for zope-testrunner: https://pypi.org/project/zope.testrunner/#some-useful-command-line-options-to-get-you-started
125120
.. _versions hosted on ReadTheDocs: https://readthedocs.org/projects/crate-python/versions/
121+
.. _zope.testrunner: https://pypi.org/project/zope.testrunner/

base.cfg

Lines changed: 0 additions & 49 deletions
This file was deleted.

bin/sphinx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env python
2+
import os
3+
import sys
4+
5+
join = os.path.join
6+
base = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
7+
base = os.path.dirname(base)
8+
9+
10+
sys.argv.extend(['-b', 'html', '-E', 'docs', './out/html'])
11+
import sphinx.cmd.build # noqa:E402
12+
13+
14+
if __name__ == '__main__':
15+
sys.exit(sphinx.cmd.build.main())

bin/test

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env python
2+
import os
3+
import sys
4+
import zope.testrunner
5+
6+
join = os.path.join
7+
base = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
8+
base = os.path.dirname(base)
9+
10+
11+
sys.argv[0] = os.path.abspath(sys.argv[0])
12+
13+
if __name__ == '__main__':
14+
sys.exit(zope.testrunner.run((['--auto-color', '--verbose']) + [
15+
'--test-path', join(base, 'src'),
16+
]))

bootstrap.sh

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/bin/bash
2+
#
3+
# Bootstrap sandbox environment for crate-python
4+
#
5+
# - Create a Python virtualenv
6+
# - Install all dependency packages and modules
7+
# - Install package in editable mode
8+
# - Drop user into an activated virtualenv
9+
#
10+
# Synopsis::
11+
#
12+
# source bootstrap.sh
13+
#
14+
15+
16+
# Trace all invocations.
17+
# set -x
18+
19+
20+
function print_header() {
21+
printf '=%.0s' {1..42}; echo
22+
echo "$1"
23+
printf '=%.0s' {1..42}; echo
24+
}
25+
26+
function ensure_virtualenv() {
27+
# Create a Python virtualenv with current version of Python 3.
28+
# TODO: Maybe take `pyenv` into account.
29+
if [[ ! -d .venv ]]; then
30+
python3 -m venv .venv
31+
fi
32+
}
33+
34+
function activate_virtualenv() {
35+
# Activate Python virtualenv.
36+
source .venv/bin/activate
37+
}
38+
39+
function before_setup() {
40+
41+
# When `wheel` is installed, Python will build `wheel` packages from all
42+
# acquired `sdist` packages and will store them into `~/.cache/pip`, where
43+
# they will be picked up by the caching machinery and will be reused on
44+
# subsequent invocations when run on CI. This makes a *significant*
45+
# difference on total runtime on CI, it is about 2x faster.
46+
#
47+
# Otherwise, there will be admonitions like:
48+
# Using legacy 'setup.py install' for foobar, since package 'wheel' is
49+
# not installed.
50+
#
51+
pip install wheel
52+
53+
BUILDOUT_VERSION=${BUILDOUT_VERSION:-2.13.7}
54+
pip install "zc.buildout==${BUILDOUT_VERSION}"
55+
56+
}
57+
58+
function setup_package() {
59+
60+
# Install package in editable mode.
61+
pip install --editable=.[sqlalchemy,test,doc]
62+
63+
}
64+
65+
function run_buildout() {
66+
buildout -N
67+
}
68+
69+
function finalize() {
70+
71+
# Some steps before dropping into the activated virtualenv.
72+
echo
73+
python -c 'import sqlalchemy; print(f"SQLAlchemy version: {sqlalchemy.__version__}")'
74+
75+
}
76+
77+
function main() {
78+
ensure_virtualenv
79+
activate_virtualenv
80+
before_setup
81+
setup_package
82+
run_buildout
83+
finalize
84+
}
85+
86+
function lint() {
87+
flake8
88+
}
89+
90+
main

buildout.cfg

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
[buildout]
2-
extends = base.cfg
3-
parts += tox
4-
sphinx
5-
scripts
2+
extends = versions.cfg
3+
versions = versions
4+
show-picked-versions = true
5+
parts = crate
66

7-
[scripts]
8-
recipe = zc.recipe.egg:script
9-
eggs = wheel
10-
docutils
11-
twine
7+
[crate:linux]
8+
recipe = hexagonit.recipe.download
9+
url = https://cdn.crate.io/downloads/releases/crate-${versions:crate_server}.tar.gz
10+
strip-top-level-dir = true
1211

13-
[tox]
14-
recipe = gp.recipe.tox
12+
[crate:macosx]
13+
recipe = hexagonit.recipe.download
14+
url = https://cdn.crate.io/downloads/releases/cratedb/x64_mac/crate-${versions:crate_server}.tar.gz
15+
strip-top-level-dir = true
1516

16-
[sphinx]
17-
recipe = zc.recipe.egg:script
18-
eggs = sphinx
19-
crate-docs-theme
20-
relative-paths=true
21-
scripts = sphinx-build=sphinx
22-
initialization =
23-
sys.argv.extend(['-N', '-q', '-b', 'html',
24-
'-E', 'docs', '${buildout:directory}/out/html'])
17+
[crate:windows]
18+
recipe = hexagonit.recipe.download
19+
url = https://cdn.crate.io/downloads/releases/cratedb/x64_windows/crate-${versions:crate_server}.zip
20+
strip-top-level-dir = true

devtools/create_tag.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ fi
4848

4949
# check if tag to create has already been created
5050
WORKING_DIR=`dirname $0`
51-
VERSION=`$WORKING_DIR/../bin/py setup.py --version`
51+
VERSION=`python setup.py --version`
5252
EXISTS=`git tag | grep $VERSION`
5353

5454
if [ "$VERSION" == "$EXISTS" ]

devtools/setup_ci.sh

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,17 @@ function main() {
4646
# Let's go.
4747
echo "Invoking tests with CrateDB ${cratedb_version} and SQLAlchemy ${sqlalchemy_version}"
4848

49-
python -m pip install --upgrade pip
50-
51-
pip install zc.buildout==2.13.4
52-
53-
# Replace SQLAlchemy version.
54-
sed -ir "s/SQLAlchemy.*/SQLAlchemy = ${sqlalchemy_version}/g" versions.cfg
49+
# Install designated SQLAlchemy version.
50+
pip install "sqlalchemy==${sqlalchemy_version}"
5551

5652
# Replace CrateDB version.
5753
if [ ${cratedb_version} = "nightly" ]; then
58-
sed -ir "s/releases/releases\/nightly/g" base.cfg
54+
sed -ir "s/releases/releases\/nightly/g" buildout.cfg
5955
sed -ir "s/crate_server.*/crate_server = latest/g" versions.cfg
6056
else
6157
sed -ir "s/crate_server.*/crate_server = ${cratedb_version}/g" versions.cfg
6258
fi
6359

64-
buildout -n -c base.cfg
65-
6660
}
6761

6862
main "$@"

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
universal = 1
33

44
[flake8]
5-
ignore = E501,C901, W504
5+
ignore = E501, C901, W504

setup.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,17 @@ def read(path):
6464
]
6565
},
6666
extras_require=dict(
67-
test=['zope.testing>=4,<5',
67+
sqlalchemy=['sqlalchemy>=1.0,<1.5',
68+
'geojson>=2.5.0'],
69+
test=['tox>=3,<4',
70+
'zope.testing>=4,<5',
71+
'zope.testrunner>=5,<6',
6872
'zc.customdoctests>=1.0.1,<2',
69-
'stopit>=1.1.2,<2'],
70-
sqlalchemy=['sqlalchemy>=1.0,<1.5', 'geojson>=2.5.0']
73+
'createcoverage>=1,<2',
74+
'stopit>=1.1.2,<2',
75+
'flake8>=4,<5'],
76+
doc=['sphinx>=3,<4',
77+
'crate-docs-theme'],
7178
),
7279
python_requires='>=3.4',
7380
install_requires=requirements,

0 commit comments

Comments
 (0)