diff --git a/setup.py b/setup.py
index 8edaea1..83daa18 100644
--- a/setup.py
+++ b/setup.py
@@ -7,6 +7,7 @@ from distutils.core import setup, Extension
# --with-zlib=
: path to zlib if needed
# --with-libmemcached=: path to libmemcached package if needed
+cmd = None
use_zlib = True
pkgdirs = [] # incdirs and libdirs get these
libs = ["memcached"]
@@ -23,6 +24,8 @@ for arg in sys.argv[1:]:
elif arg == "--without-zlib":
use_zlib = False
continue
+ elif arg == "--gen-setup":
+ cmd = arg[2:]
elif "=" in arg:
if arg.startswith("--with-libmemcached=") or \
arg.startswith("--with-zlib="):
@@ -43,6 +46,17 @@ pylibmc_ext = Extension("_pylibmc", ["_pylibmcmodule.c"],
libraries=libs, include_dirs=incdirs,
library_dirs=libdirs, define_macros=defs)
+# Hidden secret: if environment variable GEN_SETUP is set, generate Setup file.
+if cmd == "gen-setup":
+ line = " ".join((
+ pylibmc_ext.name,
+ " ".join("-l" + lib for lib in pylibmc_ext.libraries),
+ " ".join("-I" + incdir for incdir in pylibmc_ext.include_dirs),
+ " ".join("-L" + libdir for libdir in pylibmc_ext.library_dirs),
+ " ".join("-D" + name + ("=" + str(value), "")[value is None] for (name, value) in pylibmc_ext.define_macros)))
+ open("Setup", "w").write(line + "\n")
+ sys.exit(0)
+
readme_text = open("README.rst", "U").read()
version = open("pylibmc-version.h", "U").read().strip().split("\"")[1]
diff --git a/tests.py b/tests.py
index 35a7b56..adb5872 100644
--- a/tests.py
+++ b/tests.py
@@ -339,7 +339,10 @@ class TestProgram(unittest.TestProgram):
return runner.run(self.test)
if __name__ == "__main__":
- print "Starting tests with _pylibmc at", _pylibmc.__file__
+ if hasattr(_pylibmc, "__file__"):
+ print "Starting tests with _pylibmc at", _pylibmc.__file__
+ else:
+ print "Starting tests with static _pylibmc:", _pylibmc
print "Reported libmemcached version:", _pylibmc.libmemcached_version
print "Reported pylibmc version:", _pylibmc.__version__
print "Support compression:", _pylibmc.support_compression