|
| 1 | +# Copyright 2008-2011 Nokia Networks |
| 2 | +# Copyright 2011-2016 Ryan Tomac, Ed Manlove and contributors |
| 3 | +# Copyright 2016- Robot Framework Foundation |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +from pathlib import Path |
| 17 | +import re |
| 18 | +import subprocess |
| 19 | +import sys |
| 20 | + |
| 21 | +from selenium import __version__ |
| 22 | + |
| 23 | +INSTALL_DIR = Path(__file__).parent.parent |
| 24 | + |
| 25 | + |
| 26 | +def get_rf_version() -> str: |
| 27 | + process = subprocess.run( |
| 28 | + [sys.executable, "-m", "robot", "--version"], capture_output=True, check=False |
| 29 | + ) |
| 30 | + return process.stdout.decode("utf-8").split(" ")[2] |
| 31 | + |
| 32 | + |
| 33 | +def get_library_version() -> str: |
| 34 | + init_file = INSTALL_DIR / "__init__.py" |
| 35 | + with init_file.open("r") as file: |
| 36 | + data = file.read() |
| 37 | + return re.search('\n__version__ = "(.*)"', data).group(1) |
| 38 | + |
| 39 | + |
| 40 | +def print_version(ctx, param, value): |
| 41 | + """Display Python, Robot Framework, SeleniumLibrary and selenium versions""" |
| 42 | + python_version = ( |
| 43 | + f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}" |
| 44 | + ) |
| 45 | + print(f"Used Python is: {sys.executable}\nVersion: {python_version}") |
| 46 | + print(f'Robot Framework version: "{get_rf_version()}"') |
| 47 | + print(f"Installed SeleniumLibrary version is: {get_library_version()}") |
| 48 | + print(f"Installed selenium version is: {__version__}") |
0 commit comments