Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pip installation #151

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
12 changes: 6 additions & 6 deletions python/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# openEMS python interface

## Install
If openEMS was installed into `~/opt/openEMS`, then install this package with:

1. Set the environment variable `OPENEMS_INSTALL_PATH` to point to the installation of openEMS, for example in Linux:
```bash
python setup.py build_ext -I ~/opt/openEMS/include -L ~/opt/openEMS/lib -R ~/opt/openEMS/lib
python setup.py install
export OPENEMS_INSTALL_PATH="/this/is/where/I/installed/openEMS"
```

Otherwise, replace `~/opt/openEMS` with the path to the place where it was installed.
2. Run
```bash
pip install /path/to/the/folder/where/this/README.md/is
```
41 changes: 41 additions & 0 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[project]
name = 'openEMS'
version = '0.0.36'
description = "Python interface for the openEMS FDTD library"
classifiers = [
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'Intended Audience :: Information Technology',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: Implementation :: CPython',
'Topic :: Scientific/Engineering',
'Topic :: Software Development :: Libraries :: Python Modules',
'Operating System :: POSIX :: Linux',
'Operating System :: Microsoft :: Windows',
]
authors = [
{name = 'Thorsten Liebig', email = 'Thorsten.Liebig@gmx.de'}
]
maintainers = [
{name = 'Thorsten Liebig', email = 'Thorsten.Liebig@gmx.de'}
]
dependencies = [
'numpy',
'h5py',
'CSXCAD',
]

[project.urls]
Documentation = 'https://openEMS.de'
Source = 'https://github.com/thliebig/CSXCAD/tree/master/python'

[build-system]
requires = ['setuptools','Cython']
build-backend = 'setuptools.build_meta'
102 changes: 52 additions & 50 deletions python/setup.py
Original file line number Diff line number Diff line change
@@ -1,59 +1,61 @@
# -*- coding: utf-8 -*-
"""
Created on Sun Dec 13 23:48:22 2015
from setuptools import Extension, setup
from Cython.Build import cythonize
from pathlib import Path
import os
import sys

@author: thorsten
"""
# TODO remove hardcoded path:
PATH_TO_CSXCAD_PYTHON_PACKAGE = Path(__file__).parent.parent.parent/'CSXCAD/python'

from setuptools import setup
from setuptools import Extension
from Cython.Build import cythonize
# Define some functions to check that the packages are installed where we expect them to be installed, and raise meaningful errors otherwise:
def looks_like_openEMS_is_installed_there(path_to_some_folder:Path):
path_to_some_folder = Path(path_to_some_folder)
FILES_THAT_SHOULD_EXIST = [
path_to_some_folder/'bin/openEMS',
path_to_some_folder/'include/openEMS/openems.h',
]
if any([not p.is_file() for p in FILES_THAT_SHOULD_EXIST]):
return False
return True

def looks_like_CSXCAD_python_package(path_to_some_folder:Path):
path_to_some_folder = Path(path_to_some_folder)
FILES_THAT_SHOULD_EXIST = [
path_to_some_folder/'pyproject.toml',
path_to_some_folder/'CSXCAD/__init__.py',
path_to_some_folder/'CSXCAD/CSXCAD.pyx',
]
if any([not p.is_file() for p in FILES_THAT_SHOULD_EXIST]):
return False
return True

if 'OPENEMS_INSTALL_PATH' not in os.environ:
raise SystemExit('Please set the environment variable OPENEMS_INSTALL_PATH to point to where openEMS was installed. ')

import os, sys
ROOT_DIR = os.path.dirname(__file__)
path_to_openEMS_installation = Path(os.environ['OPENEMS_INSTALL_PATH']) # Environment variables are always strings, so this should never raise any error.

sys.path.append(os.path.join(ROOT_DIR,'..','..','CSXCAD','python'))
if not looks_like_openEMS_is_installed_there(path_to_openEMS_installation):
raise SystemExit(f'I was expecting to find openEMS installed in {path_to_openEMS_installation}, but it does not look like it is installed there. ')

if not looks_like_CSXCAD_python_package(PATH_TO_CSXCAD_PYTHON_PACKAGE):
raise SystemExit(f'Cannot find python module of CSXCAD in {PATH_TO_CSXCAD_PYTHON_PACKAGE}. Please modify the `PATH_TO_CSXCAD_PYTHON_PACKAGE` variable in this setup.py file, which is located in {Path(__file__).resolve()}, to point to wherever you have the CSXCAD python package. ')

sys.path.append(str(PATH_TO_CSXCAD_PYTHON_PACKAGE))

extensions = [
Extension("*", [os.path.join(os.path.dirname(__file__), "openEMS","*.pyx")],
language="c++", # generate C++ code
libraries = ['CSXCAD','openEMS', 'nf2ff']),
Extension(
'*',
['openEMS/*.pyx',],
include_dirs = [str(path_to_openEMS_installation/'include')],
library_dirs = [str(path_to_openEMS_installation/'lib')],
runtime_library_dirs = [str(path_to_openEMS_installation/'lib')],
language = 'c++',
libraries = ['openEMS','nf2ff'],
)
]

setup(
name="openEMS",
version = '0.0.36',
description = "Python interface for the openEMS FDTD library",
classifiers = [
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'Intended Audience :: Information Technology',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: Implementation :: CPython',
'Topic :: Scientific/Engineering',
'Topic :: Software Development :: Libraries :: Python Modules',
'Operating System :: POSIX :: Linux',
'Operating System :: Microsoft :: Windows',
],
author = 'Thorsten Liebig',
author_email = 'Thorsten.Liebig@gmx.de',
maintainer = 'Thorsten Liebig',
maintainer_email = 'Thorsten.Liebig@gmx.de',
url = 'https://openEMS.de',
packages=["openEMS", ],
package_data={'openEMS': ['*.pxd']},
python_requires='>=3.9',
install_requires=[
'cython>=3.0.6', # Apache License 2.0 (https://github.com/cython/cython/blob/master/LICENSE.txt)
'h5py>=3.10.0', # BSD 3-Clause (https://github.com/h5py/h5py/blob/master/LICENSE)
'numpy>=1.26.2', # BSD 3-Clause (https://github.com/numpy/numpy/blob/main/LICENSE.txt)
],
ext_modules = cythonize(extensions, language_level = 3)
)
packages = ['openEMS'],
ext_modules = cythonize(extensions),
)