-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into update/move-some-c-functions-to-python
- Loading branch information
Showing
9 changed files
with
168 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: build-docker-image | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- "Dockerfile" | ||
|
||
jobs: | ||
build-and-push-docker-image: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check Out Repo | ||
uses: actions/checkout@v4 | ||
with: | ||
sparse-checkout: | | ||
Dockerfile | ||
sparse-checkout-cone-mode: false | ||
|
||
- name: Log in to GitHub Container Registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
file: ./Dockerfile | ||
push: true | ||
tags: ghcr.io/${{ github.repository }}/ci-image:latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
FROM alpine:latest AS base | ||
|
||
RUN apk update && \ | ||
apk add --no-cache build-base cmake openblas-dev python3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export CLEED_PHASE=./PHASE | ||
EXECUTABLE=../../cleedpy/cleed/build/bin/test_cleed | ||
EXECUTABLE=../../cleedpy/cleed/bin/test_cleed | ||
|
||
${EXECUTABLE} -i Ni111_Cu.inp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import os | ||
import pathlib as pl | ||
import platform | ||
import subprocess | ||
import sys | ||
|
||
from setuptools import Extension, setup | ||
from setuptools.command.build_ext import build_ext | ||
|
||
|
||
class CMakeExtension(Extension): | ||
def __init__(self, name, source_dir=""): | ||
Extension.__init__(self, name, sources=[]) | ||
self.source_dir = pl.Path(source_dir).absolute() | ||
|
||
|
||
class CMakeBuild(build_ext): | ||
def run(self): | ||
try: | ||
subprocess.check_output(["cmake", "--version"]) | ||
except subprocess.CalledProcessError as err: | ||
raise RuntimeError( | ||
"CMake must be installed to build the following extensions: " | ||
+ ", ".join(e.name for e in self.extensions) | ||
) from err | ||
|
||
for ext in self.extensions: | ||
self.build_extension(ext) | ||
|
||
def build_extension(self, ext: CMakeExtension): | ||
ext_dir = pl.Path(self.get_ext_fullpath(ext.name)).parent.absolute() | ||
|
||
cmake_args = ["-DPYTHON_EXECUTABLE=" + sys.executable] | ||
|
||
cfg = "Debug" if self.debug else "Release" | ||
build_args = ["--config", cfg] | ||
|
||
if platform.system() == "Windows": | ||
cmake_args += [f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{cfg.upper()}={ext_dir}"] | ||
if sys.maxsize > 2**32: | ||
# We are on a Win 64-bit system | ||
cmake_args += ["-A", "x64"] | ||
build_args += ["--", "/m"] | ||
else: | ||
# These flags are passed as-is to the underlying build tool (make) | ||
build_args += ["--", "-j2"] | ||
|
||
env = os.environ.copy() | ||
env["CXXFLAGS"] = '{} -DVERSION_INFO="{}"'.format( | ||
env.get("CXXFLAGS", ""), self.distribution.get_version() | ||
) | ||
|
||
build_dir = pl.Path(self.build_temp) | ||
build_dir.mkdir(parents=True, exist_ok=True) | ||
|
||
try: | ||
subprocess.check_call( | ||
["cmake", "-S", ext.source_dir.as_posix(), "-B", "."] + cmake_args, | ||
cwd=build_dir, | ||
env=env, | ||
) | ||
subprocess.check_call(["cmake", "--build", "."] + build_args, cwd=build_dir) | ||
except subprocess.CalledProcessError as err: | ||
raise RuntimeError(f"CMake error: {err}") from err | ||
|
||
|
||
setup( | ||
name="cleedpy", | ||
ext_modules=[ | ||
CMakeExtension( | ||
"cleed", (pl.Path(__file__).parent / "cleedpy" / "cleed").as_posix() | ||
) | ||
], | ||
cmdclass={"build_ext": CMakeBuild}, | ||
# The following includes *any* library file found in the package directory | ||
package_data={"cleedpy": ["**/*.dylib", "**/*.so", "**/*.dll"]}, | ||
) |