Skip to content
Merged
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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ git pull
git checkout <commit|tag>
```

NOTE: Spack may have an undocumented update command now. The following worked for me with Spack `1.0.0.dev0 (b63f793f74c672eaf4768b7a5a711c83882bbebd)`:
```bash
spack repo update
```

### Spack <1.0.0

Updating with Spack <1.0.0 is approximately the same as >=1.0.0, and must be done by manually updating the cloned GitHub repository. The following commands will update *all* `nwchemex.*` sub-repos at once. You do not need to run this separately for each `nwchemex.*` sub-repo!
Expand Down Expand Up @@ -108,3 +113,7 @@ For more information, see the Spack's [Search Order and Overriding Packages](htt
## Helpful Spack Commands

For a broader list of helpful Spack repository management commands, see Spack's [The `spack repo` Command](https://spack.readthedocs.io/en/latest/repositories.html#the-spack-repo-command).

### Developing Packages in a Spack Environment

https://spack.readthedocs.io/en/latest/environments.html#developing-packages-in-a-spack-environment
1 change: 1 addition & 0 deletions spack-repo-index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
repo_index:
# Relative paths from project root to repos
paths:
- spack_repo/nwchemex/common
- spack_repo/nwchemex/core
- spack_repo/nwchemex/overrides
14 changes: 14 additions & 0 deletions spack_repo/nwchemex/common/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# NWChemEx Common Package Components

As of Spack package repository `api: v2.0`, package repositories integrate smoothly with Python's import system and can be imported for use in other packages. This repository is a collection of helpers and abstractions for NWChemEx packages to help with maintenance and development.

## Usage

In other repositories, use the following import statement form:
```python
from spack_repo.nwchemex._common.packages.<package_name>.package import Package
# Or, more generally
from spack_repo.nwchemex._common.<module>.<path> import <desired_item>
```

For more information about importing from packages after `api:v2.0`, see Spack's [Repository Namespaces and Python](https://spack.readthedocs.io/en/latest/repositories.html#repository-namespaces-and-python).
4 changes: 4 additions & 0 deletions spack_repo/nwchemex/common/mixins/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .cmaize import CMaizePackage
from .nwchemex import NWChemExBaseCXX, NWChemExBasePybindings

__all__ = ["CMaizePackage", "NWChemExBaseCXX", "NWChemExBasePybindings"]
66 changes: 66 additions & 0 deletions spack_repo/nwchemex/common/mixins/cmaize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from spack.package import join_path
from spack_repo.builtin.build_systems.cmake import CMakePackage


class CMaizePackage(CMakePackage):

@staticmethod
def cmaize_sanity_check_dirs(project_name: str) -> list[str]:
# Could also use cls.__name__.lower() if it should always match
project_name_lowercase = project_name.lower()

# Create NWChemEx project locations
project_include_path = join_path("include", project_name_lowercase)
project_lib_path = join_path("lib", project_name_lowercase)
project_lib_cmake_path = join_path(
project_lib_path,
"cmake",
)

directories = [
join_path(project_include_path),
join_path(project_lib_path),
join_path(project_lib_cmake_path),
# CMaize's "external/" should not be a strict requirement since it
# can be empty, especially with Spack managing most/all deps.
# join_path(project_lib_path, "external"),
]

return directories

@staticmethod
def cmaize_sanity_check_files(project_name: str) -> list[str]:
project_name_lowercase = project_name.lower()

# Create NWChemEx project locations
project_lib_path = join_path("lib", project_name_lowercase)
project_lib_cmake_path = join_path(
project_lib_path,
"cmake",
)

files = [
join_path(
project_lib_cmake_path,
f"{project_name_lowercase}Config.cmake",
),
join_path(
project_lib_cmake_path,
f"{project_name_lowercase}ConfigVersion.cmake",
),
join_path(
project_lib_cmake_path,
f"{project_name_lowercase}-target.cmake",
),
# TODO: Conditionally check these once there is a "shared" variant
# if even possible
# join_path(
# project_lib_path, f"lib{project_name_lowercase}.a"
# ),
# join_path(
# project_lib_path,
# f"lib{project_name_lowercase}.so",
# ),
]

return files
125 changes: 125 additions & 0 deletions spack_repo/nwchemex/common/mixins/nwchemex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import os

from spack import package as pkg
from spack.package_base import PackageBase

from .cmaize import CMaizePackage


class NWChemExBaseGit(PackageBase):

# Latest commit from GitHub
# "This download method is untrusted, and is not recommended. Branches are
# moving targets, so the commit you get when you install the package likely
# won’t be the same commit that was used when the package was first
# written."
# ~~~~ From the Spack docs
# Is there a way to warn the user about this while still providing
# the option?
pkg.version("master", branch="master", preferred=True)


class NWChemExBaseCXX(NWChemExBaseGit, CMaizePackage):

pkg.variant("docs", default=False, description="Build documentation")
pkg.variant(
"shared",
default=True,
description="Build shared libraries",
sticky=True,
)

pkg.variant(
"cxxstd",
default="17",
# NOTE: Comma after "17" is necessary so Spack doesn't split it into
# individual characters
values=("17",),
multi=False,
description="Use the specified C++ standard when building",
sticky=True,
)

pkg.depends_on("cxx", type="build")

# Test dependencies
pkg.depends_on("catch2", type=("build", "test"))

def cmake_args(self):
args = super().cmake_args()

args.extend(
[
self.define_from_variant(
"CMAKE_POSITION_INDEPENDENT_CODE", "shared"
),
self.define_from_variant("BUILD_SHARED_LIBS", "shared"),
self.define_from_variant("BUILD_DOCS", "docs"),
self.define_from_variant("CMAKE_CXX_STANDARD", "cxxstd"),
self.define("BUILD_TESTING", self.run_tests),
]
)

if "CMAKE_TOOLCHAIN_FILE" in os.environ:
args.append(
f"-DCMAKE_TOOLCHAIN_FILE={os.environ["CMAKE_TOOLCHAIN_FILE"]}"
)
# TODO: +debug flag? +verbose flag?
args.append(self.define("CMAKE_MESSAGE_LOG_LEVEL", "DEBUG"))
# Silence FetchContent by default
args.append(self.define("FETCHCONTENT_QUIET", True))
args.append("-Wno-dev")
# https://cmake.org/cmake/help/latest/policy/CMP0152.html
# Added in 3.28; OLD is deprecated now
args.append(self.define("CMAKE_POLICY_DEFAULT_CMP0152", "NEW"))

# DEBUG REMOVE ME
args.append(
self.define(
"CMAKE_VERBOSE_MAKEFILE",
True,
)
)

return args


class NWChemExBasePybindings(NWChemExBaseCXX):

pkg.variant(
"pybindings",
default=False,
description="Build the Python bindings with Pybind11",
sticky=True,
)

pkg.depends_on("py-pybind11", when="+pybindings")

def cmake_args(self):
args = super().cmake_args()

args.extend(
[
self.define_from_variant(
"BUILD_PYBIND11_PYBINDINGS", "pybindings"
),
self.define_from_variant("PYBIND11_FINDPYTHON", "pybindings"),
]
)

if self.spec.satisfies("+pybindings"):
if "NWX_MODULE_DIRECTORY" in os.environ:
args.append(
self.define(
"NWX_MODULE_DIRECTORY",
os.environ["NWX_MODULE_DIRECTORY"],
)
)
# TODO: Allow the user to configure this?
# args.append(
# "-DNWX_MODULE_DIRECTORY={}".format(
# self.prefix.lib.join(self.project.lower()).join("python")
# )
# )

return args
10 changes: 10 additions & 0 deletions spack_repo/nwchemex/common/repo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# For more information on Spack package repositories, see
# https://spack.readthedocs.io/en/latest/repositories.html

repo:
# Unique identifier for this repository
# For more details, see https://spack.readthedocs.io/en/latest/repositories.html#namespaces
namespace: 'nwchemex.common'

# Spack package API this repo adheres to
api: v2.0
Loading