diff options
author | Ben Sima <ben@bsima.me> | 2023-08-28 21:05:25 -0400 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2023-09-20 17:56:12 -0400 |
commit | 6e4a65579c3ade76feea0890072099f0d0caf416 (patch) | |
tree | 95671321c951134753323978854cece5f7d5435b /Biz/Bild.hs | |
parent | 13added53bbf996ec25a19b734326a6834918279 (diff) |
Prototype Mynion
This implements a prototype Mynion, my chatbot which will eventually
help me write code here. In fact he's already helping me, and works
pretty well over xmpp.
The prompt is currently not checked in because I'm experimenting with it
a lot, and it should probably be a runtime parameter anyways.
In the course of writing this I added some helper libraries to get me
going, configured black (didn't even know that was possible), and added
'outlines' and its dependencies even though I didn't end up using it.
I'll keep outlines around for now, but I'm not sure how useful it really
is because afaict its just pre-defining some stop conditions. But it
took a while to get it working so I'll just keep it in for now.
Diffstat (limited to 'Biz/Bild.hs')
-rw-r--r-- | Biz/Bild.hs | 94 |
1 files changed, 60 insertions, 34 deletions
diff --git a/Biz/Bild.hs b/Biz/Bild.hs index 9c4f035..22d3882 100644 --- a/Biz/Bild.hs +++ b/Biz/Bild.hs @@ -312,10 +312,10 @@ data Target = Target deriving (Show, Generic, Aeson.ToJSON) -- | Use this to just get a target to play with at the repl. -dev_getTarget :: IO Target -dev_getTarget = do +dev_getTarget :: FilePath -> IO Target +dev_getTarget fp = do root <- Env.getEnv "BIZ_ROOT" - path <- Dir.makeAbsolute "Biz/Bild.hs" + path <- Dir.makeAbsolute fp Namespace.fromPath root path |> \case Nothing -> panic "Could not get namespace from path" @@ -448,34 +448,35 @@ analyze hmap ns = case Map.lookup ns hmap of Namespace.Md -> pure Nothing Namespace.None -> pure Nothing Namespace.Py -> - Meta.detectAll "#" contentLines |> \Meta.Parsed {..} -> - Target - { builder = "python", - wrapper = Nothing, - compiler = CPython, - compilerFlags = - -- This doesn't really make sense for python, but I'll leave - -- it here for eventual --dev builds - [ "-c", - "\"import py_compile;import os;" - <> "py_compile.compile(file='" - <> str quapath - <> "', cfile=os.getenv('BIZ_ROOT')+'/_/int/" - <> str quapath - <> "', doraise=True)\"" - ], - sysdeps = psys, - langdeps = pdep, - outPath = outToPath pout, - out = pout, - -- implement detectPythonImports, then I can fill this out - srcs = Set.empty, - packageSet = "python.packages", - mainModule = Namespace.toModule namespace, - .. - } - |> Just - |> pure + contentLines + |> Meta.detectAll "#" + |> \Meta.Parsed {..} -> + detectPythonImports contentLines +> \srcs -> + Target + { builder = "python", + wrapper = Nothing, + compiler = CPython, + compilerFlags = + -- This doesn't really make sense for python, but I'll leave + -- it here for eventual --dev builds + [ "-c", + "\"import py_compile;import os;" + <> "py_compile.compile(file='" + <> str quapath + <> "', cfile=os.getenv('BIZ_ROOT')+'/_/int/" + <> str quapath + <> "', doraise=True)\"" + ], + sysdeps = psys, + langdeps = pdep, + outPath = outToPath pout, + out = pout, + packageSet = "python.packages", + mainModule = Namespace.toModule namespace, + .. + } + |> Just + |> pure Namespace.Sh -> pure Nothing Namespace.C -> Meta.detectAll "//" contentLines |> \Meta.Parsed {..} -> do @@ -713,6 +714,27 @@ detectLispImports contentLines = |> Set.fromList |> pure +-- | Finds local imports. Does not recurse to find transitive imports like +-- 'detectHaskellImports' does. Someday I will refactor these detection +-- functions and have a common, well-performing, complete solution. +detectPythonImports :: [Text] -> IO (Set FilePath) +detectPythonImports contentLines = + contentLines + /> Text.unpack + /> Regex.match pythonImport + |> catMaybes + /> Namespace.fromPythonModule + /> Namespace.toPath + |> filterM Dir.doesPathExist + /> Set.fromList + where + -- only detects 'import x' because I don't like 'from' + pythonImport :: Regex.RE Char String + pythonImport = + Regex.string "import" + *> Regex.some (Regex.psym Char.isSpace) + *> Regex.many (Regex.psym isModuleChar) + ghcPkgFindModule :: Set String -> String -> IO (Set String) ghcPkgFindModule acc m = Env.getEnv "GHC_PACKAGE_PATH" +> \packageDb -> @@ -755,9 +777,13 @@ build andTest loud analysis = Env.getEnv "BIZ_ROOT" +> \root -> forM (Map.elems analysis) <| \target@Target {..} -> fst </ case compiler of - CPython -> - Log.info ["bild", "nix", "python", nschunk namespace] - >> nixBuild loud target + CPython -> case out of + Meta.Bin _ -> + Log.info ["bild", "nix", "python", nschunk namespace] + >> nixBuild loud target + _ -> + Log.info ["bild", "nix", "python", nschunk namespace, "cannot build library"] + >> pure (Exit.ExitSuccess, mempty) Gcc -> Log.info ["bild", label, "gcc", nschunk namespace] >> nixBuild loud target |