setup.py 3.4 KB

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