-
Notifications
You must be signed in to change notification settings - Fork 23
1042 stub generation for python bindings #1044
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e0b2ab9
generate stubs with cmake
8f53340
Generate stubs with python script and additional package
4515925
Merge branch 'main' into 1042-stub-generation-for-python-bindings
bfe958c
fix wrong package data
0b7a53c
readme
75ed278
requested changes
ff25628
delete py.typed file, not only include in setup.py
daec67c
bug in setup.py
88a27e5
comment
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
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
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 |
|---|---|---|
|
|
@@ -20,8 +20,7 @@ | |
| author_email='[email protected]', maintainer_email='[email protected]', | ||
| url='https://github.com/SciCompMod/memilio', | ||
| description='Part of MEmilio project, python bindings to the C++ libraries that contain the models and simulations.', | ||
| packages=find_packages( | ||
| where=os.path.dirname(os.path.abspath(__file__))), | ||
| packages=find_packages(where=os.path.dirname(os.path.abspath(__file__))), | ||
| setup_requires=['cmake'], | ||
| # need shared libs so there is one shared log level | ||
| cmake_args=['-DMEMILIO_BUILD_SHARED_LIBS:BOOL=ON'], | ||
|
|
@@ -36,4 +35,5 @@ | |
| 'numpy>=1.22,<1.25', | ||
| ], | ||
| }, | ||
| long_description='', test_suite='memilio.simulation_test',) | ||
| long_description='', test_suite='memilio.simulation_test', | ||
|
reneSchm marked this conversation as resolved.
|
||
| ) | ||
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 |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import os | ||
| import subprocess | ||
| import sys | ||
| import importlib.util | ||
| import pkgutil | ||
| import memilio.simulation | ||
|
|
||
| setup_content = f""" | ||
| from setuptools import setup, find_packages | ||
|
|
||
| setup( | ||
| name='memilio-stubs', | ||
| version='0.1', | ||
| packages=['memilio-stubs'], | ||
| package_data={{ | ||
| 'memilio-stubs': ['simulation/*.pyi'], | ||
| }}, | ||
| ) | ||
| """ | ||
|
|
||
| if __name__ == "__main__": | ||
|
|
||
| python_interpreter = sys.executable | ||
|
|
||
| # Check for needed packages. If it fails either pacakge is not installed or the wrong python interpreter is detected. | ||
| # For the latter try setting python_interpreter with full path | ||
| if importlib.util.find_spec('pybind11_stubgen') is None: | ||
| print('pybind11_stubgen is not installed') | ||
| exit() | ||
| if importlib.util.find_spec('memilio.simulation') is None: | ||
| print('memilio.simulation is not installed') | ||
| exit() | ||
|
|
||
| file_path = os.path.dirname(os.path.abspath(__file__)) | ||
| package_dir = os.path.abspath(os.path.join( | ||
| file_path, "../../memilio-simulation-stubs")) | ||
| output_dir = os.path.join(package_dir, "memilio-stubs/simulation") | ||
| output_module_dir = os.path.join(output_dir, 'memilio') | ||
|
|
||
| # create folders, if they do not exist | ||
| try: | ||
| # output_module_dir is generated by pybind11_stubgen | ||
| os.makedirs(output_dir) | ||
|
reneSchm marked this conversation as resolved.
|
||
| except: | ||
| pass | ||
|
|
||
| # get all model modules from memilio.simulation | ||
| # if package structure changes this needs to be adjusted | ||
| models = [m.name for m in pkgutil.iter_modules( | ||
| memilio.simulation.__path__)] | ||
|
|
||
| # generate stubs and moce them into correct folder with right name | ||
| # memilio-stubs/simulation module needs same structure as memilio/simulation | ||
| subprocess.check_call( | ||
| [python_interpreter, '-m', 'pybind11_stubgen', '--ignore-all-errors', '-o', output_dir, 'memilio._simulation']) | ||
| os.rename(os.path.join(output_module_dir, '_simulation.pyi'), | ||
| os.path.join(output_dir, '__init__.pyi')) | ||
|
|
||
| for model in models: | ||
| module_name = "memilio._simulation_" + model | ||
| subprocess.check_call( | ||
| [python_interpreter, '-m', 'pybind11_stubgen', '--ignore-all-errors', '-o', output_dir, module_name]) | ||
| os.rename(os.path.join(output_module_dir, '_simulation_' + model + '.pyi'), | ||
| os.path.join(output_dir, model + '.pyi')) | ||
|
|
||
| os.rmdir(output_module_dir) | ||
|
|
||
| # create setup.py and install package | ||
| with open(os.path.join(package_dir, "setup.py"), "w") as setup_file: | ||
| setup_file.write(setup_content) | ||
| subprocess.check_call( | ||
| [python_interpreter, '-m', 'pip', 'install', package_dir]) | ||
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.