Last active
June 23, 2022 20:07
-
-
Save kana-sama/bec55d4dcf49d398d54a76b97e22ea1b 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
import Data.Generics.Uniplate.Data (universeBi) | |
import Data.List (nub, intercalate) | |
import Language.Python.Common | |
import Language.Python.Version3 (parseModule) | |
import System.Environment (getArgs) | |
fromName :: DottedNameSpan -> String | |
fromName dn = intercalate "." [s | Ident s _ <- dn] | |
extract :: StatementSpan -> [String] | |
extract (Import items _) = [fromName name | ImportItem name _ _ <- items] | |
extract (FromImport (ImportRelative _ (Just name) _) _ _) = [fromName name] | |
extract _ = [] | |
main :: IO () | |
main = do | |
[path] <- getArgs | |
source <- readFile path | |
let Right (module_, _) = parseModule source path | |
putStrLn (unlines (nub (universeBi module_ >>= extract))) |
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
name: hspg | |
dependencies: | |
- base | |
- language-python | |
- uniplate | |
executables: | |
hspg-exe: | |
main: Main.hs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment