Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions salt/syspaths.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
else:
__PLATFORM = sys.platform.lower()

typo_warning = True
missing_vars_warning = True
log = logging.getLogger(__name__)
EXPECTED_VARIABLES = (
"ROOT_DIR",
Expand Down Expand Up @@ -64,12 +64,12 @@
if hasattr(__generated_syspaths, key):
continue
else:
if typo_warning:
log.warning("Possible Typo?")
if missing_vars_warning:
log.warning("Missing variable in _syspaths.py")
log.warning(
"To dissolve this warning add `[variable] = None` to _syspaths.py"
"To resolve this warning add `[variable] = None` to _syspaths.py"
)
typo_warning = False
missing_vars_warning = False
log.warning("Variable %s is missing, value set to None", key)
setattr(
__generated_syspaths, key, None
Expand Down
16 changes: 10 additions & 6 deletions tests/unit/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,11 @@ def setUpClass(cls):
os.makedirs(RUNTIME_VARS.TMP)

def setUp(self):
# Prevent .pyc files from being written to avoid performance issues
# when modules are reloaded quickly (see TODO comments below)
self._original_dont_write_bytecode = sys.dont_write_bytecode
sys.dont_write_bytecode = True

self.tmp_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP)
self.addCleanup(shutil.rmtree, self.tmp_dir, ignore_errors=True)

Expand All @@ -581,6 +586,9 @@ def setUp(self):
)

def tearDown(self):
# Restore original dont_write_bytecode setting
sys.dont_write_bytecode = self._original_dont_write_bytecode

for attrname in ("tmp_dir", "utils", "proxy", "loader", "minion_mods", "utils"):
try:
delattr(self, attrname)
Expand All @@ -602,15 +610,11 @@ def update_module(self):
fh.flush()
os.fsync(fh.fileno()) # flush to disk

# pyc files don't like it when we change the original quickly
# since the header bytes only contain the timestamp (granularity of seconds)
# TODO: don't write them? Is *much* slower on re-load (~3x)
# https://docs.python.org/2/library/sys.html#sys.dont_write_bytecode
remove_bytecode(self.module_path)
# .pyc files are prevented by sys.dont_write_bytecode = True in setUp()

def rm_module(self):
os.unlink(self.module_path)
remove_bytecode(self.module_path)
# .pyc files are prevented by sys.dont_write_bytecode = True in setUp()

@property
def module_path(self):
Expand Down