Skip to content

Commit 439dc02

Browse files
committed
feat: Use entry_points instead of scripts
1 parent 3c12b5d commit 439dc02

File tree

4 files changed

+80
-90
lines changed

4 files changed

+80
-90
lines changed

bin/cf-run

Lines changed: 0 additions & 88 deletions
This file was deleted.

codeforces/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
from . import api
55
from . import error
66
from . import problem
7+
from . import cf_run
78

8-
__all__ = ['error', 'api', 'problem']
9+
__all__ = ['error', 'api', 'problem', 'cf_run']

codeforces/cf_run.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/usr/bin/env python
2+
3+
import argparse
4+
import subprocess
5+
import time
6+
7+
import colorama
8+
9+
import codeforces
10+
11+
colorama.init(autoreset=True)
12+
13+
def main(argv=None):
14+
parser = argparse.ArgumentParser()
15+
16+
parser.add_argument('contestId', type=int,
17+
help=("Id of the contest. It is not the round number. "
18+
"It can be seen in contest URL."))
19+
20+
parser.add_argument('index', type=str,
21+
help=("A letter or a letter followed by a digit, that "
22+
"represent a problem index in a contest."))
23+
24+
parser.add_argument('program', type=str,
25+
help="Path to executable that needs to be tested")
26+
27+
parser.add_argument('-t', '--timeout', type=int, default=10,
28+
help=("Timeout for program in seconds, -1 for no time "
29+
"limit (default: 10)"))
30+
31+
parser.add_argument('-g', '--gym', action='store_true',
32+
help=("If true open gym contest instead of regular "
33+
"contest. (default: false)"))
34+
35+
if argv:
36+
args = parser.parse_args(argv)
37+
else:
38+
args = parser.parse_args()
39+
40+
args.timeout = None if args.timeout == -1 else args.timeout
41+
42+
title, time_limit, memory_limit, sample_tests = codeforces.problem.get_info(
43+
args.contestId, args.index, gym=args.gym
44+
)
45+
46+
print(title)
47+
print("time limit per test:", time_limit)
48+
print("memory limit per test:", memory_limit)
49+
50+
print()
51+
52+
for inp, ans in sample_tests:
53+
start = time.time()
54+
55+
out = subprocess.run(
56+
args.program,
57+
input=inp.encode('utf-8'),
58+
capture_output=True,
59+
timeout=args.timeout
60+
).stdout.decode('utf-8')
61+
62+
time_used = time.time() - start
63+
64+
print('-' * 80, '\n')
65+
66+
print('Time: %d ms\n' % (time_used * 1000))
67+
68+
print(colorama.Style.BRIGHT + 'Input')
69+
print(inp)
70+
71+
print(colorama.Style.BRIGHT + "Participant's output")
72+
print(out)
73+
74+
print(colorama.Style.BRIGHT + "Jury's answer")
75+
print(ans)

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
packages=find_packages(exclude=['docs']),
2626
install_requires=['beautifulsoup4', 'colorama'],
2727
extras_requires={'docs': ['sphinx', 'sphinx_rtd_theme']},
28-
scripts=['bin/cf-run'],
28+
entry_points={
29+
'console_scripts': ['cf-run = codeforces.cf_run:main']
30+
},
2931
python_requires='>=3.6,<4',
3032
project_urls={
3133
"Bug Tracker": "https://github.com/Mukundan314/python-codeforces/issues/",

0 commit comments

Comments
 (0)