Skip to content

Commit

Permalink
build in package dir with default gfortran
Browse files Browse the repository at this point in the history
doc
  • Loading branch information
scivision committed Jun 30, 2019
1 parent 13a283e commit da3a170
Show file tree
Hide file tree
Showing 15 changed files with 98 additions and 139 deletions.
7 changes: 3 additions & 4 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@ image:
- Visual Studio 2017
- ubuntu1804

stack: python 3
stack: python 3.7

environment:
MINGW_DIR: C:\mingw-w64\x86_64-7.2.0-posix-seh-rt_v5-rev1\mingw64\bin
PY_DIR: C:\Python37-x64

clone_depth: 3
clone_depth: 25

build: off

init:
- cmd: set PATH=%MINGW_DIR%;%PATH%
- cmd: set PATH=%PY_DIR%;%PY_DIR%\Scripts;%PATH%

install:
- pip install -e .[tests]
install: pip install -e .[tests]

test_script: pytest -rsv

3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length = 132
exclude = .git,__pycache__,.eggs/,doc/,docs/,build/,dist/,archive/
15 changes: 12 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ group: travis_latest
dist: xenial

git:
depth: 3
depth: 25
quiet: true

python:
Expand All @@ -18,15 +18,24 @@ addons:
matrix:
include:
- os: linux
name: Integration install
python: 3.7
install:
- python setup.py install
- pip install $(basename $TRAVIS_REPO_SLUG)[tests,full]
script:
- cd $HOME
- python -m pytest $TRAVIS_BUILD_DIR/tests
- os: linux
name: PEP8 MyPy Coverage
python: 3.7
install: pip install -e .[tests,cov]
script:
- flake8
- mypy . --ignore-missing-imports
- mypy .
after_success:
- pytest --cov
- coveralls
# travis osx image issue
# - os: osx
# language: minimal
# before_install: brew install gcc
Expand Down
1 change: 0 additions & 1 deletion LICENSE → LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

