setup.py 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. from typing import TextIO, List, Sequence, Union
  4. def python_version_check(major: int = 3, minor: int = 7):
  5. """description"""
  6. import sys
  7. assert sys.version_info.major == major and sys.version_info.minor >= minor, (
  8. f"This project is utilises language features only present Python {major}.{minor} and greater. "
  9. f"You are running {sys.version_info}."
  10. )
  11. python_version_check()
  12. from pathlib import Path
  13. import re
  14. from setuptools import find_packages, setup
  15. def read_reqs(file: str, path: Path) -> List[str]:
  16. """description"""
  17. def readlines_ignore_comments(f: TextIO):
  18. """description"""
  19. return [a_ for a_ in f.readlines() if "#" not in a_ and a_]
  20. def recursive_flatten_ignore_str(seq: Sequence) -> Sequence:
  21. """description"""
  22. if not seq: # is empty Sequence
  23. return seq
  24. if isinstance(seq[0], str):
  25. return seq
  26. if isinstance(seq[0], Sequence):
  27. return (
  28. *recursive_flatten_ignore_str(seq[0]),
  29. *recursive_flatten_ignore_str(seq[1:]),
  30. )
  31. return (*seq[:1], *recursive_flatten_ignore_str(seq[1:]))
  32. def unroll_nested_reqs(req_str: str, base_path: Path) -> Sequence:
  33. """description"""
  34. if req_str.startswith("-r"):
  35. with open(base_path / req_str.strip("-r").strip()) as f:
  36. return [
  37. unroll_nested_reqs(req.strip(), base_path)
  38. for req in readlines_ignore_comments(f)
  39. ]
  40. else:
  41. return (req_str,)
  42. requirements_group = []
  43. with open(str(path / file)) as f:
  44. requirements = readlines_ignore_comments(f)
  45. for requirement in requirements:
  46. requirements_group.extend(
  47. recursive_flatten_ignore_str(
  48. unroll_nested_reqs(requirement.strip(), path)
  49. )
  50. )
  51. req_set = set(requirements_group)
  52. req_set.discard("")
  53. return list(req_set)
  54. with open(Path(__file__).parent / "draugr" / "__init__.py", "r") as project_init_file:
  55. content = project_init_file.read() # get strings from module
  56. version = re.search(r"__version__ = ['\"]([^'\"]*)['\"]", content, re.M).group(1)
  57. project_name = re.search(r"__project__ = ['\"]([^'\"]*)['\"]", content, re.M).group(
  58. 1
  59. )
  60. author = re.search(r"__author__ = ['\"]([^'\"]*)['\"]", content, re.M).group(1)
  61. __author__ = author
  62. class DraugrPackage:
  63. @property
  64. def test_dependencies(self) -> list:
  65. return read_reqs(
  66. "requirements_tests.txt", Path(__file__).parent / "requirements"
  67. )
  68. @property
  69. def setup_dependencies(self) -> list:
  70. """description"""
  71. return read_reqs(
  72. "requirements_setup.txt", Path(__file__).parent / "requirements"
  73. )
  74. @property
  75. def package_name(self) -> str:
  76. """description"""
  77. return project_name
  78. @property
  79. def url(self) -> str:
  80. """description"""
  81. return "https://github.com/pything/draugr"
  82. @property
  83. def download_url(self) -> str:
  84. """description"""
  85. return f"{self.url}/releases"
  86. @property
  87. def readme_type(self) -> str:
  88. """description"""
  89. return "text/markdown"
  90. @property
  91. def packages(self) -> List[Union[bytes, str]]:
  92. """description"""
  93. return find_packages(
  94. exclude=[
  95. # 'Path/To/Exclude'
  96. ]
  97. )
  98. @property
  99. def author_name(self) -> str:
  100. """description"""
  101. return author
  102. @property
  103. def author_email(self) -> str:
  104. """description"""
  105. return "christian.heider@alexandra.dk"
  106. @property
  107. def maintainer_name(self) -> str:
  108. """description"""
  109. return self.author_name
  110. @property
  111. def maintainer_email(self) -> str:
  112. """description"""
  113. return self.author_email
  114. @property
  115. def package_data(self) -> dict:
  116. """description"""
  117. emds = [str(p) for p in Path(__file__).parent.rglob(".md")]
  118. return {"draugr": [*emds]}
  119. @property
  120. def entry_points(self) -> dict:
  121. """description"""
  122. return {
  123. "console_scripts": [
  124. # "name_of_executable = module.with:function_to_execute"
  125. "draugr-darkmode-toggle = draugr.entry_points.toggle_darkmode:main",
  126. "draugr-tb = draugr.entry_points.tensorboard_entry_point:main",
  127. "draugr-cpu = draugr.entry_points.cpu_usage_entry_point:main",
  128. "draugr-vis = draugr.entry_points.visdom_entry_point:main",
  129. ]
  130. }
  131. @property
  132. def extras(self) -> dict:
  133. """description"""
  134. these_extras = {
  135. # 'ExtraName':['package-name; platform_system == "System(Linux,Windows)"'
  136. }
  137. path: Path = Path(__file__).parent / "requirements"
  138. for file in path.iterdir():
  139. if file.name.startswith("requirements_"):
  140. group_name_ = "_".join(file.name.strip(".txt").split("_")[1:])
  141. these_extras[group_name_] = read_reqs(file.name, path)
  142. all_dependencies = []
  143. for group_name in these_extras:
  144. all_dependencies += these_extras[group_name]
  145. these_extras["all"] = list(set(all_dependencies))
  146. return these_extras
  147. @property
  148. def requirements(self) -> list:
  149. """description"""
  150. return read_reqs("requirements.txt", Path(__file__).parent)
  151. @property
  152. def description(self) -> str:
  153. """description"""
  154. return "A package for plotting directly in your terminal"
  155. @property
  156. def readme(self) -> str:
  157. """description"""
  158. with open("README.md", encoding="utf8") as f:
  159. return f.read()
  160. @property
  161. def changelog(self) -> str:
  162. """description"""
  163. with open("CHANGELOG.md") as f:
  164. return f.read()
  165. @property
  166. def keyword(self) -> str:
  167. """description"""
  168. with open("KEYWORDS.md") as f:
  169. return f.read()
  170. @property
  171. def license(self) -> str:
  172. """description"""
  173. return "Apache License, Version 2.0"
  174. @property
  175. def classifiers(self) -> List[str]:
  176. """description"""
  177. return [
  178. "Development Status :: 4 - Beta",
  179. "Environment :: Console",
  180. "Intended Audience :: End Users/Desktop",
  181. "Intended Audience :: Developers",
  182. "License :: OSI Approved :: Apache Software License",
  183. "Operating System :: MacOS :: MacOS X",
  184. "Operating System :: Microsoft :: Windows",
  185. "Operating System :: POSIX",
  186. "Operating System :: OS Independent",
  187. "Programming Language :: Python :: 3",
  188. "Natural Language :: English",
  189. # 'Topic :: Scientific/Engineering :: Artificial Intelligence'
  190. # 'Topic :: Software Development :: Bug Tracking',
  191. ]
  192. @property
  193. def version(self) -> str:
  194. """description"""
  195. return version
  196. if __name__ == "__main__":
  197. pkg = DraugrPackage()
  198. setup(
  199. name=pkg.package_name,
  200. version=pkg.version,
  201. packages=pkg.packages,
  202. package_data=pkg.package_data,
  203. author=pkg.author_name,
  204. author_email=pkg.author_email,
  205. maintainer=pkg.maintainer_name,
  206. maintainer_email=pkg.maintainer_email,
  207. description=pkg.description,
  208. license=pkg.license,
  209. keywords=pkg.keyword,
  210. url=pkg.url,
  211. download_url=pkg.download_url,
  212. install_requires=pkg.requirements,
  213. extras_require=pkg.extras,
  214. setup_requires=pkg.setup_dependencies,
  215. entry_points=pkg.entry_points,
  216. classifiers=pkg.classifiers,
  217. long_description_content_type=pkg.readme_type,
  218. long_description=pkg.readme,
  219. tests_require=pkg.test_dependencies,
  220. include_package_data=True,
  221. python_requires=">=3.6",
  222. )