meson-python-sources-fixer 1.0__tar.gz → 1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: meson-python-sources-fixer
3
- Version: 1.0
3
+ Version: 1.1
4
4
  Summary: Linter to list all Python sources in meson.build
5
5
  Author-email: Omar Sandoval <osandov@osandov.com>
6
6
  License-Expression: MIT
@@ -27,7 +27,7 @@ To use it via [pre-commit](https://pre-commit.com/), add the following to your
27
27
  ```yaml
28
28
  repos:
29
29
  - repo: https://github.com/osandov/meson-python-sources-fixer
30
- rev: v1.0
30
+ rev: v1.1
31
31
  hooks:
32
32
  - id: meson-python-sources-fixer
33
33
  ```
@@ -11,7 +11,7 @@ To use it via [pre-commit](https://pre-commit.com/), add the following to your
11
11
  ```yaml
12
12
  repos:
13
13
  - repo: https://github.com/osandov/meson-python-sources-fixer
14
- rev: v1.0
14
+ rev: v1.1
15
15
  hooks:
16
16
  - id: meson-python-sources-fixer
17
17
  ```
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: meson-python-sources-fixer
3
- Version: 1.0
3
+ Version: 1.1
4
4
  Summary: Linter to list all Python sources in meson.build
5
5
  Author-email: Omar Sandoval <osandov@osandov.com>
6
6
  License-Expression: MIT
@@ -27,7 +27,7 @@ To use it via [pre-commit](https://pre-commit.com/), add the following to your
27
27
  ```yaml
28
28
  repos:
29
29
  - repo: https://github.com/osandov/meson-python-sources-fixer
30
- rev: v1.0
30
+ rev: v1.1
31
31
  hooks:
32
32
  - id: meson-python-sources-fixer
33
33
  ```
@@ -5,6 +5,7 @@
5
5
  import argparse
6
6
  import ast
7
7
  import difflib
8
+ import os
8
9
  from pathlib import Path
9
10
  import sys
10
11
  from typing import Dict, Iterable, Literal, Mapping, Optional, Set
@@ -35,7 +36,7 @@ def print_error(s: str, *, color: bool) -> None:
35
36
  if color:
36
37
  sys.stderr.write("\033[31merror:\033[m " + s + "\n")
37
38
  else:
38
- print(s, file=sys.stderr)
39
+ print("error:", s, file=sys.stderr)
39
40
 
40
41
 
41
42
  def print_diff(
@@ -79,8 +80,8 @@ def print_diff(
79
80
  sys.stdout.write(line)
80
81
 
81
82
 
82
- STRING_PATTERN = r"'(?:\\.|[^'])*'"
83
- COMMENT_PATTERN = r"[#].*"
83
+ STRING_PATTERN = r"'(?:\\.|[^'\\])*'"
84
+ COMMENT_PATTERN = r"[#].*+"
84
85
  NON_NEWLINE_WHITESPACE = r"[^\S\n]*"
85
86
  WHITESPACE_OR_COMMENT_CAPTURE = r"(?:\s|(?&comment))*"
86
87
  WHITESPACE_OR_COMMENT_EOL_CAPTURE = r"[^\S\n]*(?&comment)?$"
@@ -120,9 +121,6 @@ def find_py_installation(contents: str) -> Optional[str]:
120
121
  PY_INSTALLATION_PATTERN, contents, flags=regex.MULTILINE | regex.VERBOSE
121
122
  )
122
123
  return match.group(1) if match else None
123
- if not match:
124
- raise LookupError("import('python').find_installation() not found")
125
- return match.group(1)
126
124
 
127
125
 
128
126
  SUBDIR_PATTERN = rf"""
@@ -149,13 +147,14 @@ def find_subdirs(contents: str) -> Iterable[str]:
149
147
 
150
148
 
151
149
  def is_python_source(name: str) -> bool:
152
- return name.endswith(".py") or name.endswith(".pyi") or name == "py.typed"
150
+ return name.endswith((".py", ".pyi")) or os.path.basename(name) == "py.typed"
153
151
 
154
152
 
155
153
  def find_package_sources(source_path: Path, install_path: Path) -> Dict[str, Set[str]]:
156
154
  sources = {}
157
155
  if (source_path / "__init__.py").exists():
158
- for root, dirs, files in source_path.walk():
156
+ for root_str, dirs, files in os.walk(source_path):
157
+ root = Path(root_str)
159
158
  dirs[:] = [dir for dir in dirs if (root / dir / "__init__.py").exists()]
160
159
 
161
160
  relative = root.relative_to(source_path)
@@ -251,7 +250,7 @@ def fix_package_meson_build(
251
250
  contents,
252
251
  flags=regex.MULTILINE | regex.VERBOSE,
253
252
  ):
254
- if match.group("unrecognized"):
253
+ if match.group("unrecognized") is not None:
255
254
  raise CannotFixError(
256
255
  f"unrecognized {py_installation}.install_sources() syntax"
257
256
  )
@@ -266,7 +265,7 @@ def fix_package_meson_build(
266
265
  raise CannotFixError(
267
266
  f"unrecognized {py_installation}.install_sources() subdir syntax"
268
267
  )
269
- subdir = ast.literal_eval(subdir_arg)
268
+ subdir = str(Path(ast.literal_eval(subdir_arg)))
270
269
 
271
270
  if subdir in matches:
272
271
  raise CannotFixError(
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "meson-python-sources-fixer"
3
- version = "1.0"
3
+ version = "1.1"
4
4
  description = "Linter to list all Python sources in meson.build"
5
5
  readme = "README.md"
6
6
  license = "MIT"