Skip to content

Commit

Permalink
Create entry and print version
Browse files Browse the repository at this point in the history
  • Loading branch information
aaltat committed May 7, 2024
1 parent 1a12a4d commit cc9200d
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 1 deletion.
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions src/SeleniumLibrary/entry/__init__.py
Original file line number Diff line number Diff line change
@@ -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.
49 changes: 49 additions & 0 deletions src/SeleniumLibrary/entry/__main__.py
Original file line number Diff line number Diff line change
@@ -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()
48 changes: 48 additions & 0 deletions src/SeleniumLibrary/entry/print_version.py
Original file line number Diff line number Diff line change
@@ -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__}")

0 comments on commit cc9200d

Please sign in to comment.