Skip to content

Commit

Permalink
Merge pull request #338 from jcapriot/pyproject
Browse files Browse the repository at this point in the history
Pyproject.toml
  • Loading branch information
jcapriot authored Oct 10, 2023
2 parents 615d1b3 + 3357e9e commit ba586b7
Show file tree
Hide file tree
Showing 25 changed files with 484 additions and 225 deletions.
7 changes: 4 additions & 3 deletions .azure-pipelines/azure-pipelines-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
python.version: '3.9'
linux-Python310:
python.version: '3.10'
linux-Python311:
python.version: '3.11'
steps:

- bash: |
Expand All @@ -33,7 +35,7 @@ jobs:
- bash: |
source "${HOME}/conda/etc/profile.d/conda.sh"
conda activate discretize-test
pip install -e .
pip install --no-build-isolation --editable .
displayName: Install requirements and build
condition: ne(variables['python.version'], '3.10')
Expand All @@ -48,8 +50,7 @@ jobs:
- bash: |
source "${HOME}/conda/etc/profile.d/conda.sh"
conda activate discretize-test
export DISC_COV=1
pip install -e .
pip install --no-build-isolation --editable . --config-settings=setup-args="-Dcy_line_trace=true"
displayName: Install requirements and build for Testing
condition: eq(variables['python.version'], '3.10')
Expand Down
4 changes: 3 additions & 1 deletion .azure-pipelines/azure-pipelines-osx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
python.version: '3.9'
osx-Python310:
python.version: '3.10'
linux-Python311:
python.version: '3.11'
steps:

- bash: |
Expand All @@ -30,7 +32,7 @@ jobs:
- bash: |
source "${HOME}/conda/etc/profile.d/conda.sh"
conda activate discretize-test
pip install -e .
pip install --no-build-isolation --editable .
displayName: Install requirements and build
- script: |
Expand Down
4 changes: 3 additions & 1 deletion .azure-pipelines/azure-pipelines-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
python.version: '3.9'
win-Python310:
python.version: '3.10'
linux-Python311:
python.version: '3.11'
steps:

- powershell: Write-Host "##vso[task.prependpath]$env:CONDA\Scripts"
Expand All @@ -31,7 +33,7 @@ jobs:
- script: |
call activate discretize-test
pip install -e .
pip install --no-build-isolation --editable .
displayName: Build
- script: |
Expand Down
17 changes: 16 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
.git_archival.txt export-subst
.git_archival.txt export-subst
# Excluding files from an sdist generated by meson-python

