Skip to content

Commit 6adeeee

Browse files
authored
Format Python code to black (#37)
* blacken all the things * add linter * remove githubactions linter
1 parent d9b60f8 commit 6adeeee

File tree

4 files changed

+76
-16
lines changed

4 files changed

+76
-16
lines changed

.github/workflows/linter.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#################################
2+
#################################
3+
## Super Linter GitHub Actions ##
4+
#################################
5+
#################################
6+
name: Lint Code Base
7+
8+
#
9+
# Documentation:
10+
# https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions
11+
#
12+
13+
#############################
14+
# Start the job on all push #
15+
#############################
16+
on:
17+
push:
18+
branches-ignore: [master, main]
19+
# Remove the line above to run when pushing to master
20+
pull_request:
21+
branches: [master, main]
22+
23+
###############
24+
# Set the Job #
25+
###############
26+
jobs:
27+
build:
28+
# Name the Job
29+
name: Lint Code Base
30+
# Set the agent to run on
31+
runs-on: ubuntu-latest
32+
33+
##################
34+
# Load all steps #
35+
##################
36+
steps:
37+
##########################
38+
# Checkout the code base #
39+
##########################
40+
- name: Checkout Code
41+
uses: actions/checkout@v3
42+
with:
43+
# Full git history is needed to get a proper list of changed files within `super-linter`
44+
fetch-depth: 0
45+
46+
################################
47+
# Run Linter against code base #
48+
################################
49+
- name: Lint Code Base
50+
uses: github/super-linter/slim@v4
51+
env:
52+
VALIDATE_ALL_CODEBASE: true
53+
DEFAULT_BRANCH: main
54+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55+
# VALIDATE_GITHUB_ACTIONS: true
56+
VALIDATE_PYTHON_BLACK: true

python/app.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,39 @@
1717
app = Flask(__name__)
1818

1919
# Make instance of redis queue
20-
q = Queue(connection=Redis(host='redis_cache', port=6379))
20+
q = Queue(connection=Redis(host="redis_cache", port=6379))
2121

2222

2323
# Write the username and repo to the test table
2424
def write_to_db(username, repo):
2525
"""
2626
Writes the username, repo, and time to the test table
2727
"""
28-
conn = psycopg2.connect("host=database dbname=webhooks user=postgres password=mysecretpassword")
28+
conn = psycopg2.connect(
29+
"host=database dbname=webhooks user=postgres password=mysecretpassword"
30+
)
2931
cur = conn.cursor()
3032
try:
31-
cur.execute("""
33+
cur.execute(
34+
"""
3235
INSERT INTO test_webhook (username, target_repo, event_timestamp)
3336
VALUES (%s, %s, %s);
34-
""", (username, repo, datetime.now()))
37+
""",
38+
(username, repo, datetime.now()),
39+
)
3540
except psycopg2.Error as e:
36-
print('Error: %s', e)
41+
print("Error: %s", e)
3742
conn.commit()
3843
cur.close()
3944
conn.close()
4045

4146

4247
# Do the things
43-
@app.route('/webhook', methods=['POST'])
48+
@app.route("/webhook", methods=["POST"])
4449
def respond():
4550
username = request.json["repository"]["owner"]["login"]
4651
repo = request.json["repository"]["name"]
4752
write_to_db(username, repo)
4853
return Response(status=201)
4954
# TODO: add some business logic to do something else with the data, maybe
50-
# put it into redis to queue up something bigger?
55+
# put it into redis to queue up something bigger?

systemd/app.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,15 @@ def run_container(who_to_greet):
2828
Runs a Docker container that greets a named user
2929
"""
3030
container = client.containers.run(
31-
image='python:3.9',
32-
command='python3 -c "print(\'Hello, {}!\')"'.format(who_to_greet),
33-
detach=True
31+
image="python:3.9",
32+
command="python3 -c \"print('Hello, {}!')\"".format(who_to_greet),
33+
detach=True,
3434
)
3535

3636

3737
# Do the things
38-
@app.route('/webhook', methods=['POST'])
38+
@app.route("/webhook", methods=["POST"])
3939
def respond():
4040
who_to_greet = request.json["repository"]["owner"]["login"]
41-
job = q.enqueue_call(func=run_container, args=(),
42-
result_ttl=5000)
41+
job = q.enqueue_call(func=run_container, args=(), result_ttl=5000)
4342
return Response(status=201)

systemd/worker.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
import redis
44
from rq import Worker, Queue, Connection
55

6-
listen = ['default']
6+
listen = ["default"]
77

8-
redis_url = 'redis://localhost:16379'
8+
redis_url = "redis://localhost:16379"
99

1010
conn = redis.from_url(redis_url)
1111

12-
if __name__ == '__main__':
12+
if __name__ == "__main__":
1313
with Connection(conn):
1414
worker = Worker(list(map(Queue, listen)))
1515
worker.work()

0 commit comments

Comments
 (0)