Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass custom mpi4py communicator #94

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Prev Previous commit
Next Next commit
Further simplification
williamjameshandley committed Feb 28, 2024
commit 178ed1fa6d6fd152796098e3ae6e8b53f0d7da75
27 changes: 7 additions & 20 deletions setup.py
Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@

from setuptools import setup, Extension, find_packages, Distribution
from setuptools.command.build_py import build_py as _build_py
from setuptools.command.develop import develop as _develop
from distutils.command.clean import clean as _clean

import os, sys, subprocess, shutil
@@ -73,7 +72,7 @@ def get_version(short=False):
return line[44:50]


class DistributionWithOption(Distribution):
class DistributionWithOption(Distribution, object):
def __init__(self, *args, **kwargs):
self.global_options = self.global_options \
+ [("no-mpi", None, "Don't compile with MPI support."),
@@ -84,15 +83,16 @@ def __init__(self, *args, **kwargs):

class CustomBuildPy(_build_py):
def run(self):
env = os.environ.copy()
env = {}
env["PATH"] = os.environ["PATH"]
if self.distribution.no_mpi is None:
env["MPI"] = "1"
# These need to be set so that build_ext uses the right compilers
cc_compiler = subprocess.check_output(["make", "print_CC"]).decode('utf-8').strip()
os.environ["CC"] = cc_compiler

cxx_compiler = subprocess.check_output(["make", "print_CXX"]).decode('utf-8').strip()
env["CXX"] = cxx_compiler
os.environ["CXX"] = cxx_compiler
else:
env["MPI"] = "0"

@@ -101,31 +101,19 @@ def run(self):
env["DEBUG"] = "1"

BASE_PATH = os.path.dirname(os.path.abspath(__file__))
env["PWD"] = BASE_PATH
env["CURDIR"] = BASE_PATH
env.update({k : os.environ[k] for k in ["CC", "CXX", "FC"] if k in os.environ})

def compile():
subprocess.call(["make", "-e", "libchord.so"], env=env, cwd=BASE_PATH)

self.execute(compile, [], 'Compiling')
subprocess.check_call(["make", "-e", "libchord.so"], env=env, cwd=BASE_PATH)
if not os.path.isdir("pypolychord/lib/"):
os.makedirs(os.path.join(BASE_PATH, "pypolychord/lib/"))
shutil.copy(os.path.join(BASE_PATH, "lib/libchord.so"),
os.path.join(BASE_PATH, "pypolychord/lib/"))
self.run_command("build_ext")
return super(CustomBuildPy, self).run()


class CustomDevelop(_develop):

def run(self):
self.run_command('build_py')
super(CustomDevelop, self).run()


class CustomClean(_clean):
def run(self):
subprocess.run(["make", "veryclean"], check=True)
subprocess.run(["make", "veryclean"], check=True, env=os.environ)
return super().run()


@@ -165,7 +153,6 @@ def run(self):
distclass=DistributionWithOption,
ext_modules=[pypolychord_module],
cmdclass={'build_py' : CustomBuildPy,
'develop': CustomDevelop,
'clean' : CustomClean},
package_data={NAME: ["lib/libchord.so"]},
include_package_data=True,