mpylab.tools.nport_migration module

Migrate legacy NPORT interpolation settings in INI files.

exception mpylab.tools.nport_migration.NPortMigrationError

Bases: ValueError

Raised when an INI file cannot be migrated without ambiguity.

class mpylab.tools.nport_migration.NPortMigrationResult(source: str, replacements: int, device_type: str | None)

Bases: object

Result of inspecting or migrating one INI source.

property changed

Return whether legacy channel settings were replaced.

device_type: str | None
replacements: int
source: str
mpylab.tools.nport_migration.discover_ini_files(path, recursive=False)

Return deterministic INI inputs for one file or directory.

mpylab.tools.nport_migration.main(argv=None)

Run the mpylab-nport-migrate command.

mpylab.tools.nport_migration.migrate_nport_ini_file(path, *, write=False, remove_db_factor=False)

Inspect and optionally migrate one NPORT-style INI file.

Parameters:
  • path (path-like) – Input INI file; symbolic links are rejected.

  • write (bool, optional) – Write changes atomically, preserving BOM and file permissions.

  • remove_db_factor (bool, optional) – Also remove deprecated DB_FACTOR options with values 10 or 20.

Returns:

Original source and migration result.

Return type:

tuple of str and NPortMigrationResult

Raises:
  • NPortMigrationError – If encoding or configuration is invalid, or path is a symbolic link.

  • OSError – If reading or writing fails.

mpylab.tools.nport_migration.migrate_nport_ini_source(source, *, remove_db_factor=False)

Return an explicitly configured equivalent of a legacy NPORT INI.

Only NPORT, CABLE, ANTENNA and AMPLIFIER files are considered. Both historical INTERPOLATION = LIN and LOG are converted to the explicit settings that preserve the old NPORT behavior.

Parameters:
  • source (str) – Original INI text.

  • remove_db_factor (bool, optional) – Also remove deprecated channel DB_FACTOR values of 10 or 20, retaining their comments. Invalid or duplicate factors are rejected.

Returns:

Updated source, number of settings changed and device type.

Return type:

NPortMigrationResult

Raises:

NPortMigrationError – If the configuration cannot be migrated unambiguously.