def METHOD_NAME(sw_dir=None):
    """
    Returns the software directory defined in the ``core.software_dir`` config. When *sw_dir* is not
    *None*, it is expanded and returned instead.
    """
    if sw_dir is None:
        cfg = Config.instance()
        sw_dir = cfg.get_expanded("core", "software_dir")
    sw_dir = os.path.expandvars(os.path.expanduser(sw_dir))
    return sw_dir