Skip to content

Commit 9390bd0

Browse files
committed
micropython-lib: Update to master, split target package
The package has been reworked to install the same files that are available to be downloaded/installed by mip, the package manager new to MicroPython 1.20.0. This also splits the original target package into four: * micropython-lib * Includes packages common to all MicroPython ports (python-stdlib, python-ecosys, micropython) * Contains mpy bytecode files * micropython-lib-src * Includes packages common to all MicroPython ports (python-stdlib, python-ecosys, micropython) * Contains py source files * micropython-lib-unix * Includes packages specific to the MicroPython Unix port (unix-ffi) * Contains mpy bytecode files * Installs a specific launcher (micropython-unix) that adds the Unix package directory into MicroPython's library path * micropython-lib-unix-src * Includes packages specific to the MicroPython Unix port (unix-ffi) * Contains py source files This also updates the package license, title, and description. Patches: * 001-build-unix-ffi.patch This enables the repo build script to also build the Unix-specific packages. Not sure if upstream is open to accepting this since the Unix-specific packages don't fit well into the existing package distribution mechanism. * 002-add-unix-ffi-os-path.patch and 003-add-unix-ffi-uu.patch These fix instances where the unix-ffi version of the os package is overridden by the python-stdlib version. These have been submitted to upstream: micropython/micropython-lib#672 Signed-off-by: Jeffery To <jeffery.to@gmail.com>
1 parent a4ae384 commit 9390bd0

File tree

6 files changed

+291
-16
lines changed

6 files changed

+291
-16
lines changed

lang/python/micropython-lib/Makefile

Lines changed: 99 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,125 @@ PKG_RELEASE:=1
1212

1313
PKG_SOURCE_PROTO:=git
1414
PKG_SOURCE_URL:=https://github.com/micropython/micropython-lib.git
15-
PKG_SOURCE_VERSION:=db4c739863e49fc874bdaae8aa8c316c7ed4276a
16-
PKG_SOURCE_DATE:=20220506
17-
PKG_MIRROR_HASH:=ec4be91755fcd4d4fa61e1e7eadc748377ba63b82b7bb4254864473fafcd3173
15+
PKG_SOURCE_VERSION:=7128d423c2e7c0309ac17a1e6ba873b909b24fcc
16+
PKG_SOURCE_DATE:=20230522
17+
PKG_MIRROR_HASH:=1f094aac257d2094ee91b457164f845f6461df1cf1d0ed7ee556c98f273f5afb
1818

1919
PKG_MAINTAINER:=Jeffery To <jeffery.to@gmail.com>
20-
PKG_LICENSE:=MIT PSF-2.0
20+
PKG_LICENSE:=MIT Python-2.0.1
2121
PKG_LICENSE_FILES:=LICENSE
2222

23+
PKG_BUILD_DEPENDS:=python3/host
2324
PKG_BUILD_PARALLEL:=1
2425

26+
# keep in sync with micropython
27+
MP_VERSION:=1.20.0
28+
MP_MPY_FILE_VERSION:=6
29+
2530
include $(INCLUDE_DIR)/package.mk
2631

27-
define Package/micropython-lib
32+
define Package/micropython-lib/Default
2833
SUBMENU:=Python
2934
SECTION:=lang
3035
CATEGORY:=Languages
31-
TITLE:=micropython-lib
36+
TITLE:=MicroPython package repository
3237
URL:=https://github.com/micropython/micropython-lib
38+
endef
39+
40+
define Package/micropython-lib
41+
$(call Package/micropython-lib/Default)
3342
DEPENDS:=+micropython
3443
endef
3544

