Skip to content

Commit 1ce90ef

Browse files
committed
bump version 0.4
1 parent 6575ede commit 1ce90ef

File tree

13 files changed

+297
-93
lines changed

13 files changed

+297
-93
lines changed

β€Ž.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ script:
1212
- isort --check-only --recursive coderunner
1313
- black --check --diff coderunner
1414
- flake8 coderunner --max-line-length=88 --ignore=F401
15-
- pylint coderunner --disable=bad-continuation,invalid-name,too-many-instance-attributes
15+
- pylint coderunner --disable=bad-continuation,invalid-name,too-many-instance-attributes,too-many-arguments

β€ŽREADME.md

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,33 @@
22

33
> [Judge0 API](https://api.judge0.com/) Interface written in Python
44
5-
[![Build Status](https://travis-ci.org/codeclassroom/CodeRunner.svg?branch=master)](https://travis-ci.org/codeclassroom/CodeRunner)
65
![PyPI](https://img.shields.io/pypi/v/coderunner?color=blue)
6+
[![Build Status](https://travis-ci.org/codeclassroom/CodeRunner.svg?branch=master)](https://travis-ci.org/codeclassroom/CodeRunner)
7+
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/coderunner)
78
[![Documentation Status](https://readthedocs.org/projects/coderunner/badge/?version=latest)](https://coderunner.readthedocs.io/en/latest/?badge=latest)
89
[![GitHub license](https://img.shields.io/github/license/codeclassroom/CodeRunner)](https://github.com/codeclassroom/CodeRunner/blob/master/LICENSE)
910
[![GitHub issues](https://img.shields.io/github/issues/codeclassroom/CodeRunner?color=blueviolet)](https://github.com/codeclassroom/CodeRunner/issues)
1011
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-orange.svg)](http://makeapullrequest.com)
1112

1213

13-
### Prerequisites
14+
## Usage
15+
16+
- Install `coderunner`.
17+
```bash
18+
pip install coderunner
19+
```
20+
21+
## Documentation
22+
23+
[CodeRunner Documentation](https://coderunner.readthedocs.io/en/latest/)
24+
25+
26+
## Testing
27+
28+
##### Prerequisites
1429
1. Python 3.6+
1530
2. virtualenv
1631

17-
### Installation
1832
1. Create virtual environment.
1933
```bash
2034
virtualenv -p python3 venv && cd venv && source bin/activate
@@ -31,43 +45,14 @@ pip install -r requirements.txt
3145
```bash
3246
python3 tests.py
3347
```
34-
35-
### Usage
36-
- Install the package.
48+
5. Lint the project with
3749
```bash
38-
pip install coderunner
50+
flake8 coderunner --max-line-length=88 --ignore=F401
51+
pylint coderunner --disable=bad-continuation,invalid-name,too-many-instance-attributes
3952
```
4053

41-
```python
42-
import coderunner
43-
import pprint
44-
program_name = "testfiles/" + "test_python.py"
45-
language = "Python"
46-
output = "testfiles/" + "output2.txt"
47-
Input = "testfiles/" + "input.txt"
48-
r = coderunner.Run(program_name, language, output, Input)
49-
print("Status : " + r.getStatus())
50-
if r.getError() != None:
51-
pprint.pprint("Error : " + r.getError())
52-
else:
53-
print("Standard Output : ")
54-
pprint.pprint(r.getStandardOutput())
55-
print("Execution Time : " + r.getTime())
56-
print("Memory : " + str(r.getMemory()))
57-
```
58-
59-
60-
### Pointers ✏
61-
- In a `Java` program the class name should always be ***`Main`***.
62-
- Currently supported languages :
63-
- C (gcc 7.2.0)
64-
- C++ (g++ 7.2.0)
65-
- Java (OpenJDK 8)
66-
- Python (3.6.0)
67-
68-
6954

70-
### Author
55+
## Author
7156

7257
πŸ‘₯ **Bhupesh Varshney**
7358

@@ -80,4 +65,4 @@ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file
8065

8166
## πŸ‘‹ Contributing
8267

83-
Please read the [CONTRIBUTING](CONTRIBUTING.md) file for the process of submitting pull requests to us.
68+
Please read the [CONTRIBUTING](CONTRIBUTING.md) guidelines for the process of submitting pull requests to us.

β€Žcoderunner/coderunner.py

Lines changed: 58 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
====================================
44
The core module of CodeRunner
55
"""
6+
import os
7+
68
import requests
79

8-
# language IDs on judge0, see README.md
10+
# language IDs on judge0, see Documentation
911
languages = {"C++": 10, "Java": 27, "Python": 34, "C": 4}
1012

1113
api_params = {
@@ -22,35 +24,51 @@
2224
}
2325

2426
API_URL = "https://api.judge0.com/submissions/"
27+
FIELDS = "?fields=stdout,memory,time,status,stderr,exit_code,created_at"
2528

2629

2730
class Run:
2831
"""
2932
Args:
30-
- Source Code path
33+
- Source Code
3134
- Language
32-
- Expected Output File Path
33-
- Standard Input File Path
35+
- Expected Output
36+
- Standard Input (Optional)
37+
- path (optional)
3438
"""
3539

36-
def __init__(self, program_name: str, lang: str, output: str, inp: str = None):
37-
"""Constructor method
38-
"""
39-
self.program_name = program_name
40-
self.lang = lang
40+
def __init__(
41+
self, source: str, lang: str, output: str, inp: str = None, path: bool = True
42+
):
43+
44+
self.path = path
4145
if lang not in languages:
4246
raise ValueError(f"{lang} is not a supported language {languages.keys()}")
43-
44-
self.output = output
45-
self.inp = inp
47+
self.lang = lang
4648
self.language_id = languages[lang]
4749
self.__response = None
4850
self.__memory = None
4951
self.__time = None
5052
self.__stdout = None
5153

54+
if self.path:
55+
if not os.path.exists(source):
56+
raise OSError(f"{source} is not a valid file path")
57+
self.source = source
58+
59+
if not os.path.exists(output):
60+
raise OSError(f"{output} is not a valid file path")
61+
self.output = output
62+
63+
if inp is not None and not os.path.exists(inp):
64+
raise OSError(f"{inp} is not a valid file path")
65+
self.inp = inp
66+
self.source = source
67+
self.output = output
68+
self.inp = inp
69+
5270
def __readCode(self):
53-
with open(self.program_name, "r") as myfile:
71+
with open(self.source, "r") as myfile:
5472
data = myfile.read()
5573
return data
5674

@@ -69,7 +87,7 @@ def __readStatus(self, token: str):
6987
Check Submission status
7088
"""
7189
while True:
72-
req = requests.get(API_URL + token["token"])
90+
req = requests.get(API_URL + token["token"] + FIELDS)
7391
self.__response = req.json()
7492
self.__memory = self.__response["memory"]
7593
self.__time = self.__response["time"]
@@ -88,68 +106,61 @@ def __submit(self):
88106

89107
api_params["expected_output"] = self.output
90108
api_params["language_id"] = self.language_id
91-
api_params["source_code"] = self.program_name
109+
api_params["source_code"] = self.source
92110

93111
res = requests.post(API_URL, data=api_params)
94112
token = res.json()
95113
return token
96114

97-
def getStandardOutput(self):
115+
def getSubmissionDate(self):
116+
"""
117+
return submission date/time of program
118+
"""
119+
return self.__response["created_at"]
120+
121+
def getExitCode(self):
122+
"""
123+
return exitcode of program (0 or 1)
98124
"""
99-
Return the standard output of the program
125+
return self.__response["exit_code"]
100126

101-
:param: None
102-
:rtype: String
127+
def getOutput(self):
128+
"""
129+
return standard output of program
103130
"""
104131
return self.__stdout
105132

106133
def getMemory(self):
107134
"""
108-
Return the memory used by the program (in kilobytes)
109-
110-
:param: None
111-
:return: Return the memory for eg 3564 KiloBytes
112-
:rtype: String
135+
return memory used by the program
113136
"""
114137
return self.__memory
115138

116139
def getError(self):
117140
"""
118-
Return any error occured during program execution
119-
120-
:param: None
121-
:rtype: String
141+
return any error message occured during execution of program
122142
"""
123143
if self.__response["stderr"] != "":
124144
return self.__response["stderr"]
125145
return None
126146

127147
def getTime(self):
128148
"""
129-
Return execution time used by the program
130-
131-
:param: None
132-
:return: Returns the execution time used by Source Code for e.g 0.037 secs
133-
:rtype: String
149+
return execution time of program
134150
"""
135151
return self.__time
136152

137153
def getStatus(self):
138154
"""
139-
Submits the program on Judge0's server and returns its status
140-
141-
:param: None
142-
:return: Returns either `Accepted` or `Run Time Error`
143-
:rtype: String
155+
submit the source code on judge0's server & return status
144156
"""
145-
self.program_name = self.__readCode()
146-
self.output = self.__readExpectedOutput()
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()
162+
163+
token = self.__submit()
164+
status = self.__readStatus(token)
147165

148-
if self.inp is not None:
149-
self.inp = self.__readStandardInput()
150-
token = self.__submit()
151-
status = self.__readStatus(token)
152-
else:
153-
token = self.__submit()
154-
status = self.__readStatus(token)
155166
return status

β€Ždemo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
pprint.pprint("Error : " + r.getError())
1313
else:
1414
print("Standard Output : ")
15-
pprint.pprint(r.getStandardOutput())
15+
pprint.pprint(r.getOutput())
1616
print("Execution Time : " + r.getTime())
1717
print("Memory : " + str(r.getMemory()))

β€Ždocs/about.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
1-
## About coderunner
1+
## About
2+
3+
coderunner was built by :
4+
5+
πŸ‘₯ **Bhupesh Varshney**
6+
7+
- Twitter: [@bhupeshimself](https://twitter.com/bhupeshimself)
8+
- DEV: [bhupesh](https://dev.to/bhupesh)
9+
- GitHub: [Bhupesh-V](https://github.com/Bhupesh-V)
10+
11+
## πŸ“ License
12+
13+
This project is licensed under the MIT License. See the [LICENSE](https://github.com/codeclassroom/CodeRunner/blob/master/LICENSE) file for details.
14+
15+
## πŸ‘‹ Contributing
16+
17+
Please read the [CONTRIBUTING](https://github.com/codeclassroom/CodeRunner/blob/master/CONTRIBUTING.md) guidelines for the process of submitting pull requests to us.

0 commit comments

Comments
Β (0)