Skip to content

Commit 9d7de28

Browse files
authored
Merge pull request #14 from matsjoyce/regenerate-cache-on-version-change
Regenerate cache on version change
2 parents 840c21d + 6cac1c4 commit 9d7de28

File tree

7 files changed

+30
-4
lines changed

7 files changed

+30
-4
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ jobs:
4545
python -m pip install --upgrade pip
4646
echo "PySide6==${{ matrix.pyside6_version }}" > constraint.txt
4747
pip install -r requirements.txt -c constraint.txt
48+
hatch build --hooks-only
4849
- name: Check formatting with black
4950
run: |
5051
black --check .

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ Generate QML stub files (.qmltypes) from Python modules (which use PySide6)
5454

5555
Usage:
5656
pyside6-qml-stubgen <in-dir>... --out-dir=<out-dir> [--ignore=<path>...] [--metatypes-dir=<dir>] [--qmltyperegistrar-path=<path>] [--force-rebuild] [--file-relative-path=<div>] [--extra-external-modules=<modules>]
57+
pyside6-qml-stubgen (-h | --help)
58+
pyside6-qml-stubgen --version
5759

5860
Options:
5961
--ignore=<path> Ignore all Python files that are children of this path
@@ -63,4 +65,6 @@ Options:
6365
--file-relative-path=<div> Make all paths in generated type files relative to this path
6466
(useful for if the generated stubs need to be used on different systems)
6567
--extra-external-modules=<modules> Additional modules which should be assumed to contain QML exposed types (comma separated)
68+
-h --help Show this screen
69+
--version Show version
6670
```

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ build-backend = "hatchling.build"
3838
[tool.hatch.version]
3939
source = "vcs"
4040

41+
[tool.hatch.build.hooks.vcs]
42+
version-file = "pyside6_qml_stubgen/_version.py"
43+
4144
[tool.mypy]
4245
python_version = "3.10"
4346
warn_unused_configs = true
@@ -50,3 +53,6 @@ warn_unused_ignores = true
5053
warn_unreachable = true
5154
strict_equality = true
5255
local_partial_types = true
56+
57+
[tool.black]
58+
extend-exclude = "_version.py"

pyside6_qml_stubgen/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from PySide6 import QtCore
1414

1515
from . import dirty_file_detection, pyside_patching, qmlregistrar_types
16+
from ._version import __version__, __version_tuple__
1617

1718

1819
def parse_module(
@@ -267,7 +268,10 @@ def import_dirty_modules(
267268
)
268269

269270
dirty_file_detection.save_modules_metadata(
270-
out_dir, dirty_file_detection.PythonModulesMetadata(module_metadata)
271+
out_dir,
272+
dirty_file_detection.PythonModulesMetadata(
273+
module_metadata, generating_version=__version__
274+
),
271275
)
272276

273277
extra_info.resolve_delayed()

pyside6_qml_stubgen/__main__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
44
Usage:
55
pyside6-qml-stubgen <in-dir>... --out-dir=<out-dir> [--ignore=<path>...] [--metatypes-dir=<dir>] [--qmltyperegistrar-path=<path>] [--force-rebuild] [--file-relative-path=<div>] [--extra-external-modules=<modules>]
6+
pyside6-qml-stubgen (-h | --help)
7+
pyside6-qml-stubgen --version
68
79
Options:
810
--ignore=<path> Ignore all Python files that are children of this path
@@ -12,17 +14,19 @@
1214
--file-relative-path=<div> Make all paths in generated type files relative to this path
1315
(useful for if the generated stubs need to be used on different systems)
1416
--extra-external-modules=<modules> Additional modules which should be assumed to contain QML exposed types (comma separated)
17+
-h --help Show this screen
18+
--version Show version
1519
"""
1620

1721
import pathlib
1822

1923
import docopt
2024

21-
from . import process
25+
from . import _version, process
2226

2327

2428
def main() -> None:
25-
args = docopt.docopt(__doc__)
29+
args = docopt.docopt(__doc__, version=_version.__version__)
2630
process(
2731
in_dirs=[pathlib.Path(p) for p in args["<in-dir>"]],
2832
ignore_dirs=[pathlib.Path(ig) for ig in args["--ignore"]],

pyside6_qml_stubgen/dirty_file_detection.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import pydantic
77

8+
from . import _version
9+
810

911
@dataclasses.dataclass
1012
class PythonModuleMetadata:
@@ -16,16 +18,19 @@ class PythonModuleMetadata:
1618
@dataclasses.dataclass
1719
class PythonModulesMetadata:
1820
modules: typing.Mapping[str, PythonModuleMetadata | None]
21+
generating_version: str = ""
1922

2023

2124
PYTHON_MODULES_METADATA_TYPE_ADAPTER = pydantic.TypeAdapter(PythonModulesMetadata)
2225

2326

2427
def load_modules_metadata(dir_path: pathlib.Path) -> PythonModulesMetadata:
2528
if (dir_path / "metadata.json").exists():
26-
return PYTHON_MODULES_METADATA_TYPE_ADAPTER.validate_json(
29+
metadata = PYTHON_MODULES_METADATA_TYPE_ADAPTER.validate_json(
2730
(dir_path / "metadata.json").read_bytes()
2831
)
32+
if metadata.generating_version == _version.__version__:
33+
return metadata
2934
return PythonModulesMetadata({})
3035

3136

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ PySide6
2222
PySide6_Addons
2323
PySide6_Essentials
2424
shiboken6
25+
hatch
26+
hatch-vcs

0 commit comments

Comments
 (0)