45+
define Package/micropython-lib-src
46+
$(call Package/micropython-lib/Default)
47+
TITLE+= (sources)
48+
endef
49+
50+
define Package/micropython-lib-unix
51+
$(call Package/micropython-lib/Default)
52+
TITLE+= - Unix port packages
53+
DEPENDS:=+micropython +libpcre +librt +libsqlite3
54+
endef
55+
56+
define Package/micropython-lib-unix-src
57+
$(call Package/micropython-lib/Default)
58+
TITLE+= - Unix port packages (sources)
59+
endef
60+
61+
define Package/micropython-lib/Default/description
62+
This is a repository of packages designed to be useful for writing
63+
MicroPython applications.
64+
endef
65+
3666
define Package/micropython-lib/description
37-
This is a repository of libraries designed to be useful for writing
38-
MicroPython applications.
67+
$(call Package/micropython-lib/Default/description)
68+
69+
This contains packages common to all MicroPython ports.
70+
endef
71+
72+
define Package/micropython-lib-src/description
73+
$(call Package/micropython-lib/Default/description)
74+
75+
This contains source files for packages common to all MicroPython ports.
76+
endef
77+
78+
define Package/micropython-lib-unix/description
79+
$(call Package/micropython-lib/Default/description)
80+
81+
This contains packages specific to the MicroPython Unix port.
82+
endef
83+
84+
define Package/micropython-lib-unix-src/description
85+
$(call Package/micropython-lib/Default/description)
86+
87+
This contains source files for packages specific to the MicroPython Unix
88+
port.
89+
endef
90+
91+
MP_INSTALLDEV_PATH:=$(STAGING_DIR)/host/lib/micropython-$(MP_VERSION)
92+
93+
define MicroPythonLib/Compile
94+
cd "$(PKG_BUILD_DIR)" && python3 tools/build.py \
95+
--hash-prefix 64 \
96+
--micropython "$(MP_INSTALLDEV_PATH)" \
97+
--mpy-cross "$(MP_INSTALLDEV_PATH)/mpy-cross/build/mpy-cross" \
98+
--output "$(PKG_BUILD_DIR)/$(strip $(1))" \
99+
$(2)
100+
endef
101+
102+
define MicroPythonLib/Install
103+
python3 install.py \
104+
--input "$(PKG_BUILD_DIR)/$(strip $(1))" \
105+
--output "$(strip $(3))" \
106+
--version "$(strip $(2))"
39107
endef
40108

41-
Build/Compile:=:
109+
define Build/Compile
110+
$(call MicroPythonLib/Compile)
111+
$(call MicroPythonLib/Compile,unix-ffi-index,--unix-ffi)
112+
endef
42113

