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

Allow building ESMPy with setuptools/pip #49

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/addon/ESMPy/doc/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,13 @@ with the following command issued from the top level ESMPy directory:

.. code::

python setup.py build --ESMFMKFILE=<DIR_TO_esmf.mk>/esmf.mk install
ESMFMKFILE=<DIR_TO_esmf.mk>/esmf.mk python -m pip install .

- custom install location:

.. code::

python setup.py build --ESMFMKFILE=<DIR_TO_esmf.mk>/esmf.mk

python setup.py install --prefix=<custom_install_location>
ESMFMKFILE=<DIR_TO_esmf.mk>/esmf.mk python -m pip install . --prefix=<custom_install_location>

setenv PYTHONPATH <custom_install_location>/lib/\*/site_packages

Expand Down
26 changes: 18 additions & 8 deletions src/addon/ESMPy/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import os
import sys
from distutils.core import setup, Command
from setuptools import setup
from distutils.core import Command
from distutils.util import get_platform
from distutils.command.build import build as _build
import subprocess


Expand All @@ -25,9 +27,11 @@ class AbstractESMFCommand(Command):
user_options = []

def initialize_options(self):
super().initialize_options()
self.cwd = None

def finalize_options(self):
super().finalize_options()
self.cwd = os.getcwd()

def _validate_(self):
Expand Down Expand Up @@ -76,12 +80,13 @@ def nosetests_command(cls):
return ret


class BuildCommand(AbstractESMFCommand):
class BuildCommand(AbstractESMFCommand, _build):
description = "build: will build the ESMF package"
user_options = [('ESMFMKFILE=', 'e',
"Location of esmf.mk for the ESMF installation")]

def initialize_options(self):
super().initialize_options()
self.cwd = None
self.ESMFMKFILE = None
SITEDIR = os.system('%s -m site --user-site' % sys.executable)
Expand All @@ -90,6 +95,7 @@ def initialize_options(self):
self.plat_name = None

def finalize_options(self):
super().finalize_options()
self.cwd = os.getcwd()
if isinstance(self.ESMFMKFILE, type(None)):
self.ESMFMKFILE = os.getenv('ESMFMKFILE')
Expand All @@ -98,19 +104,19 @@ def finalize_options(self):
if isinstance(self.plat_name, type(None)):
self.plat_name = get_platform()

if self.ESMFMKFILE is None:
raise NameError("ESMFMKFILE environment variable is not set")

def run(self):
super().run()
assert os.getcwd() == self.cwd, 'Must be in package root: %s' % self.cwd

# Create "esmfmkfile.py" file holding the path to the ESMF "esmf.mk" file
if not isinstance(self.ESMFMKFILE, type(None)):
f = open(os.path.join('src', 'ESMF', 'interface', 'esmfmkfile.py'), 'w')
f = open(os.path.join(self.build_lib, 'ESMF', 'interface', 'esmfmkfile.py'), 'w')
f.write('ESMFMKFILE = "%s"' % self.ESMFMKFILE)
f.close()

# Attempt to load ESMF.
update_system_path()
import ESMF.interface.loadESMF


class CleanCommand(AbstractESMFCommand):
description = "clean: will remove all libraries, log and output files"
Expand Down Expand Up @@ -275,4 +281,8 @@ def _get_dot_(path, root='src'):
'test_regrid_from_file': TestRegridFromFileCommand,
'test_regrid_from_file_dryrun': TestRegridFromFileDryrunCommand,
'test_regrid_parallel': TestRegridParallelCommand,
'test_regrid_from_file_parallel': TestRegridFromFileParallelCommand})
'test_regrid_from_file_parallel': TestRegridFromFileParallelCommand},
install_requires=[
"numpy",
],
)