Skip to content

Commit

Permalink
Merge pull request #12 from WISDEM/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
gbarter committed Jan 17, 2024
2 parents 49aba7f + 0cf7ddf commit 541d46c
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 202 deletions.
44 changes: 33 additions & 11 deletions .github/workflows/CI_pyFrame3DD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,32 @@ jobs:
python-version: ${{ matrix.python-version }}
update-environment: true

- name: Editable Pip Install pyFrame3DD
env:
CC: '${{ steps.install_cc.outputs.cc }}'
CXX: '${{ steps.install_cc.outputs.cxx }}'
run: |
'${{ steps.cp.outputs.python-path }}' -m pip install --upgrade pip
'${{ steps.cp.outputs.python-path }}' -m pip install meson-python meson numpy ninja wheel
'${{ steps.cp.outputs.python-path }}' -m pip install --no-build-isolation -e .[test]
- name: Editable Test run
run: |
'${{ steps.cp.outputs.python-path }}' -m pytest test
- name: Pip Install pyFrame3DD
env:
MESON_ARGS: -Dpython_target=${{ steps.cp.outputs.python-path }}
CC: '${{ steps.install_cc.outputs.cc }}'
CXX: '${{ steps.install_cc.outputs.cxx }}'
run: |
'${{ steps.cp.outputs.python-path }}' -m pip install -vv .[test]
'${{ steps.cp.outputs.python-path }}' -m pip uninstall pyframe3dd
'${{ steps.cp.outputs.python-path }}' -m pip install -v .[test]
#- name: Setup tmate session
# uses: mxschmitt/action-tmate@v3
# with:
# detached: true
# if: contains( matrix.os, 'ubuntu')

