Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions mesonbuild/mesondata.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import importlib.resources
from pathlib import PurePosixPath, Path
import sys
import typing as T

if T.TYPE_CHECKING:
Expand All @@ -24,13 +25,16 @@ def write_once(self, path: Path) -> None:
path.write_text(data, encoding='utf-8')

def write_to_private(self, env: 'Environment') -> Path:
try:
resource = importlib.resources.files('mesonbuild') / self.path
if isinstance(resource, Path):
return resource
except AttributeError:
# fall through to python 3.7 compatible code
pass
if sys.version_info >= (3, 10):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be fine with 3.9 too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error in the previous lint run was occurring for 3.7 and 3.8 only -- and it said "files() doesn't exist".

try:
# The issue that mypy/pyright see here is caused by a bug in typeshed:
# https://github.com/python/typeshed/pull/15108
resource = importlib.resources.files('mesonbuild') / self.path # type: ignore[operator]
if isinstance(resource, Path):
return resource
except AttributeError:
# fall through to python 3.7 compatible code
pass

out_file = Path(env.scratch_dir) / 'data' / self.path.name
out_file.parent.mkdir(exist_ok=True)
Expand Down
1 change: 1 addition & 0 deletions run_mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
'mesonbuild/interpreter/interpreterobjects.py',
'mesonbuild/interpreter/type_checking.py',
'mesonbuild/machinefile.py',
'mesonbuild/mesondata.py',
'mesonbuild/mcompile.py',
'mesonbuild/mdevenv.py',
'mesonbuild/mconf.py',
Expand Down
Loading