Skip to content

Commit 131714f

Browse files
authored
Merge pull request #3 from codeclassroom/dev
0.5 release
2 parents a89b6d9 + e15b03b commit 131714f

37 files changed

+549
-160
lines changed

.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
17+
- pylint coderunner --disable=bad-continuation,invalid-name,too-many-instance-attributes,too-many-arguments,attribute-defined-outside-init
1818
after_success:
1919
- codecov

CHANGELOG.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
6+
## [0.5] - Dec 20, 2019
7+
8+
### Added
9+
10+
- New instance method - `run()`.
11+
- `run()` is now used to run the code i.e the code is submitted to Judge0 api using this method.
12+
- Support for *Bash 4.4*.
13+
14+
### Changed
15+
- Renamed Class `Run` to `code` for easier usage.
16+
- `getStatus()`, now only returns the status in comparison to earlier versions where it performed multiple tasks.
17+
This is effect fixes [#2](https://github.com/codeclassroom/CodeRunner/issues/2).
18+
19+
### Removed
20+
- `requests` as a dependency, Network requests are now 50% faster.
21+
22+
23+
## [0.4] - Nov 11, 2019
24+
25+
### Added
26+
27+
- `getSubmissionDate()`, `getExitCode` new methods.
28+
- Official Documentation.
29+
30+
### Changed
31+
32+
- Class Run `init` - Now you can pass _source code_, _input_ and _output_ to program as strings (limited to file paths in prior versions).
33+
34+
35+
## [0.3] - Nov 9, 2019
36+
37+
### Added
38+
39+
- Removed redundant imports
40+
- Added Module/Class docstrings for documentation
41+
- Formatted Code
42+
43+
44+
## [0.2] - Oct 31, 2019
45+
46+
### Changed
47+
48+
- Fix import requests problem.
49+
50+
51+
## [0.1] - Oct 30, 2019
52+
- Initial Release

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CodeRunner 🏃
22

3-
> [Judge0 API](https://api.judge0.com/) Interface written in Python
3+
> A judge 👨🏽‍⚖️ for your programs, run and test your programs through Python
44
55

66
![PyPI](https://img.shields.io/pypi/v/coderunner?color=blue)
@@ -25,25 +25,26 @@ or directly from GitHub if you cannot wait to test new features
2525
```bash
2626
pip install git+https://github.com/codeclassroom/CodeRunner.git
2727
```
28+
2829
## Usage
2930

3031
```python
3132

3233
import coderunner
3334

34-
program_name = "path-to/test_python.py"
35+
source_code = "path-to/test_python.py"
3536
language = "Python"
36-
output = "path-to/output.txt"
37-
Input = "path-to/input.txt"
37+
expected_output = "path-to/output.txt"
38+
standard_input = "path-to/input.txt"
3839

3940
# use this if you have a standard input to Program
40-
r = coderunner.Run(program_name, language, output, Input)
41+
r = coderunner.code(source_code, language, expected_output, standard_input)
4142

4243
# otherwise
43-
r = coderunner.Run(program_name, language, output)
44+
r = coderunner.code(source_code, language, expected_output)
4445

45-
# if not using file paths
46-
r = coderunner.Run("Hello, World", language, "Hello, World", path=False)
46+
# Use path=False if not using file paths
47+
r = coderunner.code("Hello, World", language, "Hello, World", path=False)
4748
```
4849

4950
## Documentation
@@ -79,9 +80,9 @@ flake8 coderunner --max-line-length=88 --ignore=F401
7980
pylint coderunner --disable=bad-continuation,invalid-name,too-many-instance-attributes
8081
```
8182

82-
## Changelog
83+
## 📝 Changelog
8384

84-
Changelog can be found in [Releases](https://github.com/codeclassroom/CodeRunner/releases)
85+
See the [CHANGELOG.md](CHANGELOG.md) file for details.
8586

8687

8788
## Author
@@ -93,7 +94,7 @@ Changelog can be found in [Releases](https://github.com/codeclassroom/CodeRunner
9394

9495
[![forthebadge](https://forthebadge.com/images/badges/built-with-love.svg)](https://forthebadge.com)
9596

96-
## 📝 License
97+
## 📜 License
9798

9899
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
99100

coderunner/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
"""Import Run() for initializing program data"""
2-
from coderunner.coderunner import Run
2+
from coderunner.coderunner import code

coderunner/coderunner.py

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
====================================
44
The core module of CodeRunner
55
"""
6+
import json
67
import os
7-
8-
import requests
8+
import urllib.parse
9+
import urllib.request
910

1011
# language IDs on judge0, see Documentation
11-
languages = {"C++": 10, "Java": 27, "Python": 34, "C": 4}
12+
languages = {"C++": 10, "Java": 27, "Python": 34, "C": 4, "Bash": 1}
1213

1314
api_params = {
1415
"number_of_runs": "1",
@@ -27,7 +28,7 @@
2728
FIELDS = "?fields=stdout,memory,time,status,stderr,exit_code,created_at"
2829

2930

30-
class Run:
31+
class code:
3132
"""
3233
Args:
3334
- Source Code
@@ -87,8 +88,11 @@ def __readStatus(self, token: str):
8788
Check Submission status
8889
"""
8990
while True:
90-
req = requests.get(API_URL + token["token"] + FIELDS)
91-
self.__response = req.json()
91+
req = urllib.request.Request(API_URL + token["token"] + FIELDS)
92+
with urllib.request.urlopen(req) as response:
93+
req = response.read()
94+
95+
self.__response = json.loads(req.decode("utf-8"))
9296
self.__memory = self.__response["memory"]
9397
self.__time = self.__response["time"]
9498
status = self.__response["status"]["description"]
@@ -108,8 +112,12 @@ def __submit(self):
108112
api_params["language_id"] = self.language_id
109113
api_params["source_code"] = self.source
110114

111-
res = requests.post(API_URL, data=api_params)
112-
token = res.json()
115+
post_data = urllib.parse.urlencode(api_params).encode("ascii")
116+
req = urllib.request.Request(API_URL, post_data)
117+
with urllib.request.urlopen(req) as response:
118+
req = response.read()
119+
token = json.loads(req.decode("utf-8"))
120+
113121
return token
114122

115123
def getSubmissionDate(self):
@@ -150,17 +158,24 @@ def getTime(self):
150158
"""
151159
return self.__time
152160

153-
def getStatus(self):
161+
def run(self):
154162
"""
155163
submit the source code on judge0's server & return status
156164
"""
157-
if self.path:
158-
if self.inp is not None:
159-
self.inp = self.__readStandardInput()
160-
self.source = self.__readCode()
161-
self.output = self.__readExpectedOutput()
165+
if os.path.exists(self.source):
166+
if self.path:
167+
if self.inp is not None:
168+
self.inp = self.__readStandardInput()
169+
self.source = self.__readCode()
170+
self.output = self.__readExpectedOutput()
162171

163172
token = self.__submit()
164-
status = self.__readStatus(token)
173+
self.__token = token
174+
175+
def getStatus(self):
176+
"""
177+
Return submission status
178+
"""
179+
status = self.__readStatus(self.__token)
165180

166181
return status

demo.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
11
from coderunner import coderunner
22
import pprint
33

4-
program_name = "testfiles/" + "test_python.py"
4+
source_code = "testfiles/" + "test_python_input.py"
55
language = "Python"
6-
output = "testfiles/" + "output2.txt"
7-
Input = "testfiles/" + "input.txt"
8-
r = coderunner.Run(program_name, language, output, Input)
6+
output = "testfiles/output/" + "output2.txt"
7+
Input = "testfiles/input/" + "input.txt"
8+
r = coderunner.code(source_code, language, output, Input)
99

10+
r2 = coderunner.code("print(\"yo\")", "Python", "YO", path=False)
11+
12+
# run the code
13+
r.run()
14+
15+
print("Run r :")
1016
print("Status : " + r.getStatus())
11-
if r.getError() != None:
12-
pprint.pprint("Error : " + r.getError())
17+
18+
r2.run()
19+
20+
print("Run r2 :")
21+
print("Status : " + r2.getStatus())
22+
23+
# check if any error occured
24+
if r.getError() is not None:
25+
pprint.pprint("Error : " + r.getError())
1326
else:
14-
print("Standard Output : ")
15-
pprint.pprint(r.getOutput())
27+
print("Standard Output : ")
28+
pprint.pprint(r.getOutput())
1629
print("Execution Time : " + r.getTime())
17-
print("Memory : " + str(r.getMemory()))
30+
print("Memory : " + str(r.getMemory()))

docs/changelog.md

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,54 @@
11
# Changelog
22

3-
See changelog on [GitHub](https://github.com/codeclassroom/CodeRunner/releases)
43

5-
## Releases
4+
5+
## [0.5] - Dec 20, 2019
6+
7+
### Added
8+
9+
- New instance method - `run()`.
10+
- `run()` is now used to run the code i.e the code is submitted to Judge0 api using this method.
11+
- Support for *Bash 4.4*.
12+
13+
### Changed
14+
- Renamed Class `Run` to `code` for easier usage.
15+
- `getStatus()`, now only returns the status in comparison to earlier versions where it performed multiple tasks.
16+
This is effect fixes [#2](https://github.com/codeclassroom/CodeRunner/issues/2).
17+
18+
### Removed
19+
- `requests` as a dependency, Network requests are now 50% faster.
20+
21+
22+
## [0.4] - Nov 11, 2019
23+
24+
### Added
25+
26+
- `getSubmissionDate()`, `getExitCode` new methods.
27+
- Official Documentation.
28+
29+
### Changed
30+
31+
- Class Run `init` - Now you can pass _source code_, _input_ and _output_ to program as strings (limited to file paths in prior versions).
32+
33+
34+
## [0.3] - Nov 9, 2019
35+
36+
### Added
37+
38+
- Removed redundant imports
39+
- Added Module/Class docstrings for documentation
40+
- Formatted Code
41+
42+
43+
## [0.2] - Oct 31, 2019
44+
45+
### Changed
46+
47+
- Fix import requests problem.
48+
49+
50+
## [0.1] - Oct 30, 2019
51+
- Initial Release
52+
53+
# Releases
654
See releases on [PyPi](https://pypi.org/project/coderunner/#history)

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CodeRunner 🏃
22

3-
> [Judge0 API](https://api.judge0.com/) Interface written in Python
3+
> A judge 👨🏽‍⚖️ for your programs, run and test your programs through Python
44
55
[![Build Status](https://travis-ci.org/codeclassroom/CodeRunner.svg?branch=master)](https://travis-ci.org/codeclassroom/CodeRunner)
66
![PyPI](https://img.shields.io/pypi/v/coderunner?color=blue)

docs/installation.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ Installing coderunner is pretty simple, just run
44

55
`pip install coderunner`
66

7-
or to install a specific verison
7+
Install a specific verison
88

9-
`pip install coderunner==0.3`
9+
`pip install coderunner==0.4`
10+
11+
or directly from GitHub if you cannot wait to test new features
12+
13+
`pip install git+https://github.com/codeclassroom/CodeRunner.git`
1014

1115
If you have already installed it and want to update
1216

docs/judge0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# [judge0](https://judge0.com/)
22

3-
CodeRunner is powered by judge0 api.<br>
3+
CodeRunner is powered by Judge0 api.<br>
44

55
### [API Docs](https://api.judge0.com/)
66
### [GItHub Repository](https://github.com/judge0/api)

0 commit comments

Comments
 (0)