diff options
| -rw-r--r-- | dodo.py | 2 | ||||
| -rw-r--r-- | requirements.pip.dev.txt | 2 | ||||
| -rw-r--r-- | src_c/common.c | 257 | ||||
| -rw-r--r-- | src_c/common.h | 10 | ||||
| -rw-r--r-- | src_c/main.c | 57 | ||||
| -rw-r--r-- | src_c/pool.c | 85 | ||||
| -rw-r--r-- | src_c/pool.h | 22 | ||||
| -rw-r--r-- | src_doit/__init__.py | 12 | ||||
| -rw-r--r-- | src_doit/c.py | 40 | ||||
| -rw-r--r-- | src_doit/dist/__init__.py | 45 |
10 files changed, 416 insertions, 116 deletions
@@ -1,6 +1,6 @@ from hat.doit import common DOIT_CONFIG = common.init(python_paths=['src_py'], - default_tasks=['build']) + default_tasks=['wheel']) from src_doit import * # NOQA diff --git a/requirements.pip.dev.txt b/requirements.pip.dev.txt index e65fe71..cf3f526 100644 --- a/requirements.pip.dev.txt +++ b/requirements.pip.dev.txt @@ -4,7 +4,7 @@ build ~= 0.7.0 doit ~= 0.33.1 flake8 ~= 3.9.2 furo >= 2021.10.9 -hat-doit ~= 0.7.0 +hat-doit ~= 0.7.2 peru >= 1.3.0 pytest ~= 6.2.5 pytest-asyncio ~= 0.15.1 diff --git a/src_c/common.c b/src_c/common.c index 8088dd3..d7135a6 100644 --- a/src_c/common.c +++ b/src_c/common.c @@ -7,12 +7,94 @@ static inline bool is_token_val(char *json, jsmntok_t *token, char *val) { - return strncmp(val, json + token->start, token->end - tokens->start) == 0; + return strncmp(val, json + token->start, token->end - token->start) == 0; +} + + +static int write_number(double val, FILE *stream) { + if (fprintf(stream, "%f", val) < 0) + return OPCUT_ERROR; + + return OPCUT_SUCCESS; +} + + +static int write_bool(bool val, FILE *stream) { + if (fputs((val ? "true" : "false"), stream) < 0) + return OPCUT_ERROR; + + return OPCUT_SUCCESS; +} + + +static int write_str(opcut_str_t *str, FILE *stream) { + if (fprintf(stream, "\"%*s\"", str->len, str->data) < 0) + return OPCUT_ERROR; + + return OPCUT_SUCCESS; +} + + +static int write_panel(opcut_panel_t *panel, FILE *stream) { + if (fputs("{\"id\":", stream) < 0) + return OPCUT_ERROR; + + if (write_str(&(panel->id), stream)) + return OPCUT_ERROR; + + if (fputs(",\"width\":", stream) < 0) + return OPCUT_ERROR; + + if (write_number(panel->width, stream)) + return OPCUT_ERROR; + + if (fputs(",\"height\":", stream) < 0) + return OPCUT_ERROR; + + if (write_number(panel->height, stream)) + return OPCUT_ERROR; + + if (fputs("}", stream) < 0) + return OPCUT_ERROR; + + return OPCUT_SUCCESS; +} + + +static int write_item(opcut_item_t *item, FILE *stream) { + if (fputs("{\"id\":", stream) < 0) + return OPCUT_ERROR; + + if (write_str(&(item->id), stream)) + return OPCUT_ERROR; + + if (fputs(",\"width\":", stream) < 0) + return OPCUT_ERROR; + + if (write_number(item->width, stream)) + return OPCUT_ERROR; + + if (fputs(",\"height\":", stream) < 0) + return OPCUT_ERROR; + + if (write_number(item->height, stream)) + return OPCUT_ERROR; + + if (fputs(",\"can_rotate\":", stream) < 0) + return OPCUT_ERROR; + + if (write_bool(item->can_rotate, stream)) + return OPCUT_ERROR; + + if (fputs("}", stream) < 0) + return OPCUT_ERROR; + + return OPCUT_SUCCESS; } static int write_params(opcut_params_t *params, FILE *stream) { - if (fputs("{\"cut_width\":", fputs) < 0) + if (fputs("{\"cut_width\":", stream) < 0) return OPCUT_ERROR; if (write_number(params->cut_width, stream)) @@ -28,12 +110,12 @@ static int write_params(opcut_params_t *params, FILE *stream) { return OPCUT_ERROR; for (size_t i = 0; i < params->panels_len; ++i) { - if (write_panel(result->panels + i, stream)) + if (write_panel(params->panels + i, stream)) return OPCUT_ERROR; - if (i < result->panels_len - 1) { + if (i < params->panels_len - 1) { if (fputs(",", stream) < 0) - return OPCUT_ERROR + return OPCUT_ERROR; } } @@ -41,12 +123,12 @@ static int write_params(opcut_params_t *params, FILE *stream) { return OPCUT_ERROR; for (size_t i = 0; i < params->items_len; ++i) { - if (write_item(result->items + i, stream)) + if (write_item(params->items + i, stream)) return OPCUT_ERROR; - if (i < result->items_len - 1) { + if (i < params->items_len - 1) { if (fputs(",", stream) < 0) - return OPCUT_ERROR + return OPCUT_ERROR; } } @@ -58,31 +140,31 @@ static int write_params(opcut_params_t *params, FILE *stream) { static int write_used(opcut_used_t *used, FILE *stream) { - if (fputs("{\"panel\":", fputs) < 0) + if (fputs("{\"panel\":", stream) < 0) return OPCUT_ERROR; if (write_str(&(used->panel->id), stream)) return OPCUT_ERROR; - if (fputs(",\"item\":", fputs) < 0) + if (fputs(",\"item\":", stream) < 0) return OPCUT_ERROR; if (write_str(&(used->item->id), stream)) return OPCUT_ERROR; - if (fputs(",\"x\":", fputs) < 0) + if (fputs(",\"x\":", stream) < 0) return OPCUT_ERROR; if (write_number(used->x, stream)) return OPCUT_ERROR; - if (fputs(",\"y\":", fputs) < 0) + if (fputs(",\"y\":", stream) < 0) return OPCUT_ERROR; if (write_number(used->y, stream)) return OPCUT_ERROR; - if (fputs(",\"rotate\":", fputs) < 0) + if (fputs(",\"rotate\":", stream) < 0) return OPCUT_ERROR; if (write_bool(used->rotate, stream)) @@ -96,31 +178,31 @@ static int write_used(opcut_used_t *used, FILE *stream) { static int write_unused(opcut_unused_t *unused, FILE *stream) { - if (fputs("{\"panel\":", fputs) < 0) + if (fputs("{\"panel\":", stream) < 0) return OPCUT_ERROR; if (write_str(&(unused->panel->id), stream)) return OPCUT_ERROR; - if (fputs(",\"width\":", fputs) < 0) + if (fputs(",\"width\":", stream) < 0) return OPCUT_ERROR; if (write_number(unused->width, stream)) return OPCUT_ERROR; - if (fputs(",\"height\":", fputs) < 0) + if (fputs(",\"height\":", stream) < 0) return OPCUT_ERROR; if (write_number(unused->height, stream)) return OPCUT_ERROR; - if (fputs(",\"x\":", fputs) < 0) + if (fputs(",\"x\":", stream) < 0) return OPCUT_ERROR; if (write_number(unused->x, stream)) return OPCUT_ERROR; - if (fputs(",\"y\":", fputs) < 0) + if (fputs(",\"y\":", stream) < 0) return OPCUT_ERROR; if (write_number(unused->y, stream)) @@ -133,83 +215,111 @@ static int write_unused(opcut_unused_t *unused, FILE *stream) { } -static int write_panel(opcut_panel_t *panel, FILE *stream) { - if (fputs("{\"id\":", fputs) < 0) +static int read_number(char *json, double *val, jsmntok_t *token) { + if (token->type != JSMN_PRIMITIVE) return OPCUT_ERROR; - if (write_str(&(panel->id), stream)) + if (sscanf(json + token->start, "%lf", val) < 0) return OPCUT_ERROR; - if (fputs(",\"width\":", fputs) < 0) - return OPCUT_ERROR; + return OPCUT_SUCCESS; +} - if (write_number(panel->width, stream)) - return OPCUT_ERROR; - if (fputs(",\"height\":", fputs) < 0) +static int read_bool(char *json, bool *val, jsmntok_t *token) { + if (token->type != JSMN_PRIMITIVE) return OPCUT_ERROR; - if (write_number(panel->height, stream)) - return OPCUT_ERROR; + if (json[token->start] == 't') { + *val = true; + return OPCUT_SUCCESS; + } - if (fputs("}", stream) < 0) - return OPCUT_ERROR; + if (json[token->start] == 'f') { + *val = false; + return OPCUT_SUCCESS; + } - return OPCUT_SUCCESS; + return OPCUT_ERROR; } -static int write_item(opcut_item_t *item, FILE *stream) { - if (fputs("{\"id\":", fputs) < 0) +static int read_string(char *json, opcut_str_t *str, jsmntok_t *token) { + if (token->type != JSMN_STRING) return OPCUT_ERROR; - if (write_str(&(item->id), stream)) - return OPCUT_ERROR; + str->data = json + token->start; + str->len = token->end - token->start; + return OPCUT_SUCCESS; +} - if (fputs(",\"width\":", fputs) < 0) - return OPCUT_ERROR; - if (write_number(item->width, stream)) +static int read_panel(char *json, opcut_panel_t *panel, jsmntok_t *tokens, + size_t *pos) { + jsmntok_t *id_token = tokens + ((*pos)++); + jsmntok_t *panel_token = tokens + ((*pos)++); + if (panel_token->type != JSMN_OBJECT) return OPCUT_ERROR; - if (fputs(",\"height\":", fputs) < 0) + if (!read_string(json, &(panel->id), id_token)) return OPCUT_ERROR; - if (write_number(item->height, stream)) - return OPCUT_ERROR; + panel->width = 0; + panel->height = 0; - if (fputs(",\"can_rotate\":", fputs) < 0) - return OPCUT_ERROR; + for (size_t i = 0; i < panel_token->size; ++i) { + jsmntok_t *key_token = tokens + ((*pos)++); + jsmntok_t *value_token = tokens + ((*pos)++); + if (key_token->type != JSMN_STRING) + return OPCUT_ERROR; - if (write_bool(item->can_rotate, stream)) - return OPCUT_ERROR; + if (is_token_val(json, key_token, "width")) { + if (read_number(json, &(panel->width), value_token)) + return OPCUT_ERROR; - if (fputs("}", stream) < 0) - return OPCUT_ERROR; + } else if (is_token_val(json, key_token, "height")) { + if (read_number(json, &(panel->height), value_token)) + return OPCUT_ERROR; + } + } return OPCUT_SUCCESS; } -static int write_number(double val, FILE *stream) { - if (fprintf(stream, "%f", val) < 0) +static int read_item(char *json, opcut_item_t *item, jsmntok_t *tokens, + size_t *pos) { + jsmntok_t *id_token = tokens + ((*pos)++); + jsmntok_t *item_token = tokens + ((*pos)++); + if (item_token->type != JSMN_OBJECT) return OPCUT_ERROR; - return OPCUT_SUCCESS; -} + if (!read_string(json, &(item->id), id_token)) + return OPCUT_ERROR; + item->width = 0; + item->height = 0; + item->can_rotate = false; -static int write_bool(bool val, FILE *stream) { - if (fputs((val ? "true" : "false"), stream) < 0) - return OPCUT_ERROR; + for (size_t i = 0; i < item_token->size; ++i) { + jsmntok_t *key_token = tokens + ((*pos)++); + jsmntok_t *value_token = tokens + ((*pos)++); + if (key_token->type != JSMN_STRING) + return OPCUT_ERROR; - return OPCUT_SUCCESS; -} + if (is_token_val(json, key_token, "width")) { + if (read_number(json, &(item->width), value_token)) + return OPCUT_ERROR; + } else if (is_token_val(json, key_token, "height")) { + if (read_number(json, &(item->height), value_token)) + return OPCUT_ERROR; -static int write_str(opcut_str_t *str, FILE *stream) { - if (fprintf(stream, "\"%*s\"", str->len, str->data) < 0) - return OPCUT_ERROR; + } else if (is_token_val(json, key_token, "can_rotate")) { + if (read_bool(json, &(item->can_rotate), value_token)) + return OPCUT_ERROR; + } + } return OPCUT_SUCCESS; } @@ -218,7 +328,7 @@ static int write_str(opcut_str_t *str, FILE *stream) { static int read_params(char *json, opcut_params_t *params, jsmntok_t *tokens, size_t *pos) { jsmntok_t *params_token = tokens + ((*pos)++); - if (tokens_len < 1 || params_token->type != JSMN_OBJECT) + if (params_token->type != JSMN_OBJECT) return OPCUT_ERROR; params->cut_width = 0; @@ -243,7 +353,7 @@ static int read_params(char *json, opcut_params_t *params, jsmntok_t *tokens, goto error_cleanup; } else if (is_token_val(json, key_token, "panels")) { - if (value_token->type != JSMN_ARRAY) + if (value_token->type != JSMN_OBJECT) goto error_cleanup; if (params->panels) { @@ -262,7 +372,7 @@ static int read_params(char *json, opcut_params_t *params, jsmntok_t *tokens, } } else if (is_token_val(json, key_token, "items")) { - if (value_token->type != JSMN_ARRAY) + if (value_token->type != JSMN_OBJECT) goto error_cleanup; if (params->items) { @@ -299,29 +409,12 @@ error_cleanup: } -static int read_panel(char *json, opcut_panel_t *panel, jsmntok_t *tokens, - size_t *pos) {} - - -static int read_item(char *json, opcut_item_t *item, jsmntok_t *tokens, - size_t *pos) {} - - -static int read_number(char *json, double *val, jsmntok_t *token) {} - - -static int read_bool(char *json, bool *val, jsmntok_t *token) {} - - -static int read_string(char *json, opcut_str_t *str, jsmntok_t *token) {} - - int opcut_params_init(opcut_params_t *params, opcut_str_t *json) { jsmn_parser parser; int tokens_len; jsmn_init(&parser); - tokens_len = jsmn_parse(&parser, json, json_len, NULL, 0); + tokens_len = jsmn_parse(&parser, json->data, json->len, NULL, 0); if (tokens_len < 0) return OPCUT_ERROR; @@ -352,7 +445,7 @@ int opcut_result_write(opcut_result_t *result, FILE *stream) { if (fputs("{\"params\":", stream) < 0) return OPCUT_ERROR; - if (write_params(result->params + i, stream)) + if (write_params(result->params, stream)) return OPCUT_ERROR; if (fputs(",\"used\":[", stream) < 0) @@ -364,7 +457,7 @@ int opcut_result_write(opcut_result_t *result, FILE *stream) { if (i < result->used_len - 1) { if (fputs(",", stream) < 0) - return OPCUT_ERROR + return OPCUT_ERROR; } } diff --git a/src_c/common.h b/src_c/common.h index e8eb9d1..16aeb9b 100644 --- a/src_c/common.h +++ b/src_c/common.h @@ -1,14 +1,12 @@ #ifndef OPCUT_COMMON_H #define OPCUT_COMMON_H - -#import <stdbool.h> -#import <stdio.h> +#include <stdbool.h> +#include <stdio.h> #define OPCUT_SUCCESS 0 -#define OPCUT_ERROR -1 -#define OPCUT_UNSOLVABLE 1 - +#define OPCUT_ERROR 1 +#define OPCUT_UNSOLVABLE 2 #ifdef __cplusplus extern "C" { diff --git a/src_c/main.c b/src_c/main.c new file mode 100644 index 0000000..9cc71ed --- /dev/null +++ b/src_c/main.c @@ -0,0 +1,57 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "common.h" + + +static int read_stdin(opcut_str_t *json) { + size_t json_data_size = 0; + json->data = NULL; + json->len = 0; + + while (!(json->len < json_data_size)) { + char *old_json_data = json->data; + json_data_size += 4096; + json->data = realloc(json->data, json_data_size); + if (!json->data) { + free(old_json_data); + return OPCUT_ERROR; + } + json->len += + fread(json->data + json->len, 1, json_data_size - json->len, stdin); + } + + return OPCUT_SUCCESS; +} + + +int main(int argc, char **argv) { + char *method = NULL; + for (size_t i = 1; i < argc - 1; ++i) { + if (strcmp("--method", argv[i]) == 0) + method = argv[++i]; + } + + opcut_str_t json; + if (!read_stdin(&json)) + return OPCUT_ERROR; + + opcut_params_t params; + if (!opcut_params_init(¶ms, &json)) { + free(json.data); + return OPCUT_ERROR; + } + + opcut_result_t result = {.params = ¶ms, + .used = NULL, + .used_len = 0, + .unused = NULL, + .unused_len = 0}; + + size_t res = opcut_result_write(&result, stdout); + + opcut_params_destroy(¶ms); + free(json.data); + + return res; +} diff --git a/src_c/pool.c b/src_c/pool.c new file mode 100644 index 0000000..619a97d --- /dev/null +++ b/src_c/pool.c @@ -0,0 +1,85 @@ +#include <stdlib.h> +#include "pool.h" + + +#define PAGE_SIZE 4096 + + +typedef struct header_t { + struct header_t *next; +} header_t; + + +struct opcut_pool_t { + size_t item_size; + header_t *blocks; + header_t *items; +}; + + +static void allocate_block(opcut_pool_t *pool) { + size_t items_per_block = + (PAGE_SIZE - sizeof(header_t)) / (sizeof(header_t) + pool->item_size); + if (items_per_block < 1) + items_per_block = 1; + + header_t *block = + malloc(sizeof(header_t) + + items_per_block * (sizeof(header_t) + pool->item_size)); + if (!block) + return; + block->next = pool->blocks; + pool->blocks = block; + + for (size_t i = 0; i < items_per_block; ++i) { + header_t *header = (void *)block + sizeof(header_t) + + i * (sizeof(header_t) + pool->item_size); + header->next = pool->items; + pool->items = header; + } +} + + +opcut_pool_t *opcut_pool_create(size_t item_size) { + opcut_pool_t *pool = malloc(sizeof(opcut_pool_t)); + if (!pool) + return NULL; + + if (item_size % sizeof(void *) != 0) + item_size += sizeof(void *) - (item_size % sizeof(void *)); + + pool->item_size = item_size; + pool->blocks = NULL; + pool->items = NULL; + + return pool; +} + + +void opcut_pool_destroy(opcut_pool_t *pool) { + while (pool->blocks) { + header_t *block = pool->blocks; + pool->blocks = block->next; + free(block); + } + free(pool); +} + + +void *opcut_pool_get(opcut_pool_t *pool) { + if (!pool->items) + allocate_block(pool); + + if (!pool->items) + return NULL; + + header_t *header = pool->items; + pool->items = header->next; + return header + 1; +} + +void opcut_pool_return(opcut_pool_t *pool, void *item) { + header_t *header = (header_t *)item - 1; + header->next = pool->items; + pool->items = header; +} diff --git a/src_c/pool.h b/src_c/pool.h new file mode 100644 index 0000000..784278e --- /dev/null +++ b/src_c/pool.h @@ -0,0 +1,22 @@ +#ifndef OPCUT_POOL_H +#define OPCUT_POOL_H + +#include <stddef.h> + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct opcut_pool_t opcut_pool_t; + + +opcut_pool_t *opcut_pool_create(size_t item_size); +void opcut_pool_destroy(opcut_pool_t *pool); +void *opcut_pool_get(opcut_pool_t *pool); +void opcut_pool_return(opcut_pool_t *pool, void *item); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src_doit/__init__.py b/src_doit/__init__.py index 89ba32c..524fa53 100644 --- a/src_doit/__init__.py +++ b/src_doit/__init__.py @@ -10,18 +10,21 @@ from hat.doit.py import (build_wheel, run_flake8) from hat.doit.js import run_eslint +from .c import * # NOQA from .dist import * # NOQA +from . import c from . import dist __all__ = ['task_clean_all', - 'task_build', + 'task_wheel', 'task_check', 'task_test', 'task_ui', 'task_deps', 'task_format', 'task_json_schema_repo', + *c.__all__, *dist.__all__] @@ -34,6 +37,7 @@ docs_dir = Path('docs') schemas_dir = Path('schemas') node_modules_dir = Path('node_modules') +build_py_dir = build_dir / 'py' ui_dir = src_py_dir / 'opcut/ui' json_schema_repo_path = src_py_dir / 'opcut/json_schema_repo.json' @@ -45,13 +49,13 @@ def task_clean_all(): json_schema_repo_path])]} -def task_build(): - """Build""" +def task_wheel(): + """Build wheel""" def build(): build_wheel( src_dir=src_py_dir, - dst_dir=build_dir, + dst_dir=build_py_dir, name='opcut', description='Cutting stock problem optimizer', url='https://github.com/bozokopic/opcut', diff --git a/src_doit/c.py b/src_doit/c.py new file mode 100644 index 0000000..618dd8d --- /dev/null +++ b/src_doit/c.py @@ -0,0 +1,40 @@ +from pathlib import Path + +from hat.doit.c import (exe_suffix, + CBuild) + + +__all__ = ['task_c', + 'task_c_obj', + 'task_c_dep'] + + +build_dir = Path('build') +src_c_dir = Path('src_c') +deps_dir = Path('deps') + +build_c_dir = build_dir / 'c' +exe_path = build_c_dir / f'opcut-calculate{exe_suffix}' + + +def task_c(): + """Build native app""" + return _build.get_task_exe(exe_path) + + +def task_c_obj(): + """Build .o files""" + yield from _build.get_task_objs() + + +def task_c_dep(): + """Build .d files""" + yield from _build.get_task_deps() + + +_build = CBuild( + src_paths=[*src_c_dir.rglob('*.c')], + src_dir=src_c_dir, + build_dir=build_c_dir, + cc_flags=['-fPIC', '-O2', f'-I{deps_dir / "jsmn"}'], + task_dep=['deps']) diff --git a/src_doit/dist/__init__.py b/src_doit/dist/__init__.py index de8d98c..6c490fa 100644 --- a/src_doit/dist/__init__.py +++ b/src_doit/dist/__init__.py @@ -1,7 +1,6 @@ from pathlib import Path import subprocess import zipfile -import sys from hat.doit import common @@ -16,8 +15,10 @@ package_path = Path(__file__).parent build_dir = Path('build') cache_dir = Path('cache') -build_windows_dir = build_dir / f'opcut-{common.get_version()}-windows' -build_container_dir = build_dir / f'opcut-{common.get_version()}-container' +wheel_dir = build_dir / 'py/dist' +dist_dir = build_dir / 'dist' +dist_windows_dir = dist_dir / f'opcut-{common.get_version()}-windows' +dist_container_dir = dist_dir / f'opcut-{common.get_version()}-container' win_python_url = 'https://www.python.org/ftp/python/3.9.7/python-3.9.7-embed-amd64.zip' # NOQA cache_win_python_path = cache_dir / win_python_url.split('/')[-1] @@ -35,9 +36,9 @@ def task_dist_windows(): """Build windows distribution""" def build(): - common.rm_rf(build_windows_dir) - common.mkdir_p(build_windows_dir.parent) - common.cp_r(package_path / 'windows', build_windows_dir) + common.rm_rf(dist_windows_dir) + common.mkdir_p(dist_windows_dir.parent) + common.cp_r(package_path / 'windows', dist_windows_dir) common.mkdir_p(cache_dir) if not cache_win_python_path.exists(): @@ -46,14 +47,14 @@ def task_dist_windows(): '-L', win_python_url], check=True) - python_dir = build_windows_dir / 'python' + python_dir = dist_windows_dir / 'python' common.mkdir_p(python_dir) with zipfile.ZipFile(str(cache_win_python_path)) as f: f.extractall(str(python_dir)) python_lib_path = python_dir / 'python39.zip' python_lib_dir = python_dir / 'lib' - common.mkdir_p(build_windows_dir / 'python/lib') + common.mkdir_p(dist_windows_dir / 'python/lib') with zipfile.ZipFile(str(python_lib_path)) as f: f.extractall(str(python_lib_dir)) common.rm_rf(python_lib_path) @@ -65,10 +66,10 @@ def task_dist_windows(): 'import site\n' ) - packages_dir = build_windows_dir / 'packages' + packages_dir = dist_windows_dir / 'packages' common.mkdir_p(packages_dir) - packages = [*(str(i) for i in (build_dir / 'dist').glob('*.whl'))] + packages = [*(str(i) for i in wheel_dir.glob('*.whl'))] subprocess.run(['pip', 'install', '-q', '-t', str(packages_dir), '--only-binary=:all:', @@ -76,38 +77,38 @@ def task_dist_windows(): *packages], check=True) - zip_path = build_dir / f'{build_windows_dir.name}.zip' + zip_path = dist_dir / f'{dist_windows_dir.name}.zip' common.rm_rf(zip_path) with zipfile.ZipFile(str(zip_path), 'w', zipfile.ZIP_DEFLATED) as f: - for i in build_windows_dir.rglob('*'): + for i in dist_windows_dir.rglob('*'): if i.is_dir(): continue - f.write(str(i), str(i.relative_to(build_windows_dir))) + f.write(str(i), str(i.relative_to(dist_windows_dir))) return {'actions': [build], - 'task_dep': ['build']} + 'task_dep': ['wheel']} def task_dist_container(): """Build container distribution""" def build(): - common.rm_rf(build_container_dir) - common.mkdir_p(build_container_dir.parent) - common.cp_r(package_path / 'container', build_container_dir) + common.rm_rf(dist_container_dir) + common.mkdir_p(dist_container_dir.parent) + common.cp_r(package_path / 'container', dist_container_dir) - for i in (build_dir / 'dist').glob('*.whl'): - common.cp_r(i, build_container_dir / i.name) + for i in wheel_dir.glob('*.whl'): + common.cp_r(i, dist_container_dir / i.name) name = f'opcut:{common.get_version()}' - img_path = build_dir / f'{build_container_dir.name}.tar' + img_path = dist_dir / f'{dist_container_dir.name}.tar' subprocess.run(['podman', 'build', '-q', '-t', name, '.'], - cwd=str(build_container_dir), + cwd=str(dist_container_dir), check=True) subprocess.run(['podman', 'save', '-q', '-o', str(img_path), name], check=True) return {'actions': [build], - 'task_dep': ['build']} + 'task_dep': ['wheel']} |
