-
Notifications
You must be signed in to change notification settings - Fork 119
[Draft] Build with meson-python backend
#431
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
Closed
Closed
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
e6d9105
Modify inner meson.build files
whophil d6aa7d1
Modify outer meson.build
whophil 15314e6
setup.py -> pyproject.toml
whophil d7c080c
remove unused helper
whophil 89a5e74
Add meson-python dep to win GHA
whophil 03ab46f
Remove extra flags
whophil a6af469
Remove chdir to tools
whophil 67761cb
Missed install: true for pyPSQP
whophil 27adf08
Add permalink to scipy snippets
whophil 8a0bfdf
Remove extra #
whophil 9148746
enable pyNSGA2 build
whophil 324b08a
Get version dynamically via meson
whophil 396457b
Replace py3_target -> py3
whophil afaa272
Remove postprocessing/meson.build
whophil 970547c
Replace py3_command -> py3
whophil f2a13e1
Merge remote-tracking branch 'mdolab/main' into meson-py
ewu63 bccffe8
add back cyipopt in testing dep
ewu63 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ dependencies: | |
| - numpy >=2.0 | ||
| - swig | ||
| - meson >=1.3.2 | ||
| - meson-python | ||
| - compilers | ||
| - pkg-config | ||
| - pip | ||
|
|
||
This file contains hidden or 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 hidden or 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,97 +1,61 @@ | ||
| # NumPy include directory - needed in all submodules | ||
| incdir_numpy = get_option('incdir_numpy') | ||
| if incdir_numpy == '' | ||
| incdir_numpy = run_command(py3_target, | ||
| [ | ||
| '-c', | ||
| 'import os; os.chdir(".."); import numpy; print(numpy.get_include())' | ||
| ], | ||
| check: true | ||
| ).stdout().strip() | ||
| # <!-- from https://github.com/scipy/scipy/blob/4d9f5e65af06d4cc3f770407f1a66a185675eea9/scipy/meson.build | ||
|
|
||
| incdir_numpy = meson.get_external_property('numpy-include-dir', 'not-given') | ||
| if incdir_numpy == 'not-given' | ||
| incdir_numpy = run_command(py3, | ||
| [ | ||
| '-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() | ||
|
|
||
| # We do need an absolute path to feed to `cc.find_library` below | ||
| _incdir_numpy_abs = run_command(py3, | ||
| ['-c', 'import os; os.chdir(".."); import numpy; print(numpy.get_include())'], | ||
| check: true | ||
| ).stdout().strip() | ||
| else | ||
| _incdir_numpy_abs = incdir_numpy | ||
| endif | ||
| # this creates a raw string which is useful for Windows use of '\' for paths | ||
| incdir_numpy = '''@0@'''.format(incdir_numpy) | ||
|
|
||
| # HACK: Meson prefixes filenames of intermediate compiled objects with their filepath. This poses a problem for conda builds | ||
| # since conda ensures the host environment directory has 255 characters so the meson object filenames then exceed 255 | ||
| # characters. To remedy this, the fortranobject.c file from numpy is copied into pyoptsparse so that the meson build | ||
| # uses a relative path, rather than an absolute path, thus reducing the auto generated object filename | ||
| # see for example https://github.com/mesonbuild/meson/issues/4226 | ||
| run_command(py3_command, | ||
| [ | ||
| '-c', | ||
| 'import os; os.chdir(".."); import shutil; shutil.copy(os.path.join(r"' + incdir_numpy + '", "..", "..", "f2py", "src", "fortranobject.c"), "pyoptsparse")' | ||
| ], | ||
| check: true | ||
| ) | ||
|
|
||
| inc_np = include_directories(incdir_numpy) | ||
|
|
||
| # Don't use the deprecated NumPy C API. Define this to a fixed version instead of | ||
| # NPY_API_VERSION in order not to break compilation for released SciPy versions | ||
| # when NumPy introduces a new deprecation. | ||
| numpy_nodepr_api = ['-DNPY_NO_DEPRECATED_API=NPY_1_9_API_VERSION'] | ||
| np_dep = declare_dependency(include_directories: inc_np, compile_args: numpy_nodepr_api) | ||
|
|
||
| # TODO: pyoptsparse supports numpy>=1.16 but numpy.f2py.get_include() wasnt added until later, raise numpy version? | ||
| #incdir_f2py = run_command(py3_target, | ||
| # [ | ||
| # '-c', | ||
| # 'import os; os.chdir(".."); import numpy.f2py; print(numpy.f2py.get_include())' | ||
| # ], | ||
| # check : true | ||
| #).stdout().strip() | ||
| incdir_f2py = incdir_numpy / '..' / '..' / 'f2py' / 'src' | ||
| inc_f2py = include_directories(incdir_f2py) | ||
| fortranobject_c = incdir_f2py / 'fortranobject.c' | ||
|
|
||
| # Share this object across multiple modules. | ||
| fortranobject_lib = static_library('_fortranobject', | ||
| fortranobject_c, | ||
| c_args: numpy_nodepr_api, | ||
| dependencies: py3_dep, | ||
| include_directories: [inc_np, inc_f2py], | ||
| gnu_symbol_visibility: 'hidden', | ||
| ) | ||
| fortranobject_dep = declare_dependency( | ||
| link_with: fortranobject_lib, | ||
| include_directories: [inc_np, inc_f2py], | ||
| ) | ||
|
|
||
|
|
||
| # TODO: this is kept in here so that when meson becomes pep517-compliant | ||
| # we can uncomment these to have meson install the source files | ||
|
|
||
| #python_sources = [ | ||
| # '__init__.py', | ||
| # 'pyOpt_MPI.py', | ||
| # 'pyOpt_constraint.py', | ||
| # 'pyOpt_error.py', | ||
| # 'pyOpt_gradient.py', | ||
| # 'pyOpt_history.py', | ||
| # 'pyOpt_objective.py', | ||
| # 'pyOpt_optimization.py', | ||
| # 'pyOpt_optimizer.py', | ||
| # 'pyOpt_solution.py', | ||
| # 'pyOpt_utils.py', | ||
| # 'pyOpt_variable.py', | ||
| # 'types.py' | ||
| #] | ||
|
|
||
| #py3_target.install_sources( | ||
| # python_sources, | ||
| # pure: true, | ||
| # subdir: 'pyoptsparse' | ||
| #) | ||
| # --!> | ||
|
|
||
| subdir('pySNOPT') | ||
| subdir('pySLSQP') | ||
| subdir('pyCONMIN') | ||
| subdir('pyNLPQLP') | ||
| subdir('pyNSGA2') | ||
| subdir('pyPSQP') | ||
| #subdir('pyALPSO') | ||
| #subdir('pyParOpt') | ||
| #subdir('postprocessing') | ||
|
|
||
| # test imports | ||
| # envdata = environment() | ||
| # python_paths = [join_paths(meson.current_build_dir(), '..')] | ||
| # envdata.prepend('PYTHONPATH', python_paths) | ||
|
|
||
| # progs = [['SLSQP', 'pySLSQP', 'slsqp'], | ||
| # ['CONMIN', 'pyCONMIN', 'conmin'], | ||
| # ['PSQP', 'pyPSQP', 'psqp'], | ||
| # ['NSGA2', 'pyNSGA2', 'nsga2']] | ||
|
|
||
|
|
||
| # foreach p : progs | ||
| # import_command = 'from pyoptsparse.' + p[1] + ' import '+p[2]+'; print('+p[2]+'.__file__)' | ||
| # test( | ||
| # 'import test for '+p[0], | ||
| # py3_command, | ||
| # args: ['-c', import_command], | ||
| # env: envdata | ||
| # ) | ||
| # endforeach | ||
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.