Permalink
Browse files

Merge branch 'distutils_compat_layer'

  • Loading branch information...
2 parents d6d9072 + 8dc4ee2 commit 8987a3c2b2762b58a863ed41e9c3761113174bfb @cournape committed Mar 1, 2011
View
@@ -62,6 +62,8 @@ Library:
bento.core,
bento.core.parser,
bento.core.platforms,
+ bento.distutils,
+ bento.distutils.commands,
bento.private,
bentomakerlib
if flag(bundling):
View
@@ -11,6 +11,9 @@
from bento.core.subpackage \
import \
get_extensions, get_compiled_libraries, get_packages
+from bento.core.pkg_objects \
+ import \
+ DataFiles
from bento.commands.core \
import \
@@ -83,7 +86,7 @@ def build_packages(pkg):
build_packages
def build_config_py(pkg):
- return _build_config_py(pkg, ctx.get_paths_scheme())
+ return _build_config_py(pkg, ctx.get_paths_scheme(), ctx.top_node, ctx.build_root)
self.section_writer.sections_callbacks["bentofiles"] = \
build_config_py
self.section_writer.update_sections(ctx.pkg)
@@ -139,23 +142,26 @@ def _build_python_files(pkg, top_node):
return {"library": py_section}
-def _build_config_py(pkg, paths):
+def _build_config_py(pkg, paths, src_root, build_root):
if pkg.config_py is not None:
- tmp_config = os.path.join(BUILD_DIR, "__tmp_config.py")
- fid = open(tmp_config, "w")
+ tmp_config_node = build_root.make_node(os.path.join(pkg.name, "__tmp_config.py"))
+ p = tmp_config_node.parent
+ p.mkdir()
+
+ fid = open(tmp_config_node.abspath(), "w")
try:
for name, value in paths.items():
fid.write('%s = "%s"\n' % (name.upper(), subst_vars(value, paths)))
finally:
fid.close()
- target = os.path.join(os.path.dirname(tmp_config),
- pkg.config_py)
- ensure_dir(target)
- rename(tmp_config, target)
+ target = build_root.make_node(pkg.config_py)
+ target.parent.mkdir()
+ rename(tmp_config_node.abspath(), target.abspath())
section = InstalledSection.from_source_target_directories("bentofiles", "config",
- os.path.join("$_srcrootdir", BUILD_DIR),
- "$sitedir", [pkg.config_py])
+ os.path.join("$_srcrootdir", target.parent.path_from(src_root)),
+ os.path.join("$sitedir", os.path.dirname(pkg.config_py)),
+ [os.path.basename(pkg.config_py)])
return {"bentofiles": section}
else:
return {}
@@ -164,9 +170,11 @@ def build_data_files(pkg):
ret = {}
# Get data files
for name, data_section in pkg.data_files.items():
- data_section.files = data_section.resolve_glob()
- data_section.source_dir = os.path.join("$_srcrootdir", data_section.source_dir)
- ret[name] = InstalledSection.from_data_files(name, data_section)
+ files = data_section.resolve_glob()
+ source_dir = os.path.join("$_srcrootdir", data_section.source_dir)
+ new_data_section = DataFiles(data_section.name, files,
+ data_section.target_dir, source_dir)
+ ret[name] = InstalledSection.from_data_files(name, new_data_section)
return ret
@@ -94,6 +94,7 @@ def __init__(self, cmd, cmd_argv, options_context, pkg, top_node):
self.cmd_argv = cmd_argv
self.top_node = top_node
+ self.build_root = top_node.make_node("build")
self._configured_state = None
View
@@ -17,10 +17,24 @@
"py_modules": lambda pkg: [v for v in pkg.py_modules],
}
-for k in ["name", "version", "summary", "url", "author",
- "author_email", "maintainer", "maintainer_email",
- "license", "description", "download_url"]:
- _PKG_TO_DIST[k] = lambda pkg: getattr(pkg, k)
+_META_PKG_TO_DIST = {}
+def _setup():
+ for k in ["name", "version", "summary", "url", "author",
+ "author_email", "maintainer", "maintainer_email",
+ "license", "description", "download_url"]:
+ def _f(attr):
+ return lambda pkg: getattr(pkg, attr)
+ _META_PKG_TO_DIST[k] = _f(k)
+_setup()
+_PKG_TO_DIST.update(_META_PKG_TO_DIST)
+
+def pkg_to_distutils_meta(pkg):
+ """Obtain meta data information from pkg into a dictionary which may be
+ used directly as an argument for setup function in distutils."""
+ d = {}
+ for k, v in _META_PKG_TO_DIST.items():
+ d[k] = v(pkg)
+ return d
def pkg_to_distutils(pkg):
"""Convert PackageDescription instance to a dict which may be used
View
@@ -87,7 +87,7 @@ def expand_glob(pattern, ref_dir=None):
glob_pattern = pattern
matched = glob.glob(glob_pattern)
if len(matched) < 1:
- raise IOError("no files following pattern %s found" % pattern)
+ raise IOError("no files following pattern %s from %r found" % (pattern, ref_dir))
if ref_dir:
return [relpath(i, ref_dir) for i in matched]
@@ -0,0 +1,2 @@
+# Keep this import: it monkey-patches the distribution class
+import bento.distutils.dist
No changes.
@@ -0,0 +1,38 @@
+import os
+
+from bento.distutils.utils \
+ import \
+ _is_setuptools_activated
+if _is_setuptools_activated():
+ from setuptools.command.bdist_egg \
+ import \
+ bdist_egg as old_bdist_egg
+else:
+ raise ValueError("You cannot use bdist_egg without setuptools enabled first")
+
+from bento._config \
+ import \
+ IPKG_PATH
+from bento.installed_package_description \
+ import \
+ InstalledPkgDescription
+from bento.commands.build_egg \
+ import \
+ build_egg
+
+class bdist_egg(old_bdist_egg):
+ def __init__(self, *a, **kw):
+ old_bdist_egg.__init__(self, *a, **kw)
+
+ def initialize_options(self):
+ old_bdist_egg.initialize_options(self)
+
+ def finalize_options(self):
+ old_bdist_egg.finalize_options(self)
+
+ def run(self):
+
+ build = self.get_finalized_command("build")
+ build.run()
+ ipkg = InstalledPkgDescription.from_file(IPKG_PATH)
+ build_egg(ipkg)
@@ -0,0 +1,57 @@
+import sys
+
+from bento._config \
+ import \
+ IPKG_PATH
+from bento.core.platforms \
+ import \
+ get_scheme
+
+from distutils.command.build \
+ import \
+ build as old_build
+from bento.commands.build \
+ import \
+ SectionWriter, _build_config_py
+
+class build(old_build):
+ def __init__(self, *a, **kw):
+ old_build.__init__(self, *a, **kw)
+
+ def initialize_options(self):
+ old_build.initialize_options(self)
+
+ def finalize_options(self):
+ old_build.finalize_options(self)
+
+ def run(self):
+ dist = self.distribution
+
+ build_root = dist.top_node.make_node(self.build_base)
+ section_writer = SectionWriter()
+
+ def build_packages(pkg):
+ from bento.commands.build import _build_python_files
+ return _build_python_files(dist.pkg, dist.top_node)
+
+ def build_config_py(pkg):
+ install = self.get_finalized_command("install")
+ # FIXME: this should be centralized with other scheme-related stuff
+ scheme = get_scheme(sys.platform)[0]
+ scheme["pkgname"] = pkg.name
+ py_version = sys.version.split()[0]
+ scheme["py_version_short"] = py_version[:3]
+ if hasattr(install, "install_dir"):
+ scheme["sitedir"] = install.install_dir
+ # end of scheme hackish stuff
+
+ return _build_config_py(pkg, scheme, dist.top_node, build_root)
+ section_writer.sections_callbacks["pythonfiles"] = build_packages
+
+ section_writer.sections_callbacks["bentofiles"] = build_config_py
+
+ section_writer.update_sections(dist.pkg)
+ ipkg_path = dist.top_node.make_node(IPKG_PATH)
+ ipkg_path.parent.mkdir()
+
+ section_writer.store(ipkg_path.abspath(), dist.pkg)
@@ -0,0 +1,40 @@
+import os
+import sys
+
+from distutils.command.install_data \
+ import \
+ install_data as old_install_data
+
+from bento._config \
+ import \
+ IPKG_PATH
+from bento.core.platforms \
+ import \
+ get_scheme
+from bento.installed_package_description \
+ import \
+ InstalledPkgDescription, iter_files
+from bento.commands.install \
+ import \
+ copy_installer
+
+class install_data(old_install_data):
+ def __init__(self, *a, **kw):
+ old_install_data.__init__(self, *a, **kw)
+
+ def initialize_options(self):
+ old_install_data.initialize_options(self)
+
+ def finalize_options(self):
+ old_install_data.finalize_options(self)
+
+ def run(self):
+ self.run_command('build')
+
+ ipkg = InstalledPkgDescription.from_file(IPKG_PATH)
+ ipkg.update_paths({"prefix": self.install_dir, "eprefix": self.install_dir})
+
+ file_sections = ipkg.resolve_paths()
+ for kind, source, target in iter_files(file_sections):
+ if kind in ["datafiles"]:
+ copy_installer(source, target, kind)
@@ -0,0 +1,48 @@
+import os
+import sys
+
+from bento.distutils.utils \
+ import \
+ _is_setuptools_activated
+if _is_setuptools_activated():
+ from setuptools.command.install_lib \
+ import \
+ install_lib as old_install_lib
+else:
+ from distutils.command.install_lib \
+ import \
+ install_lib as old_install_lib
+
+from bento._config \
+ import \
+ IPKG_PATH
+from bento.core.platforms \
+ import \
+ get_scheme
+from bento.installed_package_description \
+ import \
+ InstalledPkgDescription, iter_files
+from bento.commands.install \
+ import \
+ copy_installer
+
+class install_lib(old_install_lib):
+ def __init__(self, *a, **kw):
+ old_install_lib.__init__(self, *a, **kw)
+
+ def initialize_options(self):
+ old_install_lib.initialize_options(self)
+
+ def finalize_options(self):
+ old_install_lib.finalize_options(self)
+
+ def run(self):
+ self.run_command('build')
+
+ ipkg = InstalledPkgDescription.from_file(IPKG_PATH)
+ ipkg.update_paths({"sitedir": self.install_dir})
+
+ file_sections = ipkg.resolve_paths()
+ for kind, source, target in iter_files(file_sections):
+ if kind in ["pythonfiles", "bentofiles"]:
+ copy_installer(source, target, kind)
@@ -0,0 +1,47 @@
+import os
+
+from bento.distutils.utils \
+ import \
+ _is_setuptools_activated
+if _is_setuptools_activated():
+ from setuptools.command.sdist \
+ import \
+ sdist as old_sdist
+else:
+ from distutils.command.sdist \
+ import \
+ sdist as old_sdist
+from distutils.filelist \
+ import \
+ FileList
+
+from bento._config \
+ import \
+ BENTO_SCRIPT
+from bento.core.node \
+ import \
+ Node
+from bento.core.package \
+ import \
+ file_list, PackageDescription
+
+class sdist(old_sdist):
+ def __init__(self, *a, **kw):
+ old_sdist.__init__(self, *a, **kw)
+ self.root = Node("", None)
+ self.top = self.root.find_dir(os.getcwd())
+
+ def initialize_options(self):
+ old_sdist.initialize_options(self)
+
+ def finalize_options(self):
+ old_sdist.finalize_options(self)
+
+ def run(self):
+ pkg = PackageDescription.from_file(BENTO_SCRIPT)
+ self.filelist = FileList()
+ self.filelist.files = file_list(pkg, self.top)
+
+ if self.manifest_only:
+ return
+ self.make_distribution()
Oops, something went wrong.

0 comments on commit 8987a3c

Please sign in to comment.