I ran into an issue the other day on a shared unix environment. 2 different users need to share the same virtual environment to be able to install and upgrade packages. Everything works OK except the scripts installed do not respect the users umask. This patch tries to fix that.
I see now the mask = current_umask() should probably be in the if: block, but other than that this is probably the easiest way to fix this.
It's also possible to use os.open and pass 777 since that follows the umask by default, but that would require changing how the file mode is passed.