CAT-SOOP is a flexible, programmable learning management system based on the Python programming language. https://catsoop.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

setup.py 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. # This file is part of CAT-SOOP
  2. # Copyright (c) 2011-2019 by The CAT-SOOP Developers <catsoop-dev@mit.edu>
  3. #
  4. # This program is free software: you can redistribute it and/or modify it under
  5. # the terms of the GNU Affero General Public License as published by the Free
  6. # Software Foundation, either version 3 of the License, or (at your option) any
  7. # later version.
  8. #
  9. # This program is distributed in the hope that it will be useful, but WITHOUT
  10. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11. # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  12. # details.
  13. #
  14. # You should have received a copy of the GNU Affero General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. #
  17. #
  18. # Portions of this file were forked from the setup.py file for xonsh
  19. # (https://xon.sh/), which is available under the MIT/Expat license.
  20. import os
  21. import sys
  22. import subprocess
  23. from setuptools import setup
  24. from catsoop import __version__ as CS_VERSION, __codename__ as CODENAME
  25. logo = (
  26. "\\ "
  27. "\n/ /\\__/\\ "
  28. "\n\\__=( o_O )="
  29. "\n(__________) "
  30. "\n |_ |_ |_ |_ "
  31. "\n "
  32. "\n CAT-SOOP "
  33. )
  34. VERSION_FNAME = os.path.join(os.path.dirname(__file__), "catsoop", "__init__.py")
  35. ORIGINAL_VERSION = None
  36. def dev_number_git():
  37. try:
  38. last_version = subprocess.check_output(
  39. ["git", "describe", "--tags", "--match", "v*"]
  40. ).decode("ascii")
  41. except Exception:
  42. print("failed to find git tags", file=sys.stderr)
  43. return
  44. try:
  45. _, N, sha = last_version.strip().split("-")
  46. N = int(N)
  47. except ValueError: # tag name may contain "-"
  48. print("failed to parse git version", file=sys.stderr)
  49. return
  50. sha = sha.lstrip("g")
  51. try:
  52. _cmd = ["git", "show", "-s", "--format=%cD", sha]
  53. _date = subprocess.check_output(_cmd)
  54. _date = _date.decode("ascii")
  55. _date = "".join(_date.split(" ", 1)[1:])
  56. except:
  57. _date = ""
  58. print("failed to get git commit date", file=sys.stderr)
  59. return ("Git", sha, N, _date)
  60. def _version_sort(x):
  61. return tuple(map(int, x[1:].split("."))) if x.startswith("v") else (float("-inf"),)
  62. def dev_number_hg():
  63. try:
  64. tags = subprocess.check_output(["hg", "tags"]).decode("ascii")
  65. tags = dict(i.strip().split() for i in tags.splitlines())
  66. tags = {k: v.split(":") for k, v in tags.items()}
  67. except Exception:
  68. print("failed to find hg tags", file=sys.stderr)
  69. return
  70. sha = tags["tip"][1]
  71. N = int(tags["tip"][0]) - int(tags[max(tags, key=_version_sort)][0])
  72. if N <= 1:
  73. return
  74. try:
  75. _cmd = ["hg", "log", "-r", "tip"]
  76. _info = subprocess.check_output(_cmd).decode("ascii")
  77. _info = dict(i.strip().split(" ", 1) for i in _info.strip().splitlines())
  78. _date = _info["date:"].strip()
  79. except Exception:
  80. _date = ""
  81. print("failed to get hg commit date", file=sys.stderr)
  82. return ("Mercurial", sha, N, _date)
  83. def dev_number():
  84. return dev_number_hg() or dev_number_git()
  85. def dirty_version():
  86. """
  87. If install/sdist is run from a git directory, add a devN suffix to reported
  88. version number and write an ignored file that holds info about the current
  89. state of the repo.
  90. """
  91. global CS_VERSION, ORIGINAL_VERSION
  92. dev_num = dev_number()
  93. if not dev_num:
  94. return
  95. vcs, sha, N, _date = dev_num
  96. # if we get to this point, we are not at a particular tag. we'll modify
  97. # the __version__ from catsoop/__init__.py to include a .devN suffix.
  98. CS_VERSION = CS_VERSION + ".dev%s" % (N,)
  99. with open(os.path.join(os.path.dirname(__file__), "catsoop", "dev.hash"), "w") as f:
  100. f.write("{}|{}|{}".format(vcs, sha, _date))
  101. with open(VERSION_FNAME, "r") as f:
  102. ORIGINAL_VERSION = f.read()
  103. with open(VERSION_FNAME, "w") as f:
  104. f.write("__version__ = %r\n" % CS_VERSION)
  105. f.write("__codename__= %r\n" % CODENAME)
  106. def main():
  107. if sys.version_info[:2] < (3, 5):
  108. sys.exit("catsoop currently requires Python 3.5+")
  109. if "--name" not in sys.argv:
  110. print(logo)
  111. with open(os.path.join(os.path.dirname(__file__), "requirements.txt"), "r") as f:
  112. requirements = f.read().split("\n")
  113. with open(os.path.join(os.path.dirname(__file__), "README.md"), "r") as f:
  114. readme = f.read()
  115. try:
  116. dirty_version()
  117. setup(
  118. name="catsoop",
  119. version=CS_VERSION,
  120. author="CAT-SOOP Contributors",
  121. author_email="catsoop-dev@mit.edu",
  122. packages=[
  123. "catsoop",
  124. "catsoop.test",
  125. "catsoop.thirdparty",
  126. "catsoop.scripts",
  127. ],
  128. scripts=[],
  129. url="https://catsoop.org",
  130. license="AGPLv3+",
  131. description="CAT-SOOP is a tool for automatic collection and assessment of online exercises.",
  132. long_description=readme,
  133. long_description_content_type="text/markdown",
  134. include_package_data=True,
  135. entry_points={
  136. "console_scripts": ["catsoop = catsoop.main:command_line_interface"]
  137. },
  138. install_requires=requirements,
  139. package_dir={"catsoop": "catsoop"},
  140. package_data={"catsoop": ["scripts/*"]},
  141. test_suite="catsoop.test",
  142. classifiers=[
  143. "Development Status :: 4 - Beta",
  144. "Intended Audience :: Education",
  145. "License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)",
  146. "Programming Language :: Python :: 3.5",
  147. "Programming Language :: Python :: 3.6",
  148. "Programming Language :: Python :: 3.7",
  149. "Topic :: Education",
  150. "Topic :: Internet :: WWW/HTTP :: WSGI",
  151. ],
  152. )
  153. finally:
  154. if ORIGINAL_VERSION is not None:
  155. with open(VERSION_FNAME, "w") as f:
  156. f.write(ORIGINAL_VERSION)
  157. if __name__ == "__main__":
  158. main()