Skip to content

Instantly share code, notes, and snippets.

@siburu
Created December 7, 2021 16:00
Show Gist options
  • Save siburu/4972d7645871bb3ebc0e0ac67b25cdd5 to your computer and use it in GitHub Desktop.
Save siburu/4972d7645871bb3ebc0e0ac67b25cdd5 to your computer and use it in GitHub Desktop.
def calc_import_path(target: str, start: str) -> str:
import os
target = os.path.join('root', target)
start = os.path.join('root', start)
d = os.path.relpath(os.path.dirname(target), os.path.dirname(start))
if not d.startswith('.'):
d = os.path.join('.', d)
return os.path.join(d, os.path.basename(target))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment