Skip to content

Commit

Permalink
Merge branch 'releases/0.9.x' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
jlorieau committed Jul 29, 2023
2 parents 3bdc694 + 787b820 commit 11ca77b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 19 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Run pytest on the python package

on:
push:
branches:
- main
- 'releases/**'

jobs:
test:

runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.11"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -e .[dev]
- name: Test with pytest
run: |
pytest --log-level=DEBUG
2 changes: 1 addition & 1 deletion geomancy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from . import checks, cli, config, environment

# Project version
__version__ = (0, 9, 2) # Major, minor, patch, stage
__version__ = (0, 9, 3) # Major, minor, patch, stage


def get_version(version=__version__):
Expand Down
26 changes: 19 additions & 7 deletions geomancy/checks/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import typing as t
import sys
import subprocess
import logging
import re

from .version import CheckVersion
Expand All @@ -12,6 +13,8 @@

__all__ = ("CheckPythonPackage",)

logger = logging.getLogger(__name__)


class CheckPythonPackage(CheckVersion):
"""Check the availability and version of a python package"""
Expand All @@ -20,7 +23,7 @@ class CheckPythonPackage(CheckVersion):
use_pip_freeze: bool = True

# The regex to use for parsing python package names
pip_pkg_str = r"^(?P<name>{pkg_name})==(?P<ver>[\d\w.]+)$"
pip_pkg_str = r"^(?P<name>{pkg_name})\s*==\s*(?P<ver>[\d\w.]+)$"

# The results of pip freeze
pip_freeze: t.Union[str, None]
Expand All @@ -47,15 +50,15 @@ def get_current_version(self) -> t.Union[None, t.Tuple[int]]:
# "pip list" is used instead of "pip freeze" because "pip list"
# will not show paths--just package names--for packages installed
# from a local repository
proc = subprocess.run(
args=(python, "-m", "pip", "list", "--format=freeze"),
capture_output=True,
)
args = (python, "-m", "pip", "list", "--format=freeze")
proc = subprocess.run(args=args, capture_output=True)

if proc.returncode != 0:
# This command didn't work. Set the class attribute for all
# instances
CheckPythonPackage.pip_freeze = None
logger.debug(f"Trying to use pip_freeze but couldn't run "
f"'{args}'")
else:
CheckPythonPackage.pip_freeze = proc.stdout.decode("UTF-8")

Expand All @@ -66,7 +69,12 @@ def get_current_version(self) -> t.Union[None, t.Tuple[int]]:

# Convert the regex match to a version tuple
version = match.groupdict()["ver"] if match is not None else None
return version_to_tuple(version) if version is not None else None
version = version_to_tuple(version) if version is not None else None

logger.debug(f"Found '{pkg_name}' package version '{version}' with "
f"pip freeze.")
if version is not None:
return version

# Method 2 -- try importing and getting it from the __version__ string
code = f"import {pkg_name}; print({pkg_name}.__version__)"
Expand All @@ -76,7 +84,11 @@ def get_current_version(self) -> t.Union[None, t.Tuple[int]]:
version_str = (
proc.stdout.decode("UTF-8").strip() if proc.stdout is not None else None
)
return version_to_tuple(version_str) if version_str is not None else None
version = version_to_tuple(version_str) if version_str is not None else None

logger.debug(f"Found '{pkg_name}' package version '{version}' with "
f"{pkg_name}.__version__")
return version

# I'm out of ideas. Version couldn't be parsed
return None
11 changes: 0 additions & 11 deletions tests/checks/test_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,3 @@ def test_check_exec_version():
# Should be less than version 1000.
check = CheckExec(name="Check Python", value="python>=1000.0")
assert not check.check().passed


def test_check_exec_missing_version():
"""Tests CheckExec check with a command that doesn't give a version number"""
# Command without a version number
check = CheckExec(name="Check ls", value="ls>=2.0")
assert not check.check().passed

# Without a version number, the check passes
check = CheckExec(name="Check ls", value="ls")
assert check.check().passed

0 comments on commit 11ca77b

Please sign in to comment.