pyln-spec: Clean up the setup.py files

This centralizes the setup.py file, and parametrizes it so it can
auto-detect which bolt we are building. It also uses trick 3 from [1]
to avoid importing the package itself during the manifest creation,
which'd cause an import error due to missing dependencies.

[1] https://packaging.python.org/guides/single-sourcing-package-version/
This commit is contained in:
Christian Decker 2021-03-19 14:39:25 +01:00 committed by Rusty Russell
parent 6b0a7b173c
commit 0dd57cbf3c
6 changed files with 57 additions and 36 deletions

View File

@ -1,4 +0,0 @@
from pyln.spec.bolt1 import __version__, desc
from boltsetup import bolt_setup
bolt_setup(1, __version__, desc)

View File

@ -0,0 +1 @@
../setup.py

View File

@ -1,4 +0,0 @@
from pyln.spec.bolt2 import __version__, desc
from boltsetup import bolt_setup
bolt_setup(2, __version__, desc)

View File

@ -0,0 +1 @@
../setup.py

View File

@ -1,4 +0,0 @@
from pyln.spec.bolt4 import __version__, desc
from boltsetup import bolt_setup
bolt_setup(4, __version__, desc)

View File

@ -0,0 +1 @@
../setup.py

View File

@ -1,4 +0,0 @@
from pyln.spec.bolt7 import __version__, desc
from boltsetup import bolt_setup
bolt_setup(7, __version__, desc)

View File

@ -0,0 +1 @@
../setup.py

View File

@ -1,20 +0,0 @@
from setuptools import setup
import io
with io.open('requirements.txt', encoding='utf-8') as f:
requirements = [r for r in f.read().split('\n') if len(r)]
def bolt_setup(boltnum: int, version: str, desc: str):
setup(name='pyln-bolt{}'.format(boltnum),
version=version,
description=desc,
url='http://github.com/ElementsProject/lightning',
author='Rusty Russell',
author_email='rusty@rustcorp.com.au',
license='MIT',
packages=['pyln.spec.bolt{}'.format(boltnum)],
package_data={'pyln.proto.message': ['py.typed']},
scripts=[],
zip_safe=True,
install_requires=requirements)

View File

@ -0,0 +1,53 @@
from setuptools import setup
import io
import os
base = os.path.dirname(__file__)
with io.open(os.path.join(base, 'requirements.txt'), encoding='utf-8') as f:
requirements = [r for r in f.read().split('\n') if len(r)]
def bolt_meta(bolt_num):
ctx = {}
pkg_dir = os.path.join(base, 'pyln', 'spec', 'bolt{}'.format(bolt_num))
files = ['gen_version.py', 'gen_csv_version.py', 'text.py']
for f in files:
f = os.path.join(pkg_dir, f)
with open(f, 'r') as fd:
exec(fd.read(), ctx)
__version__ = '{__base_version__}.{__csv_version__}.{__post_version__}'.format(**ctx)
return {
'description': ctx['desc'],
'version': __version__,
}
def bolt_num():
"""Look into the pyln/spec/ directory to see which subpackages we provide.
"""
dirlist = os.listdir(os.path.join('pyln', 'spec'))
assert(len(dirlist) == 1) # Should only be the boltX directory
b = dirlist[0]
assert(b[:4] == 'bolt')
return int(b[4])
boltnum = bolt_num()
meta = bolt_meta(boltnum)
setup(
**meta,
name='pyln-bolt{}'.format(boltnum),
url='http://github.com/ElementsProject/lightning',
author='Rusty Russell',
author_email='rusty@rustcorp.com.au',
license='MIT',
packages=['pyln.spec.bolt{}'.format(boltnum)],
package_data={'pyln.proto.message': ['py.typed']},
scripts=[],
zip_safe=True,
install_requires=requirements
)