Skip to content

Commit 68cb3ca

Browse files
committed
Add Julia language recognition support. Fixes #4596
Signed-off-by: HasTheDev <hassanazam2021@gmail.com>
1 parent 335d0cf commit 68cb3ca

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

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
@@ -238,6 +238,17 @@ def test_compiled_elf_so_2(self):
238238
assert get_filetype(test_file) in expected
239239
assert get_filetype_pygment(test_file) == ""
240240

241+
def test_programming_language_detection_for_julia(self):
242+
# Create a temporary julia file
243+
test_file = self.get_temp_file("test.jl")
244+
with open(test_file, "w") as f:
245+
f.write('println("Hello Julia")')
246+
247+
# Get the type and check identification
248+
T = get_type(test_file)
249+
assert is_source(test_file)
250+
assert T.programming_language == "Julia"
251+
241252
@pytest.mark.xfail(
242253
on_mac or on_windows,
243254
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)