Skip to content

Commit

Permalink
Merge pull request #1709 from Scille/explicit-import-psutil
Browse files Browse the repository at this point in the history
Make explicit psutil&winreg imports in parsec.core.win_registry
  • Loading branch information
touilleMan authored May 4, 2021
2 parents 09bcffd + e48e3c9 commit 12084f4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
Empty file added newsfragments/1709.empty.rst
Empty file.
26 changes: 14 additions & 12 deletions parsec/core/win_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import os
import string
import sys
from importlib import import_module
import importlib_resources
from pathlib import Path
from structlog import get_logger
Expand All @@ -24,24 +23,27 @@

# Winreg helper

_psutil = None

# Psutil is a dependency only on Windows, winreg is part of stdlib
# but only available on Windows. Hence must rely on dynamic import
# so that the current module can be imported from any OS.
#
# On top of that, we use good ol' `import foo` (nothing beats that !) instead
# of the fancy `importlib.import_module`. This is to make sure PyInstaller
# won't mess application packaging by missing this import during
# tree-shaking (see issue #1690).

def get_psutil():
global _psutil
if not _psutil:
_psutil = import_module("psutil")
return _psutil

def get_psutil():
import psutil

_winreg = None
return psutil


def get_winreg():
global _winreg
if not _winreg:
_winreg = import_module("winreg")
return _winreg
import winreg

return winreg


def try_winreg():
Expand Down

0 comments on commit 12084f4

Please sign in to comment.