link_pyqt: Only link/copy files if they changed.
This reduces the output noise a bit and hopefully makes things a bit faster on Windows.
This commit is contained in:
parent
3879b8301f
commit
0be0884a5b
@ -28,6 +28,7 @@ import sys
|
|||||||
import glob
|
import glob
|
||||||
import subprocess
|
import subprocess
|
||||||
import platform
|
import platform
|
||||||
|
import filecmp
|
||||||
|
|
||||||
|
|
||||||
class Error(Exception):
|
class Error(Exception):
|
||||||
@ -58,6 +59,22 @@ def get_ignored_files(directory, files):
|
|||||||
return filtered
|
return filtered
|
||||||
|
|
||||||
|
|
||||||
|
def needs_update(source, dest):
|
||||||
|
"""Check if a file to be linked/copied needs to be updated."""
|
||||||
|
if os.path.islink(dest):
|
||||||
|
# No need to delete a link and relink -> skip this
|
||||||
|
return False
|
||||||
|
elif os.path.isdir(dest):
|
||||||
|
diffs = filecmp.dircmp(source, dest)
|
||||||
|
ignored = get_ignored_files(source, diffs.left_only)
|
||||||
|
has_new_files = set(ignored) != set(diffs.left_only)
|
||||||
|
return (has_new_files or diffs.right_only or
|
||||||
|
diffs.common_funny or diffs.diff_files or
|
||||||
|
diffs.funny_files)
|
||||||
|
else:
|
||||||
|
return not filecmp.cmp(source, dest)
|
||||||
|
|
||||||
|
|
||||||
def link_pyqt(sys_path, venv_path):
|
def link_pyqt(sys_path, venv_path):
|
||||||
"""Symlink the systemwide PyQt/sip into the venv.
|
"""Symlink the systemwide PyQt/sip into the venv.
|
||||||
|
|
||||||
@ -75,16 +92,24 @@ def link_pyqt(sys_path, venv_path):
|
|||||||
for fn, required in files:
|
for fn, required in files:
|
||||||
source = os.path.join(sys_path, fn)
|
source = os.path.join(sys_path, fn)
|
||||||
dest = os.path.join(venv_path, fn)
|
dest = os.path.join(venv_path, fn)
|
||||||
|
|
||||||
if not os.path.exists(source):
|
if not os.path.exists(source):
|
||||||
if required:
|
if required:
|
||||||
raise FileNotFoundError(source)
|
raise FileNotFoundError(source)
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if os.path.exists(dest):
|
if os.path.exists(dest):
|
||||||
if os.path.isdir(dest) and not os.path.islink(dest):
|
if needs_update(source, dest):
|
||||||
shutil.rmtree(dest)
|
remove(dest)
|
||||||
else:
|
else:
|
||||||
os.unlink(dest)
|
continue
|
||||||
|
|
||||||
|
copy_or_link(source, dest)
|
||||||
|
|
||||||
|
|
||||||
|
def copy_or_link(source, dest):
|
||||||
|
"""Copy or symlink source to dest."""
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
if os.path.isdir(source):
|
if os.path.isdir(source):
|
||||||
shutil.copytree(source, dest, ignore=get_ignored_files,
|
shutil.copytree(source, dest, ignore=get_ignored_files,
|
||||||
@ -97,6 +122,14 @@ def link_pyqt(sys_path, venv_path):
|
|||||||
os.symlink(source, dest)
|
os.symlink(source, dest)
|
||||||
|
|
||||||
|
|
||||||
|
def remove(filename):
|
||||||
|
"""Remove a given filename, regardless of whether it's a file or dir."""
|
||||||
|
if os.path.isdir(filename):
|
||||||
|
shutil.rmtree(filename)
|
||||||
|
else:
|
||||||
|
os.unlink(filename)
|
||||||
|
|
||||||
|
|
||||||
def get_python_lib(executable, venv=False):
|
def get_python_lib(executable, venv=False):
|
||||||
"""Get the python site-packages directory for the given executable.
|
"""Get the python site-packages directory for the given executable.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user