-
Notifications
You must be signed in to change notification settings - Fork 94
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
Support toph #323
Support toph #323
Conversation
…nto 'master' Resolve "Clone upstream locally and push to this repository" Closes online-judge-tools#1 See merge request toph/online-judge-tools!1
Resolve "Add support for Toph problem archive" Closes online-judge-tools#2 See merge request toph/online-judge-tools!2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your pull request! Your code is good!
But there are some points which can be better. Please fix these, and then I'll merge.
def from_url(cls, s: str) -> Optional['TophProblem']: | ||
result = urllib.parse.urlparse(s) | ||
dirname, basename = posixpath.split(utils.normpath(result.path)) | ||
if result.scheme in ('', 'http', 'https') \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if result.scheme in ('', 'http', 'https') \ | |
# example: https://toph.co/p/new-year-couple | |
if result.scheme in ('', 'http', 'https') \ |
onlinejudge/service/toph.py
Outdated
return None | ||
|
||
class TophProblem(onlinejudge.type.Problem): | ||
def __init__(self, slug: str, kind: Optional[str] = None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def __init__(self, slug: str, kind: Optional[str] = None): | |
def __init__(self, problem_id: str, contest_id: Optional[str] = None): | |
if contest_id is not None: | |
raise NotImplementedError |
This argument kind
is for the problems in the contest mode, right?
When we support the contest mode, it seems that this class need to have something like contest_id
since the urls of problems in contets are like https://toph.co/c/tough-dash-feb-2019/arena#!/p/set-union .
So, we should use such names from now, and mark it as not-implemented explicitly.
wow, I forgot to mention some things.
for example, the one for the $ oj download --help
usage: oj download [-h] [-f FORMAT] [-d DIRECTORY] [--overwrite] [-n] [-a]
[-s] [--json]
url
positional arguments:
url
optional arguments:
-h, --help show this help message and exit
-f FORMAT, --format FORMAT
a format string to specify paths of cases (defaut: "sample-%i.%e" if not --system)
-d DIRECTORY, --directory DIRECTORY
a directory name for test cases (default: test/)
--overwrite
-n, --dry-run don't write to files
-a, --system download system testcases
-s, --silent
--json
supported services:
Anarchy Golf
Aizu Online Judge
AtCoder
Codeforces
yukicoder
CS Academy
HackerRank
PKU JudgeOnline
Kattis
... This is in |
@kfaRabi by the way, the commits say you use two email addresses, and one of them is not associated with your GitHub account. Are you okay? If you want, you can fix this with something like |
@kmyk Thank you so much for taking the time to review the code and write suggestion + feedback. I am going to change everything as per your instructions soon. And, about the 2 emails, I actually work on GitLab. My initial commits were on GitLab, and once I was done, I committed here in GitHub. For this reason, you are probably seeing 2 emails. |
Resolve "Add support for Toph problem archive" Closes online-judge-tools#2 See merge request toph/online-judge-tools!4
Resolve "Write tests for Toph" Closes online-judge-tools#5 See merge request toph/online-judge-tools!5
@kmyk I have fixed a few things and added some tests. Could you kindly have a look at it now? |
subprocess.check_call([ojtools, 's', '-l', '58482c1804469e2585024324', '-y', '--no-open', url, 'a.py'], stdout=sys.stdout, stderr=sys.stderr) | ||
|
||
@unittest.skipIf('CI' in os.environ, 'login is required') | ||
def test_call_submit_add_them_up(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(not so important) It becomes better that this test case should submit C++ code, instead of Python code.
This tool guesses language ids (e.g. 584859c204469e2585024499
55b4af33421aa95e80000001
...) from language names (e.g. C++14
C++11
C++
Python 3
PyPy 3
...). The language names are different for each services and the guessing sometimes fails, so this case should also test this for C++.
onlinejudge/service/toph.py
Outdated
return None | ||
|
||
class TophProblem(onlinejudge.type.Problem): | ||
def __init__(self, problem_id: str, kind: Optional[str] = None, contest_id: Optional[str] = None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable kind
seems to be not necessary for now (contest_id
is None
implies it is problem
, and not None
does contest
).
I think that adding this variable is unnecessary generalization, and removing this is simple and better, but we should add this if there is another existing mode or a plan to add a new mode.
@kfaRabi Do you know another mode or a plan?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. We do not need this as Toph does not plan to add any other mode soon.
There was: $ mypy oj onlinejudge setup.py tests onlinejudge/service/toph.py:151: error: Invalid index type "Optional[str]" for "Dict[str, str]"; expected type "str"
@kfaRabi Thank you for fixing and adding tests. For CI, please cherry-pick adb59e2 and fd54382, then it will pass and I can/will merge this. |
@kfaRabi (and @hjr265) by the way, there are 3 questions:
|
onlinejudge/service/toph.py
Outdated
|
||
def get_url(self) -> str: | ||
# TODO: Check for contest_id to return the appropriate URL when support for contest is added | ||
return f'https://toph.co/p/{self.problem_id}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return f'https://toph.co/p/{self.problem_id}' | |
return 'https://toph.co/p/{}'.format(self.problem_id) |
f-string is useful and you should use it if possible, however, we need to support Python 3.5, and unfortunately Python 3.5 doesn't support f-strings.
@kmyk Regarding your questions:
Thank you for working with us closely as we implement this pull request. |
@hjr265 Thank you for answering. I'll let the community know Toph. |
$ mypy oj onlinejudge setup.py tests onlinejudge/service/toph.py:151: error: Invalid index type "Optional[str]" for "Dict[str, str]"; expected type "str"
CI succeeded 🎉 (once it failed, but it was for instability of tests) |
@kfaRabi I have merged your code. Thank you for your good work! |
I bumped version to 0.1.55. Now you can get the one which supports Toph with |
Closes #302
Add support for Toph's problem downloading (from archive/collection), login and submission(in archive/collection).
No support for test case download and submission in contest mode yet as the contest pages are being loaded dynamically using JS.