@contextmanager<EOL>def make_path_writable(path):
from rez.config import config<EOL>try:<EOL><INDENT>orig_mode = os.stat(path).st_mode<EOL>new_mode = orig_mode<EOL>if config.make_package_temporarily_writable andnot os.access(path, os.W_OK):<EOL><INDENT>new_mode = orig_mode | stat.S_IWUSR<EOL><DEDENT>if new_mode != orig_mode:<EOL><INDENT>os.chmod(path, new_mode)<EOL><DEDENT><DEDENT>except OSError:<EOL><INDENT>orig_mode = None<EOL>new_mode = None<EOL><DEDENT>try:<EOL><INDENT>yield<EOL><DEDENT>finally:<EOL><INDENT>if new_mode != orig_mode:<EOL><INDENT>os.chmod(path, orig_mode)<EOL><DEDENT><DEDENT>
Temporarily make `path` writable, if possible.

    Does nothing if:
        - config setting 'make_package_temporarily_writable' is False;
        - this can't be done (eg we don't own `path`).

    Args:
        path (str): Path to make temporarily writable