Skip to content

Commit e0a7a01

Browse files
committed
Add Julia language recognition support. Fixes #4596
Signed-off-by: HasTheDev <hassanazam2021@gmail.com>
1 parent 3f5d6e3 commit e0a7a01

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/typecode/contenttype.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,8 @@ def is_source(self):
742742
elif self.is_makefile or self.is_js_map:
743743
return False
744744

745-
elif self.is_java_source is True or self.is_c_source is True:
745+
# Recognize "known-by-extension" source types
746+
elif self.is_java_source or self.is_c_source or self.is_julia_source:
746747
return True
747748

748749
elif self.filetype_pygment or self.is_script is True:
@@ -758,9 +759,19 @@ def programming_language(self):
758759
string.
759760
"""
760761
if self.is_source:
762+
# If the custom extension check found Julia, use that name explicitly
763+
if self.is_julia_source:
764+
return "Julia"
761765
return self.filetype_pygment or ""
762766
return ""
763767

768+
@property
769+
def is_julia_source(self):
770+
"""
771+
Return True if the file is Julia source code based on .jl extension.
772+
"""
773+
return self.is_file and self.location.lower().endswith(".jl")
774+
764775
@property
765776
def is_c_source(self):
766777
C_EXTENSIONS = set(
@@ -950,7 +961,8 @@ def get_text_file_start(location, length=4096):
950961
with open(location, "rb") as f:
951962
content = text.as_unicode(f.read(length))
952963
finally:
953-
return content
964+
pass
965+
return content
954966

955967

956968
def get_filetype(location):

tests/test_contenttype.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,17 @@ def test_compiled_elf_so_2(self):
230230
assert get_filetype(test_file) in expected
231231
assert get_filetype_pygment(test_file) == ""
232232

233+
def test_programming_language_detection_for_julia(self):
234+
# Create a temporary julia file
235+
test_file = self.get_temp_file("test.jl")
236+
with open(test_file, "w") as f:
237+
f.write('println("Hello Julia")')
238+
239+
# Get the type and check identification
240+
T = get_type(test_file)
241+
assert is_source(test_file)
242+
assert T.programming_language == "Julia"
243+
233244
@pytest.mark.xfail(
234245
on_mac or on_windows,
235246
reason="Somehow we get really weird results on macOS with libmagic 5.38 and mac, win32 on libmagic 5.39: "

0 commit comments

Comments
 (0)