Skip to content

Commit

Permalink
ci: update configs and fix mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
karlicoss committed May 17, 2024
1 parent 31ee24b commit 35d675b
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 32 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ jobs:
# windows runners are pretty scarce, so let's only run lowest and highest python version
{platform: windows-latest, python-version: '3.9' },
{platform: windows-latest, python-version: '3.10'},
# NOTE: some test packages (e.g. mouseinfo) have issues with building wheels on 3.12 windows
# perhaps try again later
{platform: windows-latest, python-version: '3.12'},
{platform: windows-latest, python-version: '3.11'},

# same, macos is a bit too slow and ubuntu covers python quirks well
{platform: macos-latest , python-version: '3.9' },
Expand Down Expand Up @@ -125,7 +123,7 @@ jobs:

- uses: actions/setup-python@v5
with:
python-version: '3.8'
python-version: '3.10'

- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -155,9 +153,11 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0 # nicer to have all git history when debugging/for tests

- uses: actions/setup-node@v4
with:
node-version: '18'
node-version: '20'

- run: extension/.ci/build --lint # debug version
- run: extension/.ci/build --lint --release
Expand Down
10 changes: 6 additions & 4 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
[mypy]
namespace_packages = True
pretty = True
show_error_context = True
show_error_codes = True
show_column_numbers = True
show_error_end = True
warn_unused_ignores = True
check_untyped_defs = True
namespace_packages = True

[mypy-pytest]
ignore_missing_imports = True
enable_error_code = possibly-undefined
strict_equality = True

