#! /usr/bin/env python
"""Rectangle compression workflow

Requires the following ``SConscript(..., exports=[])``

* ``env`` - The SCons construction environment with the following required keys

  * ``abaqus_source_abspath`` - String absolute path to the EABM's Abaqus journal files
  * ``unconditional_build`` - Boolean flag to force building of conditionally ignored targets
  * ``abaqus`` - String path for the Abaqus executable
"""

import pathlib

# Inherit the parent construction environment
Import('env')

# Set project-wide paths with os-agnostic path separators
abaqus_source_abspath = pathlib.Path(env["abaqus_source_abspath"])

# Simulation variables
build_directory = pathlib.Path(Dir('.').abspath)
workflow_name = build_directory.name
model = "rectangle"

# Comment used in tutorial code snippets: marker-1

# Collect the target nodes to build a concise alias for all targets
workflow = []

# Geometry
journal_file = f"{model}_geometry"
journal_options = ""
workflow.extend(env.AbaqusJournal(
    target=[f"{journal_file}.cae", f"{journal_file}.jnl"],
    source=[f"{abaqus_source_abspath / journal_file}.py"],
    journal_options=journal_options))

# Comment used in tutorial code snippets: marker-3

# Collector alias based on parent directory name
env.Alias(workflow_name, workflow)

if not env['unconditional_build'] and not env['abaqus']:
    print(f"Program 'abaqus' was not found in construction environment. Ignoring '{workflow_name}' target(s)")
    Ignore(['.', workflow_name], workflow)
