Skip to content

Commit

Permalink
Package & Module: amrex (#15)
Browse files Browse the repository at this point in the history
Rename the package and import module to `amrex`.

Rename the internal C++-generated module to `amrex_pybind`.

Note: Users interface with the `amrex` module and its (future)
sub-modules. We wrap all pybind-generated modules in another,
fluffy Python module so pyAMReX developers can expand them in
pure Python if they feel like it.
  • Loading branch information
ax3l authored Feb 14, 2021
1 parent d41a124 commit a629bb1
Show file tree
Hide file tree
Showing 16 changed files with 40 additions and 40 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
run: |
python3 -m pip install -U pip setuptools wheel pytest
AMREX_MPI=ON python3 -m pip install -v .
python3 -c "import pyamrex; print(pyamrex.__version__)"
python3 -c "import amrex; print(amrex.__version__)"
- name: Unit tests
run: |
mpiexec -np 1 python3 -m pytest tests/
Expand All @@ -35,7 +35,7 @@ jobs:
export CXX=$(which g++-10)
python3 -m pip install -U pip setuptools wheel pytest
AMREX_MPI=ON python3 -m pip install -v .
python3 -c "import pyamrex; print(pyamrex.__version__)"
python3 -c "import amrex; print(amrex.__version__)"
- name: Unit tests
run: |
mpiexec -np 1 python3 -m pytest tests/
Expand All @@ -54,7 +54,7 @@ jobs:
export CXX=$(which clang++)
python3 -m pip install -U pip pytest
python3 -m pip install -v .
python3 -c "import pyamrex; print(pyamrex.__version__)"
python3 -c "import amrex; print(amrex.__version__)"
- name: Unit tests
run: |
python3 -m pytest tests/
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
run: |
python3 -m pip install -U pip pytest
python3 -m pip install -v .
python3 -c "import pyamrex; print(pyamrex.__version__)"
python3 -c "import amrex; print(amrex.__version__)"
- name: Unit tests
run: |
python3 -m pytest tests/
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
run: |
python -m pip install -U pip pytest
python -m pip install -v .
python -c "import pyamrex; print(pyamrex.__version__)"
python -c "import amrex; print(amrex.__version__)"
- name: Unit tests
run: |
python -m pytest tests/
python -m pytest tests
# Build libamrex and all tutorials
clang:
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ target_link_libraries(pyAMReX PRIVATE pybind11::module pybind11::lto pybind11::w
set_target_properties(pyAMReX PROPERTIES
CXX_VISIBILITY_PRESET "hidden"
CUDA_VISIBILITY_PRESET "hidden"
ARCHIVE_OUTPUT_NAME pyamrex_cxx
LIBRARY_OUTPUT_NAME pyamrex_cxx
ARCHIVE_OUTPUT_NAME amrex_pybind
LIBRARY_OUTPUT_NAME amrex_pybind
)
pybind11_extension(pyAMReX)
pybind11_strip(pyAMReX)
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ We will add further information here once first development versions are ready f
*to do*

```python
import pyamrex
import amrex

small_end = pyamrex.Int_Vect()
big_end = pyamrex.Int_Vect(2, 3, 4)
small_end = amrex.Int_Vect()
big_end = amrex.Int_Vect(2, 3, 4)

b = pyamrex.Box(small_end, big_end)
b = amrex.Box(small_end, big_end)
print(b)

# ...
Expand Down
12 changes: 6 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def run(self):
"AMREX_libdir='{}'".format(AMREX_libdir))

# copy external libs into collection of files in a temporary build dir
dst_path = os.path.join(self.build_lib, "pyamrex")
dst_path = os.path.join(self.build_lib, "amrex")
for lib_path in libs_found:
shutil.copy(lib_path, dst_path)

Expand Down Expand Up @@ -88,7 +88,7 @@ def build_extension(self, ext):

cmake_args = [
'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' +
os.path.join(extdir, "pyamrex"),
os.path.join(extdir, "amrex"),
'-DCMAKE_VERBOSE_MAKEFILE=ON',
'-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=' + extdir,
'-DAMReX_SPACEDIM=' + dims,
Expand Down Expand Up @@ -131,7 +131,7 @@ def build_extension(self, ext):
cmake_args += [
'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format(
cfg.upper(),
os.path.join(extdir, "pyamrex")
os.path.join(extdir, "amrex")
)
]
if sys.maxsize > 2**32:
Expand Down Expand Up @@ -216,15 +216,15 @@ def build_extension(self, ext):
# keyword reference:
# https://packaging.python.org/guides/distributing-packages-using-setuptools
setup(
name='pyamrex',
name='amrex',
# note PEP-440 syntax: x.y.zaN but x.y.z.devN
version = '21.02',
packages = ['pyamrex'],
packages = ['amrex'],

# Python sources:
package_dir = {'': 'src'},

# pyamrex authors:
# pyAMReX authors:
author='Axel Huebl, Shreyas Ananthan, Steven R. Brandt, Andrew Myers, Weiqun Zhang, et al.',
author_email='axelhuebl@lbl.gov, shreyas.ananthan@nrel.gov, sbrandt@cct.lsu.edu, atmyers@lbl.gov, weiqunzhang@lbl.gov',
# wheel/pypi packages:
Expand Down
2 changes: 1 addition & 1 deletion src/Base/AMReX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void init_AMReX(py::module& m)

m.def("initialize",
[](const py::list args) {
Vector<std::string> cargs{"pyamrex"};
Vector<std::string> cargs{"amrex"};
Vector<char*> argv{&cargs.back()[0]};

// Populate the "command line"
Expand Down
2 changes: 1 addition & 1 deletion src/Base/Box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void init_Box(py::module &m) {
[](Box const & b) {
std::stringstream s;
s << b.size();
return "<pyamrex.Box of size '" + s.str() + "'>";
return "<amrex.Box of size '" + s.str() + "'>";
}
)

Expand Down
2 changes: 1 addition & 1 deletion src/Base/Dim3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void init_Dim3(py::module& m)
[](const Dim3& d) {
std::stringstream s;
s << d;
return "<pyamrex.Dim3 '" + s.str() + "'>";
return "<amrex.Dim3 '" + s.str() + "'>";
}
)
.def("__str__",
Expand Down
2 changes: 1 addition & 1 deletion src/Base/IntVect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void init_IntVect(py::module &m) {
const auto iv = obj.cast<IntVect>();
std::stringstream s;
s << iv;
return "<" + name + " " + s.str() + ">";
return "<amrex." + name + " " + s.str() + ">";
}
)
.def("__str",
Expand Down
12 changes: 12 additions & 0 deletions src/amrex/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from . import amrex_pybind
from .amrex_pybind import * # noqa


__version__ = amrex_pybind.__version__
__doc__ = amrex_pybind.__doc__
__license__ = amrex_pybind.__license__
__author__ = amrex_pybind.__author__

# at this place we can enhance Python classes with additional methods written
# in pure Python or add some other Python logic
#
6 changes: 3 additions & 3 deletions src/pyAMReX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ void init_Box(py::module &);
void init_Dim3(py::module&);
void init_IntVect(py::module &);

PYBIND11_MODULE(pyamrex_cxx, m) {
PYBIND11_MODULE(amrex_pybind, m) {
m.doc() = R"pbdoc(
pyamrex_cxx
amrex_pybind
-----------
.. currentmodule:: pyamrex_cxx
.. currentmodule:: amrex_pybind
.. autosummary::
:toctree: _generate
Expand Down
12 changes: 0 additions & 12 deletions src/pyamrex/__init__.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-

import pytest
import pyamrex as amrex
import amrex

if amrex.Config.have_mpi:
from mpi4py import MPI
Expand Down
2 changes: 1 addition & 1 deletion tests/test_dim3.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest
import numpy as np
import pyamrex as amrex
import amrex

def test_dim3():
obj = amrex.Dim3(1, 2, 3)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_intvect.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest
import numpy as np
import pyamrex as amrex
import amrex

@pytest.mark.skipif(amrex.Config.spacedim != 1,
reason="Requires AMREX_SPACEDIM = 1")
Expand Down

0 comments on commit a629bb1

Please sign in to comment.