"""P4Python - Python interface to Perforce API Perforce is the fast SCM system at www.perforce.com. This package provides a simple interface from Python wrapping the Perforce C++ API to gain performance and ease of coding. Similar to interfaces available for Ruby and Perl. """ classifiers = """\ Development Status :: 5 - Production/Stable Intended Audience :: Developers License :: Freely Distributable Programming Language :: Python Topic :: Software Development :: Libraries :: Python Modules Topic :: Software Development :: Version Control Topic :: Software Development Topic :: Utilities Operating System :: Microsoft :: Windows Operating System :: Unix """ # Seems to work fine with ActiveState Python2.3 or 2.4 and Linux # Customisations needed to use to build: # 1. Set directory for p4api # 2. On other platforms, set appropriate compile flags # See notes in P4API documentation for building with API on different # platforms: # http://www.perforce.com/perforce/doc.042/manuals/p4api/02_clientprog.html from distutils.core import setup, Extension import ConfigParser import os, sys, re # Fix for older versions of Python if sys.version_info < (2, 3): _setup = setup def setup(**kwargs): if kwargs.has_key("classifiers"): del kwargs["classifiers"] _setup(**kwargs) # Extract version string from Version file - needs to be float. def get_p4_api_ver(p4_api_dir): pat = re.compile("RELEASE\s+=\s+(\d+)\s+(\d+)") # Handle 2007.2 api dir substructure and previous flat structure ver_file = os.path.join(p4_api_dir, "sample", "Version") if not os.path.exists(ver_file): ver_file = os.path.join(p4_api_dir, "Version") input = open(ver_file) for line in input: match = pat.match(line) if match: dir = match.group(1) result = "P4_API_VER=%s.%s" % (match.group(1), match.group(2)) input.close() return result doclines = __doc__.split("\n") NAME = "P4Python" VERSION = "1.0" PY_MODULES = ["p4"] P4_API_DIR = "p4api" P4_API_VER = "unknown" DESCRIPTION=doclines[0] AUTHOR="Robert Cowham" MAINTAINER="Robert Cowham" AUTHOR_EMAIL="robert@vaccaperna.co.uk" MAINTAINER_EMAIL="robert@vaccaperna.co.uk" LICENSE="http://public.perforce.com/guest/robert_cowham/perforce/API/python/main/LICENSE.txt" URL="http://public.perforce.com/guest/robert_cowham/perforce/API/python/index.html" KEYWORDS="Perforce perforce" P4_CONFIG_SECTION="p4python_config" P4_CONFIG_P4APIDIR="p4_api" def do_setup(): config = ConfigParser.ConfigParser() config.read('setup.cfg') p4_api_dir = None if config.has_section(P4_CONFIG_SECTION): if config.has_option(P4_CONFIG_SECTION, P4_CONFIG_P4APIDIR): p4_api_dir = config.get(P4_CONFIG_SECTION, P4_CONFIG_P4APIDIR) if not p4_api_dir: print "Error: %s section in setup.cfg needs option %s set to the directory containing the perforce API!" % ( P4_CONFIG_SECTION, P4_CONFIG_P4APIDIR) sys.exit(100) p4_api_ver = get_p4_api_ver(p4_api_dir) inc_path = [p4_api_dir, os.path.join(p4_api_dir, "include", "p4")] lib_path = [p4_api_dir, os.path.join(p4_api_dir, "lib")] if os.name == "nt": setup(name=NAME, version=VERSION, description=DESCRIPTION, author=AUTHOR, author_email=AUTHOR_EMAIL, maintainer=MAINTAINER, maintainer_email=MAINTAINER_EMAIL, license=LICENSE, url=URL, keywords=KEYWORDS, classifiers = filter(None, classifiers.split("\n")), long_description = "\n".join(doclines[2:]), py_modules=PY_MODULES, ext_modules=[Extension("P4Client", ["P4Clientmodule.cc"], include_dirs=inc_path, library_dirs=lib_path, libraries=["oldnames", "wsock32", "advapi32", # MSVC libs "libclient", "librpc", "libsupp"], # P4API libs extra_compile_args=["/DOS_NT", "/DMT", "/DCASE_INSENSITIVE", "/D%s" % p4_api_ver], # DEBUG options # extra_compile_args=["/DOS_NT", "/DMT", "/DCASE_INSENSITIVE", "/Od", '/Z7', '/D_DEBUG'], extra_link_args=["/NODEFAULTLIB:libcmt"], # extra_link_args=["/NODEFAULTLIB:libcmt", "/DEBUG"], )]) else: # Assume Linux setup(name=NAME, version=VERSION, description=DESCRIPTION, author=AUTHOR, author_email=AUTHOR_EMAIL, maintainer=MAINTAINER, maintainer_email=MAINTAINER_EMAIL, license=LICENSE, url=URL, keywords=KEYWORDS, classifiers = filter(None, classifiers.split("\n")), long_description = "\n".join(doclines[2:]), py_modules=PY_MODULES, ext_modules=[Extension("P4Client", ["P4Clientmodule.cc"], include_dirs=inc_path, library_dirs=lib_path, libraries=["client", "rpc", "supp"], # P4API libs extra_compile_args=["-DOS_LINUX", "-D%s" % p4_api_ver], )]) if __name__ == "__main__": do_setup()