Skip to content
This repository was archived by the owner on Sep 5, 2025. It is now read-only.

Commit 5175282

Browse files
committed
fix some tests and new linter ruff
1 parent 217bb03 commit 5175282

File tree

14 files changed

+130
-250
lines changed

14 files changed

+130
-250
lines changed

.deepsource.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,3 @@ name = "python"
55

66
[analyzers.meta]
77
runtime_version = "3.x.x"
8-
9-
[[transformers]]
10-
name = "black"

.flake8

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

.github/workflows/build.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ jobs:
1212
strategy:
1313
matrix:
1414
python-version:
15-
- 3.7
16-
- 3.8
17-
- 3.9
18-
- 3.10.9
1915
- 3.11
16+
- 3.10.9
17+
- 3.9
18+
- 3.8
19+
- 3.7
2020
# env:
2121
# PYTHON_FOR_COVERAGE: "3.9"
2222
steps:

.pylintrc

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

CHANGELOG.md

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

Makefile

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
.DEFAULT_GOAL := help
2-
.PHONY: coverage deps help lint publish push test tox
32

43
apt-packages-ubuntu: ## Install packages needed
54
sudo add-apt-repository ppa:pipewire-debian/pipewire-upstream -y
@@ -10,17 +9,6 @@ deps: ## Install dependencies
109
python -m pip install --upgrade pip
1110
python -m pip install black coverage flake8 flit mccabe mypy pylint pytest pytest-cov tox tox-gh-actions
1211

13-
# coverage: ## Run tests with coverage
14-
# python -m coverage erase
15-
# python -m coverage run --include=pipewire_python/* -m pytest -ra
16-
# python -m coverage report -m
17-
# python -m coverage xml
18-
19-
# lint: ## Lint and static-check
20-
# python -m flake8 pipewire_python
21-
# python -m pylint pipewire_python
22-
# python -m mypy pipewire_python
23-
2412
publish: ## Publish to PyPi
2513
python -m flit publish
2614

@@ -33,3 +21,6 @@ test: ## Run tests [LOCALHOST]
3321
tox: ## Run tox
3422
python3 -m tox
3523
ls -la
24+
25+
help:
26+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'

