setup.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. from glob import glob
  2. from os import environ
  3. from setuptools import Extension, find_packages, setup
  4. from setuptools.command.install import install
  5. from subprocess import check_output
  6. ROOT_DIR = "."
  7. SRC_DIR = f"{ROOT_DIR}/src"
  8. CODEC_DIR = f"{SRC_DIR}/codec"
  9. CPY_DIR = f"{ROOT_DIR}/cpython"
  10. INCL_DIR = f"{ROOT_DIR}/include"
  11. EXT_DIR = f"{ROOT_DIR}/ext"
  12. LEXER = "re2c"
  13. PARSER = "lemon"
  14. sources = (
  15. glob(f"{SRC_DIR}/*.c") +
  16. glob(f"{CODEC_DIR}/grammar_*.c") +
  17. glob(f"{CODEC_DIR}/parser_*.c") +
  18. glob(f"{CODEC_DIR}/codec_*.c") +
  19. glob(f"{CPY_DIR}/*.c") +
  20. [
  21. f"{EXT_DIR}/openldap/libraries/liblmdb/mdb.c",
  22. f"{EXT_DIR}/openldap/libraries/liblmdb/midl.c",
  23. f"{EXT_DIR}/xxHash/xxhash.c",
  24. f"{EXT_DIR}/hashmap/hashmap.c",
  25. f"{EXT_DIR}/tpl/src/tpl.c",
  26. f"{EXT_DIR}/log/src/log.c",
  27. ]
  28. )
  29. include_dirs = [
  30. # ROOT_DIR,
  31. INCL_DIR,
  32. f"{INCL_DIR}/codec",
  33. CPY_DIR,
  34. f"{EXT_DIR}/hashmap",
  35. f"{EXT_DIR}/tpl/src",
  36. f"{EXT_DIR}/log/src",
  37. ]
  38. debug = bool(environ.get("DEBUG"))
  39. compile_args = [
  40. "-std=gnu11",
  41. "-Wall",
  42. # "-Wextra",
  43. "-fPIC",
  44. "-MMD",
  45. ]
  46. if debug:
  47. print("Compiling with debug flags.")
  48. compile_args.extend([
  49. "-UNDEBUG", "-U_FORTIFY_SOURCE",
  50. "-DDEBUG", "-g3", "-O1"
  51. ])
  52. else:
  53. compile_args.extend(["-g0", "-O3"])
  54. # with open(path.join(ROOT_DIR, "README.md"), "r") as fh:
  55. # long_description = fh.read()
  56. class LSUPInstallCmd(install):
  57. """
  58. Run LSUP-specific hooks in extension build phase.
  59. TODO Extending the Extension class may be best to narrow the scope to the
  60. C module.
  61. """
  62. def run(self):
  63. print("Generating parsers.")
  64. target = "codec_dbg" if debug else "codec"
  65. print(f"Making {target}.")
  66. check_output(["make", target])
  67. install.run(self)
  68. setup(
  69. name="lsup_rdf",
  70. version="1.0a3",
  71. description="Ultra-compact RDF library.",
  72. # long_description=long_description,
  73. # long_description_content_type="text/markdown",
  74. author="Stefano Cossu <https://git.knowledgetx.com/scossu>",
  75. url="https://git.knowledgetx.com/scossu/lsup_rdf",
  76. license="https://git.knowledgetx.com/scossu/lsup_rdf/src/master/LICENSE",
  77. package_dir={"lsup_rdf": "cpython/lsup_rdf"},
  78. packages=find_packages(where="cpython"),
  79. include_package_data=True,
  80. # cmdclass={"install": LSUPInstallCmd},
  81. classifiers=[
  82. "Development Status :: 3 - Alpha",
  83. "Environment :: Console",
  84. "Intended Audience :: Developers",
  85. "Intended Audience :: Information Technology",
  86. "Intended Audience :: Science/Research",
  87. "Intended Audience :: Telecommunications Industry",
  88. "License :: Public Domain",
  89. "Natural Language :: English",
  90. "Operating System :: POSIX :: BSD",
  91. "Operating System :: POSIX :: Linux",
  92. "Operating System :: POSIX :: Other",
  93. "Programming Language :: C",
  94. "Programming Language :: Python :: 3",
  95. "Programming Language :: Python :: Implementation :: CPython",
  96. "Topic :: Database :: Database Engines/Servers",
  97. "Topic :: Internet",
  98. "Topic :: Scientific/Engineering",
  99. "Topic :: Software Development :: Embedded Systems",
  100. "Topic :: Software Development :: Libraries",
  101. ],
  102. ext_modules=[
  103. Extension(
  104. "_lsup_rdf",
  105. sources,
  106. language="c",
  107. include_dirs=include_dirs,
  108. libraries=["xxhash", "lmdb", "uuid"],
  109. extra_compile_args=compile_args,
  110. ),
  111. ],
  112. python_requires=">=3.8",
  113. )