Skip to content

Commit

Permalink
Add ability to identify min_python version
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Aug 6, 2022
1 parent 860e1d8 commit 85a02a7
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
28 changes: 28 additions & 0 deletions src/ppinfo/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,29 @@
"""ppinfo package."""
import configparser
import os
from pathlib import Path
from typing import Union


# pylint: disable=too-few-public-methods
class Project:
"""Class representing a python project."""

# 3.7 default value is used because at the time this library was
# written, this was the oldest still supported version of Python
min_python: str = "3.7"

def __init__(self, path: Union[Path, str] = Path(".")) -> None:
"""Construct a python Project instance."""
if isinstance(path, str):
path = Path(path)
self.path = path

if (path / "setup.cfg").exists():
config = configparser.ConfigParser()
config.read(path / "setup.cfg")
if "options" in config:
value = config["options"].get("python_requires", None)
if not (value and value.startswith(">=")):
raise NotImplementedError("Unable to parse python_requires")
self.min_python = value[2:]
1 change: 1 addition & 0 deletions test/fixtures/proj1/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# empty setup.cfg file
2 changes: 2 additions & 0 deletions test/fixtures/py310/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[options]
python_requires = >=3.10
15 changes: 11 additions & 4 deletions test/test_ppinfo.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
"""Tests for ppinfo package."""
import pytest

from ppinfo import Project

def test_import() -> None:
"""Test that we can import ppinfo."""
# pylint: disable=unused-import,import-outside-toplevel
import ppinfo

@pytest.mark.parametrize(
("path", "expected_python"),
[("test/fixtures/proj1", "3.7"), ("test/fixtures/py310", "3.10")],
)
def test_min_version(path: str, expected_python: str) -> None:
"""Test ability to find minimal version of python required."""
project = Project(path)
assert project.min_python == expected_python

0 comments on commit 85a02a7

Please sign in to comment.