Update workflows/publish_pypi.yml
[manga-dl.git] / prepare_setup.py
blobd57a07ccd892f726f08d285761c3c1fbea2889f1
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
4 import re
5 from manga_py import meta
7 RE_VALID_PACKAGE = re.compile(r'^([a-zA-Z-_]+)')
8 RE_REPLACE_SETUP_REQ = re.compile(r'^(REQUIREMENTS\s*=\s*\[)(.*\])$')
11 def req_lines():
12 with open('requirements.txt', 'r') as _r:
13 return [line.strip() for line in _r.readlines() if RE_VALID_PACKAGE.search(line)]
16 with open('manga_py/cli/_requirements.py', 'w') as w:
17 w.write('requirements = ["%s"]' % '","'.join(req_lines()))
20 def req(lines: list):
21 requirements = ''.join(["'%s', " % line for line in req_lines()])
23 for n, line in enumerate(lines):
24 matched = RE_REPLACE_SETUP_REQ.search(line)
25 if matched is not None:
26 _b, _a = matched.groups()
27 lines[n] = '%s%s%s' % (_b, requirements, _a)
28 break
30 return lines
33 with open('setup.py.template', 'r') as r:
34 content = r.read()
36 for key in meta.__all__:
37 content = content.replace('__%s__' % key, getattr(meta, key))
39 with open('setup.py', 'w') as w:
40 w.write('\n'.join(req(content.splitlines())))