From 7558ade2d2747e4571aaea0cca4655164d56b184 Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Tue, 19 Dec 2023 14:31:10 -0800 Subject: [PATCH 1/3] Ignore generated .upm directory --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 0d458523..2f525290 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ internal/backends/python/cache internal/backends/python/regression_tests/*.txt internal/backends/python/regression_tests/test /.idea/ +.upm/ # nix build creates a "result" symlink to the nix store output result From d0e4e0f726a6b93dfbb969e06a5f9b4430130f83 Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Tue, 19 Dec 2023 13:41:35 -0800 Subject: [PATCH 2/3] Reflow "internalModules" --- internal/backends/python/grab.go | 424 +++++++++++++++---------------- 1 file changed, 208 insertions(+), 216 deletions(-) diff --git a/internal/backends/python/grab.go b/internal/backends/python/grab.go index 9a7def63..e078765e 100644 --- a/internal/backends/python/grab.go +++ b/internal/backends/python/grab.go @@ -34,213 +34,213 @@ var pyIgnoreGlobs = []string{ "**/.pythonlibs/**", } -var internalModules = []string{ - "__future__", - "__main__", - "_thread", - "abc", - "aifc", - "argparse", - "array", - "ast", - "asyncio", - "atexit", - "audioop", - "base64", - "bdb", - "binascii", - "bisect", - "builtins", - "bz2", - "calendar", - "cgi", - "cgitb", - "chunk", - "cmath", - "cmd", - "code", - "codecs", - "codeop", - "collections", - "colorsys", - "compileall", - "concurrent", - "configparser", - "contextlib", - "contextvars", - "copy", - "copyreg", - "cProfile", - "crypt", - "csv", - "ctypes", - "curses", - "dataclasses", - "datetime", - "dbm", - "decimal", - "difflib", - "dis", - "doctest", - "email", - "encodings", - "ensurepip", - "enum", - "errno", - "faulthandler", - "fcntl", - "filecmp", - "fileinput", - "fnmatch", - "fractions", - "ftplib", - "functools", - "gc", - "getopt", - "getpass", - "gettext", - "glob", - "graphlib", - "grp", - "gzip", - "hashlib", - "heapq", - "hmac", - "html", - "http", - "idlelib", - "imaplib", - "imghdr", - "importlib", - "inspect", - "io", - "ipaddress", - "itertools", - "json", - "keyword", - "lib2to3", - "linecache", - "locale", - "logging", - "lzma", - "mailbox", - "mailcap", - "marshal", - "math", - "mimetypes", - "mmap", - "modulefinder", - "msilib", - "msicrt", - "multiprocessing", - "netrc", - "nis", - "nntplib", - "numbers", - "operator", - "optparse", - "os", - "ossaudiodev", - "parser", - "pathlib", - "pdb", - "pickle", - "pickletools", - "pipes", - "pkgutil", - "platform", - "plistlib", - "poplib", - "posix", - "pprint", - "profile", - "pstats", - "pty", - "pwd", - "py_compile", - "pyclbr", - "pydoc", - "queue", - "quopri", - "random", - "re", - "readline", - "reprlib", - "resource", - "rlcompleter", - "runpy", - "sched", - "secrets", - "select", - "selectors", - "shelve", - "shlex", - "shutil", - "signal", - "site", - "sitecustomize", - "smtplib", - "sndhdr", - "socket", - "socketserver", - "spwd", - "sqlite3", - "ssl", - "stat", - "statistics", - "string", - "stringprep", - "struct", - "subprocess", - "sunau", - "symtable", - "sys", - "sysconfig", - "syslog", - "tabnanny", - "tarfile", - "telnetlib", - "tempfile", - "termios", - "test", - "textwrap", - "threading", - "time", - "timeit", - "tkinter", - "token", - "tokenize", - "tomllib", - "trace", - "traceback", - "tracemalloc", - "tty", - "turtle", - "turtledemo", - "types", - "typing", - "unicodedata", - "unittest", - "urllib", - "usercustomize", - "uu", - "uuid", - "venv", - "warnings", - "wave", - "weakref", - "webbrowser", - "winreg", - "winsound", - "wsgiref", - "xdrlib", - "xml", - "xmlrpc", - "zipapp", - "zipfile", - "zipimport", - "zlib", - "zoneinfo", +var internalModules = map[string]bool{ + "__future__": true, + "__main__": true, + "_thread": true, + "abc": true, + "aifc": true, + "argparse": true, + "array": true, + "ast": true, + "asyncio": true, + "atexit": true, + "audioop": true, + "base64": true, + "bdb": true, + "binascii": true, + "bisect": true, + "builtins": true, + "bz2": true, + "calendar": true, + "cgi": true, + "cgitb": true, + "chunk": true, + "cmath": true, + "cmd": true, + "code": true, + "codecs": true, + "codeop": true, + "collections": true, + "colorsys": true, + "compileall": true, + "concurrent": true, + "configparser": true, + "contextlib": true, + "contextvars": true, + "copy": true, + "copyreg": true, + "cProfile": true, + "crypt": true, + "csv": true, + "ctypes": true, + "curses": true, + "dataclasses": true, + "datetime": true, + "dbm": true, + "decimal": true, + "difflib": true, + "dis": true, + "doctest": true, + "email": true, + "encodings": true, + "ensurepip": true, + "enum": true, + "errno": true, + "faulthandler": true, + "fcntl": true, + "filecmp": true, + "fileinput": true, + "fnmatch": true, + "fractions": true, + "ftplib": true, + "functools": true, + "gc": true, + "getopt": true, + "getpass": true, + "gettext": true, + "glob": true, + "graphlib": true, + "grp": true, + "gzip": true, + "hashlib": true, + "heapq": true, + "hmac": true, + "html": true, + "http": true, + "idlelib": true, + "imaplib": true, + "imghdr": true, + "importlib": true, + "inspect": true, + "io": true, + "ipaddress": true, + "itertools": true, + "json": true, + "keyword": true, + "lib2to3": true, + "linecache": true, + "locale": true, + "logging": true, + "lzma": true, + "mailbox": true, + "mailcap": true, + "marshal": true, + "math": true, + "mimetypes": true, + "mmap": true, + "modulefinder": true, + "msilib": true, + "msicrt": true, + "multiprocessing": true, + "netrc": true, + "nis": true, + "nntplib": true, + "numbers": true, + "operator": true, + "optparse": true, + "os": true, + "ossaudiodev": true, + "parser": true, + "pathlib": true, + "pdb": true, + "pickle": true, + "pickletools": true, + "pipes": true, + "pkgutil": true, + "platform": true, + "plistlib": true, + "poplib": true, + "posix": true, + "pprint": true, + "profile": true, + "pstats": true, + "pty": true, + "pwd": true, + "py_compile": true, + "pyclbr": true, + "pydoc": true, + "queue": true, + "quopri": true, + "random": true, + "re": true, + "readline": true, + "reprlib": true, + "resource": true, + "rlcompleter": true, + "runpy": true, + "sched": true, + "secrets": true, + "select": true, + "selectors": true, + "shelve": true, + "shlex": true, + "shutil": true, + "signal": true, + "site": true, + "sitecustomize": true, + "smtplib": true, + "sndhdr": true, + "socket": true, + "socketserver": true, + "spwd": true, + "sqlite3": true, + "ssl": true, + "stat": true, + "statistics": true, + "string": true, + "stringprep": true, + "struct": true, + "subprocess": true, + "sunau": true, + "symtable": true, + "sys": true, + "sysconfig": true, + "syslog": true, + "tabnanny": true, + "tarfile": true, + "telnetlib": true, + "tempfile": true, + "termios": true, + "test": true, + "textwrap": true, + "threading": true, + "time": true, + "timeit": true, + "tkinter": true, + "token": true, + "tokenize": true, + "tomllib": true, + "trace": true, + "traceback": true, + "tracemalloc": true, + "tty": true, + "turtle": true, + "turtledemo": true, + "types": true, + "typing": true, + "unicodedata": true, + "unittest": true, + "urllib": true, + "usercustomize": true, + "uu": true, + "uuid": true, + "venv": true, + "warnings": true, + "wave": true, + "weakref": true, + "webbrowser": true, + "winreg": true, + "winsound": true, + "wsgiref": true, + "xdrlib": true, + "xml": true, + "xmlrpc": true, + "zipapp": true, + "zipfile": true, + "zipimport": true, + "zlib": true, + "zoneinfo": true, } func guess(ctx context.Context, python string) (map[api.PkgName]bool, bool) { @@ -284,15 +284,7 @@ func filterImports(ctx context.Context, foundPkgs map[string]bool) (map[api.PkgN // filter out internal modules for pkg := range foundPkgs { mod := getTopLevelModuleName(pkg) - found := false - for _, internalMod := range internalModules { - if internalMod == mod { - found = true - break - } - } - - if found { + if internalModules[mod] { delete(foundPkgs, pkg) } } From d1652640e132cb3e5a55b143bac860a3ec04c220 Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Tue, 19 Dec 2023 13:57:43 -0800 Subject: [PATCH 3/3] Reflow guessed packages We have a map[string]bool full of "true"... why not use it? --- internal/backends/nodejs/nodejs_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/backends/nodejs/nodejs_test.go b/internal/backends/nodejs/nodejs_test.go index b3de5167..c8d2511b 100644 --- a/internal/backends/nodejs/nodejs_test.go +++ b/internal/backends/nodejs/nodejs_test.go @@ -197,7 +197,7 @@ func verify(t *testing.T, tc TestCase, extension string) { } for key := range tc.expected { - if _, ok := result[key]; !ok { + if !result[key] { t.Errorf("Key %s not found in result map", key) } }