From cc9200d87bab9570819ae112082d8bb15d9318c8 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Tue, 7 May 2024 21:55:35 +0300 Subject: [PATCH] Create entry and print version --- requirements.txt | 3 +- src/SeleniumLibrary/entry/__init__.py | 15 +++++++ src/SeleniumLibrary/entry/__main__.py | 49 ++++++++++++++++++++++ src/SeleniumLibrary/entry/print_version.py | 48 +++++++++++++++++++++ 4 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 src/SeleniumLibrary/entry/__init__.py create mode 100644 src/SeleniumLibrary/entry/__main__.py create mode 100644 src/SeleniumLibrary/entry/print_version.py diff --git a/requirements.txt b/requirements.txt index cf7a70b10..616d9719e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ selenium >= 4.3.0 robotframework >= 4.1.3 -robotframework-pythonlibcore >= 3.0.0 +robotframework-pythonlibcore >= 4.4.1 +click >= 8.1.7 diff --git a/src/SeleniumLibrary/entry/__init__.py b/src/SeleniumLibrary/entry/__init__.py new file mode 100644 index 000000000..d83559d8d --- /dev/null +++ b/src/SeleniumLibrary/entry/__init__.py @@ -0,0 +1,15 @@ +# Copyright 2008-2011 Nokia Networks +# Copyright 2011-2016 Ryan Tomac, Ed Manlove and contributors +# Copyright 2016- Robot Framework Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. diff --git a/src/SeleniumLibrary/entry/__main__.py b/src/SeleniumLibrary/entry/__main__.py new file mode 100644 index 000000000..2d7d9be5b --- /dev/null +++ b/src/SeleniumLibrary/entry/__main__.py @@ -0,0 +1,49 @@ +# Copyright 2008-2011 Nokia Networks +# Copyright 2011-2016 Ryan Tomac, Ed Manlove and contributors +# Copyright 2016- Robot Framework Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import click + +from print_version import print_version + +CONTEXT_SETTINGS = {"help_option_names": ["-h", "--help"]} + + +@click.group( + invoke_without_command=True, context_settings=CONTEXT_SETTINGS, no_args_is_help=True +) +@click.option( + "--version", + is_flag=True, + help="Prints versions and exits", + callback=print_version, + expose_value=False, + is_eager=True, +) +def cli(): + """Robot Framework SeleniumLibrary command line tool. + + Possible commands are: + translation + + + translation will generate detaul tranlsation json file from library keywords. + + See each command argument help for more details what (optional) arguments that command supports. + """ + pass + + +if __name__ == "__main__": + cli() diff --git a/src/SeleniumLibrary/entry/print_version.py b/src/SeleniumLibrary/entry/print_version.py new file mode 100644 index 000000000..20e1d3c2c --- /dev/null +++ b/src/SeleniumLibrary/entry/print_version.py @@ -0,0 +1,48 @@ +# Copyright 2008-2011 Nokia Networks +# Copyright 2011-2016 Ryan Tomac, Ed Manlove and contributors +# Copyright 2016- Robot Framework Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from pathlib import Path +import re +import subprocess +import sys + +from selenium import __version__ + +INSTALL_DIR = Path(__file__).parent.parent + + +def get_rf_version() -> str: + process = subprocess.run( + [sys.executable, "-m", "robot", "--version"], capture_output=True, check=False + ) + return process.stdout.decode("utf-8").split(" ")[2] + + +def get_library_version() -> str: + init_file = INSTALL_DIR / "__init__.py" + with init_file.open("r") as file: + data = file.read() + return re.search('\n__version__ = "(.*)"', data).group(1) + + +def print_version(ctx, param, value): + """Display Python, Robot Framework, SeleniumLibrary and selenium versions""" + python_version = ( + f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}" + ) + print(f"Used Python is: {sys.executable}\nVersion: {python_version}") + print(f'Robot Framework version: "{get_rf_version()}"') + print(f"Installed SeleniumLibrary version is: {get_library_version()}") + print(f"Installed selenium version is: {__version__}")