Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find_missing #3

Merged
merged 6 commits into from
Nov 12, 2024
Merged
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
23 changes: 23 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://pre-commit.com for more information.
# See https://pre-commit.com/hooks.html for more hooks.
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-added-large-files
- id: check-toml
- id: debug-statements
- id: check-yaml
args:
- --unsafe
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.7.3
hooks:
- id: ruff
args: ["--fix"]

ci:
autofix_commit_msg: 🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
autoupdate_commit_msg: ⬆ [pre-commit.ci] pre-commit autoupdate
8 changes: 4 additions & 4 deletions docs/helpers.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Helpers


Monkay comes with two helpers
Monkay comes with some helpers

- `load(path, allow_splits=":.")`: Load a path like Monkay. `allow_splits` allows to configure if attributes are seperated via . or :.
- `load(path, *, allow_splits=":.", package=None)`: Load a path like Monkay. `allow_splits` allows to configure if attributes are seperated via . or :.
When both are specified, both split ways are possible (Default).
- `load_any(module_path, potential_attrs, *, non_first_deprecated=False)`: Checks for a module if any attribute name matches. Return attribute value or raises ImportError when non matches.
- `load_any(module_path, potential_attrs, *, non_first_deprecated=False, package=None)`: Checks for a module if any attribute name matches. Return attribute value or raises ImportError when non matches.
When `non_first_deprecated` is `True`, a DeprecationMessage is issued for the non-first attribute which matches. This can be handy for deprecating module interfaces.

- `absolutify_import(import_path, package)`. Converts a relative import_path (absolute import pathes are returned unchanged) to an absolute import path.

Example:

Expand Down
14 changes: 14 additions & 0 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Release notes

## Version 0.0.4

### Added

- `find_missing` test method.
- `getter` attribute saving the injected getter.
- `absolutify_import` helper.
- Add pre-commit.

### Changed

- Rename typo `settings_preload_name` to `settings_preloads_name`.
- Fix relative imports.

## Version 0.0.3

### Added
Expand Down
6 changes: 6 additions & 0 deletions docs/specials.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Specials

## Overwriting the used package for relative imports

Provide the `package` parameter to Monkay. By default it is set to the `__spec__.parent` of the module.
For a toplevel module it is the same name like the module.
53 changes: 53 additions & 0 deletions docs/testing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Testing


## Temporary overwrites

For tests, but not limited to, Monkay provides three methods returning a contextmanager which provides threadsafe a temporary overwrite:

- `with_settings(settings)`
- `with_extensions(extensions_dict, *, apply_extensions=False)`
- `with_instance(instance, * apply_extensions=False,use_extensions_overwrite=True)`


## Check lazy imports

Monkay provides the debug method `find_missing(*, all_var=None, search_pathes=None, ignore_deprecated_import_errors=False, require_search_path_all_var=True)`.
It is quite expensive so it should be only called for debugging, testing and in error cases.
It returns a dictionary containing items which had issues, e.g. imports failed or not in `__all__` variable.

When providing `search_pathes` (module pathes as string), all exports are checked if they are in the value set of Monkey.

When providing `__all__` as `all_var`, it is checked for all imports.

Returned is a dictionary in the format:

- key: import name or import path
- value: set with errors

Errors:

- `all_var`: key is not in the provided `__all__` variable
- `import`: key had an ImportError
- `search_path_extra`: key (here a path) is not included in lazy imports.
- `search_path_import`: import of key (here the search path) failed
- `search_path_all_var`: module imported as search path had no `__all__`. This error can be disabled with `require_search_path_all_var=False`

### Ignore import errors when lazy import is deprecated

The parameter `ignore_deprecated_import_errors=True` silences errors happening when an lazy import which was marked as deprecated failed.

### Example

Using Monkay for tests is confortable and easy:

``` python

import edgy

def test_edgy_lazy_imports():
assert not edgy.monkay.find_missing(all_var=edgy.__all__, search_pathes=["edgy.core.files", "edgy.core.db.fields", "edgy.core.connection"])

```

That was the test. Now we know that no lazy import is broken.
4 changes: 3 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
site_name: Monkay
site_description: The ultimate preload, settings, lazy import manager..
site_url: https://devkral.github.io/monkay
site_url: https://dymmond.github.io/monkay

nav:
- Home: index.md
- Tutorial: tutorial.md
- Helpers: helpers.md
- Testing: testing.md
- Specials: specials.md
1 change: 1 addition & 0 deletions monkay/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
"ExtensionProtocol",
"load",
"load_any",
"absolutify_import",
]
Loading