Skip to content

Commit 267fd1c

Browse files
committed
base: Replace __file__ with pkgutil
`__file__` is an optional attribute which isnt available in zipapps and PyOxidizer. Use pkgutil.get_data instead. Closes pypi#25
1 parent 66938c5 commit 267fd1c

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

stdlib_list/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
from ._version import get_versions
2+
23
__version__ = get_versions()['version']
34
del get_versions
45

56
# Import all the things that used to be in here for backwards-compatibility reasons
6-
from .base import stdlib_list, in_stdlib, get_canonical_version, short_versions, long_versions, base_dir, list_dir
7+
from .base import (
8+
stdlib_list,
9+
in_stdlib,
10+
get_canonical_version,
11+
short_versions,
12+
long_versions,
13+
)

stdlib_list/base.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
from __future__ import print_function, absolute_import
22

33
import os
4+
import pkgutil
45
import sys
56

67
try:
78
from functools import lru_cache
89
except ImportError:
910
from functools32 import lru_cache
1011

11-
base_dir = os.path.dirname(os.path.realpath(__file__))
12-
13-
list_dir = os.path.join(base_dir, "lists")
14-
1512
long_versions = ["2.6.9", "2.7.9", "3.2.6", "3.3.6", "3.4.3", "3.5", "3.6",
1613
"3.7", "3.8"]
1714

@@ -45,10 +42,11 @@ def stdlib_list(version=None):
4542
version = get_canonical_version(version) if version is not None else '.'.join(
4643
str(x) for x in sys.version_info[:2])
4744

48-
module_list_file = os.path.join(list_dir, "{}.txt".format(version))
45+
module_list_file = os.path.join("lists", "{}.txt".format(version))
46+
47+
data = pkgutil.get_data("stdlib_list", module_list_file).decode()
4948

50-
with open(module_list_file) as f:
51-
result = [y for y in [x.strip() for x in f.readlines()] if y]
49+
result = [y for y in [x.strip() for x in data.splitlines()] if y]
5250

5351
return result
5452

0 commit comments

Comments
 (0)