Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV: Allow symlink in Windows for editable install #1373

Merged
merged 1 commit into from
Jun 10, 2022
Merged
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
40 changes: 25 additions & 15 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,31 +125,41 @@ def run(self):
if '--user' in sys.prefix: # TODO: is there a better way to find out?
target_dir = user_dir()
target_dir = os.path.join(target_dir)
is_win = sys.platform.startswith('win')

for prefix_target, name in self.prefix_targets:
source = os.path.join('share', 'jupyter', prefix_target, name)
target = os.path.join(target_dir, prefix_target, name)
target_subdir = os.path.dirname(target)
if not os.path.exists(target_subdir):
os.makedirs(target_subdir)
if not is_win:
rel_source = os.path.relpath(os.path.abspath(
source), os.path.abspath(target_subdir))
else: # relpath does not work if source/target on different Windows disks
rel_source = os.path.abspath(source)
abs_source = os.path.abspath(source)

try:
rel_source = os.path.relpath(abs_source, os.path.abspath(target_subdir))
except Exception:
# relpath does not work if source/target on different Windows disks.
do_symlink = False
else:
do_symlink = True

try:
os.remove(target)
except Exception:
try:
shutil.rmtree(target) # Maybe not a symlink
except Exception:
pass

# Cannot symlink without relpath or Windows admin priv in some OS versions.
try:
if not is_win:
os.remove(target)
if do_symlink:
print(rel_source, '->', target)
os.symlink(rel_source, target)
else:
shutil.rmtree(target)
raise OSError('just make copies')
except Exception:
pass
print(rel_source, '->', target)
if not is_win:
os.symlink(rel_source, target)
else: # Cannot symlink without relpath or Windows admin priv in some OS versions
shutil.copytree(rel_source, target)
print(abs_source, '->', target)
shutil.copytree(abs_source, target)

super(DevelopCmd, self).run()

Expand Down