Skip to content

Commit

Permalink
An attempt to get Python binding to work better
Browse files Browse the repository at this point in the history
using changes from PR AcademySoftwareFoundation#624 by mottosso.
  • Loading branch information
bsilvaLS committed Dec 6, 2019
1 parent f6c6b57 commit e3253f7
Showing 1 changed file with 48 additions and 42 deletions.
90 changes: 48 additions & 42 deletions src/rez/bind/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
"""
from __future__ import absolute_import
from rez.bind._utils import check_version, find_exe, extract_version, \
make_dirs, log, run_python_command
make_dirs, log #, run_python_command
from rez.package_maker__ import make_package
from rez.system import system
from rez.utils.lint_helper import env
from rez.utils.platform_ import platform_
from rez.vendor.version.version import Version
import shutil
import os.path
# from rez.utils.lint_helper import env
# from rez.utils.platform_ import platform_
# from rez.vendor.version.version import Version
# import shutil
# import os.path


def setup_parser(parser):
Expand All @@ -20,70 +20,76 @@ def setup_parser(parser):


def commands():
env.PATH.append('{this.root}/bin')
# env.PATH.append('{this.root}/bin')
global alias
alias("python", "{this.exe}")


def post_commands():
# these are the builtin modules for this python executable. If we don't
# include these, some python behavior can be incorrect.
import os, os.path
# def post_commands():
# # these are the builtin modules for this python executable. If we don't
# # include these, some python behavior can be incorrect.
# import os, os.path

path = os.path.join(this.root, "python")
for dirname in os.listdir(path):
path_ = os.path.join(path, dirname)
env.PYTHONPATH.append(path_)
# path = os.path.join(this.root, "python")
# for dirname in os.listdir(path):
# path_ = os.path.join(path, dirname)
# env.PYTHONPATH.append(path_)


def bind(path, version_range=None, opts=None, parser=None):
# find executable, determine version
exepath = find_exe("python", opts.exe)
code = "import sys; print('.'.join(str(x) for x in sys.version_info))"
if platform.system ==
# code = "import sys; print('.'.join(str(x) for x in sys.version_info))"
code = "import sys;print('.'.join(str(x) for x in sys.version_info))"
version = extract_version(exepath, ["-c", code])

check_version(version, version_range)
log("binding python: %s" % exepath)

# find builtin modules
builtin_paths = {}
entries = [("lib", "os"),
("extra", "setuptools")]
# # find builtin modules
# builtin_paths = {}
# entries = [("lib", "os"),
# ("extra", "setuptools")]

for dirname, module_name in entries:
success, out, err = run_python_command([
"import %s" % module_name,
"print(%s.__file__)" % module_name])
# for dirname, module_name in entries:
# success, out, err = run_python_command([
# "import %s" % module_name,
# "print(%s.__file__)" % module_name])

if success:
pypath = os.path.dirname(out)
if os.path.basename(pypath) == module_name:
pypath = os.path.dirname(pypath)
# if success:
# pypath = os.path.dirname(out)
# if os.path.basename(pypath) == module_name:
# pypath = os.path.dirname(pypath)

if pypath not in builtin_paths.values():
builtin_paths[dirname] = pypath
# if pypath not in builtin_paths.values():
# builtin_paths[dirname] = pypath

# make the package
#

def make_root(variant, root):
binpath = make_dirs(root, "bin")
link = os.path.join(binpath, "python")
platform_.symlink(exepath, link)

if builtin_paths:
pypath = make_dirs(root, "python")
for dirname, srcpath in builtin_paths.items():
destpath = os.path.join(pypath, dirname)
log("Copying builtins from %s to %s..." % (srcpath, destpath))
shutil.copytree(srcpath, destpath)
# binpath = make_dirs(root, "bin")
# link = os.path.join(binpath, "python")
# platform_.symlink(exepath, link)

# if builtin_paths:
# pypath = make_dirs(root, "python")
# for dirname, srcpath in builtin_paths.items():
# destpath = os.path.join(pypath, dirname)
# log("Copying builtins from %s to %s..." % (srcpath, destpath))
# shutil.copytree(srcpath, destpath)
make_dirs(root, "python")

with make_package("python", path, make_root=make_root) as pkg:
pkg.version = version
pkg.tools = ["python"]
pkg.commands = commands
pkg.variants = [system.variant]

if builtin_paths:
pkg.post_commands = post_commands
# if builtin_paths:
# pkg.post_commands = post_commands
pkg.exe = exepath

return pkg.installed_variants

Expand Down

0 comments on commit e3253f7

Please sign in to comment.