In Drupal 8, module's weight is stored into ConfigFactory. Here's how to get or set module weight.

Get module weight:

$extension_config = \Drupal::configFactory()->getEditable('core.extension');
$module_weight = $extension_config->get("module.MODULE_NAME");
echo $module_weight;

Set module weight:

module_set_weight('MODULE_NAME', 100);
Tags: