Skip to content

Commit 29398cf

Browse files
committed
working but needs to be cleaned up
1 parent 58981c2 commit 29398cf

10 files changed

+79
-90
lines changed

Diff for: MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
recursive-include data *
22
recursive-include out/NR_files/ *.dat
33
recursive-include lib/ pygfunc.f90
4+
recursive-include lib/ pygfunc.pyf
45
recursive-include lib/ *.f90
56
recursive-include work/ *
67
recursive-include DOCUMENTATION/ *

Diff for: Makefile

+4-7
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,18 @@ install:
88
sudo python2 setup.py install
99

1010
.PHONY: phantom
11-
phantom: lib/pygfunc.c
12-
python setup.py build_ext --inplace
11+
phantom: lib/pygfunc.pyf
1312

14-
lib/pygfunc.c:
15-
cython -a lib/pygfunc.pyx
1613

1714
.PHONY: dist
18-
dist:
19-
python2 setup.py sdist
15+
dist: phantom
16+
python3 setup.py sdist
2017

2118
.PHONY: upload
2219
upload: dist
2320
twine upload --verbose dist/*
2421

2522
.PHONY: clean
2623
clean:
27-
rm -f *.mod lib/*.o lib/pygfunc.c lib/pygfunc.html pygfunc.so
24+
rm -f *.mod lib/*.o lib/pygfunc.pyf pygfunc.*.so
2825
rm -rf build dist

Diff for: install_phantom.sh

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
4+
pushd lib
5+
6+
# -m is name the module pygfunc
7+
# generates the pygfunc.pyf file
8+
f2py3 pygfunc.f90 -m pygfunc -h pygfunc.pyf
9+
10+
# generates .so file
11+
f2py3 -c pygfunc.pyf write_data_phantom.f90 pygfunc.f90 -m pygfunc
12+
13+
popd

Diff for: lib/io_lib.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import sys
2525
from MESA2HYDRO.lib import converge_funcs as cf
2626
from MESA2HYDRO.lib import hdf5lib
27-
from MESA2HYDRO.lib import pygfunc
27+
import pygfunc
2828

2929
###############################################################
3030
#

Diff for: lib/try.sh

-7
This file was deleted.

Diff for: local_setup.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import sys
5+
import subprocess
6+
7+
################################
8+
9+
PKG_DIR = os.path.abspath(os.path.dirname(__file__))
10+
PYPATH_DIR = os.path.dirname(PKG_DIR)
11+
12+
13+
PYGFUNC_F90_FILE = "lib/pygfunc.f90"
14+
PYGFUNC_PYF_FILE = "lib/pygfunc.pyf"
15+
WRITE_DATA_PHANTOM_F90_FILE = "lib/write_data_phantom.f90"
16+
17+
18+
python_path = os.environ.get('PYTHONPATH') or ''
19+
python_paths = [os.path.abspath(path) for path in python_path.split(':')]
20+
21+
if PYPATH_DIR not in python_paths:
22+
print("{} not in PYTHONPATH, needed for local development of MESA2HYDRO"
23+
.format(PYPATH_DIR))
24+
print("Appending {} to PYTHONPATH in ~/.bashrc".format(PYPATH_DIR))
25+
with open(os.path.expanduser('~/.bashrc'), 'w+') as f:
26+
f.write('# ADDED BY MESA2HYDRO FOR LOCAL DEVELOPMENT')
27+
f.write('export PYTHONPATH=$PYTHONPATH:~/')
28+
29+
subprocess.run("pip install -r requirements.txt", shell=True)
30+
31+
# install fortran locally
32+
subprocess.run('./install_phantom.sh', shell=True)

Diff for: requirements.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
numpy
2+
scipy
3+
matplotlib
4+
healpy
5+
h5py

Diff for: setup.py

+19-71
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
11
#!/usr/bin/env python3
22

3-
from setuptools import setup, find_packages
3+
import os
4+
import sys
45

5-
#import os
6-
#import sys
7-
#import shutil
8-
#import subprocess
9-
#from numpy import get_include, f2py
6+
from numpy.distutils.core import setup, Extension
7+
from numpy import f2py
108

119
################################
1210

11+
VERSION = '0.1.2146'
12+
PYGFUNC_F90_FILE = "lib/pygfunc.f90"
13+
PYGFUNC_PYF_FILE = "lib/pygfunc.pyf"
14+
WRITE_DATA_PHANTOM_F90_FILE = "lib/write_data_phantom.f90"
1315

14-
# TODO: Add "local" option again that adds MESA2HYDRO_ROOT to python path and installs dependencies
16+
if not os.path.exists(PYGFUNC_PYF_FILE):
17+
print("Making {} file".format(PYGFUNC_PYF_FILE))
18+
f2py.run_main([PYGFUNC_F90_FILE, '-m', 'pygfunc', '-h', PYGFUNC_PYF_FILE])
19+
20+
21+
fortran_ext = Extension(
22+
name = 'pygfunc',
23+
sources = [PYGFUNC_PYF_FILE, WRITE_DATA_PHANTOM_F90_FILE, PYGFUNC_F90_FILE]
24+
)
1525

1626
setup(name='MESA2HYDRO',
17-
version='0.1.2146',
27+
version=VERSION,
1828
description=('Convert 1D stellar structure models to 3D particle '
1929
'distributions using the HEALPix spherical tessellation algorithm'),
2030
long_description=('Convert 1D stellar structure models to 3D particle '
@@ -50,67 +60,5 @@
5060
'lib/write_data_phantom.f90',
5161
'lib/pygfunc.f90',
5262
'DOCUMENTATION/*']},
53-
install_requires=['numpy', 'scipy', 'matplotlib', 'healpy', 'h5py', 'setuptools']
63+
ext_modules=[fortran_ext]
5464
)
55-
56-
57-
"""
58-
PKG_DIR = os.path.abspath(os.path.dirname(__file__))
59-
PYGFUNC_F90_FILE = "{}/lib/pygfunc.f90".format(PKG_DIR)
60-
PYGFUNC_PYF_FILE = "{}/lib/pygfunc.pyf".format(PKG_DIR)
61-
WRITE_DATA_PHANTOM_F90_FILE = "{}/lib/write_data_phantom.f90".format(PKG_DIR)
62-
63-
64-
65-
if len(sys.argv) > 2 and sys.argv[1] == 'install':
66-
f2py.run_main([PYGFUNC_F90_FILE, '-m', 'pygfunc', '-h', PYGFUCN_PYF_FILE])
67-
f2py.run_main(['-c', PYGFUNC_PYF_FILE, "--opts='-std=f2003'", WRITE_DATA_PHANTOM_F90_FILE, PYGFUNC_F90_FILE, '-m', 'pygfunc'])
68-
69-
"""
70-
71-
"""
72-
## must explicitly include all f90, h, and pyx files
73-
setup(name='MESA2HYDRO',
74-
scripts=['work/confirm_density_profile.py',
75-
'work/confirm_mass_profile.py',
76-
'work/run_conversion.py',
77-
'uninstall_MESA2HYDRO.py'],
78-
cmdclass={'build_ext': build_ext},
79-
include_dirs=[get_include()],
80-
ext_modules=cythonize(ext_modules, compiler_directives={'language_level': "3"}),
81-
packages=['MESA2HYDRO',
82-
'MESA2HYDRO.work',
83-
'MESA2HYDRO.lib'],
84-
package_dir={'MESA2HYDRO': '',
85-
'MESA2HYDRO.work': 'work',
86-
'MESA2HYDRO.lib': 'lib',
87-
'MESA2HYDRO.data': 'data',
88-
'MESA2HYDRO.out': 'out',
89-
'MESA2HYDRO.DOCUMENTATION': 'DOCUMENTATION'},
90-
91-
package_data={'': ['data/*/*',
92-
'work/*.cfg',
93-
'out/NR_files/*.dat',
94-
'out/sample_MESA_output/*.data',
95-
'lib/write_data_phantom.f90',
96-
'lib/pygfunc.f90',
97-
'DOCUMENTATION/*']},
98-
99-
version='0.1.2146',
100-
description='Convert 1D stellar structure models to 3D particle distributions using the HEALPix spherical tessellation algorithm',
101-
long_description='Convert 1D stellar structure models to 3D particle distributions using the HEALPix spherical tessellation algorithm\
102-
\n\
103-
see academic paper https://iopscience.iop.org/article/10.3847/1538-4357/ab3405/meta\
104-
\n\
105-
and User\'s Guide\
106-
\n\
107-
https://github.com/mjoyceGR/MESA2HYDRO/blob/master/DOCUMENTATION/MESA2HYDRO_users_guide.pdf\n\
108-
for more information',
109-
author='Meridith Joyce',
110-
author_email='[email protected]',
111-
url='https://github.com/mjoyceGR/MESA2HYDRO',
112-
download_url='https://github.com/mjoyceGR/MESA2HYDRO/archive/0.1.0.tar.gz',
113-
keywords=['MESA', 'stellar evolution', 'stellar structure','astronomy', 'stellar modeling','hydrodynamical ICs','HEALPix'],
114-
classifiers=[]
115-
)
116-
"""

Diff for: uninstall_MESA2HYDRO.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python2
1+
#!/usr/bin/python3
22

33
import os
44
import sys
@@ -25,7 +25,7 @@
2525
location = location[:-1]
2626
if not os.path.isfile(location):
2727
continue
28-
result = raw_input("Remove {}(y/N)?".format(location))
28+
result = input("Remove {}(y/N)?".format(location))
2929
if result.upper().startswith("Y"):
3030
try:
3131
os.remove(location)
@@ -56,7 +56,7 @@
5656
print("Skipping {} because doesn't exist".format(location))
5757
continue
5858

59-
result = raw_input("Remove {}?(y/N)".format(location))
59+
result = input("Remove {}?(y/N)".format(location))
6060
if result.upper().startswith("Y"):
6161
try:
6262
if os.path.isdir(location):
@@ -70,7 +70,7 @@
7070

7171
file_path = os.path.abspath(__file__)
7272

73-
result = raw_input("Remove this file ({})?(y/N)".format(file_path))
73+
result = input("Remove this file ({})?(y/N)".format(file_path))
7474
print(result)
7575
if result.upper().startswith("Y"):
7676
try:

Diff for: work/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)