Skip to content

Commit 3a094ec

Browse files
authored
Merge pull request #22 from netinvent/encoding-hotfix
Encoding hotfix
2 parents 11951e2 + ea1b8b1 commit 3a094ec

File tree

6 files changed

+35
-15
lines changed

6 files changed

+35
-15
lines changed

.github/workflows/linux.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ jobs:
1010
matrix:
1111
os: [ubuntu-latest]
1212
# Python 3.3 and 3.4 have been removed since github won't provide these anymore
13-
python-version: [2.7, 3.5, 3.6, 3.7, 3.8, 3.9, "3.10", 'pypy-3.6', 'pypy-3.7', 'pypy-3.8']
13+
# As of 2023/01/09, we have removed python 3.5 and 3.6 as they don't work anymore with linux on github
14+
python-version: [2.7, 3.7, 3.8, 3.9, "3.10", "3.11", 'pypy-3.6', 'pypy-3.7', 'pypy-3.8']
1415

1516
steps:
16-
- uses: actions/checkout@v2
17+
- uses: actions/checkout@v3
1718
- name: Set up Python ${{ matrix.python-version }}
18-
uses: actions/setup-python@v2
19+
uses: actions/setup-python@v3
1920
with:
2021
python-version: ${{ matrix.python-version }}
2122
- name: Install dependencies
@@ -30,4 +31,4 @@ jobs:
3031
pip install pytest coverage
3132
python -m coverage run -m pytest -vvs tests
3233
- name: Upload Coverage to Codecov
33-
uses: codecov/codecov-action@v1
34+
uses: codecov/codecov-action@v3

.github/workflows/windows.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ jobs:
1414
strategy:
1515
matrix:
1616
os: [windows-latest]
17-
python-version: [2.7, 3.5, 3.6, 3.7, 3.8, 3.9, "3.10", 'pypy-3.6', 'pypy-3.7', 'pypy-3.8']
17+
python-version: [2.7, 3.5, 3.6, 3.7, 3.8, 3.9, "3.10", "3.11", 'pypy-3.6', 'pypy-3.7', 'pypy-3.8']
1818

1919
steps:
20-
- uses: actions/checkout@v2
20+
- uses: actions/checkout@v3
2121
- name: Set up Python ${{ matrix.python-version }}
22-
uses: actions/setup-python@v2
22+
uses: actions/setup-python@v3
2323
with:
2424
python-version: ${{ matrix.python-version }}
2525
- name: Install dependencies
@@ -34,4 +34,4 @@ jobs:
3434
pip install pytest coverage
3535
python -m coverage run -m pytest -vvs tests
3636
- name: Upload Coverage to Codecov
37-
uses: codecov/codecov-action@v1
37+
uses: codecov/codecov-action@v3

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# v1.4.1 - command and conquer them all, don't nod
2+
3+
- Fix endoding always was set to os default unless explicitly disabled by setting `encoding=False`
4+
15
# v1.4.0 - command and conquer them all
26

37
## Features

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BSD 3-Clause License
22

3-
Copyright (c) 2015-2022, netinvent, Orsiris de Jong, contact@netinvent.fr
3+
Copyright (c) 2015-2023, netinvent, Orsiris de Jong, contact@netinvent.fr
44
All rights reserved.
55

66
Redistribution and use in source and binary forms, with or without

README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ while solving various problems a developer may face among:
2020
- Optional Windows UAC elevation module compatible with CPython, PyInstaller & Nuitka
2121
- Optional Linux sudo elevation compatible with CPython, PyInstaller & Nuitka
2222

23-
It is compatible with Python 2.7+ (backports some newer Python 3.5 functionality) and is tested on both Linux and Windows.
23+
It is compatible with Python 2.7+, tested up to Python 3.11 (backports some newer Python 3.5 functionality) and is tested on both Linux and Windows.
2424
It is also compatible with PyPy Python implementation.
2525
...and yes, keeping Python 2.7 compatibility has proven to be quite challenging.
2626

@@ -98,7 +98,7 @@ exit_code, output = command_runner(command, encoding='unicode_escape')
9898

9999
Earlier subprocess.popen implementations didn't have an encoding setting so command_runner will deal with encoding for those.
100100

101-
You can also disable command_runner's encoding in order to get raw process output (bytes) by passing False boolean.
101+
You can also disable command_runner's internal encoding in order to get raw process output (bytes) by passing False boolean.
102102

103103
Example:
104104
```python
@@ -403,6 +403,21 @@ It also uses the following standard arguments:
403403

404404
**Note that ALL other subprocess.Popen arguments are supported, since they are directly passed to subprocess.**
405405

406+
### logging
407+
408+
Even muted, `command_runner` will still log errors.
409+
If you want to completely mute `command_runner`, you will have to set it's logger instance to `logger.CRITICAL` level, since this level is never called.
410+
411+
Example of entirely muted `command_runner` execution:
412+
```
413+
rom command_runner import command_runner
414+
import logging
415+
416+
logging.getLogger("command_runner").setLevel(logging.CRITICAL)
417+
418+
err_code, stdout, stderr = command_runner("ping 127.0.0.1", timeout=1, method='monitor', live_output=False, stdout=False, stderr=False, split_streams=True)
419+
```
420+
406421
## UAC Elevation / sudo elevation
407422

408423
command_runner package allowing privilege elevation.

command_runner/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919

2020
__intname__ = "command_runner"
2121
__author__ = "Orsiris de Jong"
22-
__copyright__ = "Copyright (C) 2015-2022 Orsiris de Jong"
22+
__copyright__ = "Copyright (C) 2015-2023 Orsiris de Jong for NetInvent SASU"
2323
__licence__ = "BSD 3 Clause"
24-
__version__ = "1.4.0"
25-
__build__ = "2022053001"
24+
__version__ = "1.4.1"
25+
__build__ = "2023010901"
2626
__compat__ = "python2.7+"
2727

2828
import io
@@ -384,7 +384,7 @@ def command_runner(
384384
# cp437 encoding assures we catch most special characters from cmd.exe
385385
# Unless encoding=False in which case nothing gets encoded except Exceptions and logger strings for Python 2
386386
error_encoding = "cp437" if os.name == "nt" else "utf-8"
387-
if encoding is not False:
387+
if encoding is None:
388388
encoding = error_encoding
389389

390390
# Fix when unix command was given as single string

0 commit comments

Comments
 (0)