Skip to content

Commit

Permalink
Add typer and remove rich-click (#304)
Browse files Browse the repository at this point in the history
Co-authored-by: Carlos Kidman <[email protected]>
  • Loading branch information
ElSnoMan and Carlos Kidman authored Jun 17, 2023
1 parent 1afd697 commit 1d558b5
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 180 deletions.
6 changes: 2 additions & 4 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
[flake8]
extend-ignore = E203
extend-ignore = E203, C901
exclude =
.git,
__pycache__,
docs/source/conf.py,
docs,
old,
build,
dist
max-complexity = 10
max-line-length = 160
6 changes: 2 additions & 4 deletions .github/workflows/test-pylenium.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ jobs:
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
poetry run flake8 ./tests --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
poetry run flake8 ./tests --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
# Using .flake8 file
poetry run poe lint
- name: Run Unit Tests
run: |
Expand Down
71 changes: 38 additions & 33 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

120 changes: 96 additions & 24 deletions pylenium/scripts/allure_reporting.py
Original file line number Diff line number Diff line change
@@ -1,53 +1,125 @@
""" Allure reporting integration """

import platform
from typing import List
import rich_click as click
from pylenium.scripts.cli_utils import run_process, parse_response

import typer

from pylenium.scripts.cli_utils import parse_response, run_process


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

if answer == "n" or answer is not None:
click.echo("❌ Command aborted")
typer.secho("❌ Command aborted")
return
except FileNotFoundError:
click.echo("One of the commands was not found...")
click.echo("Visit their docs for more info: https://docs.qameta.io/allure/#_get_started")
typer.secho("One of the commands was not found...", fg=typer.colors.BRIGHT_RED)
typer.secho("Visit their docs for more info: https://docs.qameta.io/allure/#_get_started", fg=typer.colors.BRIGHT_CYAN)


def install_for_linux():
"""Install allure on a Debian-based Linux machine."""
click.echo("This command only works for Debian-based Linux and uses sudo:\n")
click.echo(" sudo apt-add-repository ppa:qameta/allure")
click.echo(" sudo apt-get update")
click.echo(" sudo apt-get install allure")
_install([
"sudo", "apt-add-repository", "ppa:qameta/allure", "-y",
"sudo", "apt-get", "update", "-y",
"sudo", "apt-get", "install", "allure", "-y",
])
typer.secho("This command only works for Debian-based Linux and uses sudo:\n", fg=typer.colors.BRIGHT_YELLOW)
typer.secho(" sudo apt-add-repository ppa:qameta/allure")
typer.secho(" sudo apt-get update")
typer.secho(" sudo apt-get install allure")
_install(
[
"sudo",
"apt-add-repository",
"ppa:qameta/allure",
"-y",
"sudo",
"apt-get",
"update",
"-y",
"sudo",
"apt-get",
"install",
"allure",
"-y",
]
)


def install_for_mac():
click.echo("This command uses homebrew to do the installation:\n")
click.echo(" brew install allure")
typer.secho("This command uses homebrew to do the installation:\n", fg=typer.colors.BRIGHT_YELLOW)
typer.secho(" brew install allure")
_install(["brew", "install", "allure"])


def install_for_windows():
click.echo("This command uses scoop to do the installation:\n")
click.echo(" scoop install allure")
typer.secho("This command uses scoop to do the installation:\n", fg=typer.colors.BRIGHT_YELLOW)
typer.secho(" scoop install allure")
_install(["scoop", "install", "allure"])


app = typer.Typer()


@app.command()
def check():
"""Check if the allure CLI is installed on the current machine."""
typer.secho("\n$ allure --version")
err_message = "\n❌ allure is not installed or not added to the PATH. Visit https://docs.qameta.io/allure/#_get_started"
try:
response = run_process(["allure", "--version"])
out, err = parse_response(response)
if response.returncode != 0:
typer.secho(err_message, fg=typer.colors.BRIGHT_RED)
typer.secho(err, fg=typer.colors.BRIGHT_RED)
return
typer.secho(f"\n✅ allure is installed with version: {out}", fg=typer.colors.BRIGHT_GREEN)
except FileNotFoundError:
typer.secho(err_message)


@app.command()
def install():
"""Install the allure CLI to the current machine."""
typer.secho(
"\n💡 For more installation options and details, please visit allure's docs: https://docs.qameta.io/allure/#_get_started", fg=typer.colors.BRIGHT_CYAN
)
operating_system = platform.system()
if operating_system.upper() == "LINUX":
install_for_linux()
return

if operating_system.upper() == "DARWIN":
install_for_mac()
return

if operating_system.upper() == "WINDOWS":
install_for_windows()
return


@app.command()
def serve(folder: str = typer.Option("allure-report", "--folder", "-f", help="The folder path to the allure report")):
"""Start the allure server and serve the allure report given its folder path."""
typer.secho(f"\n$ allure serve {folder}")
typer.secho("Press <Ctrl+C> to exit", fg=typer.colors.BRIGHT_CYAN)
try:
response = run_process(["allure", "serve", folder])
_, err = parse_response(response)
if response.returncode != 0:
typer.secho(f"\n❌ Unable to serve allure report. Check that the folder path is valid. {err}", fg=typer.colors.BRIGHT_RED)
except FileNotFoundError:
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)


if __name__ == "__main__":
app()
Loading

0 comments on commit 1d558b5

Please sign in to comment.