diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 93179f3..e48f05c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -71,7 +71,8 @@ jobs: - name: Create build scripts in scripts/scripts shell: bash run: > - python3 scripts.py + python3 build.py + --create-scripts --platform ${{ runner.os }} --compiler ${{ matrix.toolchain.exe }} --mode debug @@ -169,7 +170,7 @@ jobs: - name: Prepare for uploading Python package wheel of pyCFML shell: bash - run: echo "WHEEL_DIR=$(python3 scripts.py --print-wheel-dir)" >> $GITHUB_ENV + run: echo "WHEEL_DIR=$(python3 build.py --print-wheel-dir)" >> $GITHUB_ENV - name: Upload zipped Python package wheel of pyCFML for next job uses: actions/upload-artifact@v4 @@ -228,7 +229,8 @@ jobs: - name: Create job step scripts shell: bash run: > - python3 scripts.py + python3 build.py + --create-scripts --platform ${{ runner.os }} --compiler ${{ matrix.toolchain.exe }} --mode debug @@ -237,7 +239,7 @@ jobs: - name: Prepare for downloading Python package wheel of pyCFML shell: bash - run: echo "WHEEL_DIR=$(python3 scripts.py --print-wheel-dir)" >> $GITHUB_ENV + run: echo "WHEEL_DIR=$(python3 build.py --print-wheel-dir)" >> $GITHUB_ENV - name: Download zipped pyCFML wheel from previous job uses: actions/download-artifact@v4 @@ -325,7 +327,8 @@ jobs: - name: Create build scripts in scripts/scripts shell: bash run: > - python3 scripts.py + python3 build.py + --create-scripts --platform ${{ runner.os }} --compiler ${{ matrix.toolchain.exe }} --mode debug @@ -399,9 +402,9 @@ jobs: - name: Prepare for uploading Python package wheel of pyCFML shell: bash run: | - echo "WHEEL_DIR=$(python3 scripts.py --print-wheel-dir)" >> $GITHUB_ENV - echo "RELEASE_VERSION=$(python3 scripts.py --print-release-version)" >> $GITHUB_ENV - echo "RELEASE_TITLE=$(python3 scripts.py --print-release-title)" >> $GITHUB_ENV + echo "WHEEL_DIR=$(python3 build.py --print-wheel-dir)" >> $GITHUB_ENV + echo "RELEASE_VERSION=$(python3 build.py --print-release-version)" >> $GITHUB_ENV + echo "RELEASE_TITLE=$(python3 build.py --print-release-title)" >> $GITHUB_ENV - name: Upload Python package wheel to releases (non-master branch) if: github.event_name == 'push' && env.BRANCH_NAME != 'master' diff --git a/scripts.py b/build.py similarity index 98% rename from scripts.py rename to build.py index 61e26fe..6614b43 100644 --- a/scripts.py +++ b/build.py @@ -7,6 +7,7 @@ import sysconfig import toml #import tomllib +from colorama import Fore, Back, Style from pathlib import Path from pygit2 import Repository @@ -14,6 +15,7 @@ global CONFIG MSG_COLOR = r'\033[0;33m' # orange +ERROR_COLOR = r'\033[0;31m' # red HEAD_COLOR = r'\033[1;34m' # bold blue COLOR_OFF = r'\033[0m' @@ -52,7 +54,7 @@ def _echo_cmd(): return 'echo -e' return 'echo' -def _echo_msg(msg: str): +def _echo_msg(msg:str): return f'{_echo_cmd()} "{MSG_COLOR}:::::: {msg}{COLOR_OFF}"' def _echo_progress_msg(current: int, total: int, msg: str): @@ -60,7 +62,7 @@ def _echo_progress_msg(current: int, total: int, msg: str): msg = f"[{progress:>3}%] {msg}" return _echo_msg(msg) -def _echo_header(msg: str): +def _echo_header(msg:str): msg = f'{HEAD_COLOR}:::::: {msg} ::::::{COLOR_OFF}' sep = ':' * (len(msg) - len(f'{HEAD_COLOR}') - len(f'{COLOR_OFF}')) lines = [] @@ -70,6 +72,12 @@ def _echo_header(msg: str): lines.append(f'{_echo_cmd()} "{HEAD_COLOR}{sep}{COLOR_OFF}"') return lines +def _print_msg(msg:str): + print(Fore.GREEN + f':::::: {msg}' + Style.RESET_ALL) + +def _print_error_msg(msg:str): + print(Fore.RED + f':::::: ERROR: {msg}' + Style.RESET_ALL) + def _processor(): processor = platform.processor() processor = processor.split()[0] # get the 1st word from string, such as 'Intel64 Family 6 Model 154 Stepping 3, GenuineIntel' @@ -403,6 +411,9 @@ def _compile_executables_script_lines(modules: str, def parsed_args(): parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) + parser.add_argument("--create-scripts", + action='store_true', + help="create scripts for building and testing") parser.add_argument("--platform", default="macos", choices=['macos', 'linux', 'windows'], @@ -1031,8 +1042,8 @@ def change_runpath_for_built_pycfml(): # install_name_tool -rpath /opt/intel/oneapi/compiler/2023.2.0/mac/bin/intel64/../../compiler/lib @loader_path dist/pyCFML/pycrysfml/crysfml08lib.so # install_name_tool -delete_rpath /usr/local/Cellar/gcc/13.2.0/lib/gcc/current dist/pyCFML/pycrysfml/crysfml08lib.so # install_name_tool -change /usr/local/opt/gcc/lib/gcc/current/libgfortran.5.dylib @rpath/libgfortran.5.dylib dist/pyCFML/pycrysfml/crysfml08lib.so - # otool -l dist/pyCFML/pycrysfml/crysfml08lib.so | grep RPATH -A2 # build.rpaths in in scripts.toml - # otool -L dist/pyCFML/pycrysfml/crysfml08lib.so # build.dependent-libs in scripts.toml + # otool -l dist/pyCFML/pycrysfml/crysfml08lib.so | grep RPATH -A2 # build.rpaths in in build.toml + # otool -L dist/pyCFML/pycrysfml/crysfml08lib.so # build.dependent-libs in build.toml try: rpaths = CONFIG['build']['rpaths'][_platform()][_processor()][_compiler_name()] except KeyError: @@ -1316,7 +1327,7 @@ def run_pycfml_functional_tests_no_benchmarks(): if __name__ == '__main__': ARGS = parsed_args() PYPROJECT = loaded_pyproject() - CONFIG = loaded_config('scripts.toml') + CONFIG = loaded_config('build.toml') if ARGS.print_wheel_dir: # NEED FIX. Maybe save extras to toml as in EDA? _print_wheel_dir() @@ -1330,6 +1341,10 @@ def run_pycfml_functional_tests_no_benchmarks(): _print_release_title() exit(0) + if not ARGS.create_scripts: # NEED FIX. Need proper check if create scripts or print flags are given + _print_error_msg('Incorrect set of command line arguments') + exit(1) + CFML = CONFIG['cfml']['log-name'] pyCFML = CONFIG['pycfml']['log-name'] @@ -1407,3 +1422,5 @@ def run_pycfml_functional_tests_no_benchmarks(): add_main_script_header(f"Run {pyCFML} tests") run_pycfml_unit_tests() run_pycfml_functional_tests_no_benchmarks() + + _print_msg(f'All scripts were successfully created in {_scripts_path()}') diff --git a/scripts.toml b/build.toml similarity index 99% rename from scripts.toml rename to build.toml index 9db1f74..7cb3064 100644 --- a/scripts.toml +++ b/build.toml @@ -35,7 +35,7 @@ pyapigen = 'repo/CFML/Scripts/PythonAPI/apigen.py' [pycfml] log-name = 'pyCFML' src-name = 'crysfml08lib' -dynamic-lib-name = 'crysfml08lib' # NEED FIX: currently not in use in scripts.py +dynamic-lib-name = 'crysfml08lib' # NEED FIX: currently not in use in build.py [pycfml.dir] build-src = 'build/pyCFML/src' # content will be generated by apigen.py diff --git a/pyproject.toml b/pyproject.toml index 1978678..13cff5c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,6 +32,7 @@ ci = [ 'validate-pyproject[all]', 'build', 'wheel', + 'colorama', 'toml' # need this, as tomllib is only available for python >=3.11 ] test = [