Skip to content

Commit

Permalink
Merge branch 'main' into release/0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
RobPasMue committed May 4, 2023
2 parents 33e417b + caee5b5 commit 9f50bae
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 28 deletions.
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ tests = [
"packaging==23.1",
"PyGithub==1.58.1",
"appdirs==1.4.4",
"requests==2.28.2",
"requests==2.29.0",
"PySide6==6.5.0",
"pytest==7.3.1",
"pytest-cov==4.0.0",
"pytest-qt==4.2.0",
]
doc = [
"Sphinx==6.2.0",
"Sphinx==7.0.0",
"ansys-sphinx-theme==0.9.8",
"sphinx-copybutton==0.5.2",
]
Expand All @@ -57,7 +57,7 @@ freeze = [
"packaging==23.1",
"PyGithub==1.58.1",
"appdirs==1.4.4",
"requests==2.28.2",
"requests==2.29.0",
"PySide6==6.5.0",
]

Expand Down
7 changes: 5 additions & 2 deletions src/ansys/tools/installer/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
LOG = logging.getLogger(__name__)
LOG.setLevel("DEBUG")


ABOUT_TEXT = f"""<h2>Ansys Python Installer {__version__}</h2>
<p>Created by the PyAnsys Team.</p>
<p>If you have any questions or issues, please open an issue in <a href='https://github.com/pyansys/python-installer-qt-gui/issues'>python-installer-qt-gui Issues</a> page.</p>
Expand All @@ -26,13 +25,16 @@

ANSYS_VENVS = ".ansys_python_venvs"

ANSYS_ENV_VAR_START = "awp_root"

ANSYS_SUPPORTED_PYTHON_VERSIONS = ["3_7", "3_10"]

INSTALL_TEXT = """Choose to use either the standard Python install from <a href='https://www.python.org/'>python.org</a> or <a href='https://github.com/conda-forge/miniforge'>miniforge</a>."""

PYTHON_VERSION_TEXT = """Choose the version of Python to install.
While choosing the latest version of Python is generally recommended, some third-party libraries and applications may not yet be fully compatible with the newest release. Therefore, it is recommended to try the second newest version, as it will still have most of the latest features and improvements while also having broader support among third-party packages."""


PYTHON_VERSION_SELECTION_FOR_VENV = """Choose the version of Python to use for your virtual environment.
Please select the Python version from the table below to create its respective virtual environment."""
Expand All @@ -57,6 +59,7 @@


ASSETS_PATH = os.path.join(THIS_PATH, "assets")

ANSYS_FAVICON = os.path.join(ASSETS_PATH, "ansys-favicon.png")

PYANSYS_DOCS_SITES = {
Expand Down
56 changes: 33 additions & 23 deletions src/ansys/tools/installer/find_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
from pathlib import Path
import subprocess

from ansys.tools.installer.constants import ANSYS_VENVS
from ansys.tools.installer.constants import (
ANSYS_ENV_VAR_START,
ANSYS_SUPPORTED_PYTHON_VERSIONS,
ANSYS_VENVS,
)

# only used on windows
try:
Expand Down Expand Up @@ -100,30 +104,35 @@ def _find_installed_python_win(admin=False):
return paths


def _find_installed_python_win(admin=False):
"""Check the windows registry for any installed instances of Python."""
if admin:
root_key = winreg.HKEY_LOCAL_MACHINE
else:
root_key = winreg.HKEY_CURRENT_USER
def _find_installed_ansys_win():
"""Check the environment variables for Ansys installations."""
env_keys = []
for key in os.environ.keys():
if key.lower().startswith(ANSYS_ENV_VAR_START):
env_keys.append(key)
return env_keys

paths = {}
try:
base_key = "SOFTWARE\\Python\\PythonCore"
with winreg.OpenKey(
root_key,
base_key,
access=winreg.KEY_READ,
) as reg_key:
info = winreg.QueryInfoKey(reg_key)
for i in range(info[0]):
name = winreg.EnumKey(reg_key, i)
ver, path = _get_python_info_win(f"{base_key}\\{name}", root_key)
if ver is not None and path is not None:
paths[path] = (ver, admin)

except FileNotFoundError:
pass
def _find_installed_ansys_python_win():
"""Check the Ansys installation folder for installed Python."""
installed_ansys = _find_installed_ansys_win()
paths = {}
for ansys_ver_env_key in installed_ansys:
ansys_path = os.environ[ansys_ver_env_key]
for ansys_py_ver in ANSYS_SUPPORTED_PYTHON_VERSIONS:
path = os.path.join(
ansys_path,
f"commonfiles\\CPython\\{ansys_py_ver}\\winx64\\Release\\python",
)
if os.path.exists(path):
version_output = subprocess.check_output(
[f"{path}\\python.exe", "--version"], text=True
).strip()
try:
version = version_output.split()[1]
paths[path] = (version, False)
except Exception:
pass

return paths

Expand Down Expand Up @@ -204,6 +213,7 @@ def find_all_python():
if os.name == "nt":
paths = _find_installed_python_win(True)
paths.update(_find_installed_python_win(False))
paths.update(_find_installed_ansys_python_win())
else:
paths = _find_installed_python_linux()

Expand Down

0 comments on commit 9f50bae

Please sign in to comment.