1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
from pathlib import Path
import packaging.requirements
from hat import json
from . import common
__all__ = ['task_py_build',
'task_py_json_schema_repo']
build_dir = Path('build')
src_py_dir = Path('src_py')
schemas_json_dir = Path('schemas_json')
requirements_path = Path('requirements.pip.runtime.txt')
json_schema_repo_path = src_py_dir / 'restlog/json_schema_repo.json'
def task_py_build():
"""Python - build"""
def build():
common.rm_rf(build_dir)
build_dir.mkdir(parents=True, exist_ok=True)
common.cp_r(src_py_dir, build_dir)
common.rm_rf(*build_dir.rglob('__pycache__'))
manifest_path = build_dir / 'MANIFEST.in'
paths = [path for path in build_dir.rglob('*') if not path.is_dir()]
with open(manifest_path, 'w', encoding='utf-8') as f:
for path in paths:
f.write(f"include {path.relative_to(manifest_path.parent)}\n")
readme = Path('README.rst').read_text()
requirements = list(_get_requirements(requirements_path))
setup_py = _setup_py.format(readme=repr(readme),
requirements=repr(requirements))
(build_dir / 'setup.py').write_text(setup_py)
return {'actions': [build],
'task_dep': ['py_json_schema_repo',
'js_build']}
def task_py_json_schema_repo():
"""Python - JSON schema repo"""
src_paths = list(schemas_json_dir.rglob('*.yaml'))
def generate():
repo = json.SchemaRepository(*src_paths)
data = repo.to_json()
json.encode_file(data, json_schema_repo_path, indent=None)
return {'actions': [generate],
'file_dep': src_paths,
'targets': [json_schema_repo_path]}
def _get_requirements(path):
# TODO: implement full format
# https://pip.pypa.io/en/stable/cli/pip_install/
for i in path.read_text().split('\n'):
i = i.strip()
if not i or i.startswith('#'):
continue
requirement = packaging.requirements.Requirement(i)
yield str(requirement)
_setup_py = r"""
from setuptools import setup
readme = {readme}
requirements = {requirements}
setup(
name='restlog',
version='0.0.1',
description='JSON log-structured data storage with REST API',
long_description=readme,
long_description_content_type='text/x-rst',
url='https://github.com/bnozokopic/restlog',
license='GPLv3',
classifiers=[
'Programming Language :: Python :: 3',
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)'],
packages=['restlog'],
include_package_data=True,
install_requires=requirements,
python_requires='>=3.8',
zip_safe=False,
entry_points={{
'console_scripts': ['restlog = restlog.main:main']
}})
""" # NOQA
|