diff --git a/CHANGELOG.md b/CHANGELOG.md index 2336904382641de1d67806a440362f4a28bdb8c1..9046fbe0bac096d1c862244ca5d7ddbb32925856 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ -## Version 1.1.3 +## Version 1.2.0 -* Add compile flag `--conda-warnings off` only if pyccel version is 1.8.0 or greater. \ No newline at end of file +* Compile with language C by default. +* Added command line options, seen with `compile-gvec-tp -h` +* The "--compiler" option can now take the four compilers available in pyccel ("GNU" is the default, "intel", "PGI", "nvidia"). +Moreover, a JSON file can be specified to define a custom compiler (see pyccel doc). \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 68564bd74615d616840a5b95201b66a07dc732b4..5e6afd4b152ec710373b7969320224b8e853b6d1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "gvec-to-python" -version = "1.1.3" +version = "1.2.0" readme = "README.md" requires-python = ">=3.7" license = {file = "LICENSE"} @@ -21,13 +21,14 @@ classifiers = [ "Programming Language :: Python :: 3", ] dependencies = [ - 'matplotlib>=3.3.3', - 'numpy>=1.19.5', - 'pandas>=1.2.1', + 'matplotlib', + 'numpy', + 'pandas', 'pyccel', - 'scipy>=1.6.0', - 'tqdm>=4.56.0', - 'vtk>=9.0.3', + 'scipy', + 'tqdm', + 'vtk', + 'argcomplete', ] [project.urls] diff --git a/src/gvec_to_python/Makefile b/src/gvec_to_python/Makefile index 29b50e12c3a5b31d0ba470bdf412f185f3392be5..c2c2d60009843c8c727c7daee187fe78041e9d77 100644 --- a/src/gvec_to_python/Makefile +++ b/src/gvec_to_python/Makefile @@ -5,6 +5,8 @@ PYTHON := python3 SO_EXT := $(shell $(PYTHON) -c "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))") LIBDIR := $(shell $(PYTHON) -c "import sysconfig; print(sysconfig.get_config_var('LIBDIR'))") +install_path := $(shell $(PYTHON) -c "import gvec_to_python as _; print(_.__path__[0])") + FLAGS := --libdir $(LIBDIR) $(flags) #-------------------------------------- @@ -28,10 +30,10 @@ OUTPUTS := $(SOURCES:.py=$(SO_EXT)) all: $(OUTPUTS) $(BK)$(SO_EXT) : $(BK).py - pyccel $< $(FLAGS) + pyccel $(FLAGS) $< $(BEV1)$(SO_EXT) : $(BEV1).py $(BK)$(SO_EXT) - pyccel $< $(FLAGS) + pyccel $(FLAGS) $< #-------------------------------------- diff --git a/src/gvec_to_python/console/compile.py b/src/gvec_to_python/console/compile.py index 40a0f008ff8c35c74715dc8abb9b5401e6614021..c7cc0f010c78b6f57a7375e259bf45370cd3cd29 100644 --- a/src/gvec_to_python/console/compile.py +++ b/src/gvec_to_python/console/compile.py @@ -4,23 +4,85 @@ def compile_gvec_to_python(): import os import gvec_to_python import pyccel + import argparse + import importlib.metadata + import argcomplete - libpath = gvec_to_python.__path__[0] + # setup argument parser + parser = argparse.ArgumentParser(prog='gvec_to_python', + description='3D MHD equilibria from GVEC in Python.') + + # version message + __version__ = importlib.metadata.version("gvec_to_python") + version_message = f'gvec_to_python {__version__}\n' + version_message += 'Copyright 2022 (c) T.K. Cheng, F. Hindenlang, S. Possanner | Max Planck Institute for Plasma Physics\n' + version_message += 'MIT license\n' + + # arguments + parser.add_argument('-v', '--version', action='version', + version=version_message) - # pyccel flags - flags = '' + parser.add_argument('--language', + type=str, + metavar='LANGUAGE', + help='either "c" (default) or "fortran"', + default='c') + + parser.add_argument('--compiler', + type=str, + metavar='COMPILER', + help='either "GNU" (default), "intel", "PGI", "nvidia" or the path to a JSON compiler file.', + default='GNU') + + parser.add_argument('-d', '--delete', + help='remove .f90/.c and .so files (for running pure Python code)', + action='store_true') + + parser.add_argument('--verbose', + help='call pyccel with --verbose compiler option', + action='store_true') - _li = pyccel.__version__.split('.') - _num = int(_li[0])*100 + int(_li[1])*10 + int(_li[2]) - if _num >= 180: - flags += '--conda-warnings off' + # parse argument + argcomplete.autocomplete(parser) + args = parser.parse_args() + kwargs = vars(args) + + libpath = gvec_to_python.__path__[0] + + if any([s == ' ' for s in libpath]): + raise NameError( + f'gvec-to.python installation path MUST NOT contain blank spaces. Please rename "{libpath}".') + + if kwargs['delete']: + + # (change dir not to be in source path) + print('\nDeleting .f90/.c and .so files ...') + subprocess.run(['make', + 'clean', + '-f', + os.path.join(libpath, 'Makefile'), + ], check=True, cwd=libpath) + print('Done.') - print('\nCompiling gvec-to-python kernels ...') - subprocess.run(['make', - '-f', - os.path.join(libpath, 'Makefile'), - 'flags=' + flags, - 'install_path=' + libpath, - ], check=True, cwd=libpath) - print('Done.') + else: + # pyccel flags + flags = '--language=' + kwargs['language'] + flags += ' --compiler=' + kwargs['compiler'] + + _li = pyccel.__version__.split('.') + _num = int(_li[0])*100 + int(_li[1])*10 + int(_li[2]) + if _num >= 180: + flags += ' --conda-warnings off' + + if kwargs['verbose']: + flags += ' --verbose' + + print('\nCompiling gvec-to-python kernels ...') + subprocess.run(['make', + '-f', + os.path.join(libpath, 'Makefile'), + 'flags=' + flags, + 'install_path=' + libpath, + ], check=True, cwd=libpath) + print('Done.')