Skip to content

Commit 0dd57cb

Browse files
cdeckerrustyrussell
authored andcommitted
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/
1 parent 6b0a7b1 commit 0dd57cb

File tree

6 files changed

+57
-36
lines changed

6 files changed

+57
-36
lines changed

contrib/pyln-spec/bolt1/setup.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

contrib/pyln-spec/bolt1/setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../setup.py

contrib/pyln-spec/bolt2/setup.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

contrib/pyln-spec/bolt2/setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../setup.py

contrib/pyln-spec/bolt4/setup.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

contrib/pyln-spec/bolt4/setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../setup.py

contrib/pyln-spec/bolt7/setup.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

contrib/pyln-spec/bolt7/setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../setup.py

contrib/pyln-spec/boltsetup.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

contrib/pyln-spec/setup.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
from setuptools import setup
2+
import io
3+
import os
4+
5+
base = os.path.dirname(__file__)
6+
with io.open(os.path.join(base, 'requirements.txt'), encoding='utf-8') as f:
7+
requirements = [r for r in f.read().split('\n') if len(r)]
8+
9+
10+
def bolt_meta(bolt_num):
11+
ctx = {}
12+
pkg_dir = os.path.join(base, 'pyln', 'spec', 'bolt{}'.format(bolt_num))
13+
14+
files = ['gen_version.py', 'gen_csv_version.py', 'text.py']
15+
16+
for f in files:
17+
f = os.path.join(pkg_dir, f)
18+
with open(f, 'r') as fd:
19+
exec(fd.read(), ctx)
20+
21+
__version__ = '{__base_version__}.{__csv_version__}.{__post_version__}'.format(**ctx)
22+
return {
23+
'description': ctx['desc'],
24+
'version': __version__,
25+
}
26+
27+
28+
def bolt_num():
29+
"""Look into the pyln/spec/ directory to see which subpackages we provide.
30+
"""
31+
dirlist = os.listdir(os.path.join('pyln', 'spec'))
32+
assert(len(dirlist) == 1) # Should only be the boltX directory
33+
b = dirlist[0]
34+
assert(b[:4] == 'bolt')
35+
return int(b[4])
36+
37+
38+
boltnum = bolt_num()
39+
meta = bolt_meta(boltnum)
40+
41+
setup(
42+
**meta,
43+
name='pyln-bolt{}'.format(boltnum),
44+
url='http://github.com/ElementsProject/lightning',
45+
author='Rusty Russell',
46+
author_email='[email protected]',
47+
license='MIT',
48+
packages=['pyln.spec.bolt{}'.format(boltnum)],
49+
package_data={'pyln.proto.message': ['py.typed']},
50+
scripts=[],
51+
zip_safe=True,
52+
install_requires=requirements
53+
)

0 commit comments

Comments
 (0)