(scad: Path)
return namespace
cases:
        single scad file:
            return a namespace populated with `use()`
        directory
            recurse into all subdirectories and *.scad files
            return namespace if scad files are underneath, otherwise None
        non-scad file:
            return None
cases:
        single scad file:
            return a namespace populated with `use()`
        directory
            recurse into all subdirectories and *.scad files
            return namespace if scad files are underneath, otherwise None
        non-scad file:
            return None
cases : single scad file : return a namespace populated with use () directory recurse into all subdirectories and * . scad files return namespace if scad files are underneath otherwise None non - scad file : return None
def _import_scad(scad: Path) -> Optional[SimpleNamespace]:
    '''
    cases:
        single scad file:
            return a namespace populated with `use()`
        directory
            recurse into all subdirectories and *.scad files
            return namespace if scad files are underneath, otherwise None
        non-scad file:
            return None            
    '''
    namespace: Optional[SimpleNamespace] = None
    if scad.is_file() and scad.suffix == '.scad':
        namespace = SimpleNamespace()
        use(scad.absolute(), dest_namespace_dict=namespace.__dict__)
    elif scad.is_dir():
        subspaces = [(f, _import_scad(f)) for f in scad.iterdir() if f.is_dir() or f.suffix == '.scad']
        for f, subspace in subspaces:
            if subspace:
                if namespace is None:
                    namespace = SimpleNamespace()
                # Add a subspace to namespace named by the file/dir it represents
                package_name = f.stem
                # Prefix an underscore to packages starting with a digit, which
                # are valid in OpenSCAD but not in Python
                if package_name[0].isdigit():
                    package_name = '_' + package_name

                setattr(namespace, package_name, subspace)

    return namespace
def _import_scad ( scad : Path ) -> Optional [ SimpleNamespace ] : namespace : Optional [ SimpleNamespace ] = None if scad . is_file ( ) and scad . suffix == '.scad' : namespace = SimpleNamespace ( ) use ( scad . absolute ( ) , dest_namespace_dict = namespace . __dict__ ) elif scad . is_dir ( ) : subspaces = [ ( f , _import_scad ( f ) ) for f in scad . iterdir ( ) if f . is_dir ( ) or f . suffix == '.scad' ] for f , subspace in subspaces : if subspace : if namespace is None : namespace = SimpleNamespace ( ) # Add a subspace to namespace named by the file/dir it represents package_name = f . stem # Prefix an underscore to packages starting with a digit, which # are valid in OpenSCAD but not in Python if package_name [ 0 ] . isdigit ( ) : package_name = '_' + package_name setattr ( namespace , package_name , subspace ) return namespace