Skip to content

Commit

Permalink
Rename scripts to build
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSazonov committed Jul 24, 2024
1 parent 6114d0a commit 8fc3097
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
19 changes: 11 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down
27 changes: 22 additions & 5 deletions scripts.py → build.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
import sysconfig
import toml
#import tomllib
from colorama import Fore, Back, Style
from pathlib import Path
from pygit2 import Repository

global ARGS
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'

Expand Down Expand Up @@ -52,15 +54,15 @@ 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):
progress = _compiling_progress(current, total)
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 = []
Expand All @@ -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'
Expand Down Expand Up @@ -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'],
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand All @@ -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']

Expand Down Expand Up @@ -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()}')
2 changes: 1 addition & 1 deletion scripts.toml → build.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ ci = [
'validate-pyproject[all]',
'build',
'wheel',
'colorama',
'toml' # need this, as tomllib is only available for python >=3.11
]
test = [
Expand Down

0 comments on commit 8fc3097

Please sign in to comment.