Skip to content

Commit 8a2958e

Browse files
committed
pkg_resources: Support "frozen" resources (in R.py module).
1 parent e1f7510 commit 8a2958e

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

pkg_resources/pkg_resources.py

+25-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
1-
import os
2-
import os.path
1+
import uio
2+
3+
c = {}
34

45
def resource_stream(package, resource):
5-
p = __import__(package)
6-
d = os.path.dirname(p.__file__)
7-
if d[0] != "/":
8-
d = os.getcwd() + "/" + d
9-
return open(d + "/" + resource, "rb")
6+
if package not in c:
7+
try:
8+
if package:
9+
p = __import__(package + ".R", None, None, True)
10+
else:
11+
p = __import__("R")
12+
c[package] = p.R
13+
except ImportError:
14+
if package:
15+
p = __import__(package)
16+
d = p.__path__
17+
else:
18+
d = "."
19+
if d[0] != "/":
20+
import uos
21+
d = uos.getcwd() + "/" + d
22+
c[package] = d + "/"
23+
24+
p = c[package]
25+
if isinstance(p, dict):
26+
return uio.BytesIO(p[resource])
27+
return open(p + resource, "rb")

0 commit comments

Comments
 (0)