Skip to content

Commit bd37778

Browse files
committed
upip: Get rid of FFI dependency, use builtin _os module instead.
Also, delete as many as possible other dependencies (needed functions are just copied into codebase). This will allow to work on static MicroPython builds (including being a first step to support bare-metal ports).
1 parent 1773bc0 commit bd37778

File tree

8 files changed

+37
-507
lines changed

8 files changed

+37
-507
lines changed

upip/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ all:
22

33
# This target prepares snapshot of all dependency modules, for
44
# self-contained install
5-
deps: upip_ffilib.py upip_os.py upip_os_path.py upip_errno.py upip_gzip.py upip_stat.py upip_utarfile.py
5+
deps: upip_errno.py upip_gzip.py upip_utarfile.py
66

77
upip_ffilib.py: ../ffilib/ffilib.py
88
cp $^ $@

upip/metadata.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
srctype = micropython-lib
22
type = module
3-
version = 0.5.9
3+
version = 0.6
44
author = Paul Sokolovsky
5-
extra_modules = upip_ffilib, upip_errno, upip_gzip, upip_os, upip_os_path, upip_stat, upip_utarfile
5+
extra_modules = upip_errno, upip_gzip, upip_utarfile
66
desc = Simple package manager for MicroPython.
77
long_desc = Simple package manager for MicroPython, targetting to be self-hosted (but not yet there). Compatible only with packages without custom setup.py code.

upip/setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
setup(name='micropython-upip',
9-
version='0.5.9',
9+
version='0.6',
1010
description='Simple package manager for MicroPython.',
1111
long_description='Simple package manager for MicroPython, targetting to be self-hosted (but not yet there). Compatible only with packages without custom setup.py code.',
1212
url='https://github.com/micropython/micropython/issues/405',
@@ -15,4 +15,4 @@
1515
maintainer='MicroPython Developers',
1616
maintainer_email='[email protected]',
1717
license='MIT',
18-
py_modules=['upip', 'upip_ffilib', 'upip_errno', 'upip_gzip', 'upip_os', 'upip_os_path', 'upip_stat', 'upip_utarfile'])
18+
py_modules=['upip', 'upip_errno', 'upip_gzip', 'upip_utarfile'])

upip/upip.py

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ def upip_import(mod, sub=None):
1111
return m
1212

1313
sys = upip_import("sys")
14-
os = upip_import("os")
15-
#os.path = upip_import("os.path").path
16-
ospath = upip_import("os", "path")
14+
import _os as os
1715

1816
errno = upip_import("errno")
1917
gzip = upip_import("gzip")
@@ -35,6 +33,35 @@ def upip_import(mod, sub=None):
3533
class NotFoundError(Exception):
3634
pass
3735

36+
def op_split(path):
37+
if path == "":
38+
return ("", "")
39+
r = path.rsplit("/", 1)
40+
if len(r) == 1:
41+
return ("", path)
42+
head = r[0]
43+
if not head:
44+
head = "/"
45+
return (head, r[1])
46+
47+
def op_basename(path):
48+
return op_split(path)[1]
49+
50+
def _makedirs(name, mode=0o777):
51+
ret = False
52+
s = ""
53+
for c in name.rstrip("/").split("/"):
54+
s += c + "/"
55+
try:
56+
os.mkdir(s)
57+
ret = True
58+
except OSError as e:
59+
if e.args[0] != errno.EEXIST:
60+
raise
61+
ret = False
62+
return ret
63+
64+
3865
def save_file(fname, subf):
3966
outf = open(fname, "wb")
4067
while True:
@@ -68,12 +95,8 @@ def install_tar(f, prefix):
6895
if save:
6996
outfname = prefix + fname
7097
if info.type == tarfile.DIRTYPE:
71-
try:
72-
os.makedirs(outfname)
98+
if _makedirs(outfname):
7399
print("Created " + outfname)
74-
except OSError as e:
75-
if e.args[0] != errno.EEXIST:
76-
raise
77100
else:
78101
if debug:
79102
print("Extracting " + outfname)
@@ -163,7 +186,7 @@ def install_pkg(pkg_spec, install_path):
163186
assert len(packages) == 1
164187
package_url = packages[0]["url"]
165188
print("Installing %s %s from %s" % (pkg_spec, latest_ver, package_url))
166-
package_fname = ospath.basename(package_url)
189+
package_fname = op_basename(package_url)
167190
download(package_url, package_fname)
168191

169192
data = gzdecompress(package_fname)

upip/upip_ffilib.py

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

upip/upip_os.py

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

0 commit comments

Comments
 (0)