mirror of
https://github.com/ModOrganizer2/pystubs-generation.git
synced 2026-07-27 14:07:13 -07:00
Compare commits
11
Commits
v2.5.1a0
...
2.6.0.dev0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6fe9b1d569 | ||
|
|
dd80b67a0a | ||
|
|
8789b59f23 | ||
|
|
72c652daaa | ||
|
|
80a365f19a | ||
|
|
1b8d6840e2 | ||
|
|
d7c1ecd6f2 | ||
|
|
6a76dda9d7 | ||
|
|
0c807ad974 | ||
|
|
a3542ca1c4 | ||
|
|
d6760273a2 |
@@ -15,15 +15,16 @@ jobs:
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: 3.11
|
||||
python-version: 3.12
|
||||
- uses: abatilo/actions-poetry@v2
|
||||
- name: Install
|
||||
run: |
|
||||
poetry install
|
||||
run: poetry install
|
||||
- name: Install libgl1
|
||||
run: sudo apt install -y libgl1 libegl1 libglib2.0-0 libxkbcommon0 libdbus-1-3
|
||||
- name: Copy stubs
|
||||
run: cp stubs/2.5.0/mobase-stubs/__init__.pyi docs/mobase.py
|
||||
run: |
|
||||
mkdir -p docs/src
|
||||
cp -r stubs/2.5.2/mobase-stubs docs/src/mobase
|
||||
- name: Build
|
||||
run: poetry run sphinx-build -b html docs/source docs/build
|
||||
env:
|
||||
@@ -10,15 +10,11 @@ jobs:
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: 3.11
|
||||
python-version: 3.12
|
||||
- uses: abatilo/actions-poetry@v2
|
||||
- name: Install
|
||||
run: |
|
||||
poetry install
|
||||
- name: Lint
|
||||
run: |
|
||||
poetry run black src --check --diff
|
||||
poetry run isort -c src
|
||||
poetry run mypy src
|
||||
poetry run ruff src
|
||||
poetry run pyright src
|
||||
poetry run poe lint
|
||||
|
||||
@@ -22,7 +22,7 @@ jobs:
|
||||
replace-with: "$1"
|
||||
- uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: 3.11
|
||||
python-version: 3.12
|
||||
- uses: abatilo/actions-poetry@v2
|
||||
- name: Build
|
||||
run: |
|
||||
|
||||
@@ -109,7 +109,6 @@ import mobase
|
||||
import mobase.widgets
|
||||
```
|
||||
|
||||
|
||||
**Note:** Most classes in `mobase` cannot be instantiated, so this is mostly intended
|
||||
for MO2 developers.
|
||||
|
||||
|
||||
+191
-41
@@ -3,12 +3,11 @@
|
||||
version: 2
|
||||
|
||||
# version of the stubs - this is overridden when publishing
|
||||
__version__: "2.5.0"
|
||||
__version__: "2.5.2"
|
||||
|
||||
# This is the root of the mobase module and will contain everything
|
||||
# related to functions / classes, including their documentation.
|
||||
mobase:
|
||||
|
||||
getFileVersion:
|
||||
__doc__: Retrieve the file version of the given executable.
|
||||
args:
|
||||
@@ -114,6 +113,12 @@ mobase:
|
||||
DATE:
|
||||
LITERAL:
|
||||
|
||||
GameFeature:
|
||||
__doc__: |
|
||||
Base class for all game features, cannot be inherited, used only for typing
|
||||
purpose in Python.
|
||||
__abstract__: true
|
||||
|
||||
# TODO:
|
||||
BSAInvalidation:
|
||||
__doc__:
|
||||
@@ -296,7 +301,7 @@ mobase:
|
||||
hasSuffix.2:
|
||||
__doc__: Check if this entry has the given suffix.
|
||||
args:
|
||||
suffix: Suffix to check.
|
||||
suffix: Suffix to check.
|
||||
returns: True if this entry is a file and has the given suffix.
|
||||
|
||||
isDir:
|
||||
@@ -349,6 +354,138 @@ mobase:
|
||||
The last extension of this entry, or an empty string if the file has no extension
|
||||
or is directory.
|
||||
|
||||
IGameFeatures:
|
||||
__doc__: |
|
||||
Interface for the game features, accessible through IOrganizer.gameFeatures().
|
||||
|
||||
gameFeature:
|
||||
__doc__: Retrieve the given game feature, if one exists.
|
||||
abstract: false
|
||||
args:
|
||||
feature_type:
|
||||
__doc__: The class of feature to retrieve.
|
||||
type: Type[GameFeatureType]
|
||||
returns:
|
||||
__doc__: |
|
||||
The game feature corresponding to the given type, or `None` if the feature is
|
||||
not available.
|
||||
type: GameFeatureType
|
||||
|
||||
registerFeature.1:
|
||||
__doc__: |
|
||||
Register game feature for the specified game.
|
||||
|
||||
This method register a game feature to combine or replace with other features
|
||||
of the same kind. Some features are merged (e.g., ModDataContent,
|
||||
ModDataChecker), while other override previous features (e.g., SaveGameInfo).
|
||||
|
||||
For features that can be combined, the priority argument indicates the order of
|
||||
priority (e.g., the order of the checks for ModDataChecker). For other features,
|
||||
the feature with the highest priority will be used. The features provided by the
|
||||
game plugin itself always have lowest priority.
|
||||
|
||||
The feature is associated to the plugin that registers it, if the plugin is
|
||||
disabled, the feature will not be available.
|
||||
|
||||
This function will return True if the feature was registered, even if the
|
||||
feature is not used du to its low priority.
|
||||
|
||||
args:
|
||||
games: Names of the game to enable the feature for.
|
||||
feature: Game feature to register.
|
||||
priority: |
|
||||
Priority of the game feature. If the plugin registering the feature
|
||||
is a game plugin, this parameter is ignored.
|
||||
replace: |
|
||||
If True, remove features of the same kind registered by the current plugin,
|
||||
otherwise add the feature alongside existing ones.
|
||||
|
||||
returns: True if the game feature was properly registered, False otherwise.
|
||||
|
||||
registerFeature.2:
|
||||
__doc__: |
|
||||
Register game feature for the specified game.
|
||||
|
||||
This method register a game feature to combine or replace with other features
|
||||
of the same kind. Some features are merged (e.g., ModDataContent,
|
||||
ModDataChecker), while other override previous features (e.g., SaveGameInfo).
|
||||
|
||||
For features that can be combined, the priority argument indicates the order of
|
||||
priority (e.g., the order of the checks for ModDataChecker). For other features,
|
||||
the feature with the highest priority will be used. The features provided by the
|
||||
game plugin itself always have lowest priority.
|
||||
|
||||
The feature is associated to the plugin that registers it, if the plugin is
|
||||
disabled, the feature will not be available.
|
||||
|
||||
This function will return True if the feature was registered, even if the
|
||||
feature is not used du to its low priority.
|
||||
|
||||
args:
|
||||
game: Game to enable the feature for.
|
||||
feature: Game feature to register.
|
||||
priority: |
|
||||
Priority of the game feature. If the plugin registering the feature
|
||||
is a game plugin, this parameter is ignored.
|
||||
replace: |
|
||||
If True, remove features of the same kind registered by the current plugin,
|
||||
otherwise add the feature alongside existing ones.
|
||||
|
||||
returns: True if the game feature was properly registered, False otherwise.
|
||||
|
||||
registerFeature.3:
|
||||
__doc__: |
|
||||
Register game feature for all games.
|
||||
|
||||
This method register a game feature to combine or replace with other features
|
||||
of the same kind. Some features are merged (e.g., ModDataContent,
|
||||
ModDataChecker), while other override previous features (e.g., SaveGameInfo).
|
||||
|
||||
For features that can be combined, the priority argument indicates the order of
|
||||
priority (e.g., the order of the checks for ModDataChecker). For other features,
|
||||
the feature with the highest priority will be used. The features provided by the
|
||||
game plugin itself always have lowest priority.
|
||||
|
||||
The feature is associated to the plugin that registers it, if the plugin is
|
||||
disabled, the feature will not be available.
|
||||
|
||||
This function will return True if the feature was registered, even if the
|
||||
feature is not used du to its low priority.
|
||||
|
||||
args:
|
||||
feature: Game feature to register.
|
||||
priority: |
|
||||
Priority of the game feature. If the plugin registering the feature
|
||||
is a game plugin, this parameter is ignored.
|
||||
replace: |
|
||||
If True, remove features of the same kind registered by the current plugin,
|
||||
otherwise add the feature alongside existing ones.
|
||||
|
||||
returns: True if the game feature was properly registered, False otherwise.
|
||||
|
||||
unregisterFeature:
|
||||
__doc__: |
|
||||
Unregister the given game feature.
|
||||
|
||||
This function is safe to use even if the given feature was never registered.
|
||||
args:
|
||||
feature: Feature to unregister.
|
||||
returns: True if the feature was successfully unregistered, False otherwise.
|
||||
|
||||
unregisterFeatures:
|
||||
__doc__: |
|
||||
Unregister all features of the given type registered by the calling plugin.
|
||||
|
||||
This function is safe to use even if the plugin has no feature of the given type
|
||||
register.
|
||||
|
||||
args:
|
||||
feature_type:
|
||||
__doc__: The class of feature to unregister.
|
||||
type: Type[GameFeatureType]
|
||||
|
||||
returns: The number of unregistered features.
|
||||
|
||||
GamePlugins:
|
||||
__abstract__: true
|
||||
getLoadOrder:
|
||||
@@ -356,8 +493,8 @@ mobase:
|
||||
returns:
|
||||
lightPluginsAreSupported:
|
||||
returns: True if light plugins are supported, False otherwise.
|
||||
overridePluginsAreSupported:
|
||||
returns: True if override plugins are supported, False otherwise.
|
||||
mediumPluginsAreSupported:
|
||||
returns: True if medium plugins are supported, False otherwise.
|
||||
readPluginLists:
|
||||
__doc__:
|
||||
args:
|
||||
@@ -441,7 +578,6 @@ mobase:
|
||||
returns: The list of variants for this GuessedString.
|
||||
|
||||
IDownloadManager:
|
||||
|
||||
downloadPath:
|
||||
__doc__: Retrieve the (absolute) path of the specified download.
|
||||
args:
|
||||
@@ -599,7 +735,7 @@ mobase:
|
||||
given path.
|
||||
args:
|
||||
path: Path to the file to create.
|
||||
replace_if_exists: |
|
||||
replace_if_exists: |
|
||||
If True and an entry already exists at the given location, it will be replaced by
|
||||
a new entry. This will replace both files and directories.
|
||||
returns: A FileTreeEntry corresponding to the created file.
|
||||
@@ -862,7 +998,6 @@ mobase:
|
||||
returns: The result of the installation.
|
||||
|
||||
IModInterface:
|
||||
|
||||
absolutePath:
|
||||
returns: Absolute path to the mod to be used in file system operations.
|
||||
|
||||
@@ -1198,7 +1333,6 @@ mobase:
|
||||
returns: The state of the given mod.
|
||||
|
||||
IModRepositoryBridge:
|
||||
|
||||
__bases__:
|
||||
- PyQt6.QtCore.QObject
|
||||
|
||||
@@ -1476,6 +1610,9 @@ mobase:
|
||||
pattern: The glob pattern to use to filter files.
|
||||
returns: The list of matching files.
|
||||
|
||||
gameFeatures:
|
||||
returns: The interface to the game features.
|
||||
|
||||
getFileOrigins:
|
||||
__doc__: |
|
||||
Retrieve the file origins for the specified file.
|
||||
@@ -1995,6 +2132,10 @@ mobase:
|
||||
dataDirectory:
|
||||
returns: The path to the directory containing data (absolute path).
|
||||
|
||||
displayGameName:
|
||||
abstract: False
|
||||
returns: The name of the game to user for display, default to gameName().
|
||||
|
||||
documentsDirectory:
|
||||
returns: The directory of the documents folder where configuration files and such for this game reside.
|
||||
|
||||
@@ -2009,29 +2150,6 @@ mobase:
|
||||
abstract: false
|
||||
returns: A list of automatically discovered executables of the game itself and tools surrounding it.
|
||||
|
||||
feature:
|
||||
__doc__: Retrieve a specified game feature from this plugin.
|
||||
abstract: false
|
||||
args:
|
||||
feature_type:
|
||||
__doc__: The class of feature to retrieve.
|
||||
type: Type[GameFeatureType]
|
||||
returns:
|
||||
__doc__: |
|
||||
The game feature corresponding to the given type, or `None` if the feature is
|
||||
not implemented.
|
||||
type: GameFeatureType
|
||||
|
||||
featureList:
|
||||
__doc__: |
|
||||
Retrieve the list of game features implemented for this plugin.
|
||||
|
||||
Python plugin should not implement this method but `_featureList()`.
|
||||
abstract: false
|
||||
returns:
|
||||
__doc__: A mapping from feature type to actual game features.
|
||||
type: dict[Type[GameFeatureType], GameFeatureType]
|
||||
|
||||
gameDirectory:
|
||||
returns: The directory containing the game installation.
|
||||
|
||||
@@ -2039,7 +2157,7 @@ mobase:
|
||||
returns: The icon representing the game.
|
||||
|
||||
gameName:
|
||||
returns: The name of the game (as displayed to the user).
|
||||
returns: The name of the game (for internal usage).
|
||||
|
||||
gameNexusName:
|
||||
abstract: false
|
||||
@@ -2107,6 +2225,11 @@ mobase:
|
||||
directory: Directory to check.
|
||||
returns: True if the directory looks like a valid installation of this game, False otherwise.
|
||||
|
||||
lootGameName:
|
||||
abstract: False
|
||||
returns: |
|
||||
The game name to use when calling LOOT from MO2, default to gameShortName().
|
||||
|
||||
nexusGameID:
|
||||
__doc__: |
|
||||
Retrieve the Nexus game ID for this game.
|
||||
@@ -2352,7 +2475,6 @@ mobase:
|
||||
installation did not succeed.
|
||||
|
||||
IPluginList:
|
||||
|
||||
__doc__: Primary interface to the list of plugins.
|
||||
|
||||
isMaster:
|
||||
@@ -2388,9 +2510,18 @@ mobase:
|
||||
True if the given file has a .esm extension, False otherwise or if the
|
||||
file does not exist.
|
||||
|
||||
hasNoRecords:
|
||||
__doc__: |
|
||||
Determine if a plugin has no records.
|
||||
args:
|
||||
name: Filename of the plugin (without path but with file extension).
|
||||
returns: |
|
||||
True if the given file plugin contains no records, False if it does OR if the
|
||||
file does not exist.
|
||||
|
||||
isLightFlagged:
|
||||
__doc__: |
|
||||
Determine if a plugin is flagged as light
|
||||
Determine if a plugin is flagged as light.
|
||||
|
||||
In gamebryo games, a master file will usually have a .esl file extension but
|
||||
technically an esp can be flagged as light.
|
||||
@@ -2400,6 +2531,18 @@ mobase:
|
||||
True if the given plugin is a light plugin, False otherwise or if the
|
||||
file does not exist.
|
||||
|
||||
isMediumFlagged:
|
||||
__doc__: |
|
||||
Determine if a plugin is flagged as medium.
|
||||
|
||||
This plugin flag was added in Starfield and signifies plugin records that
|
||||
update existing records
|
||||
args:
|
||||
name: Filename of the plugin (without path but with file extension).
|
||||
returns: |
|
||||
True if the given plugin is a medium plugin, False otherwise or if the
|
||||
file does not exist.
|
||||
|
||||
hasLightExtension:
|
||||
__doc__: |
|
||||
Determine if a plugin has a .esl extension.
|
||||
@@ -2510,7 +2653,6 @@ mobase:
|
||||
returns: The state of the plugin.
|
||||
|
||||
IPluginModPage:
|
||||
|
||||
_parentWidget:
|
||||
abstract: false
|
||||
returns: The parent widget.
|
||||
@@ -2556,15 +2698,27 @@ mobase:
|
||||
by qt are implemented (including dds) but no audio files and no 3d mesh formats.
|
||||
|
||||
genFilePreview:
|
||||
__doc__: Generate a preview for the specified file.
|
||||
__doc__: Generate a preview widget for the specified file.
|
||||
args:
|
||||
filename: Path to the file to preview.
|
||||
max_size: Maximum size of the generated widget.
|
||||
returns: The widget showing a preview of the file.
|
||||
|
||||
genDataPreview:
|
||||
__doc__: Generate a preview widget from in-memory data.
|
||||
args:
|
||||
file_data: In-memory data to preview.
|
||||
filename: Name of the file the data comes from.
|
||||
max_size: Maximum size of the generated widget.
|
||||
returns: The widget showing a preview of the in-memory data.
|
||||
|
||||
supportedExtensions:
|
||||
returns: The list of file extensions that are supported by this preview plugin.
|
||||
|
||||
supportsArchives:
|
||||
__doc__: Check if this preview plugin supports preview from in-memory data.
|
||||
returns: True if the plugin supports preview from raw data, False otherwise.
|
||||
|
||||
IPluginRequirement:
|
||||
__doc__: Class representing requirements for plugins.
|
||||
|
||||
@@ -2647,7 +2801,6 @@ mobase:
|
||||
plugin: The name of the plugin that must be enabled.
|
||||
returns: The constructed requirement.
|
||||
|
||||
|
||||
IPluginTool:
|
||||
__doc__: |
|
||||
This is the simplest of plugin interfaces. Such plugins simply place an icon inside the tools sub-menu
|
||||
@@ -2775,7 +2928,6 @@ mobase:
|
||||
returns:
|
||||
|
||||
Mapping:
|
||||
|
||||
__init__.1:
|
||||
__doc__: Creates an empty Mapping.
|
||||
|
||||
@@ -3196,7 +3348,6 @@ mobase:
|
||||
returns: The version scheme in effect for this VersionInfo.
|
||||
|
||||
mobase.widgets:
|
||||
|
||||
TaskDialog:
|
||||
__doc__: Customizable choice dialog.
|
||||
|
||||
@@ -3285,7 +3436,6 @@ mobase.widgets:
|
||||
args:
|
||||
width: Width of the dialog.
|
||||
|
||||
|
||||
TaskDialogButton:
|
||||
__doc__: Special button to be used inside TaskDialog widgets.
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,4 +0,0 @@
|
||||
sphinx-rtd-theme
|
||||
sphinx-autodoc-typehints
|
||||
sphinx-automodapi
|
||||
PyQt6
|
||||
+5
-1
@@ -27,8 +27,9 @@ extensions = [
|
||||
"sphinx.ext.autodoc",
|
||||
"sphinx_autodoc_typehints",
|
||||
"sphinx.ext.napoleon",
|
||||
"autoapi.extension",
|
||||
# "sphinx.ext.autosummary",
|
||||
"sphinx_automodapi.automodapi",
|
||||
# "sphinx_automodapi.automodapi",
|
||||
]
|
||||
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
@@ -39,6 +40,9 @@ templates_path = ["_templates"]
|
||||
# This pattern also affects html_static_path and html_extra_path.
|
||||
exclude_patterns = []
|
||||
|
||||
autoapi_dirs = ["../src"]
|
||||
autoapi_member_order = "groupwise"
|
||||
|
||||
|
||||
# -- Options for HTML output -------------------------------------------------
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ This documentation is dedicated to writting MO2 **Python** plugins.
|
||||
plugin-types
|
||||
writing-plugins
|
||||
faq
|
||||
mobase
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
``mobase`` API
|
||||
==============
|
||||
|
||||
.. currentmodule:: mobase
|
||||
|
||||
.. automodapi:: mobase
|
||||
:no-inheritance-diagram:
|
||||
:no-heading:
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 4
|
||||
@@ -1,7 +0,0 @@
|
||||
mobase
|
||||
======
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 4
|
||||
|
||||
mobase
|
||||
@@ -64,10 +64,8 @@ These plugins (shall eventually) implement all the game specific features and fu
|
||||
able to add support for further games.
|
||||
The plugin is also responsible to help MO determine if (and where) the game is installed in the first place.
|
||||
Since supporting a game properly requires extensions in many places of the UI.
|
||||
To allow this without creating one huge plugin interface that involves every aspect of MO, game plugins
|
||||
expose a *feature list*.
|
||||
The list of possible features can be found in the "game_features" project and each feature can itself be
|
||||
considered a plugin interface.
|
||||
To allow this without creating one huge plugin interface that involves every aspect of MO,
|
||||
game plugins can register only the features they need to MO2 using :meth:`registerFeature<mobase.IGameFeatures.registerFeature>`
|
||||
|
||||
As an example for a game feature take BSA invalidation: If the game requires BSA invalidation it will implement
|
||||
this feature.
|
||||
@@ -147,4 +145,4 @@ File Mappings
|
||||
|
||||
This interface allows plugins to add virtual file (or directory) links to the virtual file system in addition to the
|
||||
mod files.
|
||||
Profile-local save games, ini-files and load-orders are all implemented this way in MO2.
|
||||
Profile-local save games, ini-files and load-orders are all implemented this way in MO2.
|
||||
|
||||
Generated
+818
File diff suppressed because it is too large
Load Diff
+25
-32
@@ -11,51 +11,44 @@ packages = [{ include = "mo2", from = "src" }]
|
||||
mo2-stubs-generator = "mo2.stubs.generator.__main__:main"
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.11"
|
||||
pyqt6 = "^6.5.2"
|
||||
python = "^3.12"
|
||||
pyqt6 = "6.7.1"
|
||||
pyyaml = "^6.0.1"
|
||||
|
||||
typing-extensions = "^4.12.2"
|
||||
|
||||
[tool.poetry.group.dev.dependencies]
|
||||
black = "^23.9.1"
|
||||
mypy = "^1.5.1"
|
||||
pyright = "^1.1.327"
|
||||
isort = "^5.12.0"
|
||||
ruff = "^0.0.290"
|
||||
flake8 = "^6.1.0"
|
||||
flake8-black = "^0.3.6"
|
||||
flake8-pyproject = "^1.2.3"
|
||||
types-pyyaml = "^6.0.12.11"
|
||||
|
||||
pyright = "^1.1.374"
|
||||
ruff = "^0.5.5"
|
||||
types-pyyaml = "^6.0.12.20240724"
|
||||
poethepoet = "^0.27.0"
|
||||
|
||||
[tool.poetry.group.doc.dependencies]
|
||||
sphinx-rtd-theme = "^1.3.0"
|
||||
sphinx-autodoc-typehints = "^1.24.0"
|
||||
sphinx-automodapi = "^0.16.0"
|
||||
sphinx = "^7.2.6"
|
||||
sphinx-rtd-theme = "^2.0.0"
|
||||
sphinx-autodoc-typehints = "^2.2.3"
|
||||
sphinx-automodapi = "^0.17.0"
|
||||
sphinx = "<8"
|
||||
sphinx-autoapi = "^3.2.1"
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
|
||||
[tool.flake8]
|
||||
max-line-length = 88
|
||||
extend-ignore = ["E203"]
|
||||
|
||||
[tool.isort]
|
||||
profile = "black"
|
||||
multi_line_output = 3
|
||||
[tool.poe.tasks]
|
||||
format-imports = "ruff check --select I src --fix"
|
||||
format-ruff = "ruff format src"
|
||||
format.sequence = ["format-imports", "format-ruff"]
|
||||
lint-ruff = "ruff check src"
|
||||
lint-ruff-format = "ruff format --check src"
|
||||
lint-pyright = "pyright src"
|
||||
lint.sequence = ["lint-ruff", "lint-ruff-format", "lint-pyright"]
|
||||
lint.ignore_fail = "return_non_zero"
|
||||
|
||||
[tool.ruff]
|
||||
line-length = 88
|
||||
target-version = "py311"
|
||||
target-version = "py310"
|
||||
|
||||
[tool.mypy]
|
||||
warn_return_any = true
|
||||
warn_unused_configs = true
|
||||
namespace_packages = true
|
||||
[tool.ruff.lint]
|
||||
extend-select = ["B", "Q", "I"]
|
||||
|
||||
[tool.pyright]
|
||||
# reportMissingTypeStubs = true
|
||||
# reportUntypedBaseClass = false
|
||||
typeCheckingMode = "strict"
|
||||
reportMissingTypeStubs = true
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
import argparse
|
||||
import inspect
|
||||
import logging
|
||||
import subprocess
|
||||
import types
|
||||
from collections.abc import Sequence
|
||||
from pathlib import Path
|
||||
from typing import Callable
|
||||
|
||||
import black
|
||||
import isort
|
||||
|
||||
from .loader import load_mobase
|
||||
from .mtypes import Class, PyTyping
|
||||
from .mtypes import Class, Constant, Enum, Function, PyTyping
|
||||
from .parser import is_enum
|
||||
from .register import MobaseRegister
|
||||
from .utils import Settings, clean_class
|
||||
@@ -18,7 +17,9 @@ from .writer import Writer, is_list_of_functions
|
||||
LOGGER = logging.getLogger(__package__)
|
||||
|
||||
|
||||
def extract_objects(module: object, skips: list[str] = []) -> list[tuple[str, type]]:
|
||||
def extract_objects(
|
||||
module: object, skips: Sequence[str] = []
|
||||
) -> list[tuple[str, type]]:
|
||||
objects: list[tuple[str, type]] = []
|
||||
|
||||
assert hasattr(module, "__name__")
|
||||
@@ -56,12 +57,9 @@ def add_mobase_header(writer: Writer):
|
||||
"Callable",
|
||||
"Dict",
|
||||
"Iterator",
|
||||
"List",
|
||||
"Optional",
|
||||
"overload",
|
||||
"Sequence",
|
||||
"Set",
|
||||
"Tuple",
|
||||
"Type",
|
||||
"TypeVar",
|
||||
"Union",
|
||||
@@ -148,9 +146,12 @@ def main() -> None:
|
||||
[
|
||||
# the "real" IPlugin is IPluginBase
|
||||
"IPlugin",
|
||||
|
||||
# this is deprecated
|
||||
"PluginSetting"
|
||||
],
|
||||
),
|
||||
"mobase.widgets": extract_objects(getattr(mobase, "widgets")),
|
||||
"mobase.widgets": extract_objects(mobase.widgets), # type: ignore
|
||||
}
|
||||
|
||||
for name, objects in module_objects.items():
|
||||
@@ -173,6 +174,10 @@ def main() -> None:
|
||||
# Create the corresponding object:
|
||||
c = register.make_object(n, o)
|
||||
|
||||
|
||||
for n, o in objects:
|
||||
c = register.get_object(n)
|
||||
|
||||
if isinstance(c, Class):
|
||||
# Clean the class (e.g., remove duplicates methods due to wrappers):
|
||||
clean_class(c)
|
||||
@@ -180,7 +185,7 @@ def main() -> None:
|
||||
# Path the class using the configuration:
|
||||
settings.patch_class(c)
|
||||
|
||||
elif isinstance(c, PyTyping):
|
||||
elif isinstance(c, (PyTyping, Constant)):
|
||||
...
|
||||
|
||||
elif is_list_of_functions(c):
|
||||
@@ -200,6 +205,21 @@ def main() -> None:
|
||||
# create directory if required
|
||||
output_folder.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# sort the stubs
|
||||
def _key_fn(o: Class | Constant | list[Function] | PyTyping) -> tuple[int, ...]:
|
||||
# order is PyTyping -> Constant -> Function -> Enum -> Top-Level Class -> Child Level Classes
|
||||
return (
|
||||
not isinstance(o, PyTyping),
|
||||
not isinstance(o, Constant),
|
||||
not isinstance(o, list),
|
||||
not isinstance(o, Enum),
|
||||
isinstance(o, Class) and len(o.all_bases),
|
||||
)
|
||||
|
||||
stub_objects = sorted(
|
||||
(register.get_object(n) for n, _o in objects), key=_key_fn
|
||||
)
|
||||
|
||||
# write everything
|
||||
with open(output_folder.joinpath("__init__.pyi"), "w") as output:
|
||||
writer = Writer(package=name, output=output, settings=settings)
|
||||
@@ -210,19 +230,28 @@ def main() -> None:
|
||||
|
||||
module_headers[name](writer)
|
||||
|
||||
for n, o in objects:
|
||||
# Get the corresponding object:
|
||||
c = register.get_object(n)
|
||||
|
||||
for c in stub_objects:
|
||||
writer.print_object(c)
|
||||
|
||||
black.format_file_in_place(
|
||||
output_folder.joinpath("__init__.pyi"),
|
||||
fast=False,
|
||||
mode=black.Mode(is_pyi=True),
|
||||
write_back=black.WriteBack.YES,
|
||||
subprocess.run(
|
||||
[
|
||||
"ruff",
|
||||
"format",
|
||||
"--silent",
|
||||
output_folder.joinpath("__init__.pyi").as_posix(),
|
||||
]
|
||||
)
|
||||
subprocess.run(
|
||||
[
|
||||
"ruff",
|
||||
"check",
|
||||
"--silent",
|
||||
"--select",
|
||||
"I",
|
||||
"--fix",
|
||||
output_folder.joinpath("__init__.pyi").as_posix(),
|
||||
]
|
||||
)
|
||||
isort.api.sort_file(output_folder.joinpath("__init__.pyi"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -33,7 +33,7 @@ def load_mobase(path: os.PathLike[Any]) -> Module:
|
||||
os.add_dll_directory(str(path.joinpath("dlls"))) # type: ignore
|
||||
|
||||
# We need to add plugins/data to sys.path, mainly for PyQt6
|
||||
sys.path.insert(1, path.joinpath("plugins", "plugin_python", "libs").as_posix())
|
||||
sys.path.insert(1, path.joinpath("proxies", "python", "libs").as_posix())
|
||||
|
||||
import mobase # type: ignore
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from collections.abc import Sequence
|
||||
from typing import Final, TypeVar
|
||||
|
||||
|
||||
@@ -164,7 +165,6 @@ class Argument:
|
||||
|
||||
|
||||
class Exception:
|
||||
|
||||
"""
|
||||
Small class representing exception that can be raised from functions.
|
||||
"""
|
||||
@@ -313,20 +313,20 @@ class Class:
|
||||
self,
|
||||
package: str,
|
||||
name: str,
|
||||
bases: list[Class],
|
||||
methods: list[Method],
|
||||
constants: list[Constant] = [],
|
||||
properties: list[Property] = [],
|
||||
inner_classes: list[Class] = [],
|
||||
bases: Sequence[Class],
|
||||
methods: Sequence[Method],
|
||||
constants: Sequence[Constant] = [],
|
||||
properties: Sequence[Property] = [],
|
||||
inner_classes: Sequence[Class] = [],
|
||||
doc: str = "",
|
||||
):
|
||||
self.package = package
|
||||
self.name = name
|
||||
self.bases = bases
|
||||
self.methods = methods
|
||||
self.properties = properties
|
||||
self.constants = constants
|
||||
self.inner_classes = inner_classes
|
||||
self.bases = list(bases)
|
||||
self.methods = list(methods)
|
||||
self.properties = list(properties)
|
||||
self.constants = list(constants)
|
||||
self.inner_classes = list(inner_classes)
|
||||
self.doc = ""
|
||||
self.abstract = False
|
||||
self.outer_class = None
|
||||
@@ -385,7 +385,6 @@ class Class:
|
||||
|
||||
|
||||
class PyClass(Class):
|
||||
|
||||
"""
|
||||
Class use to wrap Python class to be used as parent class for some classes
|
||||
in mobase.
|
||||
@@ -401,7 +400,6 @@ class PyClass(Class):
|
||||
|
||||
|
||||
class Enum(Class):
|
||||
|
||||
"""
|
||||
Class representing an enum.
|
||||
"""
|
||||
|
||||
@@ -134,7 +134,6 @@ def is_enum(e: type) -> bool:
|
||||
|
||||
|
||||
class Overload:
|
||||
|
||||
"""Small class to avoid mypy issues..."""
|
||||
|
||||
return_type: PyType
|
||||
@@ -176,8 +175,8 @@ def parse_pybind11_function_docstring(e: type) -> list[Overload]:
|
||||
|
||||
try:
|
||||
return_type, arguments = parse_python_signature(signature, e.__name__)
|
||||
except ValueError:
|
||||
raise ValueError(f"invalid signature: {e.__name__}, {e.__doc__}")
|
||||
except ValueError as err:
|
||||
raise ValueError(f"invalid signature: {e.__name__}, {e.__doc__}") from err
|
||||
overloads.append(Overload(return_type=return_type, arguments=arguments))
|
||||
|
||||
return overloads
|
||||
@@ -221,7 +220,8 @@ def make_class(e: type, register: MobaseRegister) -> Class:
|
||||
|
||||
# This contains ALL the parent classes, not the direct ones:
|
||||
base_classes: list[Class] = [
|
||||
register.make_object(name) for name in base_classes_s # type: ignore
|
||||
register.make_object(name)
|
||||
for name in base_classes_s # type: ignore
|
||||
]
|
||||
|
||||
# retrieve all the attributes that are not in a base class
|
||||
@@ -234,6 +234,8 @@ def make_class(e: type, register: MobaseRegister) -> Class:
|
||||
# members to exclude
|
||||
EXCLUDED_MEMBERS = [
|
||||
"__init_subclass__",
|
||||
"__dict__",
|
||||
"__doc__",
|
||||
"__module__",
|
||||
"__subclasshook__",
|
||||
"__hash__",
|
||||
@@ -346,7 +348,7 @@ def make_class(e: type, register: MobaseRegister) -> Class:
|
||||
|
||||
direct_bases: list[Class] = []
|
||||
for c in e.__bases__:
|
||||
if c.__module__ != "pybind11_builtins":
|
||||
if c.__module__ not in ("pybind11_builtins", "builtins"):
|
||||
b = register.get_object(c.__name__)
|
||||
assert isinstance(b, Class)
|
||||
direct_bases.append(b)
|
||||
|
||||
@@ -4,7 +4,7 @@ from __future__ import annotations
|
||||
|
||||
from collections import OrderedDict
|
||||
|
||||
from .mtypes import Class, Function, PyTyping
|
||||
from .mtypes import Class, Constant, Function, PyType, PyTyping
|
||||
|
||||
|
||||
class MobaseRegister:
|
||||
@@ -12,7 +12,7 @@ class MobaseRegister:
|
||||
Class that register classes.
|
||||
"""
|
||||
|
||||
objects: dict[str, Class | list[Function] | PyTyping]
|
||||
objects: dict[str, Class | Constant | list[Function] | PyTyping]
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.raw_objects: dict[str, type] = OrderedDict()
|
||||
@@ -23,9 +23,9 @@ class MobaseRegister:
|
||||
|
||||
def make_object(
|
||||
self, name: str, e: type | None = None
|
||||
) -> Class | list[Function] | PyTyping:
|
||||
) -> Class | list[Function] | Constant | PyTyping:
|
||||
"""
|
||||
Construct a Function, Class or Enum for the given object.
|
||||
Construct a Function, Class, Constant or Enum for the given object.
|
||||
|
||||
Args:
|
||||
name: The name of the object to inspect.
|
||||
@@ -47,14 +47,14 @@ class MobaseRegister:
|
||||
self.objects[name] = make_class(e, self)
|
||||
elif callable(e):
|
||||
self.objects[name] = make_functions(e)
|
||||
|
||||
# typing stuff
|
||||
elif type(e).__module__ == "types" or type(e).__module__ == "typing":
|
||||
self.objects[name] = PyTyping(name, e)
|
||||
else:
|
||||
self.objects[name] = Constant(name, type=PyType(type(e)), value=e)
|
||||
|
||||
return self.objects[name]
|
||||
|
||||
def get_object(self, name: str) -> Class | list[Function] | PyTyping:
|
||||
def get_object(self, name: str) -> Class | Constant | list[Function] | PyTyping:
|
||||
"""
|
||||
Retrieve the object if the given name. Fails if no object with this
|
||||
name exists (if `make_object(name, ...)` has never been called).
|
||||
|
||||
@@ -220,7 +220,9 @@ class Settings:
|
||||
f"mobase.{setting_name}."
|
||||
)
|
||||
|
||||
for setting_arg, method_arg in zip(function_settings.args, fn.args):
|
||||
for setting_arg, method_arg in zip(
|
||||
function_settings.args, fn.args, strict=True
|
||||
):
|
||||
method_arg.doc = setting_arg.doc
|
||||
if not setting_arg.type.is_none():
|
||||
method_arg.type = setting_arg.type
|
||||
@@ -371,7 +373,7 @@ class Settings:
|
||||
)
|
||||
|
||||
for settings_arg, method_arg in zip(
|
||||
function_settings.args, method_arguments
|
||||
function_settings.args, method_arguments, strict=True
|
||||
):
|
||||
method_arg.doc = settings_arg.doc
|
||||
if (
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user