Skip to content

Commit 8a66bd1

Browse files
committed
Add ability to identify min_python version
1 parent 82a2b14 commit 8a66bd1

8 files changed

Lines changed: 55 additions & 14 deletions

File tree

.flake8

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ extend-ignore =
55
F401, # duplicate of pylint W0611 (unused-import)
66
F821, # duplicate of pylint E0602 (undefined-variable)
77
F841, # duplicate of pylint W0612 (unused-variable)
8+
DAR # we don't use darling

.github/workflows/tox.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,15 @@ on:
2121
jobs:
2222
tox:
2323
name: ${{ matrix.name }}
24-
runs-on: ${{ matrix.os }}
24+
runs-on: ${{ matrix.os || 'ubuntu-latest' }}
2525
strategy:
2626
fail-fast: false
2727
matrix:
28-
python-version:
29-
- 3.9
30-
os:
31-
- ubuntu-20.04
3228
include:
3329
- name: lint
30+
python-version: "3.9"
3431
- name: packaging
32+
python-version: "3.9"
3533
- name: py37
3634
python-version: "3.7"
3735
- name: py38

.pre-commit-config.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,14 @@ repos:
7878
- id: mypy
7979
# empty args needed in order to match mypy cli behavior
8080
args: ["--strict"]
81+
additional_dependencies:
82+
- pytest
8183
- repo: https://github.com/pycqa/pylint
8284
rev: v2.14.5
8385
hooks:
8486
- id: pylint
87+
additional_dependencies:
88+
- pytest
8589
# Keep last due to being considerably slower than the others:
8690
- repo: local
8791
hooks:
@@ -90,7 +94,7 @@ repos:
9094
name: Upgrade constraints files and requirements
9195
files: ^(setup\.py|setup\.cfg|requirements\.txt)$
9296
language: python
93-
entry: python -m piptools compile --upgrade -q --extra docs --extra test --output-file=requirements.txt setup.cfg
97+
entry: python -m piptools compile --upgrade -q --strip-extras --extra test --output-file=requirements.txt setup.cfg
9498
pass_filenames: false
9599
stages:
96100
- manual
@@ -100,7 +104,7 @@ repos:
100104
name: Check constraints files and requirements
101105
files: ^(setup\.py|setup\.cfg|requirements\.txt)$
102106
language: python
103-
entry: python -m piptools compile -q --extra docs --extra test --output-file=requirements.txt setup.cfg
107+
entry: python -m piptools compile -q --strip-extras --extra test --output-file=requirements.txt setup.cfg
104108
pass_filenames: false
105109
additional_dependencies:
106110
- pip-tools>=6.8.0

requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
# This file is autogenerated by pip-compile with python 3.9
33
# To update, run:
44
#
5-
# pip-compile --extra=docs --extra=test --output-file=requirements.txt setup.cfg
5+
# pip-compile --extra=test --output-file=requirements.txt --strip-extras setup.cfg
66
#
77
attrs==22.1.0
88
# via pytest
9-
coverage[toml]==6.4.2
9+
coverage==6.4.2
1010
# via pytest-cov
1111
iniconfig==1.1.1
1212
# via pytest
@@ -22,7 +22,7 @@ pytest==7.1.2
2222
# via
2323
# ppinfo (setup.cfg)
2424
# pytest-cov
25-
pytest-cov[all]==3.0.0
25+
pytest-cov==3.0.0
2626
# via ppinfo (setup.cfg)
2727
tomli==2.0.1
2828
# via

src/ppinfo/__init__.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,29 @@
11
"""ppinfo package."""
2+
import configparser
3+
import os
4+
from pathlib import Path
5+
from typing import Union
6+
7+
8+
# pylint: disable=too-few-public-methods
9+
class Project:
10+
"""Class representing a python project."""
11+
12+
# 3.7 default value is used because at the time this library was
13+
# written, this was the oldest still supported version of Python
14+
min_python: str = "3.7"
15+
16+
def __init__(self, path: Union[Path, str] = Path(".")) -> None:
17+
"""Construct a python Project instance."""
18+
if isinstance(path, str):
19+
path = Path(path)
20+
self.path = path
21+
22+
if (path / "setup.cfg").exists():
23+
config = configparser.ConfigParser()
24+
config.read(path / "setup.cfg")
25+
if "options" in config:
26+
value = config["options"].get("python_requires", None)
27+
if not (value and value.startswith(">=")):
28+
raise NotImplementedError("Unable to parse python_requires")
29+
self.min_python = value[2:]

test/fixtures/proj1/setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# empty setup.cfg file

test/fixtures/py310/setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[options]
2+
python_requires = >=3.10

test/test_ppinfo.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
"""Tests for ppinfo package."""
2+
import pytest
23

4+
from ppinfo import Project
35

4-
def test_import() -> None:
5-
"""Test that we can import ppinfo."""
6-
# pylint: disable=unused-import,import-outside-toplevel
7-
import ppinfo
6+
7+
@pytest.mark.parametrize(
8+
("path", "expected_python"),
9+
[("test/fixtures/proj1", "3.7"), ("test/fixtures/py310", "3.10")],
10+
)
11+
def test_min_version(path: str, expected_python: str) -> None:
12+
"""Test ability to find minimal version of python required."""
13+
project = Project(path)
14+
assert project.min_python == expected_python

0 commit comments

Comments
 (0)