Skip to content

Commit

Permalink
WIP: Meson build files
Browse files Browse the repository at this point in the history
  • Loading branch information
pastewka committed Nov 29, 2022
1 parent 504101c commit 1270f85
Show file tree
Hide file tree
Showing 18 changed files with 388 additions and 0 deletions.
23 changes: 23 additions & 0 deletions c/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Find numpy include directory
include_numpy = run_command(python,
['-c', 'import os; os.chdir(".."); import numpy; print(numpy.get_include())'],
check : true
).stdout().strip()

# Build and install the extension module
module = python.extension_module(
'_SurfaceTopography', # Name of the module
[ # List of sources
'angle_distribution.c',
'islands.cpp',
'neighbours.c',
'ring_statistics.cpp',
'tools.c',
'matscipymodule.c'
],
install: true, # Install it
include_directories: include_directories(include_numpy),
dependencies: [ # List of dependencies
python.dependency(), # Add Python.h as dependency
]
)
64 changes: 64 additions & 0 deletions discover_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#
# Copyright 2022 Lars Pastewka
#
# ### MIT license
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# 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.
#

import subprocess


def get_version_from_git():
"""
Discover muSpectre version from git repository.
"""
git_describe = subprocess.run(
['git', 'describe', '--tags', '--dirty', '--always'],
stdout=subprocess.PIPE)
if git_describe.returncode != 0:
raise RuntimeError('git execution failed')
version = git_describe.stdout.decode('latin-1').strip()
git_hash = subprocess.run(
['git', 'show', '-s', '--format=%H'],
stdout=subprocess.PIPE)
if git_hash.returncode != 0:
raise RuntimeError('git execution failed')
hash = git_hash.stdout.decode('latin-1').strip()

dirty = version.endswith('-dirty')

# Make version PEP 440 compliant
if dirty:
version = version.replace('-dirty', '')
version = version.replace('-', '.dev', 1)
version = version.replace('-', '+', 1)
if dirty:
version += '-dirty'

return dirty, version, hash


dirty, version, hash = get_version_from_git()

#
# Print version to screen
#

print(version)
15 changes: 15 additions & 0 deletions matscipy/calculators/eam/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# https://mesonbuild.com/Python-module.html

# Pure Python sources
python_sources = [
'__init__.py',
'average_atom.py',
'calculator.py',
'io.py'
]

# Install pure Python
python.install_sources(
python_sources,
subdir: 'matscipy/calculators/eam'
)
14 changes: 14 additions & 0 deletions matscipy/calculators/mcfm/mcfm_parallel/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# https://mesonbuild.com/Python-module.html

# Pure Python sources
python_sources = [
'__init__.py',
'mcfm_parallel_control.py',
'mcfm_parallel_worker.py'
]

# Install pure Python
python.install_sources(
python_sources,
subdir: 'matscipy/calculators/mcfm/mcfm_parallel'
)
19 changes: 19 additions & 0 deletions matscipy/calculators/mcfm/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# https://mesonbuild.com/Python-module.html

# Pure Python sources
python_sources = [
'__init__.py',
'calculator.py',
'cluster_data.py',
'qm_cluster.py'
]

# Install pure Python
python.install_sources(
python_sources,
subdir: 'matscipy/calculators/mcfm'
)

subdir('mcfm_parallel')
subdir('neighbour_list_mcfm')
subdir('qm_cluster_tools')
14 changes: 14 additions & 0 deletions matscipy/calculators/mcfm/neighbour_list_mcfm/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# https://mesonbuild.com/Python-module.html

# Pure Python sources
python_sources = [
'__init__.py',
'neighbour_list_base.py',
'neighbour_list_mcfm.py'
]

# Install pure Python
python.install_sources(
python_sources,
subdir: 'matscipy/calculators/mcfm/neighbour_list_mcfm'
)
15 changes: 15 additions & 0 deletions matscipy/calculators/mcfm/qm_cluster_tools/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# https://mesonbuild.com/Python-module.html

# Pure Python sources
python_sources = [
'__init__.py',
'base_qm_cluster_tool.py',
'qm_clustering_tool.py',
'qm_flagging_tool.py'
]

# Install pure Python
python.install_sources(
python_sources,
subdir: 'matscipy/calculators/mcfm/qm_cluster_tools'
)
19 changes: 19 additions & 0 deletions matscipy/calculators/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# https://mesonbuild.com/Python-module.html

