Skip to content

Commit 774893f

Browse files
authored
fix: fix pytest workflow uv installation (#4)
1 parent 8d5fe60 commit 774893f

File tree

9 files changed

+572
-85
lines changed

9 files changed

+572
-85
lines changed

.github/workflows/pytest.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,16 @@ jobs:
2020
steps:
2121
- uses: actions/checkout@v4
2222
- name: Install UV
23-
run: astral-sh/setup-uv@v5
24-
python-version: ${{ matrix.python-version }}
25-
- uses: astral-sh/ruff-action@v3
23+
uses: astral-sh/setup-uv@v5
24+
with:
25+
python-version: ${{ matrix.python-version }}
26+
- name: UV sync
27+
run: uv sync
28+
- name: Install pytest
29+
run: |
30+
uv tool install pytest
31+
uv add pytest-cov
32+
- uses: astral-sh/ruff-action@v3
2633
- name: Run the tests
2734
run: pytest --cov --cov-report=json:coverage.json tests/
2835
- name: Extract coverage
@@ -31,10 +38,10 @@ jobs:
3138
uses: schneegans/[email protected]
3239
with:
3340
auth: ${{ secrets.GIST_TOKEN }}
34-
gistID: 88ae1c5c4c732ba28346b3fac87b44a3
41+
gistID: 88ae1c5c4c732ba28346b3fac87b44a3
3542
filename: covbadge.json
3643
label: Coverage
3744
message: ${{ env.total }}%
3845
minColorRange: 50
3946
maxColorRange: 90
40-
valColorRange: ${{ env.total }}
47+
valColorRange: ${{ env.total }}

.pre-commit-config.yaml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1-
- repo: https://github.com/astral-sh/uv-pre-commit
2-
rev: 0.5.18
3-
hooks:
4-
- id: uv-lock
5-
- id: ruff
6-
args: [ --fix ]
7-
- id: ruff-format
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v2.3.0
4+
hooks:
5+
- id: end-of-file-fixer
6+
- id: trailing-whitespace
7+
- repo: https://github.com/astral-sh/ruff-pre-commit
8+
rev: v0.9.1
9+
hooks:
10+
- id: ruff
11+
args: [ --fix ]
12+
- id: ruff-format
13+
- repo: https://github.com/astral-sh/uv-pre-commit
14+
rev: 0.5.18
15+
hooks:
16+
- id: uv-lock
17+
- id: uv-export

lib/pyclamd.py

Lines changed: 46 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,8 @@ class ConnectionError(socket.error):
157157
"""Class for errors communication with clamd"""
158158

159159

160-
# Python 2/3 compatibility
161-
try:
162-
basestring # attempt to evaluate basestring
163-
164-
def isstr(s):
165-
return isinstance(s, basestring)
166-
167-
except NameError:
168-
169-
def isstr(s):
170-
return isinstance(s, str)
160+
def isstr(s):
161+
return isinstance(s, str)
171162

172163

173164
############################################################################
@@ -311,9 +302,9 @@ def scan_file(self, file):
311302
- socket.timeout: if timeout has expired
312303
"""
313304

314-
assert isstr(
315-
file
316-
), "Wrong type for [file], should be a string [was {0}]".format(type(file))
305+
assert isstr(file), (
306+
"Wrong type for [file], should be a string [was {0}]".format(type(file))
307+
)
317308

318309
try:
319310
self._init_socket()
@@ -359,9 +350,9 @@ def multiscan_file(self, file):
359350
May raise:
360351
- ConnectionError: in case of communication problem
361352
"""
362-
assert isstr(
363-
file
364-
), "Wrong type for [file], should be a string [was {0}]".format(type(file))
353+
assert isstr(file), (
354+
"Wrong type for [file], should be a string [was {0}]".format(type(file))
355+
)
365356

366357
try:
367358
self._init_socket()
@@ -407,9 +398,9 @@ def allmatchscan(self, file):
407398
- ConnectionError: in case of communication problem
408399
- socket.timeout: if timeout has expired
409400
"""
410-
assert isstr(
411-
file
412-
), "Wrong type for [file], should be a string [was {0}]".format(type(file))
401+
assert isstr(file), (
402+
"Wrong type for [file], should be a string [was {0}]".format(type(file))
403+
)
413404

414405
dr = {}
415406

@@ -469,9 +460,9 @@ def contscan_file(self, file):
469460
May raise:
470461
- ConnectionError: in case of communication problem
471462
"""
472-
assert isstr(
473-
file
474-
), "Wrong type for [file], should be a string [was {0}]".format(type(file))
463+
assert isstr(file), (
464+
"Wrong type for [file], should be a string [was {0}]".format(type(file))
465+
)
475466

476467
try:
477468
self._init_socket()
@@ -521,17 +512,17 @@ def scan_stream(self, stream, chunk_size=4096):
521512
"""
522513
if sys.version_info[0] <= 2:
523514
# Python2
524-
assert hasattr(stream, "read") or isinstance(
525-
stream, str
526-
), "Wrong type for [stream], should be str/file-like [was {0}]".format(
527-
type(stream)
515+
assert hasattr(stream, "read") or isinstance(stream, str), (
516+
"Wrong type for [stream], should be str/file-like [was {0}]".format(
517+
type(stream)
518+
)
528519
)
529520
else:
530521
# Python3
531-
assert hasattr(stream, "read") or isinstance(
532-
stream, (bytes, bytearray)
533-
), "Wrong type for [stream], should be bytes/bytearray/file-like [was {0}]".format(
534-
type(stream)
522+
assert hasattr(stream, "read") or isinstance(stream, (bytes, bytearray)), (
523+
"Wrong type for [stream], should be bytes/bytearray/file-like [was {0}]".format(
524+
type(stream)
525+
)
535526
)
536527

537528
is_file_like = hasattr(stream, "read")
@@ -580,7 +571,6 @@ def scan_stream(self, stream, chunk_size=4096):
580571
raise ConnectionError("Unable to scan stream")
581572

582573
if len(result) > 0:
583-
584574
if result == "INSTREAM size limit exceeded. ERROR":
585575
raise BufferTooLongError(result)
586576

@@ -693,7 +683,11 @@ def __init__(self, filename=None, timeout=None):
693683

694684
# try to get unix socket from clamd.conf
695685
if filename is None:
696-
for clamdpath in ["/etc/clamav/clamd.conf", "/etc/clamd.conf", "/opt/homebrew/etc/clamav/clamd.conf"]:
686+
for clamdpath in [
687+
"/etc/clamav/clamd.conf",
688+
"/etc/clamd.conf",
689+
"/opt/homebrew/etc/clamav/clamd.conf",
690+
]:
697691
if os.path.isfile(clamdpath):
698692
break
699693
else:
@@ -715,13 +709,13 @@ def __init__(self, filename=None, timeout=None):
715709
"Could not find clamd unix socket from /etc/clamav/clamd.conf or /etc/clamd.conf"
716710
)
717711

718-
assert isstr(
719-
filename
720-
), "Wrong type for [file], should be a string [was {0}]".format(type(file))
721-
assert (
722-
isinstance(timeout, (float, int)) or timeout is None
723-
), "Wrong type for [timeout], should be either None or a float [was {0}]".format(
724-
type(timeout)
712+
assert isstr(filename), (
713+
"Wrong type for [file], should be a string [was {0}]".format(type(filename))
714+
)
715+
assert isinstance(timeout, (float, int)) or timeout is None, (
716+
"Wrong type for [timeout], should be either None or a float [was {0}]".format(
717+
type(timeout)
718+
)
725719
)
726720

727721
_ClamdGeneric.__init__(self)
@@ -740,7 +734,7 @@ def _init_socket(self):
740734
internal use only
741735
"""
742736
self.clamd_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
743-
if not self.timeout is None:
737+
if self.timeout:
744738
self.clamd_socket.settimeout(self.timeout)
745739

746740
try:
@@ -770,16 +764,16 @@ def __init__(self, host="127.0.0.1", port=3310, timeout=None):
770764
timeout (float or None) : socket timeout
771765
"""
772766

773-
assert isinstance(
774-
host, str
775-
), "Wrong type for [host], should be a string [was {0}]".format(type(host))
776-
assert isinstance(
777-
port, int
778-
), "Wrong type for [port], should be an int [was {0}]".format(type(port))
779-
assert (
780-
isinstance(timeout, (float, int)) or timeout is None
781-
), "Wrong type for [timeout], should be either None or a float [was {0}]".format(
782-
type(timeout)
767+
assert isinstance(host, str), (
768+
"Wrong type for [host], should be a string [was {0}]".format(type(host))
769+
)
770+
assert isinstance(port, int), (
771+
"Wrong type for [port], should be an int [was {0}]".format(type(port))
772+
)
773+
assert isinstance(timeout, (float, int)) or timeout is None, (
774+
"Wrong type for [timeout], should be either None or a float [was {0}]".format(
775+
type(timeout)
776+
)
783777
)
784778

785779
_ClamdGeneric.__init__(self)
@@ -799,7 +793,7 @@ def _init_socket(self):
799793
internal use only
800794
"""
801795
self.clamd_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
802-
if not self.timeout is None:
796+
if self.timeout:
803797
self.clamd_socket.settimeout(self.timeout)
804798
try:
805799
self.clamd_socket.connect((self.host, self.port))
@@ -920,7 +914,6 @@ def _print_doc():
920914

921915
# MAIN -------------------
922916
if __name__ == "__main__":
923-
924917
_non_regression_test()
925918

926919

lib/scan.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def scan_file(self, file):
7474
self.logger.debug(message, extra={"filepath": filepath})
7575
elif result == "FOUND":
7676
self.logger.info(
77-
f"File match", extra={"file": filepath, "signature": message}
77+
"File match", extra={"file": filepath, "signature": message}
7878
)
7979
return True
8080
else:

pyclamav.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import os
2-
31
from lib.config import load_config
42
from lib.log import get_logger
53

@@ -11,13 +9,15 @@ def main():
119
logger = get_logger(config.log_folder, config.verbose)
1210
scanner = Scan(config.modified_file_datetime, logger)
1311

14-
logger.info(f"Scanning {len(config.folders)} folders with files changed during the last {config.modified_file_since}")
12+
logger.info(
13+
f"Scanning {len(config.folders)} folders with files changed during the last {config.modified_file_since}"
14+
)
1515
for folder in config.folders:
1616
logger.info(
17-
f"Scanning folder",
17+
"Scanning folder",
1818
extra={"folder": folder},
1919
)
20-
r = scanner.scan_folder(folder)
20+
scanner.scan_folder(folder)
2121

2222

2323
if __name__ == "__main__":

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ requires-python = ">=3.11"
77
dependencies = [
88
"dateparser>=1.2.0",
99
"logging>=0.4.9.6",
10+
"pre-commit>=4.0.1",
1011
"pyclamd>=0.4.0",
1112
"pydantic>=2.10.5",
1213
"pytest>=8.3.4",
1314
"python-json-logger>=3.2.1",
15+
"requests>=2.32.3",
1416
"ruff>=0.9.1",
1517
]

0 commit comments

Comments
 (0)