Get path to extra data (config, tables, etc.).
(home_dir=None)
| 473 | |
| 474 | |
| 475 | def _get_extra_data_path(home_dir=None): |
| 476 | """Get path to extra data (config, tables, etc.).""" |
| 477 | global _temp_home_dir |
| 478 | if home_dir is None: |
| 479 | home_dir = os.environ.get("_MNE_FAKE_HOME_DIR") |
| 480 | if home_dir is None: |
| 481 | # this has been checked on OSX64, Linux64, and Win32 |
| 482 | if "nt" == os.name.lower(): |
| 483 | APPDATA_DIR = os.getenv("APPDATA") |
| 484 | USERPROFILE_DIR = os.getenv("USERPROFILE") |
| 485 | if APPDATA_DIR is not None and op.isdir( |
| 486 | op.join(APPDATA_DIR, ".mne") |
| 487 | ): # backward-compat |
| 488 | home_dir = APPDATA_DIR |
| 489 | elif USERPROFILE_DIR is not None: |
| 490 | home_dir = USERPROFILE_DIR |
| 491 | else: |
| 492 | raise FileNotFoundError( |
| 493 | "The USERPROFILE environment variable is not set, cannot " |
| 494 | "determine the location of the MNE-Python configuration " |
| 495 | "folder" |
| 496 | ) |
| 497 | del APPDATA_DIR, USERPROFILE_DIR |
| 498 | else: |
| 499 | # This is a more robust way of getting the user's home folder on |
| 500 | # Linux platforms (not sure about OSX, Unix or BSD) than checking |
| 501 | # the HOME environment variable. If the user is running some sort |
| 502 | # of script that isn't launched via the command line (e.g. a script |
| 503 | # launched via Upstart) then the HOME environment variable will |
| 504 | # not be set. |
| 505 | if os.getenv("MNE_DONTWRITE_HOME", "") == "true": |
| 506 | if _temp_home_dir is None: |
| 507 | _temp_home_dir = tempfile.mkdtemp() |
| 508 | atexit.register( |
| 509 | partial(shutil.rmtree, _temp_home_dir, ignore_errors=True) |
| 510 | ) |
| 511 | home_dir = _temp_home_dir |
| 512 | else: |
| 513 | home_dir = os.path.expanduser("~") |
| 514 | |
| 515 | if home_dir is None: |
| 516 | raise ValueError( |
| 517 | "mne-python config file path could " |
| 518 | "not be determined, please report this " |
| 519 | "error to mne-python developers" |
| 520 | ) |
| 521 | |
| 522 | return op.join(home_dir, ".mne") |
| 523 | |
| 524 | |
| 525 | def get_subjects_dir(subjects_dir=None, raise_error=False): |
no outgoing calls
no test coverage detected