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 82a2b14 commit 0ec7263
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 23 deletions.
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ extend-ignore =
F401, # duplicate of pylint W0611 (unused-import)
F821, # duplicate of pylint E0602 (undefined-variable)
F841, # duplicate of pylint W0612 (unused-variable)
DAR # we don't use darling
17 changes: 3 additions & 14 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,19 @@ on:
branches: # any integration branch but not tag
- "main"
pull_request:
release:
types:
- published # It seems that you can publish directly without creating
schedule:
- cron: 1 0 * * * # Run daily at 0:01 UTC
# Run every Friday at 18:02 UTC
# https://crontab.guru/#2_18_*_*_5
# - cron: 2 18 * * 5
workflow_call:

jobs:
tox:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
runs-on: ${{ matrix.os || 'ubuntu-latest' }}
strategy:
fail-fast: false
matrix:
python-version:
- 3.9
os:
- ubuntu-20.04
include:
- name: lint
python-version: "3.9"
- name: packaging
python-version: "3.9"
- name: py37
python-version: "3.7"
- name: py38
Expand Down
8 changes: 6 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,14 @@ repos:
- id: mypy
# empty args needed in order to match mypy cli behavior
args: ["--strict"]
additional_dependencies:
- pytest
- repo: https://github.com/pycqa/pylint
rev: v2.14.5
hooks:
- id: pylint
additional_dependencies:
- pytest
# Keep last due to being considerably slower than the others:
- repo: local
hooks:
Expand All @@ -90,7 +94,7 @@ repos:
name: Upgrade constraints files and requirements
files: ^(setup\.py|setup\.cfg|requirements\.txt)$
language: python
entry: python -m piptools compile --upgrade -q --extra docs --extra test --output-file=requirements.txt setup.cfg
entry: python -m piptools compile --upgrade -q --strip-extras --extra test --output-file=requirements.txt setup.cfg
pass_filenames: false
stages:
- manual
Expand All @@ -100,7 +104,7 @@ repos:
name: Check constraints files and requirements
files: ^(setup\.py|setup\.cfg|requirements\.txt)$
language: python
entry: python -m piptools compile -q --extra docs --extra test --output-file=requirements.txt setup.cfg
entry: python -m piptools compile -q --strip-extras --extra test --output-file=requirements.txt setup.cfg
pass_filenames: false
additional_dependencies:
- pip-tools>=6.8.0
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
# This file is autogenerated by pip-compile with python 3.9
# To update, run:
#
# pip-compile --extra=docs --extra=test --output-file=requirements.txt setup.cfg
# pip-compile --extra=test --output-file=requirements.txt --strip-extras setup.cfg
#
attrs==22.1.0
# via pytest
coverage[toml]==6.4.2
coverage==6.4.2
# via pytest-cov
iniconfig==1.1.1
# via pytest
Expand All @@ -22,7 +22,7 @@ pytest==7.1.2
# via
# ppinfo (setup.cfg)
# pytest-cov
pytest-cov[all]==3.0.0
pytest-cov==3.0.0
# via ppinfo (setup.cfg)
tomli==2.0.1
# via
Expand Down
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 0ec7263

Please sign in to comment.