setup.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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", "-DDEBUG", "-D_FORTIFY_SOURCE=0", "-g3", "-O0"
  47. ])
  48. else:
  49. compile_args.extend(["-g0", "-O3"])
  50. # with open(path.join(ROOT_DIR, "README.md"), "r") as fh:
  51. # long_description = fh.read()
  52. class LSUPInstallCmd(install):
  53. """
  54. Run LSUP-specific hooks in extension build phase.
  55. TODO Extending the Extension class may be best to narrow the scope to the
  56. C module.
  57. """
  58. def run(self):
  59. print("Generating parsers.")
  60. target = "codec_dbg" if debug else "codec"
  61. print(f"Making {target}.")
  62. check_output(["make", target])
  63. install.run(self)
  64. setup(
  65. name="lsup_rdf",
  66. version="1.0a5",
  67. description="Ultra-compact RDF library.",
  68. # long_description=long_description,
  69. # long_description_content_type="text/markdown",
  70. author="Stefano Cossu <https://git.knowledgetx.com/scossu>",
  71. url="https://git.knowledgetx.com/scossu/lsup_rdf",
  72. license="https://git.knowledgetx.com/scossu/lsup_rdf/src/master/LICENSE",
  73. package_dir={"lsup_rdf": "cpython/lsup_rdf"},
  74. packages=find_packages(where="cpython"),
  75. include_package_data=True,
  76. # cmdclass={"install": LSUPInstallCmd},
  77. classifiers=[
  78. "Development Status :: 3 - Alpha",
  79. "Environment :: Console",
  80. "Intended Audience :: Developers",
  81. "Intended Audience :: Information Technology",
  82. "Intended Audience :: Science/Research",
  83. "Intended Audience :: Telecommunications Industry",
  84. "License :: CC-PDDC",
  85. "Natural Language :: English",
  86. "Operating System :: POSIX :: BSD",
  87. "Operating System :: POSIX :: Linux",
  88. "Operating System :: POSIX :: Other",
  89. "Programming Language :: C",
  90. "Programming Language :: Python :: 3",
  91. "Programming Language :: Python :: Implementation :: CPython",
  92. "Topic :: Database :: Database Engines/Servers",
  93. "Topic :: Internet",
  94. "Topic :: Scientific/Engineering",
  95. "Topic :: Software Development :: Embedded Systems",
  96. "Topic :: Software Development :: Libraries",
  97. ],
  98. ext_modules=[
  99. Extension(
  100. "_lsup_rdf",
  101. sources,
  102. language="c",
  103. include_dirs=include_dirs,
  104. libraries=["xxhash", "lmdb", "uuid"],
  105. extra_compile_args=compile_args,
  106. ),
  107. ],
  108. python_requires=">=3.8",
  109. )