Skip to content

Commit ef5db9a

Browse files
committed
Define py-geth and geth versions in one place only:
- The ``py-geth`` version set in ``setup.py`` is the exact version extracted and used by the circleci setup. - The ``geth`` version that is set in the ``GETH_BINARY`` for fixture generation is the exact version used in the name of the ``.zip`` for the test fixture and is automatically updated in the circleci config for builds.
1 parent 2338b20 commit ef5db9a

File tree

6 files changed

+57
-21
lines changed

6 files changed

+57
-21
lines changed

.circleci/config.yml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
version: 2.1
22

33
parameters:
4+
# NOTE: Do not update the `geth_version` manually. It is updated during the
5+
# integration test fixture generation.
46
geth_version:
5-
# update default value when updating geth integration test fixture
6-
default: "v1.14.5"
7-
type: string
8-
pygeth_version:
9-
# update default value when updating geth integration test fixture
10-
default: "5.0.0b1"
7+
default: "1.14.5"
118
type: string
129
go_version:
1310
default: "1.22.4"
@@ -66,8 +63,8 @@ geth_steps: &geth_steps
6663
command: |
6764
if [ "<< pipeline.parameters.geth_version >>" != "custom" ]; then
6865
export GOROOT=/usr/local/go
69-
export GETH_BINARY="$HOME/.py-geth/geth-<< pipeline.parameters.geth_version >>/bin/geth"
70-
echo "configured geth version: << pipeline.parameters.geth_version >>"
66+
export GETH_BINARY="$HOME/.py-geth/geth-v<< pipeline.parameters.geth_version >>/bin/geth"
67+
echo "configured geth version: v<< pipeline.parameters.geth_version >>"
7168
if [ ! -e "$GETH_BINARY" ]; then
7269
echo "GETH_BINARY not set, installing geth..."
7370
curl -O https://storage.googleapis.com/golang/go<< pipeline.parameters.go_version >>.linux-amd64.tar.gz
@@ -77,10 +74,12 @@ geth_steps: &geth_steps
7774
sudo ln -s /usr/local/go/bin/go /usr/local/bin/go
7875
sudo apt-get update
7976
sudo apt-get install -y build-essential
80-
pip install --user "py-geth>=<< pipeline.parameters.pygeth_version >>"
81-
python -m geth.install << pipeline.parameters.geth_version >>
77+
pygeth_version=$(python web3/scripts/parse_pygeth_version.py)
78+
echo "installing py-geth$pygeth_version"
79+
pip install --user "py-geth$pygeth_version"
80+
python -m geth.install v<< pipeline.parameters.geth_version >>
8281
fi
83-
sudo ln -s /home/circleci/.py-geth/geth-<< pipeline.parameters.geth_version >>/bin/geth /usr/local/bin/geth
82+
sudo ln -s /home/circleci/.py-geth/geth-v<< pipeline.parameters.geth_version >>/bin/geth /usr/local/bin/geth
8483
else
8584
export GOROOT=/usr/local/go
8685
export GETH_BINARY="./custom_geth"

docs/contributing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ Geth Fixtures
379379

380380
.. code:: sh
381381
382-
$ GETH_BINARY=~/.py-geth/geth-v1.14.5/bin/geth python ./tests/integration/generate_fixtures/go_ethereum.py ./tests/integration/geth-1.14.5-fixture
382+
$ GETH_BINARY=~/.py-geth/geth-v1.14.5/bin/geth python ./tests/integration/generate_fixtures/go_ethereum.py
383383
384384
3. The output of this script is your fixture, a zip file, which is now stored in ``/tests/integration/``.
385385
Update the ``/tests/integration/go_ethereum/conftest.py`` and

setup.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626
"sphinx-autobuild>=2021.3.14",
2727
"sphinx_rtd_theme>=1.0.0",
2828
"towncrier>=21,<22",
29-
# web3 will work but emit warnings with eth-account>=0.12.2,
30-
# but doctests fail between 0.12.2 and 0.13.0
31-
"eth-account>=0.13.0",
3229
],
3330
"test": [
3431
"eth-tester[py-evm]>=0.11.0b1,<0.13.0b1",

tests/core/test_library_files.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111

1212
def test_no_default_exceptions_are_raised_within_web3py():
1313
for root, dirs, files in os.walk(WEB3_PATH):
14-
if "module_testing" in dirs:
15-
dirs.remove("module_testing")
16-
continue
14+
[dirs.remove(dir_) for dir_ in dirs if dir_ in ("scripts", "module_testing")]
1715
for file in files:
1816
if file.endswith(".py"):
1917
file_path = os.path.join(root, file)

tests/integration/generate_fixtures/go_ethereum.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
import json
33
import os
44
import pprint
5+
import re
56
import shutil
67
import socket
78
import subprocess
8-
import sys
99
import time
1010

1111
import common
@@ -361,6 +361,32 @@ def setup_chain_state(w3):
361361
return geth_fixture
362362

363363

364+
def update_circleci_geth_version(new_version):
365+
file_path = "./.circleci/config.yml"
366+
with open(file_path) as file:
367+
lines = file.readlines()
368+
369+
replaced = False
370+
for i, line in enumerate(lines):
371+
if "geth_version:" in line:
372+
if "default:" in lines[i + 1]:
373+
lines[i + 1] = f' default: "{new_version}"\n'
374+
replaced = True
375+
break
376+
377+
if not replaced:
378+
raise ValueError("`geth_version` for circleci not found / replaced.")
379+
380+
with open(file_path, "w") as file:
381+
file.writelines(lines)
382+
print(f"Updated geth_version to {new_version}")
383+
384+
364385
if __name__ == "__main__":
365-
fixture_dir = sys.argv[1]
366-
generate_go_ethereum_fixture(fixture_dir)
386+
geth_binary = os.environ.get("GETH_BINARY", None)
387+
if not geth_binary:
388+
raise ValueError("GETH_BINARY not set. Cannot generate geth fixture.")
389+
390+
geth_version = re.search(r"geth-v([\d.]+)/", geth_binary).group(1)
391+
generate_go_ethereum_fixture(f"./tests/integration/geth-{geth_version}-fixture")
392+
update_circleci_geth_version(geth_version)

web3/scripts/parse_pygeth_version.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import re
2+
3+
4+
def get_pygeth_version() -> str:
5+
with open("setup.py") as f:
6+
setup_contents = f.read()
7+
version_match = re.search(r"py-geth\s*([><=~!]+)\s*([\d.]+)", setup_contents)
8+
if version_match:
9+
return "".join(version_match.group(1, 2))
10+
else:
11+
raise ValueError("py-geth not found in setup.py")
12+
13+
14+
if __name__ == "__main__":
15+
version = get_pygeth_version()
16+
print(version)

0 commit comments

Comments
 (0)