Skip to content

Commit 39bded0

Browse files
switch to poetry and modernize, touch up tests
Signed-off-by: David Ford <[email protected]>
1 parent 2408c2e commit 39bded0

File tree

15 files changed

+1643
-138
lines changed

15 files changed

+1643
-138
lines changed

poetry.lock

Lines changed: 770 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 45 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,56 @@
1-
[build-system]
2-
requires = [
3-
'setuptools>=44',
4-
'wheel>=0.30.0',
5-
'six',
1+
[project]
2+
name = "python-pam"
3+
version = "2.1.0-beta1"
4+
description = ""
5+
authors = [{name = "David Ford", email = "[email protected]"}]
6+
readme = "README.md"
7+
requires-python = ">=3.10"
8+
dependencies = [
9+
"six",
610
]
7-
build-backend = 'setuptools.build_meta'
8-
9-
# ignore the tox documentation, it IS NOT supported yet
10-
# https://github.com/tox-dev/tox/issues/2148
11-
#[tox]
12-
#isolated_build = true
1311

14-
[tool.tox]
15-
legacy_tox_ini = """
16-
[tox]
17-
envlist = py310
18-
isolated_build = true
19-
#skipsdist = true
12+
[tool.poetry]
13+
packages = [{include = "pam", from = "python-pam"}]
2014

21-
[gh-actions]
22-
python =
23-
3.7: py37
24-
3.8: py38
25-
3.9: py39
26-
3.10: py310
15+
[tool.poetry.group.dev.dependencies]
16+
pytest = "^6.2.4"
17+
pytest-cov = "^4.0.0"
18+
pylint = "^3.0.0"
19+
tox = "^4.0.0"
20+
bandit = "*"
2721

28-
[testenv]
29-
basepython = python3.10
30-
passenv = *
31-
deps =
32-
bandit
33-
flake8
34-
mypy
35-
types-six
36-
coverage
37-
pytest-cov
38-
pytest
39-
-rrequirements.txt
22+
[tool.coverage.run]
23+
source = ["pam"]
24+
omit = ["*/tests/*", "*/test_*.py"]
4025

41-
commands =
42-
flake8 src/pam/
43-
mypy
44-
bandit -r src -c "pyproject.toml"
45-
pytest --cov -r w --capture=sys -vvv --cov-report=html
46-
"""
26+
[tool.coverage.report]
27+
precision = 2
28+
show_missing = true
29+
skip_covered = false
30+
fail_under = 85.0
4731

4832
[tool.bandit]
4933
exclude_dirs = ["./venv", "./test", ]
5034
recursive = true
5135

52-
[tool.mypy]
53-
files = ["src/pam/__init__.py", "src/pam/__internals.py"]
54-
ignore_missing_imports = true
55-
56-
[tool.pytest]
57-
python_files = "test_*.py"
58-
norecursedirs = ".tox"
59-
60-
[tool.coverage.run]
61-
branch = true
62-
# awkward how I can include "pam" but I have to be incredibly specific when omitting
63-
source = ["pam"]
64-
omit = ["*/pam/pam.py", "*/pam/version.py",]
65-
66-
[tool.coverage.html]
67-
directory = "htmlcov"
36+
[tool.pylint.main]
37+
jobs = 0
38+
39+
[tool.pylint.format]
40+
max-line-length = 120
41+
42+
[tool.pylint."messages control"]
43+
disable = [
44+
"too-many-arguments",
45+
"too-many-positional-arguments",
46+
"too-many-branches",
47+
"too-many-statements",
48+
"too-many-locals",
49+
"too-many-instance-attributes",
50+
"too-few-public-methods",
51+
"wrong-import-position", # Imports are intentionally after version check
52+
]
6853

69-
[tool.coverage.report]
70-
skip_empty = true
71-
fail_under = 100
54+
[build-system]
55+
requires = ["poetry-core"]
56+
build-backend = "poetry.core.masonry.api"

python-pam.sublime-project

Lines changed: 0 additions & 9 deletions
This file was deleted.

python-pam/__init__.py

Whitespace-only changes.
Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import sys as __sys
1+
"""PAM (Pluggable Authentication Modules) interface for Python.
22
3-
if __sys.version_info < (3, ): # pragma: no cover
4-
print('WARNING, Python 2 is EOL and therefore py2 support in this '
5-
"package is deprecated. It won't be actively checked for"
6-
'correctness')
3+
This module provides a Python interface to Linux-PAM, allowing authentication
4+
against system PAM services.
5+
"""
6+
import sys as __sys
77

88
# list all the constants and export them
99
from .__internals import PAM_ACCT_EXPIRED
@@ -58,6 +58,11 @@
5858
from .__internals import PAM_XDISPLAY
5959
from .__internals import PamAuthenticator
6060

61+
if __sys.version_info < (3, ): # pragma: no cover
62+
print('WARNING, Python 2 is EOL and therefore py2 support in this '
63+
"package is deprecated. It won't be actively checked for"
64+
'correctness')
65+
6166
__all__ = [
6267
'authenticate',
6368
'pam',
@@ -124,7 +129,25 @@ def authenticate(username,
124129
encoding='utf-8',
125130
resetcreds=True,
126131
print_failure_messages=False):
127-
global __PA
132+
"""Authenticate a user against PAM.
133+
134+
This is a convenience function that creates a PamAuthenticator instance
135+
(reusing a global instance if available) and calls its authenticate method.
136+
137+
Args:
138+
username: Username to authenticate
139+
password: Password in plain text
140+
service: PAM service to authenticate against (default: 'login')
141+
env: Dictionary of environment variables to set
142+
call_end: Whether to call pam_end() after authentication (default: True)
143+
encoding: Encoding to use for string conversions (default: 'utf-8')
144+
resetcreds: Whether to reset credentials after authentication (default: True)
145+
print_failure_messages: Whether to print failure messages (default: False)
146+
147+
Returns:
148+
bool: True if authentication succeeded, False otherwise
149+
"""
150+
global __PA # noqa: PLW0603
128151

129152
if __PA is None: # pragma: no branch
130153
__PA = PamAuthenticator()
@@ -133,5 +156,5 @@ def authenticate(username,
133156

134157

135158
# legacy implementations used pam.pam()
136-
pam = PamAuthenticator
159+
pam = PamAuthenticator # noqa: N816, C0103
137160
authenticate.__doc__ = PamAuthenticator.authenticate.__doc__

0 commit comments

Comments
 (0)