core/ci: fix windows-specific issues

- use portable separators
- paths should be prepended with r' (so backwards slash isn't treated as escaping)
- sqlite connections should be closed (otherwise windows fails to remove the underlying db file)
- workaround for emojis via PYTHONUTF8=1 test for now
- make ZipPath portable
- properly use tox python environment everywhere

  this was causing issues on Windows
  e.g.
      WARNING: test command found but not installed in testenv
        cmd: C:\hostedtoolcache\windows\Python\3.9.12\x64\python3.EXE
This commit is contained in:
Dima Gerasimov 2022-05-02 18:26:22 +01:00 committed by karlicoss
parent 637982a5ba
commit 64a4782f0e
11 changed files with 67 additions and 37 deletions

View file

@ -16,6 +16,7 @@ NOT_HPI_MODULE_VAR = '__NOT_HPI_MODULE__'
###
import ast
import os
from typing import Optional, Sequence, List, NamedTuple, Iterable, cast, Any
from pathlib import Path
import re
@ -151,7 +152,7 @@ def _modules_under_root(my_root: Path) -> Iterable[HPIModule]:
mp = f.relative_to(my_root.parent)
if mp.name == '__init__.py':
mp = mp.parent
m = str(mp.with_suffix('')).replace('/', '.')
m = str(mp.with_suffix('')).replace(os.sep, '.')
if ignored(m):
continue
a: ast.Module = ast.parse(f.read_text())
@ -192,7 +193,7 @@ def test() -> None:
def test_demo() -> None:
demo = module_by_name('my.demo')
assert demo.doc is not None
assert str(demo.file) == 'my/demo.py'
assert demo.file == Path('my', 'demo.py')
assert demo.requires is None

View file

@ -203,7 +203,9 @@ class ZipPath(ZipPathBase):
def stat(self) -> os.stat_result:
# NOTE: zip datetimes have no notion of time zone, usually they just keep local time?
# see https://en.wikipedia.org/wiki/ZIP_(file_format)#Structure
dt = datetime(*self.root.getinfo(str(self.subpath)).date_time)
# note: seems that zip always uses forward slash, regardless OS?
zip_subpath = '/'.join(self.subpath.parts)
dt = datetime(*self.root.getinfo(zip_subpath).date_time)
ts = int(dt.timestamp())
params = dict(
st_mode=0,

View file

@ -48,4 +48,5 @@ def sqlite_copy_and_open(db: PathIsh) -> sqlite3.Connection:
with sqlite3.connect(str(tdir / dp.name)) as conn:
from .compat import sqlite_backup
sqlite_backup(source=conn, dest=dest)
conn.close()
return dest

View file

@ -229,9 +229,9 @@ def test_bad_modules(tmp_path: Path) -> None:
(par / 'malicious.py').write_text(f'''
from pathlib import Path
Path('{xx}').write_text('aaand your data is gone!')
Path(r'{xx}').write_text('aaand your data is gone!')
raise RuntimeError("FAIL ON IMPORT! naughy.")
raise RuntimeError("FAIL ON IMPORT! naughty.")
def stats():
return [1, 2, 3]