Skip to content

Commit 8ec2b58

Browse files
authored
Merge branch 'master' into python-shebang
2 parents 3d160d2 + 9b70523 commit 8ec2b58

File tree

284 files changed

+46372
-36836
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

284 files changed

+46372
-36836
lines changed

bpython/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Discover bpython: A Python REPL With IDE-Like Features
2+
3+
Files and scripts supplementing the [bpython](https://realpython.com/bpython-alternative-python-repl/) tutorial on Real Python.

bpython/adder-v1.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
try:
2+
x = int(input("x = "))
3+
y = int(input("y = "))
4+
z = x / y
5+
except (ValueError, ZeroDivisionError) as ex: # noqa: F841
6+
import bpython
7+
8+
bpython.embed(locals(), banner="Post-Mortem Debugging:")
9+
else:
10+
print(z)

bpython/adder-v2.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
try:
2+
x = int(input("x = "))
3+
y = int(input("y = "))
4+
import bpdb
5+
6+
bpdb.set_trace()
7+
z = x / y
8+
except (ValueError, ZeroDivisionError) as ex: # noqa: F841
9+
import bpython
10+
11+
bpython.embed(locals(), banner="Post-Mortem Debugging:")
12+
else:
13+
print(z)

bpython/custom.theme

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[syntax]
2+
keyword = M
3+
name = r
4+
comment = b
5+
string = g
6+
error = r
7+
number = B
8+
operator = c
9+
paren = b
10+
punctuation = b
11+
token = g
12+
13+
[interface]
14+
background = d
15+
output = b
16+
main = b
17+
prompt = r
18+
prompt_more = g
19+
right_arrow_suggestion = K

bpython/github_gist.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env python
2+
3+
import json
4+
import os
5+
import sys
6+
from urllib.request import Request, urlopen
7+
8+
9+
def main() -> None:
10+
"""Print the URL of a GitHub gist created from the standard input."""
11+
print(create_gist(sys.stdin.read()))
12+
13+
14+
def create_gist(content: str) -> str:
15+
"""Return the URL of the created GitHub gist."""
16+
response = post_json(
17+
url="https://api.github.com/gists",
18+
data={
19+
"description": "bpython REPL",
20+
"public": False,
21+
"files": {"repl.py": {"content": content}},
22+
},
23+
headers={
24+
"Accept": "application/vnd.github+json",
25+
"Authorization": f"Bearer {os.getenv('GITHUB_TOKEN')}",
26+
"Content-Type": "application/json",
27+
},
28+
)
29+
return response["html_url"]
30+
31+
32+
def post_json(url: str, data: dict, headers: dict = None) -> dict:
33+
"""Return the JSON response from the server."""
34+
payload = json.dumps(data).encode("utf-8")
35+
with urlopen(Request(url, payload, headers or {})) as response:
36+
return json.loads(response.read().decode("utf-8"))
37+
38+
39+
if __name__ == "__main__":
40+
try:
41+
main()
42+
except Exception as ex:
43+
print(ex)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.db
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"printWidth": 79
3+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Build a Front End for a REST API
2+
3+
This repository contains code related to the Real Python tutorial on [building a front end for a REST API](https://realpython.com/build-a-rest-api-frontend/).
4+
5+
## Setup
6+
7+
You should first create a virtual environment:
8+
9+
```console
10+
$ python -m venv venv
11+
$ source venv/bin/activate
12+
```
13+
14+
Install the pinned dependencies from `requirements.txt`:
15+
16+
```console
17+
(venv) $ python -m pip install -r requirements.txt
18+
```
19+
20+
Then you can navigate into the folder `source_code_start/` and create a new database:
21+
22+
```sh
23+
(venv) $ cd source_code_start
24+
(venv) $ python init_database.py
25+
```
26+
27+
This will create or update the `people.db` database that you can use with your project.
28+
29+
After building the database, you can start the Flask server:
30+
31+
```sh
32+
(venv) $ python app.py
33+
```
34+
35+
When the Flask server is running, you can visit the front end on `http://localhost:8000` and the API documentation on `http://localhost:8000/api/ui`.
36+
37+
## Author
38+
39+
- **Philipp Acsany**, E-mail: [[email protected]]([email protected])
40+
41+
## License
42+
43+
Distributed under the MIT license. See [`LICENSE`](../LICENSE) for more information.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
attrs==22.1.0
2+
certifi==2022.9.24
3+
charset-normalizer==2.1.1
4+
click==8.1.3
5+
clickclick==20.10.2
6+
connexion==2.14.1
7+
Flask==2.2.2
8+
flask-marshmallow==0.14.0
9+
Flask-SQLAlchemy==3.0.2
10+
idna==3.4
11+
inflection==0.5.1
12+
itsdangerous==2.1.2
13+
Jinja2==3.1.2
14+
jsonschema==4.16.0
15+
MarkupSafe==2.1.1
16+
marshmallow==3.18.0
17+
marshmallow-sqlalchemy==0.28.1
18+
packaging==21.3
19+
pyparsing==3.0.9
20+
pyrsistent==0.19.1
21+
PyYAML==6.0
22+
requests==2.28.1
23+
six==1.16.0
24+
SQLAlchemy==1.4.42
25+
swagger-ui-bundle==0.0.9
26+
urllib3==1.26.12
27+
Werkzeug==2.2.2
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from flask import render_template
2+
3+
import config
4+
from models import Person
5+
6+
app = config.connex_app
7+
app.add_api(config.basedir / "swagger.yml")
8+
9+
10+
@app.route("/")
11+
def home():
12+
people = Person.query.all()
13+
return render_template("home.html", people=people)
14+
15+
16+
if __name__ == "__main__":
17+
app.run(host="0.0.0.0", port=8000, debug=True)

0 commit comments

Comments
 (0)