Skip to content

Commit

Permalink
contrib/pyln-spec: update Makefile for poetry.
Browse files Browse the repository at this point in the history
Doesn't need to do so much stuff now.  Also, my lightning-spec dir
has changed to match GH repo name.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Sep 5, 2022
1 parent b582074 commit 16bd160
Showing 1 changed file with 19 additions and 29 deletions.
48 changes: 19 additions & 29 deletions contrib/pyln-spec/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#! /usr/bin/make

SPECDIR := ../../../lightning-rfc
SPECDIR := ../../../bolts

# This gives us something like 'v1.0-137-gae2d248b7ad8b0965f224c303019ba04c661008f'
GITDESCRIBE := $(shell git -C $(SPECDIR) describe --abbrev=40)
# -> 1.0
Expand All @@ -15,9 +16,12 @@ BOLTS := 1 2 4 7
DIRS := $(foreach b,$(BOLTS),bolt$b)
CODE_DIRS := $(foreach b,$(BOLTS),bolt$b/pyln/spec/bolt$b)

# Magic to get PYTHONPATH set.
PP := PYTHONPATH=$(shell echo $(addprefix $(shell pwd)/,$(DIRS)) | tr ' ' :)

check: $(DIRS:%=check-pytest-%)
check-pytest-%:
cd $* && pytest
cd $* && $(PP) pytest

check-source: check-source-flake8 check-source-mypy
check-source-flake8: $(DIRS:%=check-source-flake8-%)
Expand All @@ -28,46 +32,32 @@ check-source-flake8-%:

# mypy . does not recurse. I have no idea why...
check-source-mypy-%:
cd $* && mypy --ignore-missing-imports `find * -name '*.py'`
cd $* && mypy --ignore-missing-imports `find pyln -name '*.py'`

# Given a bolt number and a variable, get the value from inside the package.
extract = $(shell python3 -c 'from pyln.spec import bolt$1 as bolt;print(bolt.$2)')
extract = $(shell $(PP) python3 -c 'from pyln.spec import bolt$1 as bolt;print(bolt.$2)')
# Get the version for this bolt
version = $(call extract,$1,__version__)

# Given a direc the csv version for this bolt.
csv_version = $(call extract,$1,__csv_version__)

# Given a bolt number, get the current version.
sdistfiles = $(foreach b,$(BOLTS),bolt$b/dist/pyln-bolt$b-$(call version,$b).tar.gz)
bdistfiles = $(foreach b,$(BOLTS),bolt$b/dist/pyln_bolt$b-$(call version,$b)-py3-none-any.whl)

%.tar.gz:
cd $(dir $@)/.. && python3 setup.py sdist

%.whl:
cd $(dir $@)/.. && python3 setup.py bdist_wheel
# Build the package
build-%:
cd $* && poetry build

ARTEFACTS := $(foreach b,$(BOLTS),$(call bdistfiles,$b) $(call sdistfiles,$b))
test-publish-%: build-%
cd $* && poetry publish --dry-run

test-release-bolt%: $(ARTEFACTS)
python3 -m twine upload --repository testpypi --skip-existing $(call bdistfiles,$*) $(call sdistfiles,$*)
publish-%: testpublish-%
cd $* && poetry publish

# Create a test virtualenv, install from the testpypi and run the
# tests against it (make sure not to use any virtualenv that may have
# pyln-proto already installed).
virtualenv testpypi-$* --python=/usr/bin/python3 --download --always-copy --clear
# Install the requirements from the prod repo, they are not being kept up to date on the test repo
testpypi-$*/bin/python3 -m pip install -r requirements.txt pytest pytest-timeout
testpypi-$*/bin/python3 -m pip install -I --index-url https://test.pypi.org/simple/ --no-deps pyln-bolt$*
testpypi-$*/bin/python3 -c "from pyln.spec import bolt$* as bolt;assert(bolt.__version__ == '$(call version,$*)')"
testpypi-$*/bin/pytest bolt$*/tests
rm -rf testpypi-$*
# Call these to make a release.
test-release: check $(foreach b,$(BOLTS),test-publish-bolt$b)

test-release: check $(foreach b,$(BOLTS),test-release-bolt$b)
prod-release: check $(foreach b,$(BOLTS),publish-bolt$b)

prod-release: test-release $(ARTEFACTS)
python3 -m twine upload $(ARTEFACTS)
# Call this when spec needs updating

refresh: $(CODE_DIRS:%=%/gen_csv_version.py) $(CODE_DIRS:%=%/gen_version.py)

Expand Down

0 comments on commit 16bd160

Please sign in to comment.