# Pure Python sources
python_sources = [
'__init__.py',
'fitting.py',
'supercell_calculator.py'
]

# Install pure Python
python.install_sources(
python_sources,
subdir: 'matscipy/calculators'
)

subdir('eam')
subdir('mcfm')
subdir('pair_potential')
subdir('polydisperse')
13 changes: 13 additions & 0 deletions matscipy/calculators/pair_potential/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# https://mesonbuild.com/Python-module.html

# Pure Python sources
python_sources = [
'__init__.py',
'calculator.py'
]

# Install pure Python
python.install_sources(
python_sources,
subdir: 'matscipy/calculators/pair_potential'
)
13 changes: 13 additions & 0 deletions matscipy/calculators/polydisperse/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# https://mesonbuild.com/Python-module.html

# Pure Python sources
python_sources = [
'__init__.py',
'calculator.py'
]

# Install pure Python
python.install_sources(
python_sources,
subdir: 'matscipy/calculators/polydisperse'
)
17 changes: 17 additions & 0 deletions matscipy/contact_mechanics/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# https://mesonbuild.com/Python-module.html

# Pure Python sources
python_sources = [
'__init__.py',
'analysis.py',
'DMT.py',
'greens_function.py',
'Hertz.py',
'JKR.py'
]

# Install pure Python
python.install_sources(
python_sources,
subdir: 'matscipy/contact_mechanics'
)
15 changes: 15 additions & 0 deletions matscipy/electrochemistry/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# https://mesonbuild.com/Python-module.html

# Pure Python sources
python_sources = [
'__init__.py',
'continuous2discrete.py',
'poisson_boltzmann_distribution.py',
'poisson_nernst_planck_solver.py'
]

# Install pure Python
python.install_sources(
python_sources,
subdir: 'matscipy/electrochemistry'
)
17 changes: 17 additions & 0 deletions matscipy/fracture_mechanics/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# https://mesonbuild.com/Python-module.html

# Pure Python sources
python_sources = [
'__init__.py',
'clusters.py',
'crack.py',
'crackpathsel.py',
'energy_release.py',
'idealbrittlesolid.py'
]

# Install pure Python
python.install_sources(
python_sources,
subdir: 'matscipy/calculators/fracture_mechanics'
)
15 changes: 15 additions & 0 deletions matscipy/io/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# https://mesonbuild.com/Python-module.html

# Pure Python sources
python_sources = [
'__init__.py',
'metis.py',
'opls.py',
'tbl.py'
]

# Install pure Python
python.install_sources(
python_sources,
subdir: 'matscipy/io'
)
39 changes: 39 additions & 0 deletions matscipy/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# https://mesonbuild.com/Python-module.html

# Pure Python sources
python_sources = [
'__init__.py',
'_version.py',
'angle_distribution.py',
'atomic_strain.py',
'deformation.py',
'dislocation.py',
'distributed_computation.py',
'drift.py',
'elasticity.py',
'hessian_finite_differences.py',
'hydrogenate.py',
'logger.py',
'neighbours.py',
'opls.py',
'pressurecoupling.py',
'rings.py',
'socketcalc.py',
'spatial_correlation_function.py',
'surface.py',
'visualise.py'
]

# Install pure Python
python.install_sources(
python_sources,
subdir: 'matscipy'
)

subdir('calculators')
subdir('contact_mechanics')
subdir('electrochemistry')
subdir('fracture_mechanics')
subdir('io')
subdir('tool')

13 changes: 13 additions & 0 deletions matscipy/tool/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# https://mesonbuild.com/Python-module.html

# Pure Python sources
python_sources = [
'__init__.py',
'plot.py'
]

# Install pure Python
python.install_sources(
python_sources,
subdir: 'matscipy/tool'
)
15 changes: 15 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# https://mesonbuild.com/
project(
'matscipy', # Project name
'c', 'cpp', # Project type. We need a C and C++ compiler.
version: run_command('python3', 'discover_version.py', check: true).stdout().strip(), # Project version
)

# https://mesonbuild.com/Python-module.html
pymod = import('python')
python = pymod.find_installation('python3',
required: true,
)

subdir('c')
subdir('matscipy')
Loading

0 comments on commit 1270f85

Please sign in to comment.