57 changes: 28 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[![Zenodo DOI](https://zenodo.org/badge/32971905.svg)](https://zenodo.org/badge/latestdoi/32971905)
[![Travis-CI](https://travis-ci.org/scivision/msise00.svg)](https://travis-ci.org/scivision/msise00)

[![Build Status](https://travis-ci.com/space-physics/msise00.svg?branch=master)](https://travis-ci.com/space-physics/msise00)
[![Coverage](https://coveralls.io/repos/scivision/msise00/badge.svg?branch=master&service=github)](https://coveralls.io/github/scivision/msise00?branch=master)
[![Build status](https://ci.appveyor.com/api/projects/status/g58w79defiiiu6j6?svg=true)](https://ci.appveyor.com/project/scivision/msise00)
[![Maintainability](https://api.codeclimate.com/v1/badges/f6f206d6f6605bcf435d/maintainability)](https://codeclimate.com/github/scivision/msise00/maintainability)
[![Build status](https://ci.appveyor.com/api/projects/status/oje6aax4lx4tcryt?svg=true)](https://ci.appveyor.com/project/scivision/msise00)
[![Python versions (PyPI)](https://img.shields.io/pypi/pyversions/msise00.svg)](https://pypi.python.org/pypi/msise00)
[![PyPi Download stats](http://pepy.tech/badge/msise00)](http://pepy.tech/project/msise00)

Expand All @@ -23,42 +23,36 @@ This plot is from [Matlab](./tests/test_msise00_matlab.m) calling MSISE00:
## Install

This process is used for the Python and [Matlab](#matlab) access to MSIS.
Any Fortran compiler should work.
Fortran compiler may be installed by

1. Any Fortran compiler should work. Fortran compiler may be installed by

* Mac: `brew install gcc`
* Linux: `apt install gfortran`
* [Windows](https://www.scivision.co/windows-gcc-gfortran-cmake-make-install/)
* Mac: `brew install gcc`
* Linux: `apt install gfortran`
* [Windows](https://www.scivision.dev/windows-gcc-gfortran-cmake-make-install/)

2. get MSISE00 and install Python package
Get MSISE00 and install Python package

```sh
git clone https://github.com/scivision/msise00

cd msise00
```sh
python3 -m pip install msise00
```

python3 -m pip install -e .
```
3. one-time compilation step requires either CMake or Meson (details below).
Or if you wish to install the latest development version:

```sh
python3 -c "import msise00; msise00.build()"
```
```sh
git clone https://github.com/scivision/msise00

### CMake install
cd msise00

* Linux: Download/build/install Cmake 3 using [cmake_setup.sh](https://github.com/scivision/cmake-utils)
* Mac: `brew install cmake` or use [.dmg installer](https://cmake.org/download/)
* Windows: use Windows [win64-x64 installer](https://cmake.org/download/)
python3 -m pip install -e .
```

### Meson install
The Fortran code will automatically compile on first import.
If you need to recompile manually, use:

```sh
python3 -m pip install meson
python3 -c "import msise00; msise00.build()"
```

extract [Ninja](https://github.com/ninja-build/ninja/releases) and put it on your system path.

## Examples

MSISE00 can be used from the command line, as an imported module, and even from Matlab.
Expand Down Expand Up @@ -88,18 +82,22 @@ Simple examples include:


* Altitude Profile at a single time:

```sh
MSISE00.py -t 2017-08-21T20:48 -c 40 -90
```
* Alt. profile time-range with hourly time step:

```sh
MSISE00.py -t 2017-08-21 2017-08-22 -c 40 -90
```
* Grid: time,lat,lon: generates the plots in the README:

```sh
MSISE00.py -t 2016-09-20 2016-09-21
```
* single time lat/lon can be plotted:

```sh
MSISE00.py -t 2017-01-02T12
```
Expand All @@ -112,6 +110,7 @@ Matlab and GNU Octave users can seamlessly access Python modules, as demonstrate

1. Install MSISe00 by running [setup.m](./matlab/setup.m) from within Matlab or Octave
2. From Matlab, verify everything is working by from the `msise00/` directory:

```matlab
runtests('tests')
```
Expand All @@ -127,9 +126,9 @@ Time utilities of general interest include:

The MSISE00 Fortran source code may also be used directly.
We have provided for easy code reuse in
[CMake](./src/CMakeLists.txt)
[CMake](./CMakeLists.txt)
and
[Meson](./src/meson.build)
[Meson](./meson.build)
projects.

## Reference
Expand Down
9 changes: 2 additions & 7 deletions cmake/compilers.cmake
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
if(CMAKE_BUILD_TYPE STREQUAL Debug)
add_compile_options(-g -O0)
else()
add_compile_options(-O3)
endif()

if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU)
list(APPEND FFLAGS -mtune=native -Wall)#-Wextra -Wpedantic)
if(CMAKE_BUILD_TYPE STREQUAL Debug)
list(APPEND FFLAGS -ffpe-trap=invalid,zero,overflow)
endif()
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL Intel)
list(APPEND FFLAGS -warn)

elseif(CMAKE_Fortran_COMPILER_ID STREQUAL PGI)

elseif(CMAKE_Fortran_COMPILER_ID STREQUAL Flang)
list(APPEND FFLAGS -Mallocatable=03)

elseif(CMAKE_Fortran_COMPILER_ID STREQUAL NAG)

endif()
4 changes: 4 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
project('msise00', 'fortran',
default_options : ['default_library=static', 'buildtype=release'])

subdir('src')
10 changes: 4 additions & 6 deletions msise00/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,16 @@
from typing import Union, List
from pathlib import Path
import io
import os
import shutil

from .timeutils import todatetime
from .build import build

import geomagindices as gi

R = Path(__file__).resolve().parents[1] / 'build'
EXE = R / 'msise00_driver'
if os.name == 'nt':
EXE = EXE.with_suffix('.exe')
if not EXE.is_file():
R = Path(__file__).resolve().parent
EXE = shutil.which('msise00_driver', path=str(R))
if not EXE:
build()

species = ['He', 'O', 'N2', 'O2', 'Ar', 'Total', 'H', 'N', 'AnomalousO']
Expand Down
76 changes: 17 additions & 59 deletions msise00/build.py
Original file line number Diff line number Diff line change
@@ -1,70 +1,28 @@
"""
A generic, clean way to build C/C++/Fortran code from setup.py or manually
Michael Hirsch, Ph.D.
https://www.scivision.dev
"""
import subprocess
import shutil
from pathlib import Path
import subprocess
import os
from typing import List

R = Path(__file__).resolve().parents[1]
BINDIR = R / 'build'
SRCDIR = R / 'src'
R = Path(__file__).parent
RS = R.parent / 'src'

SOURCES = list(map(str, [RS/'nrlmsise00_sub.for', RS/'msise00_driver.f90']))
EXE_OPT = ['-o', str(R/'msise00_driver')]

def build():
"""
attempts build with Meson or CMake
"""
try:
meson_setup()
except (FileNotFoundError, RuntimeError):
cmake_setup()


def cmake_setup():
def build(sources: List[str] = SOURCES,
compiler: str = 'gfortran',
exe_opt: List[str] = EXE_OPT):
"""
attempt to build using CMake >= 3
Attempt to compile code instead of using setup.py
"""
cmake_exe = shutil.which('cmake')
if not cmake_exe:
raise FileNotFoundError('CMake not available')

wopts = ['-G', 'MinGW Makefiles', '-DCMAKE_SH="CMAKE_SH-NOTFOUND'] if os.name == 'nt' else []

subprocess.check_call([cmake_exe] + wopts + [str(SRCDIR)],
cwd=BINDIR)

ret = subprocess.run([cmake_exe, '--build', str(BINDIR)],
stderr=subprocess.PIPE,
universal_newlines=True)

result(ret)


def meson_setup():
"""
attempt to build with Meson + Ninja
"""
meson_exe = shutil.which('meson')
ninja_exe = shutil.which('ninja')

if not meson_exe or not ninja_exe:
raise FileNotFoundError('Meson or Ninja not available')

if not (BINDIR / 'build.ninja').is_file():
subprocess.check_call([meson_exe, str(SRCDIR)], cwd=BINDIR)

ret = subprocess.run(ninja_exe, cwd=BINDIR, stderr=subprocess.PIPE,
universal_newlines=True)
if isinstance(sources, (str, Path)):
sources = [sources]

result(ret)
fc = shutil.which(compiler)
if not fc:
raise FileNotFoundError(fc)

sources = list(map(str, sources))

def result(ret: subprocess.CompletedProcess):
if not ret.returncode:
print('\nBuild Complete!')
else:
raise RuntimeError(ret.stderr)
subprocess.check_call([str(fc)] + sources + EXE_OPT)
6 changes: 6 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[mypy]
ignore_missing_imports = True
strict_optional = False
allow_redefinition = True
show_error_context = False
show_column_numbers = True
2 changes: 0 additions & 2 deletions pyproject.toml

This file was deleted.

21 changes: 10 additions & 11 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[metadata]
name = msise00
version = 1.3.3
version = 1.4.0
description = Python API for Fortran MSISE-00 neutral atmosphere model.
author = Michael Hirsch, Ph.D.
author_email = scivision@users.noreply.github.com
url = https://github.com/scivision/msise00
url = https://github.com/space-physics/msise00
keywords =
atmosphere
geospace
Expand All @@ -14,13 +14,13 @@ classifiers =
Intended Audience :: Science/Research
Operating System :: OS Independent
Programming Language :: Fortran
Programming Language :: Other
Programming Language :: Python :: 3
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Topic :: Scientific/Engineering :: Atmospheric Science
license_file = LICENSE
license_files =
LICENSE.txt
long_description = file: README.md
long_description_content_type = text/markdown

Expand All @@ -29,8 +29,12 @@ python_requires = >= 3.6
setup_requires =
setuptools >= 40.6
pip >= 10
twine >= 1.11
include_package_data = True
scripts =
AltitudeProfile.py
MSISE00.py
suntest.py
TimeProfile.py
Worldgrid.py
packages = find:
install_requires =
python-dateutil
Expand All @@ -56,8 +60,3 @@ plot =
[options.entry_points]
console_scripts =
MSISE00 = MSISE00:main

[flake8]
max-line-length = 132
exclude = .git,__pycache__,.eggs/,doc/,docs/,build/,dist/,archive/

Loading

0 comments on commit da3a170

Please sign in to comment.