Skip to content

Commit 1d558b5

Browse files
ElSnoManCarlos Kidman
andauthored
Add typer and remove rich-click (#304)
Co-authored-by: Carlos Kidman <carlos@qap.dev>
1 parent 1afd697 commit 1d558b5

File tree

6 files changed

+163
-180
lines changed

6 files changed

+163
-180
lines changed

.flake8

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
[flake8]
2-
extend-ignore = E203
2+
extend-ignore = E203, C901
33
exclude =
44
.git,
55
__pycache__,
6-
docs/source/conf.py,
6+
docs,
77
old,
8-
build,
98
dist
10-
max-complexity = 10
119
max-line-length = 160

.github/workflows/test-pylenium.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ jobs:
3232
3333
- name: Lint with flake8
3434
run: |
35-
# stop the build if there are Python syntax errors or undefined names
36-
poetry run flake8 ./tests --count --select=E9,F63,F7,F82 --show-source --statistics
37-
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
38-
poetry run flake8 ./tests --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
35+
# Using .flake8 file
36+
poetry run poe lint
3937
4038
- name: Run Unit Tests
4139
run: |

poetry.lock

Lines changed: 38 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 96 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,125 @@
11
""" Allure reporting integration """
2-
2+
import platform
33
from typing import List
4-
import rich_click as click
5-
from pylenium.scripts.cli_utils import run_process, parse_response
4+
5+
import typer
6+
7+
from pylenium.scripts.cli_utils import parse_response, run_process
68

79

810
def _install(commands: List[str]):
911
"""Command to install allure via the CLI"""
10-
click.echo("\n🛑 It's recommended that you run the above command(s) yourself to see all the output 🛑")
11-
answer = click.prompt("\nWould you like to proceed? (y/n)", default="n")
12+
typer.secho("\n🛑 It's recommended that you run the above command(s) yourself to see all the output 🛑", fg=typer.colors.BRIGHT_YELLOW)
13+
answer = typer.prompt("\nWould you like to proceed? (y/n)", default="n")
1214
try:
1315
if answer == "y":
1416
response = run_process(commands)
1517
_, err = parse_response(response)
1618
if response.returncode != 0:
17-
click.echo(f"😢 Unable to install allure. {err}")
18-
click.echo("Visit allure's docs for more options: https://docs.qameta.io/allure/#_get_started")
19+
typer.secho(f"😢 Unable to install allure. {err}", fg=typer.colors.BRIGHT_RED)
20+
typer.secho("Visit allure's docs for more options: https://docs.qameta.io/allure/#_get_started", fg=typer.colors.BRIGHT_CYAN)
1921
return
20-
click.echo("✅ allure installed. Try running `pylenium allure check` to verify the installation.")
22+
typer.secho("✅ allure installed. Try running `pylenium allure check` to verify the installation.", fg=typer.colors.BRIGHT_GREEN)
2123
return
2224

2325
if answer == "n" or answer is not None:
24-
click.echo("❌ Command aborted")
26+
typer.secho("❌ Command aborted")
2527
return
2628
except FileNotFoundError:
27-
click.echo("One of the commands was not found...")
28-
click.echo("Visit their docs for more info: https://docs.qameta.io/allure/#_get_started")
29+
typer.secho("One of the commands was not found...", fg=typer.colors.BRIGHT_RED)
30+
typer.secho("Visit their docs for more info: https://docs.qameta.io/allure/#_get_started", fg=typer.colors.BRIGHT_CYAN)
2931

3032

3133
def install_for_linux():
3234
"""Install allure on a Debian-based Linux machine."""
33-
click.echo("This command only works for Debian-based Linux and uses sudo:\n")
34-
click.echo(" sudo apt-add-repository ppa:qameta/allure")
35-
click.echo(" sudo apt-get update")
36-
click.echo(" sudo apt-get install allure")
37-
_install([
38-
"sudo", "apt-add-repository", "ppa:qameta/allure", "-y",
39-
"sudo", "apt-get", "update", "-y",
40-
"sudo", "apt-get", "install", "allure", "-y",
41-
])
35+
typer.secho("This command only works for Debian-based Linux and uses sudo:\n", fg=typer.colors.BRIGHT_YELLOW)
36+
typer.secho(" sudo apt-add-repository ppa:qameta/allure")
37+
typer.secho(" sudo apt-get update")
38+
typer.secho(" sudo apt-get install allure")
39+
_install(
40+
[
41+
"sudo",
42+
"apt-add-repository",
43+
"ppa:qameta/allure",
44+
"-y",
45+
"sudo",
46+
"apt-get",
47+
"update",
48+
"-y",
49+
"sudo",
50+
"apt-get",
51+
"install",
52+
"allure",
53+
"-y",
54+
]
55+
)
4256

4357

4458
def install_for_mac():
45-
click.echo("This command uses homebrew to do the installation:\n")
46-
click.echo(" brew install allure")
59+
typer.secho("This command uses homebrew to do the installation:\n", fg=typer.colors.BRIGHT_YELLOW)
60+
typer.secho(" brew install allure")
4761
_install(["brew", "install", "allure"])
4862

4963

5064
def install_for_windows():
51-
click.echo("This command uses scoop to do the installation:\n")
52-
click.echo(" scoop install allure")
65+
typer.secho("This command uses scoop to do the installation:\n", fg=typer.colors.BRIGHT_YELLOW)
66+
typer.secho(" scoop install allure")
5367
_install(["scoop", "install", "allure"])
68+
69+
70+
app = typer.Typer()
71+
72+
73+
@app.command()
74+
def check():
75+
"""Check if the allure CLI is installed on the current machine."""
76+
typer.secho("\n$ allure --version")
77+
err_message = "\n❌ allure is not installed or not added to the PATH. Visit https://docs.qameta.io/allure/#_get_started"
78+
try:
79+
response = run_process(["allure", "--version"])
80+
out, err = parse_response(response)
81+
if response.returncode != 0:
82+
typer.secho(err_message, fg=typer.colors.BRIGHT_RED)
83+
typer.secho(err, fg=typer.colors.BRIGHT_RED)
84+
return
85+
typer.secho(f"\n✅ allure is installed with version: {out}", fg=typer.colors.BRIGHT_GREEN)
86+
except FileNotFoundError:
87+
typer.secho(err_message)
88+
89+
90+
@app.command()
91+
def install():
92+
"""Install the allure CLI to the current machine."""
93+
typer.secho(
94+
"\n💡 For more installation options and details, please visit allure's docs: https://docs.qameta.io/allure/#_get_started", fg=typer.colors.BRIGHT_CYAN
95+
)
96+
operating_system = platform.system()
97+
if operating_system.upper() == "LINUX":
98+
install_for_linux()
99+
return
100+
101+
if operating_system.upper() == "DARWIN":
102+
install_for_mac()
103+
return
104+
105+
if operating_system.upper() == "WINDOWS":
106+
install_for_windows()
107+
return
108+
109+
110+
@app.command()
111+
def serve(folder: str = typer.Option("allure-report", "--folder", "-f", help="The folder path to the allure report")):
112+
"""Start the allure server and serve the allure report given its folder path."""
113+
typer.secho(f"\n$ allure serve {folder}")
114+
typer.secho("Press <Ctrl+C> to exit", fg=typer.colors.BRIGHT_CYAN)
115+
try:
116+
response = run_process(["allure", "serve", folder])
117+
_, err = parse_response(response)
118+
if response.returncode != 0:
119+
typer.secho(f"\n❌ Unable to serve allure report. Check that the folder path is valid. {err}", fg=typer.colors.BRIGHT_RED)
120+
except FileNotFoundError:
121+
typer.secho("\n❌ allure is not installed or not added to the PATH. Visit https://docs.qameta.io/allure/#_get_started", fg=typer.colors.BRIGHT_RED)
122+
123+
124+
if __name__ == "__main__":
125+
app()

0 commit comments

Comments
 (0)