Skip to content

Commit ad856aa

Browse files
committedOct 30, 2021
remove IDEone password from code, revamp Makefile and add ability to set default website from env var
1 parent d9f5a5a commit ad856aa

File tree

7 files changed

+36
-20
lines changed

7 files changed

+36
-20
lines changed
 

Diff for: ‎.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
learnpython_env/
55

66
.vscode/
7-
venv
7+
venv
8+
app.env

Diff for: ‎Makefile

+5
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@ run-daemon:
44
docker-compose up -d
55
run-js:
66
DEFAULT_DOMAIN=learn-js.org docker-compose up
7+
build-local:
8+
python3 -m venv venv
9+
venv/bin/pip install -r requirements.txt
10+
run-local:
11+
venv/bin/python main.py

Diff for: ‎README.md

+22-13
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,20 @@ This is the open source repository for the free interactive tutorial websites:
1515
* [learn-perl.org](https://www.learn-perl.org)
1616
* [learnrubyonline.org](https://www.learnrubyonline.org)
1717
* [learn-golang.org](https://www.learn-golang.org)
18-
* [learnRust.org](https://learnRust.org)
18+
* [learnrust.org](https://learnrust.org)
1919

2020
Please feel free to contribute your tutorials or exercises by sending a pull request and adding yourself on the list.
2121

22-
To run locally in a Docker container, execute:
22+
To run locally, first create a new file called `app.env` based on `app.env.example`.
23+
(you don't need working credentials to run the website, just to execute code).
2324

24-
make run
25+
### Running with Docker
2526

26-
This command will run learnpython.org website by default
27+
Execute:
28+
29+
DEFAULT_DOMAIN=learnpython.org make run
30+
31+
This command will run learnpython.org website by default using Docker Compose.
2732

2833
To run a specific website, run with the DEFAULT_DOMAIN option set, as follows:
2934

@@ -33,18 +38,22 @@ By default, the server process will run at http://localhost:5000.
3338

3439
The web server will locally compile and load all Markdown files into memory. The docker needs to be rebuilt upon any change in the Python code or the Markdown code.
3540

36-
To run the development server outside of a Docker, create a Python 3 virtualenv and install the requirements.
41+
### Running without Docker (locally)
3742

38-
# create the virtualenv
39-
mkvirtualenv interactive-tutorials
40-
41-
# install requirements
42-
pip install -r requirements.txt
43-
44-
# run the development server. Replace learnpython.org with the domain you are working on e.g. learn-golang.org
45-
python main.py -d learnpython.org
43+
To run the development server outside of a Docker, run the following command once:
44+
45+
make build-local
46+
47+
And then run:
48+
49+
DEFAULT_DOMAIN=learn-js.org make run-local
4650

4751

52+
### IDEOne Credentials
53+
54+
To make the IDEOne execution API work locally, you must obtain a username and password,
55+
and add the credentials to a file called app.env.
56+
(TBD: add an option to use the remote version)
4857

4958
Contributors
5059
============

Diff for: ‎app.env.example

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
IDEONE_USERNAME=<user>
2+
IDEONE_PASSWORD=<password>

Diff for: ‎constants.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
IDEONE_USERNAME = "ronreiter"
2-
IDEONE_PASSWORD = "18132ce2b97e"
31
CACHE_HOST = "direct.learnpython.org"
42
DB_HOST = "direct.learnpython.org"
53
SECRET_KEY = "this is a secret. really."

Diff for: ‎docker-compose.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ services:
77
volumes: ['./:/usr/src/app']
88
environment:
99
- DEFAULT_DOMAIN=learnpython.org
10+
env_file:
11+
- app.env
1012
entrypoint: ["python", "main.py", "-d", "$DEFAULT_DOMAIN", "-H", "0.0.0.0"]

Diff for: ‎main.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
sections = re.compile(r"Tutorial\n[=\-]+\n+(.*)\n*Tutorial Code\n[=\-]+\n+(.*)\n*Expected Output\n[=\-]+\n+(.*)\n*Solution\n[=\-]+\n*(.*)\n*", re.MULTILINE | re.DOTALL)
2929
WIKI_WORD_PATTERN = re.compile('\[\[([^]|]+\|)?([^]]+)\]\]')
3030

31-
current_domain = constants.LEARNPYTHON_DOMAIN # python
31+
current_domain = os.environ.get("DEFAULT_DOMAIN", constants.LEARNPYTHON_DOMAIN)
3232

3333
if __name__ == '__main__':
3434
import argparse
@@ -38,7 +38,6 @@
3838
"--domain",
3939
help="Default domain when running in development mode",
4040
default=current_domain,
41-
required=True,
4241
choices=list(constants.DOMAIN_DATA.keys())
4342
)
4443

@@ -66,8 +65,8 @@
6665

6766
def run_code(code, language_id):
6867
ideone_api = Ideone(
69-
constants.IDEONE_USERNAME,
70-
constants.IDEONE_PASSWORD,
68+
os.environ['IDEONE_USERNAME'],
69+
os.environ['IDEONE_PASSWORD'],
7170
api_url='http://ronreiter.compilers.sphere-engine.com/api/1/service.wsdl')
7271

7372
code = ideone_api.create_submission(code, language_id=language_id, std_input="")["link"]

0 commit comments

Comments
 (0)
Please sign in to comment.