Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update _LANGUAGE_GUESS to include new languages #35

Merged
merged 1 commit into from
Mar 16, 2023

Conversation

JoelNiemela
Copy link
Contributor

In addition to adding new languages, it also does the following changes:

  • removes the entry '.h': 'C++',
  • assumes the default version of JavaScript is Node.js (it previously guessed JavaScript, which is an invalid language name)
  • assumes the default version of python is Python3 (it previously made no guess for .py files)

@niemela niemela merged commit f5c31f3 into Kattis:master Mar 16, 2023
@simonlindholm
Copy link
Member

assumes the default version of python is Python3 (it previously made no guess for .py files)

It did, actually, based on a heuristic:

kattis-cli/submit.py

Lines 129 to 161 in f5c31f3

def is_python2(files):
python2 = re.compile(r'^\s*\bprint\b *[^ \(\),\]]|\braw_input\b')
for filename in files:
try:
with open(filename) as f:
for index, line in enumerate(f):
if index == 0 and line.startswith('#!'):
if 'python2' in line:
return True
if 'python3' in line:
return False
if python2.search(line.split('#')[0]):
return True
except IOError:
return False
return False
def guess_language(ext, files):
if ext == ".C":
return "C++"
ext = ext.lower()
if ext == ".h":
if any(f.endswith(".c") for f in files):
return "C"
else:
return "C++"
if ext == ".py":
if is_python2(files):
return "Python 2"
else:
return "Python 3"
return _LANGUAGE_GUESS.get(ext, None)

Kattis's submit page uses (used?) the same heuristic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants