Skip to content

Commit

Permalink
For non-/System builds of DB, include the entire Python Standard Libr…
Browse files Browse the repository at this point in the history
…ary. Implements #127 (#156)
  • Loading branch information
justvanrossum authored and typemytype committed Dec 22, 2017
1 parent f261437 commit 8763595
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import py2app
from distutils.core import setup
from distutils.sysconfig import get_python_lib
import os
import sys
import subprocess
import shutil
import datetime
import re
from plistlib import readPlist, writePlist

from fontTools.misc.py23 import PY3
Expand All @@ -17,6 +19,58 @@
timeStamp = rawTimeStamp.strftime("%y%m%d%H%M")


_identifierPat = re.compile("[A-Za-z_][A-Za-z_0-9]*$")
def _isIdentifier(s):
return _identifierPat.match(s) is not None

def _findModules(root, extensions, skip, parent=""):
for fileName in os.listdir(root):
if fileName in skip:
continue
path = os.path.join(root, fileName)
if os.path.isdir(path):
if _isIdentifier(fileName) and os.path.exists(os.path.join(path, "__init__.py")):
if parent:
packageName = parent + "." + fileName
else:
packageName = fileName
for module in _findModules(path, extensions, skip, packageName):
yield module
elif not parent:
for module in _findModules(path, extensions, skip, ""):
yield module
elif "." in fileName:
moduleName, ext = fileName.split(".", 1)
if ext in extensions and _isIdentifier(moduleName):
if parent and moduleName == "__init__":
yield parent
elif parent:
yield parent + "." + moduleName
else:
yield moduleName

def getStdLibModules():
versionDict = dict(major=sys.version_info.major, minor=sys.version_info.minor)
stdLibPath = get_python_lib(standard_lib=True)
isSystemPython = stdLibPath.startswith("/System/")
extensions = {"py"}
if PY3:
extensions.add("cpython-%s%sm-darwin.so" % (sys.version_info.major, sys.version_info.minor))
else:
extensions.add("so")
skip = {"site-packages", "test", "turtledemo", "tkinter", "idlelib", "lib2to3"}
return list(_findModules(stdLibPath, extensions, skip)), isSystemPython


stdLibModules, isSystemPython = getStdLibModules()
if isSystemPython:
# We use the Python Standard Library from /System, so no need to include anything extra
stdLibIncludes = []
else:
# non-/System Python, we should include the entire Python Standard Library
stdLibIncludes = stdLibModules


def getValueFromSysArgv(key, default=None, isBooleanFlag=False):
if key in sys.argv:
try:
Expand Down Expand Up @@ -122,7 +176,7 @@ def getValueFromSysArgv(key, default=None, isBooleanFlag=False):
includes=[
# 'csv',
# 'this'
],
] + stdLibIncludes,
excludes=[
"numpy",
"scipy",
Expand Down

0 comments on commit 8763595

Please sign in to comment.