python-efl/setup_eolian.py

255 lines
7.9 KiB
Python
Executable File

#! /usr/bin/env python
# encoding: utf-8
import os
import sys
import subprocess
from distutils.core import setup, Command
from distutils.extension import Extension
from distutils.version import StrictVersion, LooseVersion
from efl2 import __version__ as vers
script_path = os.path.dirname(os.path.abspath(__file__))
# python-efl version (change in efl/__init__.py)
vers = vers.split(".")
RELEASE = "%s.%s.%s" % (vers[0], vers[1], vers[2])
VERSION = "%s.%s" % (vers[0], vers[1] if int(vers[2]) < 99 else int(vers[1]) + 1)
# dependencies
CYTHON_MIN_VERSION = "0.19"
EFL_MIN_VERSION = RELEASE
ELM_MIN_VERSION = RELEASE
# Add git commit count for dev builds
if vers[2] == 99:
try:
call = subprocess.Popen(
["git", "log", "--oneline"], stdout=subprocess.PIPE)
out, err = call.communicate()
except Exception:
RELEASE += "a0"
else:
log = out.decode("utf-8").strip()
if log:
ver = log.count("\n")
RELEASE += "a" + str(ver)
else:
RELEASE += "a0"
# XXX: Force default visibility. See phab T504
if os.getenv("CFLAGS") is not None and "-fvisibility=" in os.environ["CFLAGS"]:
os.environ["CFLAGS"] += " -fvisibility=default"
# === Sphinx ===
try:
from sphinx.setup_command import BuildDoc
except ImportError:
class BuildDoc(Command):
description = \
"build documentation using sphinx, that must be installed."
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
print("Error: sphinx not found")
# === pkg-config ===
def pkg_config(lib_human_name, lib_system_name, min_vers=None):
try:
sys.stdout.write("Checking for " + lib_human_name + ": ")
call = subprocess.Popen(
["pkg-config", "--modversion", lib_system_name], stdout=subprocess.PIPE)
out, err = call.communicate()
ver = out.decode("utf-8").strip()
if min_vers is not None:
assert 0 == subprocess.call(
["pkg-config", "--atleast-version", min_vers, lib_system_name])
call = subprocess.Popen(
["pkg-config", "--cflags-only-I", lib_system_name], stdout=subprocess.PIPE)
out, err = call.communicate()
cflags = out.decode("utf-8").split()
call = subprocess.Popen(
["pkg-config", "--libs", lib_system_name], stdout=subprocess.PIPE)
out, err = call.communicate()
libs = out.decode("utf-8").split()
sys.stdout.write("OK, found " + ver + "\n")
cflags = list(set(cflags))
return (cflags, libs)
except (OSError, subprocess.CalledProcessError):
raise SystemExit("Did not find " + lib_human_name + " with 'pkg-config'.")
except (AssertionError):
raise SystemExit(
lib_human_name + " version mismatch. Found: " + ver + " Needed: " + min_vers
)
# use cython or pre-generated c files
if os.getenv("DISABLE_CYTHON"):
module_suffix = ".c"
from distutils.command.build_ext import build_ext
def cythonize(modules, *args, **kwargs):
return modules
else:
try:
from Cython.Distutils import build_ext
from Cython.Build import cythonize
import Cython.Compiler.Options
except ImportError:
if not os.path.exists(os.path.join(script_path, "eolian/__init__.c")):
raise SystemExit(
"Requires Cython >= %s (http://cython.org/)" % (
CYTHON_MIN_VERSION
)
)
module_suffix = ".c"
from distutils.command.build_ext import build_ext
def cythonize(modules, *args, **kwargs):
return modules
else:
module_suffix = ".pyx"
try:
try:
assert StrictVersion(Cython.__version__) >= \
StrictVersion(CYTHON_MIN_VERSION)
except ValueError:
print("""
Your Cython version string (%s) is weird. We'll attempt to
check that it's higher than the minimum required: %s, but
this is unreliable.\n
If you run into any problems during or after installation it
may be caused by version of Cython that's too old.""" % (
Cython.__version__, CYTHON_MIN_VERSION
)
)
assert LooseVersion(Cython.__version__) >= \
LooseVersion(CYTHON_MIN_VERSION)
except AssertionError:
raise SystemExit(
"Requires Cython >= %s (http://cython.org/)" % (
CYTHON_MIN_VERSION
)
)
Cython.Compiler.Options.fast_fail = True # Stop compilation on first
# error
Cython.Compiler.Options.annotate = False # Generates HTML files with
# annotated source
Cython.Compiler.Options.docstrings = True # Set to False to disable
# docstrings
class CleanGenerated(Command):
description = "Clean C and html files generated by Cython"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
for lib in ("eo", "evas", "ecore", "edje", "edje/edit", "emotion",
"elementary", "utils"):
for root, dirs, files in \
os.walk(os.path.join(script_path, "efl", lib)):
for f in files:
if f.endswith(".c") or f.endswith(".html"):
path = os.path.join(root, f)
os.remove(path)
dbus_ml_path = os.path.join(
script_path, "efl", "dbus_mainloop", "dbus_mainloop.c")
if os.path.exists(dbus_ml_path):
os.remove(dbus_ml_path)
modules = []
packages = []
# === Eina ===
eina_cflags, eina_libs = pkg_config('Eina', 'eina', EFL_MIN_VERSION)
TOP_LEVEL_PACKAGE = "eolian"
# === Eolian ===
header_name = "Eolian"
library_name = "eolian"
eol_cflags, eol_libs = pkg_config(header_name, library_name, EFL_MIN_VERSION)
modules.append(
Extension(
"eolian.__init__", ["eolian/__init__" + module_suffix],
define_macros=[('EFL_BETA_API_SUPPORT', None)],
#include_dirs=['include/'],
extra_compile_args=eol_cflags + eina_cflags,
extra_link_args=eol_libs + eina_libs
)
)
modules.append(
Extension(
"eolian.logger", ["eolian/logger" + module_suffix],
include_dirs=['include/'],
extra_compile_args=eina_cflags,
extra_link_args=eina_libs,
),
)
packages.append("eolian")
setup(
name="python-eolian",
fullname="Python bindings for Enlightenment Foundation Libraries' Eolian",
description="Python bindings for Enlightenment Foundation Libraries' Eolian",
version=RELEASE,
author=(
"Kai Huuhko"
),
author_email="kai.huuhko@gmail.com",
maintainer="Kai Huuhko",
maintainer_email="kai.huuhko@gmail.com",
contact="Enlightenment developer mailing list",
contact_email="enlightenment-devel@lists.sourceforge.net",
url="http://www.enlightenment.org",
license="GNU Lesser General Public License (LGPL)",
cmdclass={
'build_ext': build_ext,
# 'build_doc': BuildDoc,
'clean_generated_files': CleanGenerated
},
# command_options={
# 'build_doc': {
# 'version': ('setup.py', VERSION),
# 'release': ('setup.py', RELEASE)
# }
# },
#package_dir=package_dirs,
#scripts=["scripts/eolian_py"],
packages=packages,
#ext_package="eolian", # The prefix for ext modules/packages
ext_modules=cythonize(
modules,
include_path=["include"],
compiler_directives={
#"c_string_type": "unicode",
#"c_string_encoding": "utf-8",
"embedsignature": True,
}
),
)