43114
define Package/micropython-lib/install
44-
for dir in micropython python-ecosys python-stdlib unix-ffi; do \
45-
$(INSTALL_DIR) $(1)/usr/lib/micropython/$$$$dir ; \
46-
$(CP) $(PKG_BUILD_DIR)/$$$$dir/* $(1)/usr/lib/micropython/$$$$dir/ ; \
47-
done
48-
$(FIND) $(1)/usr/lib/micropython \
49-
-not -type d \( -not -name '*.py' -o -name 'test_*' -o -name 'setup.py' \) -delete
50-
$(FIND) $(1)/usr/lib/micropython -mindepth 1 -empty -type d -delete
115+
$(call MicroPythonLib/Install,,$(MP_MPY_FILE_VERSION),$(1)/usr/lib/micropython)
116+
endef
117+
118+
define Package/micropython-lib-src/install
119+
$(call MicroPythonLib/Install,,py,$(1)/usr/lib/micropython)
120+
endef
121+
122+
define Package/micropython-lib-unix/install
123+
$(call MicroPythonLib/Install,unix-ffi-index,$(MP_MPY_FILE_VERSION),$(1)/usr/lib/micropython/unix)
124+
125+
$(INSTALL_DIR) $(1)/usr/bin
126+
$(INSTALL_BIN) ./files/micropython-unix $(1)/usr/bin/
127+
endef
128+
129+
define Package/micropython-lib-unix-src/install
130+
$(call MicroPythonLib/Install,unix-ffi-index,py,$(1)/usr/lib/micropython/unix)
51131
endef
52132

53133
$(eval $(call BuildPackage,micropython-lib))
134+
$(eval $(call BuildPackage,micropython-lib-src))
135+
$(eval $(call BuildPackage,micropython-lib-unix))
136+
$(eval $(call BuildPackage,micropython-lib-unix-src))
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
export MICROPYPATH=".frozen:~/.micropython/lib:/usr/lib/micropython/unix:/usr/lib/micropython"
3+
exec micropython "$@"
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Copyright (C) 2023 Jeffery To
4+
#
5+
# This is free software, licensed under the GNU General Public License v2.
6+
# See /LICENSE for more information.
7+
#
8+
9+
import json
10+
import os
11+
import re
12+
import shutil
13+
import sys
14+
15+
16+
def install(input_path, mpy_version, output_path):
17+
index_json_path = os.path.join(input_path, "index.json")
18+
files = {}
19+
20+
with open(index_json_path) as f:
21+
index_json = json.load(f)
22+
23+
for p in index_json["packages"]:
24+
package_name = p["name"]
25+
package_json_path = os.path.join(input_path, "package", mpy_version, package_name, "latest.json")
26+
27+
with open(package_json_path) as f:
28+
package_json = json.load(f)
29+
30+
for file_name, file_hash in package_json["hashes"]:
31+
if file_name in files:
32+
if file_hash != files[file_name]:
33+
print("File name/hash collision:", package_name, file=sys.stderr)
34+
print(" File: ", file_name, file=sys.stderr)
35+
print(" Curent hash: ", file_hash, file=sys.stderr)
36+
print(" Previous hash: ", files[file_name], file=sys.stderr)
37+
sys.exit(1)
38+
else:
39+
files[file_name] = file_hash
40+
41+
for file_name, file_hash in files.items():
42+
in_file_path = os.path.join(input_path, "file", file_hash[:2], file_hash)
43+
out_file_path = os.path.join(output_path, file_name)
44+
45+
os.makedirs(os.path.dirname(out_file_path), exist_ok=True)
46+
shutil.copy2(in_file_path, out_file_path)
47+
48+
49+
def main():
50+
import argparse
51+
52+
cmd_parser = argparse.ArgumentParser(description="Install compiled micropython-lib packages.")
53+
cmd_parser.add_argument("--input", required=True, help="input directory")
54+
cmd_parser.add_argument("--version", required=True, help="mpy version to install")
55+
cmd_parser.add_argument("--output", required=True, help="output directory")
56+
args = cmd_parser.parse_args()
57+
58+
install(args.input, args.version, args.output)
59+
60+
61+
if __name__ == "__main__":
62+
main()
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
--- a/tools/build.py
2+
+++ b/tools/build.py
3+
@@ -284,7 +284,7 @@ def _update_index_package_metadata(index
4+
index_package_json["versions"][v].append(metadata.version)
5+
6+
7+
-def build(output_path, hash_prefix_len, mpy_cross_path):
8+
+def build(output_path, unix_ffi, hash_prefix_len, mpy_cross_path):
9+
import manifestfile
10+
import mpy_cross
11+
12+
@@ -310,7 +310,7 @@ def build(output_path, hash_prefix_len,
13+
14+
# For now, don't process unix-ffi. In the future this can be extended to
15+
# allow a way to request unix-ffi packages via mip.
16+
- lib_dirs = ["micropython", "python-stdlib", "python-ecosys"]
17+
+ lib_dirs = ["unix-ffi"] if unix_ffi else ["micropython", "python-stdlib", "python-ecosys"]
18+
19+
mpy_version, _mpy_sub_version = mpy_cross.mpy_version(mpy_cross=mpy_cross_path)
20+
mpy_version = str(mpy_version)
21+
@@ -438,6 +438,7 @@ def main():
22+
23+
cmd_parser = argparse.ArgumentParser(description="Compile micropython-lib for serving to mip.")
24+
cmd_parser.add_argument("--output", required=True, help="output directory")
25+
+ cmd_parser.add_argument("--unix-ffi", action="store_true", help="process unix-ffi packages")
26+
cmd_parser.add_argument("--hash-prefix", default=8, type=int, help="hash prefix length")
27+
cmd_parser.add_argument("--mpy-cross", default=None, help="optional path to mpy-cross binary")
28+
cmd_parser.add_argument("--micropython", default=None, help="path to micropython repo")
29+
@@ -447,7 +448,7 @@ def main():
30+
sys.path.append(os.path.join(args.micropython, "tools")) # for manifestfile
31+
sys.path.append(os.path.join(args.micropython, "mpy-cross")) # for mpy_cross
32+
33+
- build(args.output, hash_prefix_len=max(4, args.hash_prefix), mpy_cross_path=args.mpy_cross)
34+
+ build(args.output, args.unix_ffi, hash_prefix_len=max(4, args.hash_prefix), mpy_cross_path=args.mpy_cross)
35+
36+
37+
if __name__ == "__main__":
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
From dcce62dd525cf0f8e572e56a8990aea7ec2f0ade Mon Sep 17 00:00:00 2001
2+
From: Jeffery To <jeffery.to@gmail.com>
3+
Date: Tue, 30 May 2023 23:47:59 +0800
4+
Subject: [PATCH] unix-ffi/os-path: Add unix-ffi version of `os-path` package.
5+
6+
This package reuses the code from the python-stdlib version of `os-path`
7+
but requires the unix-ffi version of `os`.
8+
9+
This also updates `glob` to require this version of `os-path`.
10+
11+
Signed-off-by: Jeffery To <jeffery.to@gmail.com>
12+
---
13+
unix-ffi/glob/manifest.py | 2 +-
14+
unix-ffi/os-path/manifest.py | 6 ++++++
15+
unix-ffi/os/os/__init__.py | 6 ++++++
16+
3 files changed, 13 insertions(+), 1 deletion(-)
17+
create mode 100644 unix-ffi/os-path/manifest.py
18+
19+
--- a/unix-ffi/glob/manifest.py
20+
+++ b/unix-ffi/glob/manifest.py
21+
@@ -1,7 +1,7 @@
22+
metadata(version="0.5.2")
23+
24+
require("os", unix_ffi=True)
25+
-require("os-path")
26+
+require("os-path", unix_ffi=True)
27+
require("re", unix_ffi=True)
28+
require("fnmatch")
29+
30+
--- /dev/null
31+
+++ b/unix-ffi/os-path/manifest.py
32+
@@ -0,0 +1,6 @@
33+
+metadata(version="0.1.4")
34+
+
35+
+# Originally written by Paul Sokolovsky.
36+
+
37+
+require("os", unix_ffi=True)
38+
+package("os", base_path="../../python-stdlib/os-path")
39+
--- a/unix-ffi/os/os/__init__.py
40+
+++ b/unix-ffi/os/os/__init__.py
41+
@@ -5,6 +5,12 @@ import stat as stat_
42+
import ffilib
43+
import uos
44+
45+
+# Provide optional dependencies (which may be installed separately).
46+
+try:
47+
+ from . import path
48+
+except ImportError:
49+
+ pass
50+
+
51+
R_OK = const(4)
52+
W_OK = const(2)
53+
X_OK = const(1)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
From 2e7bfd08a306bd9e80b22097ef8fe66e1dd85054 Mon Sep 17 00:00:00 2001
2+
From: Jeffery To <jeffery.to@gmail.com>
3+
Date: Wed, 31 May 2023 00:00:11 +0800
4+
Subject: [PATCH] unix-ffi/uu: Add unix-ffi version of `uu` package.
5+
6+
This package reuses the code from the python-stdlib version of `uu` but
7+
requires the unix-ffi version of `os-path`.
8+
9+
This also updates `email.message` to require this version of `uu`.
10+
11+
Signed-off-by: Jeffery To <jeffery.to@gmail.com>
12+
---
13+
unix-ffi/email.message/manifest.py | 2 +-
14+
unix-ffi/uu/manifest.py | 6 ++++++
15+
2 files changed, 7 insertions(+), 1 deletion(-)
16+
create mode 100644 unix-ffi/uu/manifest.py
17+
18+
--- a/unix-ffi/email.message/manifest.py
19+
+++ b/unix-ffi/email.message/manifest.py
20+
@@ -1,7 +1,7 @@
21+
metadata(version="0.5.3")
22+
23+
require("re", unix_ffi=True)
24+
-require("uu")
25+
+require("uu", unix_ffi=True)
26+
require("base64")
27+
require("binascii")
28+
require("email.utils", unix_ffi=True)
29+
--- /dev/null
30+
+++ b/unix-ffi/uu/manifest.py
31+
@@ -0,0 +1,6 @@
32+
+metadata(version="0.5.1")
33+
+
34+
+require("binascii")
35+
+require("os-path", unix_ffi=True)
36+
+
37+
+module("uu.py", base_path="../../python-stdlib/uu")

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy