Created
July 25, 2019 01:20
-
-
Save razzius/5d1b06f40377dd895eeff8568fd58f3c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3.7 | |
import argparse | |
import sys | |
from ripgrepy import Ripgrepy | |
parser = argparse.ArgumentParser() | |
parser.add_argument('symbol') | |
parser.add_argument('repository') | |
args = parser.parse_args() | |
symbol = args.symbol | |
repository = args.repository | |
search = Ripgrepy(f'class {symbol}', repository).json().run() | |
result = search.as_dict[0] | |
absolute_path = result['data']['path']['text'] | |
def trim_prefix(s, prefix): | |
if s.startswith(prefix): | |
return s[len(prefix):] | |
return s | |
relative_path = trim_prefix(absolute_path, repository) | |
import_path = trim_prefix(relative_path, '/').replace('.py', '').replace('/', '.') | |
print(f'from {import_path} import {symbol}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment