Skip to content

Commit 508dd6e

Browse files
authored
Merge pull request #4 from codeclassroom/dev
release 0.6
2 parents 7a8c40d + 85146b7 commit 508dd6e

File tree

12 files changed

+270
-75
lines changed

12 files changed

+270
-75
lines changed

β€Ž.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,5 @@ dmypy.json
131131

132132
# End of https://www.gitignore.io/api/python
133133

134+
# Custom
135+
sample.py

β€Ž.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ script:
1414
- isort --check-only --recursive coderunner
1515
- black --check --diff coderunner
1616
- flake8 coderunner --max-line-length=88 --ignore=F401
17-
- pylint coderunner --disable=bad-continuation,invalid-name,too-many-instance-attributes,too-many-arguments,attribute-defined-outside-init
17+
- pylint coderunner --disable=bad-continuation,invalid-name,too-many-instance-attributes,too-many-arguments,attribute-defined-outside-init,no-self-use
1818
after_success:
1919
- codecov

β€ŽCHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [0.6] - Jan 5, 2020
6+
7+
### Added
8+
9+
- New optional argument, `number_of_runs` in `run()` method, use this to specify no.of times you want to run the code. Default is set to 1.
10+
- Ported NEW Languages. CodeRunner now supports all languages provided by Judge0.
11+
- `setFlags(options)` for setting options for the compiler (i.e. compiler flags).
12+
- `setArguments(arguments)` for setting Command line arguments for the program.
13+
14+
### Changed
15+
- Minor internal improvemets.
16+
517

618
## [0.5] - Dec 20, 2019
719

β€ŽREADME.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ python tests.py
7777
5. Lint the project with
7878
```bash
7979
flake8 coderunner --max-line-length=88 --ignore=F401
80-
pylint coderunner --disable=bad-continuation,invalid-name,too-many-instance-attributes
80+
black --check --diff coderunner
8181
```
8282

8383
## πŸ“ Changelog

β€Žcoderunner/coderunner.py

Lines changed: 82 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,38 @@
99
import urllib.request
1010

1111
# language IDs on judge0, see Documentation
12-
languages = {"C++": 10, "Java": 27, "Python": 34, "C": 4, "Bash": 1}
12+
languages = {
13+
"Assembly": 45,
14+
"Bash": 46,
15+
"Basic": 47,
16+
"C": 50,
17+
"C++": 54,
18+
"C#": 51,
19+
"Common Lisp": 55,
20+
"D": 56,
21+
"Elixir": 57,
22+
"Erlang": 58,
23+
"Executable": 44,
24+
"Fortran": 59,
25+
"Go": 60,
26+
"Haskell": 61,
27+
"Java": 62,
28+
"JavaScript": 63,
29+
"Lua": 64,
30+
"OCaml": 65,
31+
"Octave": 66,
32+
"Pascal": 67,
33+
"PHP": 68,
34+
"Plain Text": 43,
35+
"Prolog": 69,
36+
"Python2": 70,
37+
"Python3": 71,
38+
"Ruby": 72,
39+
"Rust": 73,
40+
"TypeScript": 74,
41+
}
1342

1443
api_params = {
15-
"number_of_runs": "1",
1644
"cpu_time_limit": "2",
1745
"cpu_extra_time": "0.5",
1846
"wall_time_limit": "5",
@@ -28,6 +56,10 @@
2856
FIELDS = "?fields=stdout,memory,time,status,stderr,exit_code,created_at"
2957

3058

59+
class ValueTooLargeError(Exception):
60+
"""Raised when the input value is too large"""
61+
62+
3163
class code:
3264
"""
3365
Args:
@@ -51,6 +83,7 @@ def __init__(
5183
self.__memory = None
5284
self.__time = None
5385
self.__stdout = None
86+
self.languages = list(languages.keys())
5487

5588
if self.path:
5689
if not os.path.exists(source):
@@ -69,19 +102,28 @@ def __init__(
69102
self.inp = inp
70103

71104
def __readCode(self):
72-
with open(self.source, "r") as myfile:
73-
data = myfile.read()
74-
return data
105+
try:
106+
with open(self.source, "r") as program_file:
107+
data = program_file.read()
108+
return data
109+
except FileNotFoundError as e:
110+
raise e
75111

76112
def __readExpectedOutput(self):
77-
with open(self.output, "r") as out:
78-
data = out.read()
79-
return data
113+
try:
114+
with open(self.output, "r") as exp_out:
115+
data = exp_out.read()
116+
return data
117+
except FileNotFoundError as e:
118+
raise e
80119

81120
def __readStandardInput(self):
82-
with open(self.inp, "r") as out:
83-
data = out.read()
84-
return data
121+
try:
122+
with open(self.inp, "r") as standard_input:
123+
data = standard_input.read()
124+
return data
125+
except FileNotFoundError as e:
126+
raise e
85127

86128
def __readStatus(self, token: str):
87129
"""
@@ -121,47 +163,53 @@ def __submit(self):
121163
return token
122164

123165
def getSubmissionDate(self):
124-
"""
125-
return submission date/time of program
126-
"""
166+
"""Submission date/time of program"""
127167
return self.__response["created_at"]
128168

129169
def getExitCode(self):
130-
"""
131-
return exitcode of program (0 or 1)
132-
"""
170+
"""Exitcode of program (0 or 1)"""
133171
return self.__response["exit_code"]
134172

135173
def getOutput(self):
136-
"""
137-
return standard output of program
138-
"""
174+
"""Standard output of the program"""
139175
return self.__stdout
140176

141177
def getMemory(self):
142-
"""
143-
return memory used by the program
144-
"""
178+
"""Memory used by the program"""
145179
return self.__memory
146180

147181
def getError(self):
148-
"""
149-
return any error message occured during execution of program
150-
"""
182+
"""Error occured during execution of program"""
151183
if self.__response["stderr"] != "":
152184
return self.__response["stderr"]
153185
return None
154186

155187
def getTime(self):
156-
"""
157-
return execution time of program
158-
"""
188+
"""Execution time of program"""
159189
return self.__time
160190

161-
def run(self):
162-
"""
163-
submit the source code on judge0's server & return status
164-
"""
191+
def setFlags(self, options: str):
192+
"""Options for the compiler (i.e. compiler flags)"""
193+
try:
194+
if len(options) > 128:
195+
raise ValueTooLargeError
196+
api_params["compiler_options"] = options
197+
except ValueTooLargeError:
198+
print("Maximum 128 characters allowed")
199+
200+
def setArguments(self, arguments: str):
201+
"""Command line arguments for the program"""
202+
try:
203+
if len(arguments) > 128:
204+
raise ValueTooLargeError
205+
api_params["command_line_arguments"] = arguments
206+
except ValueTooLargeError:
207+
print("Maximum 128 characters allowed")
208+
209+
def run(self, number_of_runs: int = 1):
210+
"""Submit the source code on judge0's server & return status"""
211+
api_params["number_of_runs"] = number_of_runs
212+
165213
if os.path.exists(self.source):
166214
if self.path:
167215
if self.inp is not None:
@@ -173,9 +221,7 @@ def run(self):
173221
self.__token = token
174222

175223
def getStatus(self):
176-
"""
177-
Return submission status
178-
"""
224+
"""Submission status"""
179225
status = self.__readStatus(self.__token)
180226

181227
return status

β€Ždemo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
import pprint
33

44
source_code = "testfiles/" + "test_python_input.py"
5-
language = "Python"
5+
language = "Python3"
66
output = "testfiles/output/" + "output2.txt"
77
Input = "testfiles/input/" + "input.txt"
88
r = coderunner.code(source_code, language, output, Input)
99

10-
r2 = coderunner.code("print(\"yo\")", "Python", "YO", path=False)
10+
r2 = coderunner.code("print(\"yo\")", "Python3", "YO", path=False)
1111

1212
# run the code
1313
r.run()

β€Ždocs/changelog.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

33

44

5+
## [0.6] - Jan 5, 2020
6+
7+
### Added
8+
9+
- New optional argument, `number_of_runs` in `run()` method, use this to specify no.of times you want to run the code. Default is set to 1.
10+
- Ported NEW Languages. CodeRunner now supports all languages provided by Judge0.
11+
- [`setFlags(options)`](/usage/#9-setflagsoptions) for setting options for the compiler (i.e. compiler flags).
12+
- [`setArguments(arguments)`](/usage/#10-setargumentsarguments) for setting Command line arguments for the program.
13+
14+
### Changed
15+
- Minor internal improvemets.
16+
17+
518
## [0.5] - Dec 20, 2019
619

720
### Added

β€Ždocs/index.md

Lines changed: 97 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,102 @@
22

33
> A judge πŸ‘¨πŸ½β€βš–οΈ for your programs, run and test your programs through Python
44
5-
[![Build Status](https://travis-ci.org/codeclassroom/CodeRunner.svg?branch=master)](https://travis-ci.org/codeclassroom/CodeRunner)
5+
66
![PyPI](https://img.shields.io/pypi/v/coderunner?color=blue)
7+
[![Build Status](https://travis-ci.org/codeclassroom/CodeRunner.svg?branch=master)](https://travis-ci.org/codeclassroom/CodeRunner)
8+
[![codecov](https://codecov.io/gh/codeclassroom/CodeRunner/branch/master/graph/badge.svg)](https://codecov.io/gh/codeclassroom/CodeRunner)
9+
![PyPI - Format](https://img.shields.io/pypi/format/coderunner?color=orange)
10+
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/coderunner)
711
[![Documentation Status](https://readthedocs.org/projects/coderunner/badge/?version=latest)](https://coderunner.readthedocs.io/en/latest/?badge=latest)
8-
[![GitHub license](https://img.shields.io/github/license/codeclassroom/CodeRunner)](https://github.com/codeclassroom/CodeRunner/blob/master/LICENSE)
9-
[![GitHub issues](https://img.shields.io/github/issues/codeclassroom/CodeRunner?color=blueviolet)](https://github.com/codeclassroom/CodeRunner/issues)
10-
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-orange.svg)](http://makeapullrequest.com)
12+
![PyPI - Downloads](https://img.shields.io/pypi/dm/coderunner?color=blue)
13+
14+
15+
## Installation
16+
17+
Install using `pip` from PyPI
18+
19+
```bash
20+
pip install coderunner
21+
```
22+
23+
or directly from GitHub if you cannot wait to test new features
24+
25+
```bash
26+
pip install git+https://github.com/codeclassroom/CodeRunner.git
27+
```
28+
29+
## Usage
30+
31+
```python
32+
33+
import coderunner
34+
35+
source_code = "path-to/test_python.py"
36+
language = "Python"
37+
expected_output = "path-to/output.txt"
38+
standard_input = "path-to/input.txt"
39+
40+
# use this if you have a standard input to Program
41+
r = coderunner.code(source_code, language, expected_output, standard_input)
42+
43+
# otherwise
44+
r = coderunner.code(source_code, language, expected_output)
45+
46+
# Use path=False if not using file paths
47+
r = coderunner.code("Hello, World", language, "Hello, World", path=False)
48+
```
49+
50+
## Documentation
51+
52+
> [CodeRunner Documentation](https://coderunner.readthedocs.io/en/latest/)
53+
54+
55+
## Development
56+
57+
##### Prerequisites
58+
- Python 3.6+
59+
- virtualenv
60+
61+
1. Create virtual environment.
62+
```bash
63+
virtualenv -p python3 venv && cd venv && source bin/activate
64+
```
65+
2. Clone the repository.
66+
```bash
67+
git https://github.com/codeclassroom/CodeRunner.git
68+
```
69+
3. Install Dependencies.
70+
```bash
71+
pip install -r requirements.txt
72+
```
73+
4. Run tests.
74+
```bash
75+
python tests.py
76+
```
77+
5. Lint the project with
78+
```bash
79+
flake8 coderunner --max-line-length=88 --ignore=F401
80+
black --check --diff coderunner
81+
```
82+
83+
## πŸ“ Changelog
84+
85+
See the [CHANGELOG.md](CHANGELOG.md) file for details.
86+
87+
88+
## Author
89+
90+
πŸ‘₯ **Bhupesh Varshney**
91+
92+
- Twitter: [@bhupeshimself](https://twitter.com/bhupeshimself)
93+
- DEV: [bhupesh](https://dev.to/bhupesh)
94+
95+
[![forthebadge](https://forthebadge.com/images/badges/built-with-love.svg)](https://forthebadge.com)
96+
97+
## πŸ“œ License
98+
99+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
100+
101+
## πŸ‘‹ Contributing
102+
103+
Please read the [CONTRIBUTING](CONTRIBUTING.md) guidelines for the process of submitting pull requests to us.

β€Ždocs/judge0.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ CodeRunner is powered by Judge0 api.<br>
99
The following api parameters are set default by coderunner:
1010
```python
1111

12-
api_params = {
13-
"number_of_runs": "1",
12+
{
1413
"cpu_time_limit": "2",
1514
"cpu_extra_time": "0.5",
1615
"wall_time_limit": "5",

0 commit comments

Comments
Β (0)