.azure-pipelines/* export-ignore
.ci/* export-ignore
docs/* export-ignore
examples/* export-ignore
tests/* export-ignore
tutorials/* export-ignore

.coveragerc export-ignore
.flake8 export-ignore
.git* export-ignore
*.yml export-ignore
*.yaml export-ignore
requirements_style.txt export-ignore
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/psf/black
rev: 23.1a1
rev: 23.9.1
hooks:
- id: black
language_version: python3
Expand Down
8 changes: 0 additions & 8 deletions MANIFEST.in

This file was deleted.

15 changes: 9 additions & 6 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ stages:
pool:
vmImage: ubuntu-latest
variables:
python.version: '3.8'
python.version: '3.9'
steps:
- script: |
pip install -r requirements_style.txt
Expand All @@ -38,7 +38,7 @@ stages:
pool:
vmImage: ubuntu-latest
variables:
python.version: '3.8'
python.version: '3.9'
steps:
- script: |
pip install -r requirements_style.txt
Expand Down Expand Up @@ -92,13 +92,14 @@ stages:
- bash: |
source "${HOME}/conda/etc/profile.d/conda.sh"
conda activate discretize-test
pip install -e .
pip install --no-build-isolation --editable .
displayName: Build package
- bash: |
source "${HOME}/conda/etc/profile.d/conda.sh"
conda activate discretize-test
python setup.py sdist
python -m build --no-isolation --skip-dependency-check --sdist .
ls -la dist
twine upload --skip-existing dist/*
displayName: Deploy source
env:
Expand Down Expand Up @@ -139,15 +140,17 @@ stages:
python.version: '3.9'
win-Python310:
python.version: '3.10'
win-Python311:
python.version: '3.11'
pool:
vmImage: windows-latest
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '$(python.version)'
- script: pip install numpy cython twine wheel setuptools_scm
- script: pip install build twine
displayName: Install build dependencies
- script: python setup.py bdist_wheel
- script: python -m build --wheel .
displayName: Build Wheel
- script: twine upload --skip-existing dist/*
displayName: Upload to PYPI
Expand Down
9 changes: 9 additions & 0 deletions discretize/Tests/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

python_sources = [
'__init__.py',
]

py.install_sources(
python_sources,
subdir: 'discretize/Tests'
)
20 changes: 10 additions & 10 deletions discretize/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
try:
from discretize.tree_mesh import TreeMesh
except ImportError as err:
print(err)
import os

# Check if being called from non-standard location (i.e. a git repository)
Expand All @@ -56,29 +55,30 @@
# Then we are being run from a repository
raise ImportError(
"""
Unable to import TreeMesh.
It would appear that discretize is being imported from its source code
directory and is unable to load its compiled extension modules. Try changing
your directory and re-launching your python interpreter.
It would appear that discretize is being imported from its repository.
If this is intentional, you need to run:
python setup.py build_ext --inplace
to compile the cython code.
If this was intentional, you need to install discretize in an editable mode.
"""
)
else:
raise err
from discretize import tests

__author__ = "SimPEG Team"
__license__ = "MIT"
__copyright__ = "2013 - 2023, SimPEG Developers, https://simpeg.xyz"

from importlib.metadata import version, PackageNotFoundError

# Version
try:
# - Released versions just tags: 0.8.0
# - GitHub commits add .dev#+hash: 0.8.1.dev4+g2785721
# - Uncommitted changes add timestamp: 0.8.1.dev4+g2785721.d20191022
from discretize.version import version as __version__
except ImportError:
__version__ = version("discretize")
except PackageNotFoundError:
# If it was not installed, then we don't know the version. We could throw a
# warning here, but this case *should* be rare. discretize should be
# installed properly!
Expand Down
100 changes: 100 additions & 0 deletions discretize/_extensions/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# NumPy include directory
# The try-except is needed because when things are
# split across drives on Windows, there is no relative path and an exception
# gets raised. There may be other such cases, so add a catch-all and switch to
# an absolute path. Relative paths are needed when for example a virtualenv is
# placed inside the source tree; Meson rejects absolute paths to places inside
# the source tree.
# For cross-compilation it is often not possible to run the Python interpreter
# in order to retrieve numpy's include directory. It can be specified in the
# cross file instead:
# [properties]
# numpy-include-dir = /abspath/to/host-pythons/site-packages/numpy/core/include
#
# This uses the path as is, and avoids running the interpreter.
incdir_numpy = meson.get_external_property('numpy-include-dir', 'not-given')
if incdir_numpy == 'not-given'
incdir_numpy = run_command(py,
[
'-c',
'''import os
import numpy as np
try:
incdir = os.path.relpath(np.get_include())
except Exception:
incdir = np.get_include()
print(incdir)
'''
],
check: true
).stdout().strip()
else
_incdir_numpy_abs = incdir_numpy
endif
inc_np = include_directories(incdir_numpy)
np_dep = declare_dependency(include_directories: inc_np)

# Deal with M_PI & friends; add `use_math_defines` to c_args or cpp_args
# Cython doesn't always get this right itself (see, e.g., gh-16800), so
# explicitly add the define as a compiler flag for Cython-generated code.
is_windows = host_machine.system() == 'windows'
if is_windows
use_math_defines = ['-D_USE_MATH_DEFINES']
else
use_math_defines = []
endif

numpy_nodepr_api = '-DNPY_NO_DEPRECATED_API=NPY_1_9_API_VERSION'
c_undefined_ok = ['-Wno-maybe-uninitialized']

cython_c_args = [numpy_nodepr_api, use_math_defines]

cy_line_trace = get_option('cy_line_trace')
if cy_line_trace
cython_c_args += ['-DCYTHON_TRACE_NOGIL=1']
endif

cython_cpp_args = cython_c_args

module_path = 'discretize/_extensions'

py.extension_module(
'interputils_cython',
'interputils_cython.pyx',
include_directories: incdir_numpy,
c_args: cython_c_args,
install: true,
subdir: module_path,
dependencies : [py_dep, np_dep],
)

py.extension_module(
'tree_ext',
['tree_ext.pyx' , 'tree.cpp'],
include_directories: incdir_numpy,
cpp_args: cython_cpp_args,
install: true,
subdir: module_path,
dependencies : [py_dep, np_dep],
override_options : ['cython_language=cpp'],
)

py.extension_module(
'simplex_helpers',
'simplex_helpers.pyx',
include_directories: incdir_numpy,
cpp_args: cython_cpp_args,
install: true,
subdir: module_path,
dependencies : [py_dep, np_dep],
override_options : ['cython_language=cpp'],
)

python_sources = [
'__init__.py',
]

py.install_sources(
python_sources,
subdir: module_path
)
12 changes: 12 additions & 0 deletions discretize/base/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

python_sources = [
'__init__.py',
'base_mesh.py',
'base_regular_mesh.py',
'base_tensor_mesh.py',
]

py.install_sources(
python_sources,
subdir: 'discretize/base'
)
24 changes: 24 additions & 0 deletions discretize/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

python_sources = [
'__init__.py',
'curvilinear_mesh.py',
'cylindrical_mesh.py',
'tensor_cell.py',
'tensor_mesh.py',
'tests.py',
'tree_mesh.py',
'unstructured_mesh.py',
'View.py',
]

py.install_sources(
python_sources,
subdir: 'discretize'
)

subdir('base')
subdir('_extensions')
subdir('mixins')
subdir('operators')
subdir('utils')
subdir('Tests')
13 changes: 13 additions & 0 deletions discretize/mixins/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

python_sources = [
'__init__.py',
'mesh_io.py',
'mpl_mod.py',
'omf_mod.py',
'vtk_mod.py',
]

py.install_sources(
python_sources,
subdir: 'discretize/mixins'
)
6 changes: 3 additions & 3 deletions discretize/operators/inner_products.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def get_face_inner_product( # NOQA D102
invert_model=False,
invert_matrix=False,
do_fast=True,
**kwargs
**kwargs,
):
# Inherited documentation from discretize.base.BaseMesh
if "invProp" in kwargs:
Expand Down Expand Up @@ -71,7 +71,7 @@ def get_edge_inner_product( # NOQA D102
invert_model=False,
invert_matrix=False,
do_fast=True,
**kwargs
**kwargs,
):
# Inherited documentation from discretize.base.BaseMesh
if "invProp" in kwargs:
Expand Down Expand Up @@ -150,7 +150,7 @@ def _getInnerProduct(
invert_model=False,
invert_matrix=False,
do_fast=True,
**kwargs
**kwargs,
):
"""Get the inner product matrix.
Expand Down
Loading

0 comments on commit ba586b7

Please sign in to comment.