Skip to content

Commit df74ace

Browse files
Merge pull request #517 from LedgerHQ/pypi
Eth client Python package only deployed on pypi.org
2 parents 1dc403f + 08077ff commit df74ace

File tree

5 files changed

+60
-57
lines changed

5 files changed

+60
-57
lines changed

.github/workflows/python-client.yml

Lines changed: 40 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ name: Python client checks, package build and deployment
44
on:
55
workflow_dispatch:
66
push:
7+
tags:
8+
- 'client-*'
79
branches:
810
- develop
911
- master
@@ -22,9 +24,9 @@ jobs:
2224
steps:
2325
- name: Clone
2426
uses: actions/checkout@v3
25-
- run: pip install flake8
27+
- run: pip install flake8 flake8-pyproject
2628
- name: Flake8 lint Python code
27-
run: (cd client && find src/ -type f -name '*.py' -exec flake8 --max-line-length=120 '{}' '+')
29+
run: (cd client && flake8 src/)
2830

2931
mypy:
3032
name: Type checking
@@ -36,58 +38,43 @@ jobs:
3638
- name: Mypy type checking
3739
run: (cd client && mypy src/)
3840

39-
get-develop-version:
40-
name: Get develop version
41+
package_and_deploy:
42+
name: Build and deploy Ethereum Client Python package
4143
runs-on: ubuntu-latest
42-
if: ${{ github.event_name == 'pull_request' && github.base_ref == 'develop' }}
43-
outputs:
44-
develop_version: ${{ steps.get-version.outputs.develop_version }}
44+
needs: [lint, mypy]
4545
steps:
46-
- name: Check Out Code
47-
uses: actions/checkout@v3
48-
with:
49-
ref: develop
50-
- name: Set up Python
51-
uses: actions/setup-python@v4
52-
with:
53-
python-version: 3.12.0
54-
- name: Get version
55-
id: get-version
56-
env:
57-
PYTHONPATH: client/src/ledger_app_clients
58-
run: |
59-
echo "develop_version=$(python -c 'from ethereum import __version__; print(__version__)')" >> $GITHUB_OUTPUT
6046

61-
version-check:
62-
name: Check Version when opening a PR against develop
63-
runs-on: ubuntu-latest
64-
needs: get-develop-version
65-
steps:
66-
- name: Check Out Code
67-
uses: actions/checkout@v3
68-
- name: Set up Python
69-
uses: actions/setup-python@v4
70-
with:
71-
python-version: 3.12.0
72-
- name: Check Version Bump
73-
env:
74-
DEVELOP_VERSION: ${{needs.get-develop-version.outputs.develop_version}}
75-
PYTHONPATH: client/src/ledger_app_clients
76-
run: |
77-
current_version=$(python -c "from ethereum import __version__; print(__version__)")
78-
if [[ "$current_version" == "$DEVELOP_VERSION" ]]; then
79-
echo "Version in __init__.py hasn't been bumped. Please bump the version before merging."
80-
exit 1
81-
fi
47+
- name: Clone
48+
uses: actions/checkout@v3
49+
with:
50+
fetch-depth: 0
8251

83-
packaging:
84-
needs: [lint, mypy]
85-
name: Build, test and deploy the Python package
86-
uses: LedgerHQ/ledger-app-workflows/.github/workflows/reusable_pypi_deployment.yml@v1
87-
with:
88-
package_directory: "client/"
89-
stable_deployment: ${{ github.ref == 'refs/heads/master' }}
90-
check_changelog_version: true
91-
publish: ${{ github.event_name == 'push' }}
92-
secrets:
93-
pypi_token: ${{ github.ref == 'refs/heads/master' && secrets.PYPI_PUBLIC_API_TOKEN || secrets.TEST_PYPI_PUBLIC_API_TOKEN }}
52+
- name: Build Python package
53+
run: |
54+
pip install --upgrade pip build twine
55+
cd client/
56+
python -m build;
57+
python -m twine check dist/*
58+
pip install .;
59+
echo "TAG_VERSION=$(python -c 'from ledger_app_clients.ethereum import __version__; print(__version__)')" >> "$GITHUB_ENV"
60+
61+
- name: Check version against CHANGELOG
62+
if: startsWith(github.ref, 'refs/tags/')
63+
run: |
64+
CHANGELOG_VERSION=$(grep -Po '(?<=## \[)(\d+\.)+[^\]]' client/CHANGELOG.md | head -n 1)
65+
if [ "${{ env.TAG_VERSION }}" == "${CHANGELOG_VERSION}" ];
66+
then
67+
echo 'Package and CHANGELOG versions match!';
68+
exit 0;
69+
else
70+
echo "Tag '${{ env.TAG_VERSION }}' and CHANGELOG '${CHANGELOG_VERSION}' versions mismatch!";
71+
exit 1;
72+
fi
73+
74+
- name: Publish Python package on pypi.org
75+
if: success() && github.event_name == 'push'
76+
run: (cd client && python -m twine upload --verbose dist/*)
77+
env:
78+
TWINE_USERNAME: __token__
79+
TWINE_PASSWORD: ${{ secrets.PYPI_PUBLIC_API_TOKEN }}
80+
TWINE_NON_INTERACTIVE: 1

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ build/
99

1010
# Python
1111
*.pyc
12-
12+
__version__.py
1313

1414
# JS
1515
tests/node_modules

client/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.2.1] - 2023-12-01
9+
10+
### Fixed
11+
12+
- v0.2.0 version already published on pypi.org
13+
814
## [0.2.0] - 2023-12-01
915

1016
### Added

client/pyproject.toml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,18 @@ dependencies = [
3434
[tools.setuptools]
3535
include-package-data = true
3636

37-
[tool.setuptools.dynamic]
38-
version = {attr = "ledger_app_clients.ethereum.__version__"}
37+
[tool.setuptools_scm]
38+
version_file = "src/ledger_app_clients/ethereum/__version__.py"
39+
local_scheme = "no-local-version"
40+
root = "../"
41+
git_describe_command = "git describe --dirty --tags --long --match client-*[0-9]*"
42+
fallback_version = "0.0.0"
3943

4044
[project.urls]
4145
Home = "https://github.com/LedgerHQ/app-ethereum"
4246

4347
[tool.mypy]
4448
ignore_missing_imports = true
49+
50+
[tool.flake8]
51+
max-line-length = 120
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
__version__ = "0.2.0"
1+
try:
2+
from ledger_app_clients.ethereum.__version__ import __version__ # noqa
3+
except ImportError:
4+
__version__ = "unknown version" # noqa

0 commit comments

Comments
 (0)