-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to identify min_python version
- Loading branch information
Showing
4 changed files
with
42 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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:] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# empty setup.cfg file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[options] | ||
python_requires = >=3.10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |