Skip to content

Commit

Permalink
Merge pull request #28 from remyroy/reworked-setuptools-build
Browse files Browse the repository at this point in the history
Reworked setuptools and add github build process
  • Loading branch information
valefar-on-discord authored May 1, 2024
2 parents 8a45ca8 + 04ab4f6 commit 0315d9a
Show file tree
Hide file tree
Showing 14 changed files with 169 additions and 55 deletions.
108 changes: 108 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: ci-build
run-name: ${{ github.actor }} is running ci-build
on: [workflow_dispatch]
jobs:
ci-build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-12, macos-latest, windows-latest]
python-version: ["3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Setup variables (Linux & macOS)
if: ${{ startsWith(matrix.os, 'ubuntu-') || startsWith(matrix.os, 'macos-') }}
run: |
echo "PYTHONHASHSEED=42" >> "$GITHUB_ENV"
export SHORT_SHA=$(eval echo ${{ github.sha }} | cut -c -7)
echo "SHORT_SHA=${SHORT_SHA}" >> "$GITHUB_ENV"
- name: Setup variables (Windows)
if: ${{ startsWith(matrix.os, 'windows-') }}
run: |
echo "PYTHONHASHSEED=42" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
$env:SHORT_SHA = "${{ github.sha }}".Substring(0, 7)
echo ("SHORT_SHA=" + $env:SHORT_SHA) | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Install Linux build dependencies
if: ${{ startsWith(matrix.os, 'ubuntu-') }}
run: |
python -m pip install --upgrade pip
pip install -r build_configs/linux/requirements.txt
- name: Install macOS build dependencies
if: ${{ startsWith(matrix.os, 'macos-') }}
run: |
python -m pip install --upgrade pip
pip install -r build_configs/linux/requirements.txt
- name: Install Windows build dependencies
if: ${{ startsWith(matrix.os, 'windows-') }}
run: |
python -m pip install --upgrade pip
pip install -r build_configs/windows/requirements.txt
- name: Build with build.spec (Linux amd64)
if: ${{ startsWith(matrix.os, 'ubuntu-') }}
run: |
export BUILD_FILE_NAME=staking_deposit-cli-${SHORT_SHA}-linux-amd64
echo "BUILD_FILE_NAME=${BUILD_FILE_NAME}" >> "$GITHUB_ENV"
mkdir ${BUILD_FILE_NAME}
pyinstaller --distpath ./${BUILD_FILE_NAME} ./build_configs/linux/build.spec
- name: Build with build.spec (macOS amd64)
if: ${{ matrix.os == 'macos-12' }}
run: |
export BUILD_FILE_NAME=staking_deposit-cli-${SHORT_SHA}-darwin-amd64
echo "BUILD_FILE_NAME=${BUILD_FILE_NAME}" >> "$GITHUB_ENV"
mkdir ${BUILD_FILE_NAME}
pyinstaller --distpath ./${BUILD_FILE_NAME} ./build_configs/macos/build.spec
- name: Build with build.spec (macOS arm64)
if: ${{ matrix.os == 'macos-latest' }}
run: |
export BUILD_FILE_NAME=staking_deposit-cli-${SHORT_SHA}-darwin-arm64
echo "BUILD_FILE_NAME=${BUILD_FILE_NAME}" >> "$GITHUB_ENV"
mkdir ${BUILD_FILE_NAME}
pyinstaller --distpath ./${BUILD_FILE_NAME} ./build_configs/macos/build.spec
- name: Build with build.spec (Windows amd64)
if: ${{ startsWith(matrix.os, 'windows-') }}
run: |
$env:BUILD_FILE_NAME = ("staking_deposit-cli-" + $env:SHORT_SHA + "-windows-amd64")
echo ("BUILD_FILE_NAME=" + $env:BUILD_FILE_NAME) | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
mkdir $env:BUILD_FILE_NAME
$env:BUILD_FILE_NAME_PATH = (".\" + $env:BUILD_FILE_NAME)
echo ("BUILD_FILE_NAME_PATH=" + $env:BUILD_FILE_NAME_PATH) | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
pyinstaller --distpath $env:BUILD_FILE_NAME .\build_configs\windows\build.spec
- name: Install coreutils (macOS)
if: ${{ startsWith(matrix.os, 'macos-') }}
run: |
brew install coreutils
- name: Compress the file (Linux & macOS)
if: ${{ startsWith(matrix.os, 'ubuntu-') || startsWith(matrix.os, 'macos-') }}
run: |
tar -zcvf ${BUILD_FILE_NAME}.tar.gz ./${BUILD_FILE_NAME}
mkdir -p output/artifacts
cp ${BUILD_FILE_NAME}.tar.gz output/artifacts
sha256sum ${BUILD_FILE_NAME}.tar.gz | head -c 64 > output/artifacts/${BUILD_FILE_NAME}.sha256
- name: Compress the file (Windows)
if: ${{ startsWith(matrix.os, 'windows-') }}
run: |
$env:ZIP_FILE_NAME = ($env:BUILD_FILE_NAME + ".zip")
echo ("ZIP_FILE_NAME=" + $env:ZIP_FILE_NAME) | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
Compress-Archive -Path $env:BUILD_FILE_NAME_PATH -DestinationPath $env:ZIP_FILE_NAME
mkdir output\artifacts
copy $env:ZIP_FILE_NAME output\artifacts
$env:CHECKSUM_FILE_NAME_PATH = ("output\artifacts\" + $env:BUILD_FILE_NAME + ".sha256")
certUtil -hashfile $env:ZIP_FILE_NAME SHA256 | findstr /i /v "SHA256" | findstr /i /v "CertUtil" > $env:CHECKSUM_FILE_NAME_PATH
- name: Archive production artifacts (Linux & macOS)
if: ${{ startsWith(matrix.os, 'ubuntu-') || startsWith(matrix.os, 'macos-') }}
uses: actions/upload-artifact@v4
with:
name: binary-${{ matrix.os }}-${{ github.sha }}-${{ github.run_id }}
path: output/artifacts
- name: Archive production artifacts (Windows)
if: ${{ startsWith(matrix.os, 'windows-') }}
uses: actions/upload-artifact@v4
with:
name: binary-${{ matrix.os }}-${{ github.sha }}-${{ github.run_id }}
path: output\artifacts
2 changes: 1 addition & 1 deletion .github/workflows/runner.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: ci-runner
run-name: ${{ github.actor }} is running ci
run-name: ${{ github.actor }} is running ci-runner
on: [push, pull_request]
jobs:
ci-runner:
Expand Down
6 changes: 2 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@ FROM python:alpine3.19

WORKDIR /app

COPY requirements.txt setup.py ./
COPY requirements.txt ./

COPY staking_deposit ./staking_deposit

RUN apk add --update gcc libc-dev linux-headers

RUN pip3 install -r requirements.txt

RUN python3 setup.py install

ARG cli_command

ENTRYPOINT [ "python3", "./staking_deposit/deposit.py" ]
ENTRYPOINT [ "python3", "-m", "staking_deposit" ]

CMD [ $cli_command ]
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ $(VENV_NAME)/bin/activate: requirements.txt
@test -d $(VENV_NAME) || python3 -m venv --clear $(VENV_NAME)
${VENV_NAME}/bin/python -m pip install -r requirements.txt
${VENV_NAME}/bin/python -m pip install -r requirements_test.txt
${VENV_NAME}/bin/python setup.py install
@touch $(VENV_NAME)/bin/activate

venv_build: $(VENV_NAME)/bin/activate
Expand All @@ -41,7 +40,7 @@ venv_lint: venv_build_test
$(VENV_ACTIVATE) && flake8 --config=flake8.ini ./staking_deposit ./tests && mypy --config-file mypy.ini -p staking_deposit

venv_deposit: venv_build
$(VENV_ACTIVATE) && python ./staking_deposit/deposit.py $(filter-out $@,$(MAKECMDGOALS))
$(VENV_ACTIVATE) && python -m staking_deposit $(filter-out $@,$(MAKECMDGOALS))

build_macos: venv_build
${VENV_NAME}/bin/python -m pip install -r ./build_configs/macos/requirements.txt
Expand Down
29 changes: 15 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ Install the dependencies:

```sh
pip3 install -r requirements.txt
python3 setup.py install
```

Or use the helper script:
Expand Down Expand Up @@ -283,7 +282,6 @@ source venv/bin/activate
and install the dependencies:

```sh
python3 setup.py install
pip3 install -r requirements.txt
```

Expand All @@ -292,23 +290,23 @@ pip3 install -r requirements.txt
Run one of the following command to enter the interactive CLI:

```sh
python3 ./staking_deposit/deposit.py new-mnemonic
python3 -m staking_deposit new-mnemonic
```

or

```sh
python3 ./staking_deposit/deposit.py existing-mnemonic
python3 -m staking_deposit existing-mnemonic
```

You can also run the tool with optional arguments:

```sh
python3 ./staking_deposit/deposit.py new-mnemonic --num_validators=<NUM_VALIDATORS> --mnemonic_language=english --chain=<CHAIN_NAME> --folder=<YOUR_FOLDER_PATH>
python3 -m staking_deposit new-mnemonic --num_validators=<NUM_VALIDATORS> --mnemonic_language=english --chain=<CHAIN_NAME> --folder=<YOUR_FOLDER_PATH>
```

```sh
python3 ./staking_deposit/deposit.py existing-mnemonic --num_validators=<NUM_VALIDATORS> --validator_start_index=<START_INDEX> --chain=<CHAIN_NAME> --folder=<YOUR_FOLDER_PATH>
python3 -m staking_deposit existing-mnemonic --num_validators=<NUM_VALIDATORS> --validator_start_index=<START_INDEX> --chain=<CHAIN_NAME> --folder=<YOUR_FOLDER_PATH>
```

###### Language Argument
Expand Down Expand Up @@ -425,7 +423,6 @@ Install the dependencies:

```sh
pip3 install -r requirements.txt
python setup.py install
```

Or use the helper script:
Expand Down Expand Up @@ -495,7 +492,6 @@ virtualenv venv
and install the dependencies:

```cmd
python setup.py install
pip3 install -r requirements.txt
```

Expand All @@ -504,23 +500,23 @@ pip3 install -r requirements.txt
Run one of the following command to enter the interactive CLI:

```cmd
python .\staking_deposit\deposit.py new-mnemonic
python -m staking_deposit new-mnemonic
```

or

```cmd
python .\staking_deposit\deposit.py existing-mnemonic
python -m staking_deposit existing-mnemonic
```

You can also run the tool with optional arguments:

```cmd
python .\staking_deposit\deposit.py new-mnemonic --num_validators=<NUM_VALIDATORS> --mnemonic_language=english --chain=<CHAIN_NAME> --folder=<YOUR_FOLDER_PATH>
python -m staking_deposit new-mnemonic --num_validators=<NUM_VALIDATORS> --mnemonic_language=english --chain=<CHAIN_NAME> --folder=<YOUR_FOLDER_PATH>
```

```cmd
python .\staking_deposit\deposit.pyexisting-mnemonic --num_validators=<NUM_VALIDATORS> --validator_start_index=<START_INDEX> --chain=<CHAIN_NAME> --folder=<YOUR_FOLDER_PATH>
python -m staking_deposit existing-mnemonic --num_validators=<NUM_VALIDATORS> --validator_start_index=<START_INDEX> --chain=<CHAIN_NAME> --folder=<YOUR_FOLDER_PATH>
```

###### Language Argument
Expand All @@ -543,7 +539,6 @@ See [here](#generate-bls-to-execution-change-arguments) for `generate-bls-to-exe

```sh
python3 -m pip install -r requirements.txt
python3 setup.py install
```

### Install testing requirements
Expand All @@ -555,7 +550,13 @@ python3 -m pip install -r requirements_test.txt
### Run tests

```sh
python3 -m pytest .
python3 -m pytest tests
```

### Run the app

```sh
python3 -m staking_deposit [OPTIONS] COMMAND [ARGS]
```

### Building Binaries
Expand Down
3 changes: 3 additions & 0 deletions build_configs/common/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,6 @@ typing-extensions==4.9.0 \
packaging==23.2 \
--hash=sha256:048fb0e9405036518eaaf48a55953c750c11e1a1b68e0dd1a9d62ed0c092cfc5 \
--hash=sha256:8c491190033a9af7e1d931d0b5dacc2ef47509b34dd0de67ed209b5203fc88c7
setuptools==69.5.1 \
--hash=sha256:6c1fccdac05a97e598fb0ae3bbed5904ccb317337a51139dcd51453611bbb987 \
--hash=sha256:c636ac361bc47580504644275c9ad802c50415c7522212252c033bd15f301f32
13 changes: 9 additions & 4 deletions build_configs/linux/build.spec
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
# -*- mode: python ; coding: utf-8 -*-
from PyInstaller.utils.hooks import copy_metadata

datas = [
('../../staking_deposit/key_handling/key_derivation/word_lists/*.txt', './staking_deposit/key_handling/key_derivation/word_lists/'),
('../../staking_deposit/intl', './staking_deposit/intl'),
]
datas += copy_metadata('py_ecc')
datas += copy_metadata('ssz')

block_cipher = None


a = Analysis(['../../staking_deposit/deposit.py'],
binaries=[],
datas=[
('../../staking_deposit/key_handling/key_derivation/word_lists/*.txt', './staking_deposit/key_handling/key_derivation/word_lists/'),
('../../staking_deposit/intl', './staking_deposit/intl'),
],
datas=datas,
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
Expand Down
15 changes: 10 additions & 5 deletions build_configs/macos/build.spec
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
# -*- mode: python ; coding: utf-8 -*-
from PyInstaller.utils.hooks import copy_metadata

datas = [
('../../staking_deposit/key_handling/key_derivation/word_lists/*.txt', './staking_deposit/key_handling/key_derivation/word_lists/'),
('../../staking_deposit/intl', './staking_deposit/intl'),
]
datas += copy_metadata('py_ecc')
datas += copy_metadata('ssz')

block_cipher = None


a = Analysis(['../../staking_deposit/deposit.py'],
binaries=None,
datas=[
('../../staking_deposit/key_handling/key_derivation/word_lists/*.txt', './staking_deposit/key_handling/key_derivation/word_lists/'),
('../../staking_deposit/intl', './staking_deposit/intl'),
],
binaries=[],
datas=datas,
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
Expand Down
13 changes: 9 additions & 4 deletions build_configs/windows/build.spec
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
# -*- mode: python ; coding: utf-8 -*-
from PyInstaller.utils.hooks import copy_metadata

datas = [
('..\\..\\staking_deposit\\key_handling\\key_derivation\\word_lists\\*.txt', '.\\staking_deposit\\key_handling\\key_derivation\\word_lists'),
('..\\..\\staking_deposit\\intl', '.\\staking_deposit\\intl'),
]
datas += copy_metadata('py_ecc')
datas += copy_metadata('ssz')

block_cipher = None


a = Analysis(['..\\..\\staking_deposit\\deposit.py'],
binaries=[],
datas=[
('..\\..\\staking_deposit\\key_handling\\key_derivation\\word_lists\\*.txt', '.\\staking_deposit\\key_handling\\key_derivation\\word_lists'),
('..\\..\\staking_deposit\\intl', '.\\staking_deposit\\intl'),
],
datas=datas,
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
Expand Down
6 changes: 2 additions & 4 deletions deposit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,20 @@ if [[ "$OSTYPE" == "linux"* ]] || [[ "$OSTYPE" == "linux-android"* ]] || [[ "$OS
if [[ $1 == "install" ]]; then
echo "Installing dependencies..."
pip3 install -r requirements.txt
python3 setup.py install
exit 1
fi
echo "Running deposit-cli..."
python3 ./staking_deposit/deposit.py "$@"
python3 -m staking_deposit "$@"

elif [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "cygwin" ]]; then
echo $OSTYPE
if [[ $1 == "install" ]]; then
echo "Installing dependencies..."
pip install -r requirements.txt
python setup.py install
exit 1
fi
echo "Running deposit-cli..."
python ./staking_deposit/deposit.py "$@"
python -m staking_deposit "$@"

else
echo "Sorry, to run deposit-cli on" $(uname -s)", please see the trouble-shooting on https://github.com/ethereum/staking-deposit-cli"
Expand Down
3 changes: 0 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ eth-typing==4.1.0 \
eth-utils==4.1.0 \
--hash=sha256:c170168198ddecac1ea911f74937e9364de81dbd03f42450fe40725c4d6e6220 \
--hash=sha256:f2e0f617edc81e53fad0faca7f7b169e56bef59ecc530d919a7482640236a228
setuptools==69.5.1 \
--hash=sha256:6c1fccdac05a97e598fb0ae3bbed5904ccb317337a51139dcd51453611bbb987 \
--hash=sha256:c636ac361bc47580504644275c9ad802c50415c7522212252c033bd15f301f32

# Dependencies for the above
mypy-extensions==1.0.0 \
Expand Down
13 changes: 0 additions & 13 deletions setup.py

This file was deleted.

4 changes: 4 additions & 0 deletions staking_deposit/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from staking_deposit import deposit

if __name__ == "__main__":
deposit.run()
Loading

0 comments on commit 0315d9a

Please sign in to comment.