Inprogress refactor trying f-strings as template language
This commit is contained in:
+13
-13
@@ -6,22 +6,22 @@ branches:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
include:
|
include:
|
||||||
- name: Linux | x86_64 + i686 | Python 3.5
|
- name: Linux | x86_64 + i686 | Python 3.6
|
||||||
language: python
|
language: python
|
||||||
python: 3.5
|
python: 3.6
|
||||||
services: docker
|
services: docker
|
||||||
env: PYTHON=python
|
env: PYTHON=python
|
||||||
|
|
||||||
- name: Linux | arm64 | Python 3.5
|
- name: Linux | arm64 | Python 3.6
|
||||||
language: python
|
language: python
|
||||||
python: 3.5
|
python: 3.6
|
||||||
services: docker
|
services: docker
|
||||||
arch: arm64
|
arch: arm64
|
||||||
env: PYTHON=python
|
env: PYTHON=python
|
||||||
|
|
||||||
- name: Linux | ppc64le | Python 3.5
|
- name: Linux | ppc64le | Python 3.6
|
||||||
language: python
|
language: python
|
||||||
python: 3.5
|
python: 3.6
|
||||||
services: docker
|
services: docker
|
||||||
arch: ppc64le
|
arch: ppc64le
|
||||||
env: PYTHON=python
|
env: PYTHON=python
|
||||||
@@ -30,25 +30,25 @@ jobs:
|
|||||||
os: osx
|
os: osx
|
||||||
env: PYTHON=python3
|
env: PYTHON=python3
|
||||||
|
|
||||||
- name: Windows | x86_64 | Python 3.5
|
- name: Windows | x86_64 | Python 3.6
|
||||||
os: windows
|
os: windows
|
||||||
language: shell
|
language: shell
|
||||||
before_install:
|
before_install:
|
||||||
- choco install python3 --version 3.5.4 --no-progress -y
|
- choco install python3 --version 3.6.8 --no-progress -y
|
||||||
env:
|
env:
|
||||||
- PYTHON=C:\\Python35\\python
|
- PYTHON=C:\\Python36\\python
|
||||||
|
|
||||||
- &linux_s390x_35
|
- &linux_s390x_36
|
||||||
name: Linux | s390x | Python 3.5
|
name: Linux | s390x | Python 3.6
|
||||||
language: python
|
language: python
|
||||||
python: 3.5
|
python: 3.6
|
||||||
services: docker
|
services: docker
|
||||||
arch: s390x
|
arch: s390x
|
||||||
env: PYTHON=python
|
env: PYTHON=python
|
||||||
|
|
||||||
allow_failures:
|
allow_failures:
|
||||||
# must repeat the s390x job above exactly to match
|
# must repeat the s390x job above exactly to match
|
||||||
- *linux_s390x_35
|
- *linux_s390x_36
|
||||||
|
|
||||||
install: $PYTHON -m pip install -r requirements-dev.txt
|
install: $PYTHON -m pip install -r requirements-dev.txt
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import os
|
||||||
|
import io
|
||||||
|
from typing import List, Tuple
|
||||||
|
|
||||||
|
|
||||||
|
class TemplateProject:
|
||||||
|
files: List[Tuple[str, str]]
|
||||||
|
|
||||||
|
def __init__(self, files):
|
||||||
|
self.files = files
|
||||||
|
|
||||||
|
def generate(self, path):
|
||||||
|
for filename, content in self.files:
|
||||||
|
file_path = os.path.join(path, filename)
|
||||||
|
os.makedirs(os.path.dirname(file_path), exist_ok=True)
|
||||||
|
|
||||||
|
with io.open(file_path, 'w', encoding='utf8') as f:
|
||||||
|
f.write(content)
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
import textwrap
|
||||||
|
|
||||||
|
def indent(str, level):
|
||||||
|
return str
|
||||||
|
|
||||||
|
def CTemplateProject(TemplateProject):
|
||||||
|
files = {
|
||||||
|
'spam.c': textwrap.dedent(fr'''
|
||||||
|
#include <Python.h>
|
||||||
|
|
||||||
|
{spam_c_top_level_add}
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
spam_system(PyObject *self, PyObject *args)
|
||||||
|
{{
|
||||||
|
const char *command;
|
||||||
|
int sts;
|
||||||
|
if (!PyArg_ParseTuple(args, "s", &command))
|
||||||
|
return NULL;
|
||||||
|
sts = system(command);
|
||||||
|
{indent(spam_c_function_add, 4)}
|
||||||
|
return PyLong_FromLong(sts);
|
||||||
|
}}
|
||||||
|
|
||||||
|
/* Module initialization */
|
||||||
|
|
||||||
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
#define MOD_INIT(name) PyMODINIT_FUNC PyInit_##name(void)
|
||||||
|
#define MOD_DEF(m, name, doc, methods, module_state_size) \
|
||||||
|
static struct PyModuleDef moduledef = { \
|
||||||
|
PyModuleDef_HEAD_INIT, name, doc, module_state_size, methods, }; \
|
||||||
|
m = PyModule_Create(&moduledef);
|
||||||
|
#define MOD_RETURN(m) return m;
|
||||||
|
#else
|
||||||
|
#define MOD_INIT(name) PyMODINIT_FUNC init##name(void)
|
||||||
|
#define MOD_DEF(m, name, doc, methods, module_state_size) \
|
||||||
|
m = Py_InitModule3(name, methods, doc);
|
||||||
|
#define MOD_RETURN(m) return;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static PyMethodDef module_methods[] = {
|
||||||
|
{"system", (PyCFunction)spam_system, METH_VARARGS,
|
||||||
|
"Execute a shell command."},
|
||||||
|
{NULL} /* Sentinel */
|
||||||
|
};
|
||||||
|
|
||||||
|
MOD_INIT(spam)
|
||||||
|
{
|
||||||
|
PyObject* m;
|
||||||
|
|
||||||
|
MOD_DEF(m,
|
||||||
|
"spam",
|
||||||
|
"Example module",
|
||||||
|
module_methods,
|
||||||
|
-1)
|
||||||
|
|
||||||
|
MOD_RETURN(m)
|
||||||
|
}
|
||||||
|
''')
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user