pipewire_python/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@
1212
for the future of Linux application development.
1313
1414
[pipewire_python](https://pypi.org/project/pipewire_python/)
15-
controlls `pipewire` via terminal, creating shell commands and executing them as required.
15+
controlls `pipewire` via terminal, creating shell commands
16+
and executing them as required.
1617
1718
🎹 There are two ways to manage the python package:
1819
1920
1. NO_ASYNC: this way works as expected with delay time between
2021
`pipewire_python` and the rest of your code.
2122
22-
2. ASYNC: [⚠️Not yet implemented] this way works delegating the task to record or to play
23+
2. ASYNC: [⚠️Not yet implemented] this way works delegating
24+
the task to record or to play
2325
a song file in background. Works with threads.
2426
2527
3. MULTIPROCESS: [⚠️Not yet implemented] Works with processes.

pipewire_python/_utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from typing import Dict, List
99

1010
# Loading constants Constants.py
11-
from ._constants import MESSAGES_ERROR
11+
from pipewire_python._constants import MESSAGES_ERROR
1212

1313

1414
def _print_std(
@@ -57,7 +57,9 @@ def _update_dict_by_dict(
5757
Update values of one dictionary with values of another dictionary
5858
based on keys
5959
"""
60-
return main_dict.update(([(key, secondary_dict[key]) for key in secondary_dict.keys()]))
60+
return main_dict.update(
61+
([(key, secondary_dict[key]) for key in secondary_dict.keys()])
62+
)
6163

6264

6365
def _drop_keys_with_none_values(main_dict: dict):

pipewire_python/controller.py

Lines changed: 63 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@
55
`controller.py`.
66
"""
77

8-
import warnings
8+
# import warnings
9+
10+
# Loading constants Constants.py
11+
from pipewire_python._constants import (
12+
MESSAGES_ERROR,
13+
RECOMMENDED_FORMATS,
14+
RECOMMENDED_RATES,
15+
)
916

1017
# Loading internal functions
11-
from ._utils import (
18+
from pipewire_python._utils import (
1219
_drop_keys_with_none_values,
1320
_execute_shell_command,
1421
_filter_by_type,
@@ -18,9 +25,6 @@
1825
_get_dict_from_stdout,
1926
)
2027

21-
# Loading constants Constants.py
22-
from ._constants import MESSAGES_ERROR, RECOMMENDED_FORMATS, RECOMMENDED_RATES
23-
2428
# [DEPRECATED] [FLAKE8] TO_AVOID_F401 PEP8
2529
# [DEPRECATED] https://stackoverflow.com/a/31079085/10491422
2630
# NOW USED IN DOCUMENTATION
@@ -103,7 +107,9 @@ def __init__(
103107
# get default parameters with help
104108
stdout, _ = _execute_shell_command(command=mycommand, verbose=verbose) # stderr
105109
# convert stdout to dictionary
106-
dict_default_values = _get_dict_from_stdout(stdout=str(stdout.decode()), verbose=verbose)
110+
dict_default_values = _get_dict_from_stdout(
111+
stdout=str(stdout.decode()), verbose=verbose
112+
)
107113

108114
if verbose:
109115
print(self._pipewire_configs)
@@ -164,7 +170,9 @@ def get_version(
164170
if verbose:
165171
print(f"[mycommand]{mycommand}")
166172

167-
stdout, _ = _execute_shell_command(command=mycommand, timeout=-1, verbose=verbose)
173+
stdout, _ = _execute_shell_command(
174+
command=mycommand, timeout=-1, verbose=verbose
175+
)
168176
versions = stdout.decode().split("\n")[1:]
169177

170178
self._pipewire_cli["--version"] = versions
@@ -311,7 +319,9 @@ def set_config(
311319
elif target is None:
312320
pass
313321
else:
314-
raise ValueError(f"{MESSAGES_ERROR['ValueError']}[target='{target}'] EMPTY VALUE")
322+
raise ValueError(
323+
f"{MESSAGES_ERROR['ValueError']}[target='{target}'] EMPTY VALUE"
324+
)
315325
# 5 - latency
316326
if latency:
317327
if any(chr.isdigit() for chr in latency): # Contain numbers
@@ -323,7 +333,9 @@ def set_config(
323333
elif latency is None:
324334
pass
325335
else:
326-
raise ValueError(f"{MESSAGES_ERROR['ValueError']}[latency='{latency}'] EMPTY VALUE")
336+
raise ValueError(
337+
f"{MESSAGES_ERROR['ValueError']}[latency='{latency}'] EMPTY VALUE"
338+
)
327339
# 6 - rate
328340
if rate:
329341
if rate in RECOMMENDED_RATES:
@@ -336,7 +348,9 @@ def set_config(
336348
elif rate is None:
337349
pass
338350
else:
339-
raise ValueError(f"{MESSAGES_ERROR['ValueError']}[rate='{rate}'] EMPTY VALUE")
351+
raise ValueError(
352+
f"{MESSAGES_ERROR['ValueError']}[rate='{rate}'] EMPTY VALUE"
353+
)
340354
# 7 - channels
341355
if channels:
342356
if channels in [1, 2]: # values
@@ -349,7 +363,9 @@ def set_config(
349363
elif channels is None:
350364
pass
351365
else:
352-
raise ValueError(f"{MESSAGES_ERROR['ValueError']}[channels='{channels}'] EMPTY VALUE")
366+
raise ValueError(
367+
f"{MESSAGES_ERROR['ValueError']}[channels='{channels}'] EMPTY VALUE"
368+
)
353369
# 8 - channels-map
354370
if channels_map:
355371
self._pipewire_configs["--channels-map"] = str(channels_map)
@@ -371,7 +387,9 @@ def set_config(
371387
elif _format is None:
372388
pass
373389
else:
374-
raise ValueError(f"{MESSAGES_ERROR['ValueError']}[_format='{_format}'] EMPTY VALUE")
390+
raise ValueError(
391+
f"{MESSAGES_ERROR['ValueError']}[_format='{_format}'] EMPTY VALUE"
392+
)
375393
# 10 - volume
376394
if volume:
377395
if 0.0 <= volume <= 1.0:
@@ -384,7 +402,9 @@ def set_config(
384402
elif volume is None:
385403
pass
386404
else:
387-
raise ValueError(f"{MESSAGES_ERROR['ValueError']}[volume='{volume}'] EMPTY VALUE")
405+
raise ValueError(
406+
f"{MESSAGES_ERROR['ValueError']}[volume='{volume}'] EMPTY VALUE"
407+
)
388408
# 11 - quality
389409
if quality:
390410
if 0 <= quality <= 15:
@@ -396,7 +416,9 @@ def set_config(
396416
elif quality is None:
397417
pass
398418
else:
399-
raise ValueError(f"{MESSAGES_ERROR['ValueError']}[volume='{volume}'] EMPTY VALUE")
419+
raise ValueError(
420+
f"{MESSAGES_ERROR['ValueError']}[volume='{volume}'] EMPTY VALUE"
421+
)
400422

401423
# 12 - verbose cli
402424
if verbose: # True
@@ -419,13 +441,17 @@ def load_list_targets(
419441

420442
if mode == "playback":
421443
mycommand = ["pw-cat", "--playback", "--list-targets"]
422-
stdout, _ = _execute_shell_command(command=mycommand, timeout=-1, verbose=verbose)
444+
stdout, _ = _execute_shell_command(
445+
command=mycommand, timeout=-1, verbose=verbose
446+
)
423447
self._pipewire_list_targets["list_playback"] = _generate_dict_list_targets(
424448
longstring=stdout.decode(), verbose=verbose
425449
)
426450
elif mode == "record":
427451
mycommand = ["pw-cat", "--record", "--list-targets"]
428-
stdout, _ = _execute_shell_command(command=mycommand, timeout=-1, verbose=verbose)
452+
stdout, _ = _execute_shell_command(
453+
command=mycommand, timeout=-1, verbose=verbose
454+
)
429455
self._pipewire_list_targets["list_record"] = _generate_dict_list_targets(
430456
longstring=stdout.decode(), verbose=verbose
431457
)
@@ -503,10 +529,13 @@ def get_list_interfaces(
503529
```
504530
Args:
505531
filtered_by_type : If False, returns all. If not, returns a fitered dict
506-
type_interfaces : Set type of Interface ["Client","Link","Node","Factory","Module","Metadata","Endpoint","Session","Endpoint Stream","EndpointLink","Port"]
532+
type_interfaces : Set type of Interface
533+
["Client","Link","Node","Factory","Module","Metadata","Endpoint",
534+
"Session","Endpoint Stream","EndpointLink","Port"]
507535
508536
Returns:
509-
- dict_interfaces_filtered: dictionary with list of interfaces matching conditions
537+
- dict_interfaces_filtered: dictionary
538+
with list of interfaces matching conditions
510539
511540
Examples:
512541
```python
@@ -519,8 +548,12 @@ def get_list_interfaces(
519548
# if verbose:
520549
# print(f"[mycommand]{mycommand}")
521550

522-
stdout, _ = _execute_shell_command(command=mycommand, timeout=-1, verbose=verbose)
523-
dict_interfaces = _generate_dict_interfaces(longstring=stdout.decode(), verbose=verbose)
551+
stdout, _ = _execute_shell_command(
552+
command=mycommand, timeout=-1, verbose=verbose
553+
)
554+
dict_interfaces = _generate_dict_interfaces(
555+
longstring=stdout.decode(), verbose=verbose
556+
)
524557

525558
if filtered_by_type:
526559
dict_interfaces_filtered = _filter_by_type(
@@ -554,16 +587,20 @@ def playback(
554587
- stdout (`str`): Shell response to the command in stdout format
555588
- stderr (`str`): Shell response response to the command in stderr format
556589
"""
557-
warnings.warn("The name of the function may change on future releases", DeprecationWarning)
590+
# warnings.warn("The name of the function may change on future releases", DeprecationWarning)
558591

559-
mycommand = ["pw-cat", "--playback", audio_filename] + _generate_command_by_dict(
560-
mydict=self._pipewire_configs, verbose=verbose
561-
)
592+
mycommand = [
593+
"pw-cat",
594+
"--playback",
595+
audio_filename,
596+
] + _generate_command_by_dict(mydict=self._pipewire_configs, verbose=verbose)
562597

563598
if verbose:
564599
print(f"[mycommand]{mycommand}")
565600

566-
stdout, stderr = _execute_shell_command(command=mycommand, timeout=-1, verbose=verbose)
601+
stdout, stderr = _execute_shell_command(
602+
command=mycommand, timeout=-1, verbose=verbose
603+
)
567604
return stdout, stderr
568605

569606
def record(
@@ -590,7 +627,7 @@ def record(
590627
- stdout (`str`): Shell response to the command in stdout format
591628
- stderr (`str`): Shell response response to the command in stderr format
592629
"""
593-
warnings.warn("The name of the function may change on future releases", DeprecationWarning)
630+
# warnings.warn("The name of the function may change on future releases", DeprecationWarning)
594631

595632
mycommand = ["pw-cat", "--record", audio_filename] + _generate_command_by_dict(
596633
mydict=self._pipewire_configs, verbose=verbose

0 commit comments

Comments
 (0)