- name: Test run
run: |
Expand Down Expand Up @@ -88,26 +107,29 @@ jobs:
run: |
conda install -y compilers
# Install
- name: Debug
run: |
conda list
printenv
#- name: Setup tmate session
# uses: mxschmitt/action-tmate@v3
# with:
# detached: true
# if: contains( matrix.os, 'windows')
# Install
- name: Conda Install pyFrame3DD
env:
MESON_ARGS: ""
run: |
python -m pip install .
python -m pip install . -v
- name: Test run
run: |
python -m pytest test
- name: Editable Conda Install pyFrame3DD
env:
MESON_ARGS: ""
run: |
python -m pip uninstall pyframe3dd
python -m pip install --no-build-isolation -e . -v
- name: Editable Test run
run: |
python -m pytest test
31 changes: 19 additions & 12 deletions .github/workflows/Publish_pyFrame3DD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ jobs:
env:
CC: '${{ steps.install_cc.outputs.cc }}'
CXX: '${{ steps.install_cc.outputs.cxx }}'
uses: pypa/cibuildwheel@v2.16.1
uses: pypa/cibuildwheel@v2.16.2

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
path: ./wheelhouse/*.whl

build_sdist:
Expand All @@ -45,27 +46,33 @@ jobs:
- name: Build sdist
run: pipx run build --sdist

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: cibw-sdist
path: dist/*.tar.gz

upload_pypi:
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
# upload to PyPI on every tag starting with 'v'
#if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
# alternatively, to publish when a GitHub Release is created, use the following rule:
if: github.event_name == 'release' && github.event.action == 'published'
steps:
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
# unpacks default artifact into dist/
# if `name: artifact` is omitted, the action will create extra parent dir
name: artifact
# unpacks all CIBW artifacts into dist/
pattern: cibw-*
path: dist
merge-multiple: true

- name: Upload to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
#with:
# user: __token__
# password: ${{ secrets.pypi_password }}
# # To test: repository_url: https://test.pypi.org/legacy/

- uses: pypa/gh-action-pypi-publish@v1.8.10
with:
user: __token__
password: ${{ secrets.pypi_password }}
# To test: repository_url: https://test.pypi.org/legacy/
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,28 @@ There is example code that shows usage contained in ``examples/exB.py``. This f

pyFrame3DD requires a C compiler

## Install
## Install (as a library)

For detailed installation instructions of WISDEM modules see <https://github.com/WISDEM/WISDEM> or to install pyFrame3DD by itself do:

$ pip install WISDEM-pyFrame3DD


## Install (from source)

If you would like to build the project locally from source for easier access to the underlying methods and tests, do:

$ git clone https://github.com/WISDEM/pyFrame3DD.git
$ cd pyFrame3DD
$ pip install .

If developer/editable mode, do the same `git clone` step, but on install do:

$ pip install --no-build-isolation -e .

The `--no-build-isolation` option is important per [Meson guidelines](https://meson-python.readthedocs.io/en/latest/how-to-guides/editable-installs.html).


## Unit Tests

$ pytest test
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ channels:

dependencies:
- meson
- meson-python
- ninja
- numpy
- pip
- python
- pytest
- setuptools
9 changes: 1 addition & 8 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,10 @@ endif
# https://mesonbuild.com/Python-module.html
# Here we differentiate from the python used by meson, py3_command, and that python target, py3_target. This is useful
# when cross compiling like on conda-forge
py_mod = import('python')
if get_option('python_target') != ''
py3 = py_mod.find_installation(get_option('python_target'))
else
py3 = py_mod.find_installation('python')
endif
py3 = import('python').find_installation(pure: false)
py3_dep = py3.dependency()

message(py3.path())
message(py3.get_install_dir())

subdir('pyframe3dd')


3 changes: 2 additions & 1 deletion pyframe3dd/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .pyframe3dd import Frame, StaticLoadCase, NodeData, ReactionData, ElementData, Options
#import frame3dd




14 changes: 11 additions & 3 deletions pyframe3dd/meson.build
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
python_sources = [
'__init__.py',
'pyframe3dd.py',
]

py3.install_sources(
python_sources,
subdir: 'pyframe3dd',
)

sources = ['src/py_main.c',
'src/py_structs.h',
Expand All @@ -19,9 +28,8 @@ sources = ['src/py_main.c',
# We need to build a shared library NOT A PYTHON EXTENSION
# The ctypes wrapper handles the extension part.
# If the interface was done purely in C, then need the python extension.
shared_library('_pyframe3dd', sources,
temp = shared_library('_pyframe3dd', sources,
name_prefix: '',
include_directories: 'src',
dependencies : py3_dep,
install_dir: py3.get_install_dir() / 'pyframe3dd',
install : true)

66 changes: 42 additions & 24 deletions pyframe3dd/pyframe3dd.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,45 @@
import math
from ctypes import POINTER, c_int, c_double, Structure, pointer
from collections import namedtuple
import platform
import os
#from distutils.sysconfig import get_config_var

from sys import platform

libext = None #get_config_var('EXT_SUFFIX')
if libext is None or libext == '':
if platform == "linux" or platform == "linux2":
libext = '.so'
elif platform == "darwin":
libext = '.dylib'
#libext = '.so'
elif platform == "win32":
libext = '.dll'
#libext = '.pyd'
elif platform == "cygwin":
libext = '.dll'

libname = '_pyframe3dd' + libext
import sysconfig
import sys

if platform.system() == "Windows":
lib_ext = ".dll"
elif platform.system() == "Darwin":
lib_ext = ".dylib"
else:
lib_ext = ".so"

libname = '_pyframe3dd' + lib_ext

pyframe3dd_dir = os.path.dirname( os.path.abspath(__file__) )

lib_opt = [os.path.join(pyframe3dd_dir, libname), # pip installs (regular and editable)
os.path.join(os.path.dirname( os.path.dirname( pyframe3dd_dir )), "local", "lib", libname), # WEIS library
os.path.join(os.path.dirname( sysconfig.get_path('stdlib') ), libname), # conda installs
os.path.join(os.path.dirname( sysconfig.get_path('stdlib') ), "pyframe3dd", libname), # conda installs
os.path.join(os.path.dirname( sysconfig.get_path('stdlib') ), "lib", libname), # conda installs
os.path.join(os.path.dirname( sysconfig.get_path('stdlib') ), "Library", "lib", libname), # conda installs
os.path.join( sysconfig.get_path('platlib'), "pyframe3dd", libname), # system-wide pip installs
os.path.join( sysconfig.get_config_var("userbase"), "lib", "python", "site-packages", "pyframe3dd", libname), # system wide local
]

# For Meson's editable installs
for p in sys.meta_path:
if "_build_path" in p.__dict__:
lib_opt += [os.path.join(p._build_path, "pyframe3dd", libname)]

lib_path = None
for p in lib_opt:
if os.path.exists(p):
lib_path = str(p)
break

if lib_path is None:
raise Exception(f"Cannot find {libname} in {lib_opt}")

c_int_p = POINTER(c_int)
c_double_p = POINTER(c_double)
Expand Down Expand Up @@ -446,12 +466,10 @@ def __init__(self, nodes, reactions, elements, options):


# load c module
mydir = os.path.dirname(os.path.realpath(__file__)) # get path to this file
try:
self._pyframe3dd = np.ctypeslib.load_library(libname, mydir)
except:
mydir = os.path.abspath(os.path.dirname(mydir))
self._pyframe3dd = np.ctypeslib.load_library(libname, mydir)
#mydir = impresources.files(pyframe3dd)
#with impresources.as_file(mydir) as f:
# print(f)
self._pyframe3dd = np.ctypeslib.load_library(libname, os.path.dirname(lib_path))

self._pyframe3dd.run.argtypes = [POINTER(C_Nodes), POINTER(C_Reactions), POINTER(C_Elements),
POINTER(C_OtherElementData), c_int, POINTER(C_LoadCase),
Expand Down
39 changes: 15 additions & 24 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[build-system]
requires = ["setuptools", "meson>=1.1", "ninja", "wheel"]
build-backend = "setuptools.build_meta"
requires = ["numpy", "ninja", "meson>=1.1", "meson-python", "wheel"]
build-backend = "mesonpy"

[project]
name = "WISDEM-pyFrame3DD"
version = "1.0.4"
version = "1.1.0"
description = "Python bindings to Frame3DD, a code for static and dynamic structural analysis of 2D and 3D frames and trusses, with permission from Prof Henri Gavin"
readme = "README.md"
requires-python = ">=3.9"
Expand Down Expand Up @@ -36,8 +36,14 @@ classifiers = [ # Optional
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Fortran",
"Programming Language :: C",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX :: Linux",
"Operating System :: POSIX",
"Operating System :: Unix",
"Operating System :: MacOS",
]

dependencies = [
Expand Down Expand Up @@ -70,28 +76,13 @@ test = ["pytest"]
"Homepage" = "https://github.com/WISDEM/pyFrame3DD"
"Project" = "https://frame3dd.sourceforge.net"

# This is configuration specific to the `setuptools` build backend.
# If you are using a different build backend, you will need to change this.
[tool.setuptools]
zip-safe = false
include-package-data = true

#[tool.setuptools.packages]
#find = {}

[tool.setuptools.packages.find]
#where = ["wisdem"]
exclude = ["test", "examples"]
namespaces = true

[tool.setuptools.package-data]
# If there are data files included in your packages that need to be
# installed, specify them here.
"*" = ["*.so", "*.lib", "*.pyd", "*.pdb", "*.dylib", "*.dll"]
[tool.meson-python.args]
setup = ['--python.install-env=auto']
install = ['--tags=runtime,python-runtime,bin']

[tool.black]
line-length = 120
target-version = ['py39']
target-version = ['py311']
include = '\.pyi?$'
exclude = '''
/(
Expand Down Expand Up @@ -125,5 +116,5 @@ atomic = true
#src_paths=isort,test

[tool.cibuildwheel]
skip = ["cp36-*", "cp37-*", "cp38-*", "*-win32", "*arm64", "pp*"]
skip = ["cp36-*", "cp37-*", "cp38-*", "*-win32"]
build-frontend = "build"
Loading

0 comments on commit 541d46c

Please sign in to comment.