# not sure why mypy started discovering it (since 0.800??)
[mypy-hypothesis]
Expand Down
2 changes: 1 addition & 1 deletion ruff.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ignore = [
lint.ignore = [
### too opinionated style checks
"E501", # too long lines
"E702", # Multiple statements on one line (semicolon)
Expand Down
4 changes: 2 additions & 2 deletions src/promnesia/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,14 +327,14 @@ def add_index_args(parser: argparse.ArgumentParser, default_config_path: PathIsh
)

F = lambda prog: argparse.ArgumentDefaultsHelpFormatter(prog, width=120)
p = argparse.ArgumentParser(formatter_class=F) # type: ignore
p = argparse.ArgumentParser(formatter_class=F)
subp = p.add_subparsers(dest='mode', )
ep = subp.add_parser('index', help='Create/update the link database', formatter_class=F)
add_index_args(ep, default_config_path())
# TODO use some way to override or provide config only via cmdline?
ep.add_argument('--intermediate', required=False, help="Used for development, you don't need it")

sp = subp.add_parser('serve', help='Serve a link database', formatter_class=F) # type: ignore
sp = subp.add_parser('serve', help='Serve a link database', formatter_class=F)
server.setup_parser(sp)

ap = subp.add_parser('demo', help='Demo mode: index and serve a directory in single command', formatter_class=F)
Expand Down
8 changes: 4 additions & 4 deletions src/promnesia/cannon.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ def canonify(url: str) -> str:
qq = [(k, v) for i, k, v in sorted(iqq)]
# TODO still not sure what we should do..
# quote_plus replaces %20 with +, not sure if we want it...
query = urlencode(qq, quote_via=quote_via) # type: ignore[type-var]
query = urlencode(qq, quote_via=quote_via)

path = _quote_path(path)

Expand Down Expand Up @@ -683,7 +683,7 @@ def domains(it): # pragma: no cover
try:
nurl = canonify(url)
except CanonifyException as e:
print(f"ERROR while normalising! {nurl} {e}")
print(f"ERROR while normalising! {url} {e}")
c['ERROR'] += 1
continue
else:
Expand Down Expand Up @@ -718,7 +718,7 @@ def reg(url, pat):
try:
nurl = canonify(url)
except CanonifyException as e:
print(f"ERROR while normalising! {nurl} {e}")
print(f"ERROR while normalising! {url} {e}")
continue
udom = nurl[:nurl.find('/')]
usplit = udom.split('.')
Expand Down Expand Up @@ -818,7 +818,7 @@ def main() -> None: # pragma: no cover
- running comparison
sqlite3 promnesia.sqlite 'select distinct orig_url from visits where norm_url like "%twitter%" order by orig_url' | src/promnesia/cannon.py
''', formatter_class=lambda prog: argparse.RawTextHelpFormatter(prog, width=100) # type: ignore
''', formatter_class=lambda prog: argparse.RawTextHelpFormatter(prog, width=100)
)
p.add_argument('input', nargs='?')
p.add_argument('--human', action='store_true')
Expand Down
13 changes: 6 additions & 7 deletions src/promnesia/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def _get_index_function(sourceish: PreSource) -> PreExtractor:
if hasattr(sourceish, 'index'): # must be a module
res = getattr(sourceish, 'index')
else:
res = sourceish # type: ignore[assignment]
res = sourceish
return res


Expand Down Expand Up @@ -392,7 +392,7 @@ def appdirs():
under_test = os.environ.get('PYTEST_CURRENT_TEST') is not None
# todo actually use test name?
name = 'promnesia-test' if under_test else 'promnesia'
import appdirs as ad # type: ignore[import]
import appdirs as ad # type: ignore[import-untyped]
return ad.AppDirs(appname=name)


Expand Down Expand Up @@ -482,13 +482,13 @@ def fdfind_args(root: Path, follow: bool, ignore: List[str]=[]) -> List[str]:
ignore_args = []
if ignore:
# Add a statement that excludes the folder
ignore_args = [['--exclude', f'{n}'] for n in ignore]
_ignore_args = [['--exclude', f'{n}'] for n in ignore]
# Flatten the list of lists
ignore_args_l = list(itertools.chain(*ignore_args))
ignore_args = list(itertools.chain(*_ignore_args))

return [
*extra_fd_args(),
*ignore_args_l,
*ignore_args,
*(['--follow'] if follow else []),
'--type', 'f',
'.',
Expand Down Expand Up @@ -537,10 +537,9 @@ def traverse(root: Path, *, follow: bool=True, ignore: List[str]=[]) -> Iterable
def get_system_zone() -> str:
try:
import tzlocal
# note: tzlocal mypy stubs aren't aware of api change yet (see https://github.com/python/typeshed/issues/6038)
try:
# 4.0 way
return tzlocal.get_localzone_name() # type: ignore[attr-defined]
return tzlocal.get_localzone_name()
except AttributeError as e:
# 2.0 way
zone = tzlocal.get_localzone().zone # type: ignore[attr-defined]
Expand Down
2 changes: 1 addition & 1 deletion src/promnesia/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def compare_files(*files: Path, log=True) -> Iterator[Tuple[str, DbVisit]]:
engine, table = _get_stuff(PathWithMtime.make(f))

with engine.connect() as conn:
vis = [row_to_db_visit(row) for row in conn.execute(table.select())] # type: ignore[var-annotated]
vis = [row_to_db_visit(row) for row in conn.execute(table.select())]

if last is not None:
between = f'{last_dts}:{this_dts}'
Expand Down
4 changes: 2 additions & 2 deletions src/promnesia/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import importlib.util
import warnings

from .common import PathIsh, get_tmpdir, appdirs, default_output_dir, default_cache_dir, user_config_file
from .common import PathIsh, default_output_dir, default_cache_dir
from .common import Res, Source, DbVisit


Expand Down Expand Up @@ -129,7 +129,7 @@ def import_config(config_file: PathIsh) -> Config:
spec = importlib.util.spec_from_file_location(name, p); assert spec is not None
mod = importlib.util.module_from_spec(spec); assert mod is not None
loader = spec.loader; assert loader is not None
loader.exec_module(mod) # type: ignore[attr-defined]
loader.exec_module(mod)

d = {}
for f in Config._fields:
Expand Down
2 changes: 1 addition & 1 deletion src/promnesia/kjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_json_processor():
handled = []
class Proc(JsonProcessor):
def handle_dict(self, value: JDict, path):
if 'skipme' in self.kpath(path):
if 'skipme' in self.kpath(path): # type: ignore[comparison-overlap]
return JsonProcessor.SKIP

def handle_str(self, value: str, path):
Expand Down
6 changes: 3 additions & 3 deletions src/promnesia/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def mklevel(level: LevelIsh) -> Level:
def setup_logger(logger: logging.Logger, level: LevelIsh) -> None:
lvl = mklevel(level)
try:
import logzero # type: ignore[import]
import logzero # type: ignore[import-not-found]
formatter = logzero.LogFormatter(
fmt=FORMAT_COLOR,
datefmt=DATEFMT,
Expand All @@ -75,7 +75,7 @@ def setup_logger(logger: logging.Logger, level: LevelIsh) -> None:
logger.addFilter(AddExceptionTraceback())
if use_logzero and not COLLAPSE_DEBUG_LOGS: # all set, nothing to do
# 'simple' setup
logzero.setup_logger(logger.name, level=lvl, formatter=formatter)
logzero.setup_logger(logger.name, level=lvl, formatter=formatter) # type: ignore[possibly-undefined]
return

h = CollapseDebugHandler() if COLLAPSE_DEBUG_LOGS else logging.StreamHandler()
Expand All @@ -101,7 +101,7 @@ def isEnabledFor_lazyinit(*args, logger=logger, orig=logger.isEnabledFor, **kwar
# oh god.. otherwise might go into an inf loop
if not hasattr(logger, _init_done):
setattr(logger, _init_done, False) # will setup on the first call
logger.isEnabledFor = isEnabledFor_lazyinit # type: ignore[assignment]
logger.isEnabledFor = isEnabledFor_lazyinit # type: ignore[method-assign]
return cast(LazyLogger, logger)


Expand Down
2 changes: 1 addition & 1 deletion src/promnesia/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def get_testdata(path: str) -> Path:

@contextmanager
def tmp_popen(*args, **kwargs):
import psutil # type: ignore
import psutil
with psutil.Popen(*args, **kwargs) as p:
try:
yield p
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ passenv =
[testenv:ruff]
commands =
{envpython} -m pip install --use-pep517 -e .[testing]
{envpython} -m ruff src/
{envpython} -m ruff check src/


[testenv:tests]
Expand Down

0 comments on commit 35d675b

Please sign in to comment.