Skip to content

Commit

Permalink
Merge pull request #288 from SCM-NV/distutils
Browse files Browse the repository at this point in the history
DEP: Vendor a copy of `distutils.spawn.find_executable`
  • Loading branch information
BvB93 committed Feb 17, 2022
2 parents 0e2ea97 + 96a0f7d commit 96112f7
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 12 deletions.
21 changes: 10 additions & 11 deletions .github/workflows/pythonapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,27 @@ jobs:
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest]
version: ['3.6', '3.7', '3.8', '3.9']
version: ['3.6', '3.7', '3.8', '3.9', '3.10']
special: ['']
include:
- os: ubuntu-latest
special: 'pre-release'
version: '3.9'
- os: ubuntu-latest
special: 'no optional'
version: '3.9'
version: '3.10'
- os: ubuntu-latest
special: 'no optional'
version: '3.10'
- os: ubuntu-latest
special: 'CP2K 6.1'
version: '3.9'
version: '3.10'
- os: ubuntu-latest
special: 'CP2K 7.1'
version: '3.9'
version: '3.10'
- os: ubuntu-latest
special: 'CP2K 8.2'
version: '3.9'
version: '3.10'
- os: ubuntu-latest
special: 'CP2K 9.1'
version: '3.9'
version: '3.10'
env:
CP2K_DATA_DIR: "/home/runner/work/qmflows/qmflows/cp2k/data"

Expand Down Expand Up @@ -83,8 +80,9 @@ jobs:
run: |
case "${{ matrix.special }}" in
"pre-release")
conda create -n test -c conda-forge python=${{ matrix.version }} rdkit nbsphinx jupyter pandoc
conda create -n test -c conda-forge python=${{ matrix.version }} nbsphinx jupyter pandoc
source $CONDA/bin/activate test
pip install rdkit-pypi
pip install --pre -e .[test] --upgrade --force-reinstall
pip install git+https://github.com/SCM-NV/PLAMS@master --upgrade
pip install git+https://github.com/NLeSC/noodles@master --upgrade
Expand All @@ -95,8 +93,9 @@ jobs:
pip install -e .[test_no_optional]
;;
*)
conda create -n test -c conda-forge python=${{ matrix.version }} rdkit nbsphinx jupyter pandoc
conda create -n test -c conda-forge python=${{ matrix.version }} nbsphinx jupyter pandoc
source $CONDA/bin/activate test
pip install rdkit-pypi
pip install -e .[test]
;;
esac
Expand Down
48 changes: 47 additions & 1 deletion src/qmflows/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
requires_orca
requires_ams
requires_adf
find_executable
API
---
Expand All @@ -30,15 +31,16 @@
.. autodata:: requires_orca
.. autodata:: requires_ams
.. autodata:: requires_adf
.. autofunction:: find_executable
"""

import os
import sys
import textwrap
from pathlib import Path

import pytest
from distutils.spawn import find_executable

from .settings import Settings
from .warnings_qmflows import Assertion_Warning
Expand All @@ -55,6 +57,7 @@
'requires_orca'
'requires_ams',
'requires_adf',
'find_executable',
]

try:
Expand All @@ -73,6 +76,49 @@
PATH_MOLECULES = PATH / "molecules"


def find_executable(executable: str, path: "str | None" = None) -> "str | None":
"""Tries to find ``executable`` in the directories listed in ``path``.
A string listing directories separated by ``os.pathsep``; defaults to ``os.environ['PATH']``.
Returns the complete filename or ``None`` if not found.
Note
----
Vendored copy of :func:`distutils.spawn.find_executable`,
as the entirety of distutils is deprecated per PEP 632.
"""
_, ext = os.path.splitext(executable)
if (sys.platform == 'win32') and (ext != '.exe'):
executable = executable + '.exe'

if os.path.isfile(executable):
return executable

if path is None:
path = os.environ.get('PATH', None)
if path is None:
try:
path = os.confstr("CS_PATH")
except (AttributeError, ValueError):
# os.confstr() or CS_PATH is not available
path = os.defpath
# bpo-35755: Don't use os.defpath if the PATH environment variable is
# set to an empty string

# PATH='' doesn't match, whereas PATH=':' looks in the current directory
if not path:
return None

paths = path.split(os.pathsep)
for p in paths:
f = os.path.join(p, executable)
if os.path.isfile(f):
# the file exists, we have a shot at spawn working
return f
return None


def fill_cp2k_defaults(s: Settings) -> Settings:
"""Fill missing values from a job template.
Expand Down

0 comments on commit 96112f7

Please sign in to comment.