Skip to content

Commit cc23e99

Browse files
jimmodpgeorge
authored andcommitted
py/modio: Remove io.resource_stream function.
This feature is not enabled on any port, it's not in CPython's io module, and functionality is better suited to the micropython-lib implementation of pkg_resources.
1 parent d6dc4cb commit cc23e99

7 files changed

Lines changed: 0 additions & 83 deletions

File tree

ports/unix/variants/coverage/mpconfigvariant.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
#define MICROPY_PY_MATH_FACTORIAL (1)
5252
#define MICROPY_PY_URANDOM_EXTRA_FUNCS (1)
5353
#define MICROPY_PY_IO_BUFFEREDWRITER (1)
54-
#define MICROPY_PY_IO_RESOURCE_STREAM (1)
5554
#define MICROPY_PY_UASYNCIO (1)
5655
#define MICROPY_PY_URE_DEBUG (1)
5756
#define MICROPY_PY_URE_MATCH_GROUPS (1)

py/modio.c

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -204,50 +204,6 @@ STATIC const mp_obj_type_t mp_type_bufwriter = {
204204
};
205205
#endif // MICROPY_PY_IO_BUFFEREDWRITER
206206

207-
#if MICROPY_PY_IO_RESOURCE_STREAM
208-
STATIC mp_obj_t resource_stream(mp_obj_t package_in, mp_obj_t path_in) {
209-
VSTR_FIXED(path_buf, MICROPY_ALLOC_PATH_MAX);
210-
size_t len;
211-
212-
// As an extension to pkg_resources.resource_stream(), we support
213-
// package parameter being None, the path_in is interpreted as a
214-
// raw path.
215-
if (package_in != mp_const_none) {
216-
// Pass "True" as sentinel value in fromlist to force returning of leaf module
217-
mp_obj_t pkg = mp_import_name(mp_obj_str_get_qstr(package_in), mp_const_true, MP_OBJ_NEW_SMALL_INT(0));
218-
219-
mp_obj_t dest[2];
220-
mp_load_method_maybe(pkg, MP_QSTR___path__, dest);
221-
if (dest[0] == MP_OBJ_NULL) {
222-
mp_raise_TypeError(NULL);
223-
}
224-
225-
const char *path = mp_obj_str_get_data(dest[0], &len);
226-
vstr_add_strn(&path_buf, path, len);
227-
vstr_add_byte(&path_buf, '/');
228-
}
229-
230-
const char *path = mp_obj_str_get_data(path_in, &len);
231-
vstr_add_strn(&path_buf, path, len);
232-
233-
len = path_buf.len;
234-
const char *data = mp_find_frozen_str(path_buf.buf, &len);
235-
if (data != NULL) {
236-
mp_obj_stringio_t *o = m_new_obj(mp_obj_stringio_t);
237-
o->base.type = &mp_type_bytesio;
238-
o->vstr = m_new_obj(vstr_t);
239-
vstr_init_fixed_buf(o->vstr, len + 1, (char *)data);
240-
o->vstr->len = len;
241-
o->pos = 0;
242-
return MP_OBJ_FROM_PTR(o);
243-
}
244-
245-
mp_obj_t path_out = mp_obj_new_str(path_buf.buf, path_buf.len);
246-
return mp_builtin_open(1, &path_out, (mp_map_t *)&mp_const_empty_map);
247-
}
248-
STATIC MP_DEFINE_CONST_FUN_OBJ_2(resource_stream_obj, resource_stream);
249-
#endif
250-
251207
STATIC const mp_rom_map_elem_t mp_module_io_globals_table[] = {
252208
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uio) },
253209
// Note: mp_builtin_open_obj should be defined by port, it's not
@@ -256,9 +212,6 @@ STATIC const mp_rom_map_elem_t mp_module_io_globals_table[] = {
256212
#if MICROPY_PY_IO_IOBASE
257213
{ MP_ROM_QSTR(MP_QSTR_IOBase), MP_ROM_PTR(&mp_type_iobase) },
258214
#endif
259-
#if MICROPY_PY_IO_RESOURCE_STREAM
260-
{ MP_ROM_QSTR(MP_QSTR_resource_stream), MP_ROM_PTR(&resource_stream_obj) },
261-
#endif
262215
#if MICROPY_PY_IO_FILEIO
263216
{ MP_ROM_QSTR(MP_QSTR_FileIO), MP_ROM_PTR(&mp_type_fileio) },
264217
#if MICROPY_CPYTHON_COMPAT

py/mpconfig.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,17 +1281,6 @@ typedef double mp_float_t;
12811281
#define MICROPY_PY_IO_IOBASE (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
12821282
#endif
12831283

1284-
// Whether to provide "uio.resource_stream()" function with
1285-
// the semantics of CPython's pkg_resources.resource_stream()
1286-
// (allows to access binary resources in frozen source packages).
1287-
// Note that the same functionality can be achieved in "pure
1288-
// Python" by prepocessing binary resources into Python source
1289-
// and bytecode-freezing it (with a simple helper module available
1290-
// e.g. in micropython-lib).
1291-
#ifndef MICROPY_PY_IO_RESOURCE_STREAM
1292-
#define MICROPY_PY_IO_RESOURCE_STREAM (0)
1293-
#endif
1294-
12951284
// Whether to provide "io.FileIO" class
12961285
#ifndef MICROPY_PY_IO_FILEIO
12971286
#define MICROPY_PY_IO_FILEIO (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)

tests/io/resource_stream.py

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

tests/io/resource_stream.py.exp

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

tests/unix/extra_coverage.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,6 @@
8989
except ZeroDivisionError:
9090
print("ZeroDivisionError")
9191

92-
# test loading a resource from a frozen string
93-
import uio
94-
95-
buf = uio.resource_stream("frzstr_pkg2", "mod.py")
96-
print(buf.read(21))
97-
9892
# test for MP_QSTR_NULL regression
9993
from frzqstr import returns_NULL
10094

tests/unix/extra_coverage.py.exp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,5 +174,4 @@ frzstr_pkg2.mod
174174
frzmpy_pkg2.mod
175175
1
176176
ZeroDivisionError
177-
b'# test frozen package'
178177
NULL

0 commit comments

Comments
 (0)