From e0a7a01c80478b3dced76bc65fa7b33dcfa62a2c Mon Sep 17 00:00:00 2001 From: HasTheDev Date: Thu, 5 Mar 2026 00:32:41 +0000 Subject: [PATCH] Add Julia language recognition support. Fixes #4596 Signed-off-by: HasTheDev --- src/typecode/contenttype.py | 16 ++++++++++++++-- tests/test_contenttype.py | 11 +++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/typecode/contenttype.py b/src/typecode/contenttype.py index 3243e33..948208b 100644 --- a/src/typecode/contenttype.py +++ b/src/typecode/contenttype.py @@ -742,7 +742,8 @@ def is_source(self): elif self.is_makefile or self.is_js_map: return False - elif self.is_java_source is True or self.is_c_source is True: + # Recognize "known-by-extension" source types + elif self.is_java_source or self.is_c_source or self.is_julia_source: return True elif self.filetype_pygment or self.is_script is True: @@ -758,9 +759,19 @@ def programming_language(self): string. """ if self.is_source: + # If the custom extension check found Julia, use that name explicitly + if self.is_julia_source: + return "Julia" return self.filetype_pygment or "" return "" + @property + def is_julia_source(self): + """ + Return True if the file is Julia source code based on .jl extension. + """ + return self.is_file and self.location.lower().endswith(".jl") + @property def is_c_source(self): C_EXTENSIONS = set( @@ -950,7 +961,8 @@ def get_text_file_start(location, length=4096): with open(location, "rb") as f: content = text.as_unicode(f.read(length)) finally: - return content + pass + return content def get_filetype(location): diff --git a/tests/test_contenttype.py b/tests/test_contenttype.py index 1e389c6..562cdc4 100644 --- a/tests/test_contenttype.py +++ b/tests/test_contenttype.py @@ -230,6 +230,17 @@ def test_compiled_elf_so_2(self): assert get_filetype(test_file) in expected assert get_filetype_pygment(test_file) == "" + def test_programming_language_detection_for_julia(self): + # Create a temporary julia file + test_file = self.get_temp_file("test.jl") + with open(test_file, "w") as f: + f.write('println("Hello Julia")') + + # Get the type and check identification + T = get_type(test_file) + assert is_source(test_file) + assert T.programming_language == "Julia" + @pytest.mark.xfail( on_mac or on_windows, reason="Somehow we get really weird results on macOS with libmagic 5.38 and mac, win32 on libmagic 5.39: "