cppyabm  1.0.17
An agent-based library to integrate C++ and Python
setup.py
Go to the documentation of this file.
1 import setuptools
2 import codecs
3 import os.path
4 here = os.path.abspath(os.path.dirname(__file__))
5 def read(rel_path):
6 
7  with codecs.open(os.path.join(here, rel_path), 'r') as fp:
8  return fp.read()
9 
10 
11 def extract_longDiscription(file_name):
12  with open(file_name, "r") as fh:
13  long_description = fh.read()
14  return long_description
15 
16 import os
17 import pathlib
18 
19 from setuptools import setup, Extension
20 from setuptools.command.build_ext import build_ext as build_ext_orig
21 
22 
23 class CMakeExtension(Extension):
24  def __init__(self, name):
25  super().__init__(name, sources=[])
26 
27 
28 class build_ext(build_ext_orig):
29  def run(self):
30  for ext in self.extensions:
31  self.build_cmake(ext)
32  super().run()
33 
34  def build_cmake(self, ext):
35  cwd = pathlib.Path().absolute()
36  build_temp = pathlib.Path(self.build_temp)
37  build_temp.mkdir(parents=True, exist_ok=True)
38  extdir = pathlib.Path(self.get_ext_fullpath(ext.name))
39  extdir.mkdir(parents=True, exist_ok=True)
40  config = 'Debug' if self.debug else 'Release'
41  cmake_args = [
42  '-DPYBIND11=TRUE',# to incorporate pybind11
43  '-DBIND_FLAG=TRUE',# to build for binding
44  '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + str(extdir.parent.absolute()),
45  '-DCMAKE_BUILD_TYPE=' + config
46  ]
47  build_args = [
48  '--config', config,
49  '--', '-j4'
50  ]
51  os.chdir(str(build_temp))
52  self.spawn(['cmake', str(cwd)] + cmake_args)
53  if not self.dry_run:
54  self.spawn(['cmake','--build', '.'] + build_args)
55  os.chdir(str(cwd))
56 
57 setuptools.setup(
58  name="cppyabm",
59  version='1.0.17',
60  author="Jalil Nourisa",
61  author_email="jalil.nourisa@gmail.com",
62  description="General-purpose agent-based modeling framework",
63  long_description=extract_longDiscription("README.md"),
64  long_description_content_type="text/markdown",
65  url="https://github.com/janursa/CppyABM",
66  packages=['cppyabm'],
67  ext_modules=[CMakeExtension('cppyabm/cppyabm')],
68  cmdclass={
69  'build_ext': build_ext,
70  },
71  classifiers=[
72  "Programming Language :: Python :: 3",
73  "License :: OSI Approved :: MIT License",
74  "Operating System :: OS Independent",
75  ],
76  python_requires='>=3.6'
77 )
setup.build_ext.run
def run(self)
Definition: setup.py:29
setup.extract_longDiscription
def extract_longDiscription(file_name)
Definition: setup.py:11
setup.build_ext
Definition: setup.py:28
setup.read
def read(rel_path)
Definition: setup.py:5
setup.build_ext.build_cmake
def build_cmake(self, ext)
Definition: setup.py:34
setup.CMakeExtension
Definition: setup.py:23
str
Definition: pytypes.h:946
setup.CMakeExtension.__init__
def __init__(self, name)
Definition: setup.py:24