Skip to content

Commit

Permalink
project restructure, add traceback to exception, add GitHub publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
CheeseCake87 committed Aug 30, 2024
1 parent 3249ff1 commit 47806cc
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 11 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Upload Python Package

on:
release:
types: [published]

permissions:
contents: read

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flit
- name: Build package
run: flit build
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ cover/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
/.venv/
/venv/
/venv_3_8
/venv_3_9
Expand Down
4 changes: 2 additions & 2 deletions flask_example/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
def create_app():
app = Flask(__name__)

@app.route('/')
@app.route("/")
def home():
return 'Hello, World!'
return "Hello, World!"

return app

Expand Down
4 changes: 2 additions & 2 deletions flask_example/package/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
def create_app():
app = Flask(__name__)

@app.route('/')
@app.route("/")
def home():
return 'Hello, World!'
return "Hello, World!"

return app

Expand Down
8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ Source = "https://github.com/CheeseCake87/pyqwe"
[project.optional-dependencies]
dotenv = ["pyqwe-extra-dotenv"]

[tool.ruff]
src = ["src"]
fix = true
show-fixes = true
output-format = "full"

[tool.pyqwe]
gunicorn = "*:gunicorn flask_example.package:create_app"
cmd_mod_flask = "*:flask --app flask_example/module.py run"
Expand All @@ -29,6 +35,6 @@ mod_flask = "flask_example.module:run"
pac_flask = "flask_example.package:run"
pac_flask_v1 = "*:flask --app flask_example:version_1 run"
pac_flask_v2 = "*:flask --app flask_example:version_2 run"
format = "*:ruff format pyqwe"
format = "*:ruff format"
build = "*shell:flit build"
publish = "*shell:export FLIT_USERNAME=__token__ && flit publish"
2 changes: 2 additions & 0 deletions requirements/build.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ruff
flit
7 changes: 3 additions & 4 deletions src/pyqwe/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
import traceback
from pathlib import Path

from .helpers import _run, _split_runner, Colr
Expand Down Expand Up @@ -83,7 +84,5 @@ def main():
try:
_run(*_split_runner(_runner), _cwd=_cwd)
except Exception as e:
if "pyqwe: error: argument" in str(e):
print(f" {Colr.FAIL}Invalid argument [{_runner}]{Colr.END}")
else:
print(f" {Colr.FAIL}{e}{Colr.END}")
traceback.print_exc()
print(f"💥🏎️⁉️ {Colr.FAIL}{e}{Colr.END}")
2 changes: 1 addition & 1 deletion src/pyqwe/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def _no_traceback_eh(exc_type, exc_val, traceback):
pass


def _split_runner(runner_: str) -> t.Tuple:
def _split_runner(runner_: any) -> t.Tuple:
r = runner_.split(":")
sr = r[0] # start or runner

Expand Down
2 changes: 1 addition & 1 deletion src/pyqwe/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def error(self, message):
self.errored = True

@staticmethod
def print_chooser(runners: dict):
def print_chooser(runners):
print("🏎️💨")
print(
f"{Colr.FAIL}{Colr.BOLD}0 :{Colr.END}{Colr.END} {Colr.FAIL}Exit{Colr.END}"
Expand Down

0 comments on commit 47806cc

Please sign in to comment.