Skip to content

Commit 4c988ea

Browse files
committed
API change: keepalive flag not affect context manager keepalive
* keepalive_mode affect context manager behavior * in case of multiple context enter, only last `__exit__` will close connection Maintenance part: * migrate from flake8 to ruff * prepare for trusted publishing * better project metadata
1 parent 2b3dab1 commit 4c988ea

37 files changed

+815
-470
lines changed
Lines changed: 94 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,75 @@
11
name: Python package
22

3-
on: [push]
3+
on:
4+
push:
5+
branches-ignore:
6+
- 'dependabot/**'
7+
pull_request: {}
48

59
jobs:
610
PEP8:
11+
name: Check with Ruff
712
runs-on: ubuntu-latest
813
steps:
9-
- uses: actions/checkout@v3.5.2
14+
- uses: actions/checkout@v3
1015
- name: Set up Python
11-
uses: actions/setup-python@v4.6.1
16+
uses: actions/setup-python@v4
1217
with:
1318
python-version: '3.x'
1419
- name: Install dependencies
1520
run: |
1621
python -m pip install --upgrade pip
17-
pip install --upgrade -r flake8_requirements.txt
18-
- name: Lint with flake8
22+
pip install --upgrade ruff
23+
- name: Lint with ruff
1924
run: |
20-
flake8 exec_helpers
25+
ruff . --format github
2126
2227
PyLint:
2328
runs-on: ubuntu-latest
2429
steps:
25-
- uses: actions/checkout@v3.5.2
30+
- uses: actions/checkout@v3
2631
- name: Set up Python
27-
uses: actions/setup-python@v4.6.1
32+
uses: actions/setup-python@v4
2833
with:
29-
python-version: '3.7'
34+
python-version: '3.8'
3035
- name: Install dependencies
3136
run: |
3237
python -m pip install --upgrade pip
3338
pip install --upgrade -r CI_REQUIREMENTS.txt
34-
pip install --upgrade "pylint >= 2.6.0"
35-
- name: Generate version file
39+
pip install --upgrade "pylint >= 2.6.0" perflint
40+
- name: Install develop
3641
run: |
37-
python setup.py --version clean
42+
pip install -e .
3843
- name: Lint with PyLint
3944
run: |
4045
pylint exec_helpers
4146
4247
MyPy:
4348
runs-on: ubuntu-latest
4449
steps:
45-
- uses: actions/checkout@v3.5.2
50+
- uses: actions/checkout@v3
4651
- name: Set up Python
47-
uses: actions/setup-python@v4.6.1
52+
uses: actions/setup-python@v4
4853
with:
4954
python-version: '3.x'
5055
- name: Install dependencies
5156
run: |
5257
python -m pip install --upgrade pip
5358
pip install --upgrade -r CI_REQUIREMENTS.txt
5459
pip install --upgrade -r mypy_requirements.txt
55-
- name: Generate version file
60+
- name: Install develop
5661
run: |
57-
python setup.py --version clean
62+
pip install -e .
5863
- name: Lint with MyPy
5964
run: |
6065
mypy --strict --install-types --non-interactive exec_helpers
6166
6267
Black:
6368
runs-on: ubuntu-latest
6469
steps:
65-
- uses: actions/checkout@v3.5.2
70+
- uses: actions/checkout@v3
6671
- name: Set up Python
67-
uses: actions/setup-python@v4.6.1
72+
uses: actions/setup-python@v4
6873
with:
6974
python-version: '3.x'
7075
- name: Install dependencies
@@ -74,44 +79,84 @@ jobs:
7479
- name: Check code style with black
7580
run: |
7681
black --check exec_helpers
82+
Metadata:
83+
name: Validate metadata
84+
runs-on: ubuntu-latest
85+
steps:
86+
- uses: actions/checkout@v3
87+
- name: Set up Python
88+
uses: actions/setup-python@v4
89+
with:
90+
python-version: '3.x'
91+
- name: Install dependencies
92+
run: |
93+
python -m pip install --upgrade pip
94+
pip install --upgrade twine build
95+
- name: Build package
96+
run: |
97+
python -m build -s
98+
- name: Validate metadata
99+
run: |
100+
twine check dist/*
77101
78102
Test:
79-
needs: [PEP8, PyLint, MyPy, Black]
103+
needs: [PEP8, PyLint, MyPy, Black, Metadata] # isort is broken
80104
runs-on: ${{ matrix.os }}
81105
strategy:
82106
max-parallel: 6
83107
matrix:
84-
os: ["ubuntu-latest", "windows-latest"]
108+
os: [ubuntu-latest, windows-latest]
85109
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
86110

111+
name: "Script based python ${{ matrix.python-version }} on ${{ matrix.os }}"
87112
steps:
88-
- uses: actions/checkout@v3.5.2
113+
- uses: actions/checkout@v3
89114
- name: Set up Python ${{ matrix.python-version }}
90-
uses: actions/setup-python@v4.6.1
115+
uses: actions/setup-python@v4
91116
with:
92117
python-version: ${{ matrix.python-version }}
93118
- name: Install dependencies
94119
run: |
95120
python -m pip install --upgrade pip wheel
96121
pip install --upgrade -r CI_REQUIREMENTS.txt
97122
pip install --upgrade -r pytest_requirements.txt
98-
- name: Build package and install develop
123+
- name: Install develop
99124
run: |
100125
pip install -e .
101126
- name: Test with pytest
102127
run: |
103128
py.test --cov-report= --cov=exec_helpers test
104129
coverage report -m
130+
coverage xml
105131
# coverage report -m --fail-under 85
132+
- name: Coveralls Parallel
133+
uses: coverallsapp/github-action@v2
134+
with:
135+
flag-name: run-${{ matrix.python-version }}-${{ matrix.os }}
136+
parallel: true
137+
file: coverage.xml
106138

107-
Deploy:
108-
needs: [Test]
139+
UploadCoverage:
140+
name: Upload coverage to Coveralls
141+
needs: [ Test ]
142+
if: ${{ always() }}
143+
runs-on: ubuntu-latest
144+
steps:
145+
- name: Coveralls Finished
146+
uses: coverallsapp/github-action@v2
147+
with:
148+
parallel-finished: true
149+
150+
Build:
151+
needs: [ Test ]
109152
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
110153
runs-on: ubuntu-latest
111154
steps:
112-
- uses: actions/[email protected]
155+
- uses: actions/checkout@v3
156+
with:
157+
fetch-depth: 0 # need for setuptools_scm
113158
- name: Set up Python
114-
uses: actions/setup-python@v4.6.1
159+
uses: actions/setup-python@v4
115160
with:
116161
python-version: '3.x'
117162
- name: Install dependencies
@@ -121,9 +166,25 @@ jobs:
121166
- name: Build package
122167
run: |
123168
python -m build
124-
- name: Deploy
125-
env:
126-
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
127-
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
128-
run: |
129-
twine upload --skip-existing dist/*
169+
- uses: actions/upload-artifact@v3
170+
with:
171+
path: dist/*
172+
173+
Deploy:
174+
needs: [Build]
175+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
176+
runs-on: ubuntu-latest
177+
environment:
178+
name: pypi
179+
url: https://pypi.org/p/exec-helpers
180+
permissions:
181+
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
182+
steps:
183+
- uses: actions/download-artifact@v3
184+
with:
185+
# unpacks default artifact into dist/
186+
# if `name: artifact` is omitted, the action will create extra parent dir
187+
name: artifact
188+
path: dist
189+
- name: Publish package distributions to PyPI
190+
uses: pypa/gh-action-pypi-publish@release/v1

.pylintrc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ limit-inference-results=100
2828

2929
# List of plugins (as comma separated values of python modules names) to load,
3030
# usually to register additional checkers.
31-
load-plugins=pylint.extensions.docstyle,
32-
pylint.extensions.docparams,
31+
load-plugins=pylint.extensions.docparams,
32+
pylint.extensions.docstyle,
3333
pylint.extensions.overlapping_exceptions,
3434
pylint.extensions.emptystring,
3535
pylint.extensions.comparetozero,
@@ -39,6 +39,7 @@ load-plugins=pylint.extensions.docstyle,
3939
pylint.extensions.redefined_variable_type,
4040
pylint.extensions.typing,
4141
pylint.extensions.empty_comment
42+
# perflint
4243

4344
# Pickle collected data for later comparisons.
4445
persistent=yes
@@ -88,7 +89,8 @@ disable=locally-disabled,
8889
too-many-lines,
8990
broad-except,
9091
logging-fstring-interpolation,
91-
logging-format-interpolation
92+
logging-format-interpolation,
93+
invalid-name
9294

9395
# Enable the message, report, category or checker with the given id(s). You can
9496
# either give multiple identifier separated by comma (,) or put this option

doc/source/SSHClient.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ API: SSHClient and SSHAuth.
4848
.. versionchanged:: 6.0.0 private_keys is deprecated
4949
.. versionchanged:: 7.0.0 private_keys is removed
5050
.. versionchanged:: 7.0.0 keepalive_mode is removed
51+
.. versionchanged:: 7.4.0 return of keepalive_mode to prevent mix with keepalive period. Default is `False`
5152

5253
.. py:attribute:: log_mask_re
5354
@@ -91,10 +92,15 @@ API: SSHClient and SSHAuth.
9192
``bool``
9293
Use sudo for all calls, except wrapped in connection.sudo context manager.
9394

95+
.. py:attribute:: keepalive_mode
96+
97+
``bool``
98+
If `False` - close connection on exit from context manager.
99+
94100
.. py:attribute:: keepalive_period
95101
96102
``int | bool``
97-
Keepalive period for connection object. If `0` - close connection on exit from context manager.
103+
Keepalive period for connection object.
98104

99105
.. py:method:: close()
100106

doc/source/conf.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#!/usr/bin/env python3
2-
# -*- coding: utf-8 -*-
3-
#
41
# exec-helpers documentation build configuration file, created by
52
# sphinx-quickstart on Sun Oct 30 13:40:52 2016.
63
#
@@ -61,8 +58,8 @@
6158

6259
# General information about the project.
6360
project = "Exec-helpers"
64-
copyright = "2018, Alexey Stepanov"
65-
author = "Alexey Stepanov"
61+
copyright = "2018-2023, Aleksei Stepanov" # noqa: A001
62+
author = "Aleksei Stepanov"
6663

6764
# The version info for the project you're documenting, acts as replacement for
6865
# |version| and |release|, also used in various other places throughout the

exec_helpers/__init__.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2018 - 2022 Alexey Stepanov aka penguinolog.
1+
# Copyright 2018 - 2023 Aleksei Stepanov aka penguinolog.
22

33
# Licensed under the Apache License, Version 2.0 (the "License"); you may
44
# not use this file except in compliance with the License. You may obtain
@@ -21,9 +21,9 @@
2121
import typing
2222
import warnings
2323

24-
try:
24+
try: # noqa: SIM105
2525
# Local Implementation
26-
from ._version import version as __version__
26+
from ._version import version as __version__ # noqa: F401
2727
except ImportError:
2828
pass
2929

@@ -100,7 +100,11 @@ def __getattr__(name: str) -> typing.Any:
100100
:raises AttributeError: attribute is not defined for lazy load
101101
"""
102102
if name in _deprecated:
103-
warnings.warn(f"{name} is deprecated in favor of {_deprecated[name]}", DeprecationWarning)
103+
warnings.warn(
104+
f"{name} is deprecated in favor of {_deprecated[name]}",
105+
DeprecationWarning,
106+
stacklevel=2,
107+
)
104108
if name in __lazy_load_modules:
105109
mod = importlib.import_module(f"{__package__}.{name}")
106110
__locals[name] = mod
@@ -113,10 +117,10 @@ def __getattr__(name: str) -> typing.Any:
113117
raise AttributeError(f"{name} not found in {__package__}")
114118

115119

116-
__author__ = "Alexey Stepanov"
120+
__author__ = "Aleksei Stepanov"
117121
__author_email__ = "[email protected]"
118122
__maintainers__ = {
119-
"Alexey Stepanov": "[email protected]",
123+
"Aleksei Stepanov": "[email protected]",
120124
"Antonio Esposito": "[email protected]",
121125
"Dennis Dmitriev": "[email protected]",
122126
}

exec_helpers/__init__.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2018 - 2021 Alexey Stepanov aka penguinolog.
1+
# Copyright 2018 - 2023 Aleksei Stepanov aka penguinolog.
22

33
# Licensed under the Apache License, Version 2.0 (the "License"); you may
44
# not use this file except in compliance with the License. You may obtain
@@ -39,9 +39,9 @@ from .ssh import SSHClient
3939
from .ssh_auth import SSHAuth
4040
from .subprocess import Subprocess # nosec # Expected
4141

42-
try:
42+
try: # noqa: SIM105
4343
# Local Implementation
44-
from ._version import version as __version__
44+
from ._version import version as __version__ # noqa: F401
4545
except ImportError:
4646
pass
4747

exec_helpers/_log_templates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2018 - 2022 Alexey Stepanov aka penguinolog.
1+
# Copyright 2018 - 2023 Aleksei Stepanov aka penguinolog.
22

33
# Copyright 2017 Mirantis, Inc.
44

0 commit comments

Comments
 (0)