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

Release 0.8.0 #25

Merged
merged 7 commits into from
Sep 17, 2023
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
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[Makefile]
indent_style = tab
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.8.0] - 2023-09-17

### Changed

- Move the tests to a dedicated folder outside of the source code. This will avoid polluting the exports.

### Fixed

- Better default value for the config option mapper (None instead of a default mapper function).

## [0.7.0] - 2023-09-14

### Changed
Expand Down
36 changes: 18 additions & 18 deletions docs/toolbox.config.config.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ config = Config({"foo": "bar", "value": 42})

---

<a href="../toolbox/config/config.py#L38"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../toolbox/config/config.py#L37"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>class</kbd> `Config`
Handles a configuration.
Expand Down Expand Up @@ -101,7 +101,7 @@ data = config.get_config()
config.set_config(data)
```

<a href="../toolbox/config/config.py#L96"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../toolbox/config/config.py#L95"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `__init__`

Expand Down Expand Up @@ -145,7 +145,7 @@ config = Config({"foo": "bar"},

---

<a href="../toolbox/config/config.py#L324"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../toolbox/config/config.py#L323"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `choices`

Expand Down Expand Up @@ -181,7 +181,7 @@ config.choices("bar") # ()

---

<a href="../toolbox/config/config.py#L300"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../toolbox/config/config.py#L299"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `describe`

Expand Down Expand Up @@ -217,7 +217,7 @@ config.describe("bar") # ""

---

<a href="../toolbox/config/config.py#L275"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../toolbox/config/config.py#L274"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `drop`

Expand Down Expand Up @@ -253,7 +253,7 @@ config.drop("bar") # False

---

<a href="../toolbox/config/config.py#L182"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../toolbox/config/config.py#L181"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `get`

Expand Down Expand Up @@ -295,7 +295,7 @@ config.get("bar", "foo") # "foo"

---

<a href="../toolbox/config/config.py#L432"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../toolbox/config/config.py#L431"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `get_config`

Expand Down Expand Up @@ -326,7 +326,7 @@ config.get_config() # {"foo": "bar"}

---

<a href="../toolbox/config/config.py#L349"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../toolbox/config/config.py#L348"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `get_option`

Expand Down Expand Up @@ -362,7 +362,7 @@ config.get_option("bar") # None

---

<a href="../toolbox/config/config.py#L413"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../toolbox/config/config.py#L412"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `get_options`

Expand Down Expand Up @@ -393,7 +393,7 @@ config.get_options() # [{"name": "foo", "value": "bar", "default": None, ...}]

---

<a href="../toolbox/config/config.py#L161"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../toolbox/config/config.py#L160"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `has`

Expand Down Expand Up @@ -429,7 +429,7 @@ config.has("bar") # False

---

<a href="../toolbox/config/config.py#L137"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../toolbox/config/config.py#L136"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `keys`

Expand Down Expand Up @@ -465,7 +465,7 @@ print(list(keys)) # ["foo"]

---

<a href="../toolbox/config/config.py#L248"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../toolbox/config/config.py#L247"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `reset`

Expand Down Expand Up @@ -503,7 +503,7 @@ config.reset("bar") # Create the option "bar" with the value None

---

<a href="../toolbox/config/config.py#L480"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../toolbox/config/config.py#L479"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `reset_config`

Expand Down Expand Up @@ -534,7 +534,7 @@ config.get_config() # {"foo": None}

---

<a href="../toolbox/config/config.py#L213"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../toolbox/config/config.py#L212"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `set`

Expand Down Expand Up @@ -581,7 +581,7 @@ config.set("bar", "bar") # Create the option "bar" with the value "bar"

---

<a href="../toolbox/config/config.py#L452"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../toolbox/config/config.py#L451"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `set_config`

Expand Down Expand Up @@ -622,7 +622,7 @@ config.set_config({"foo": "bar"})

---

<a href="../toolbox/config/config.py#L370"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../toolbox/config/config.py#L369"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `set_option`

Expand All @@ -632,7 +632,7 @@ set_option(
value: Any = None,
default: Any = None,
description: str = None,
mapper: Callable = <function passthrough at 0x101b45580>,
mapper: Callable = None,
choices: list = None
) → None
```
Expand All @@ -647,7 +647,7 @@ Adds a configuration option.
- <b>`value`</b> (Any, optional): The initial value of the option. Defaults to None.
- <b>`default`</b> (Any, optional): The value returned when there is no defined value. Defaults to None.
- <b>`description`</b> (str, optional): A description for the option. Defaults to "".
- <b>`mapper`</b> (ConfigOptionMapper, optional): A mapper function for casting the value. Defaults to passthrough.
- <b>`mapper`</b> (ConfigOptionMapper, optional): A mapper function for casting the value. Defaults to None.
- <b>`choices`</b> (Iterable, optional): A list of possible values.


Expand Down
22 changes: 11 additions & 11 deletions docs/toolbox.config.config_option.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ print(age.get()) # 20

---

<a href="../toolbox/config/config_option.py#L417"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../toolbox/config/config_option.py#L420"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `create_options`

Expand Down Expand Up @@ -125,7 +125,7 @@ __init__(
value: 'Any' = None,
default: 'Any' = None,
description: 'str' = '',
mapper: 'ValueMapper' = <function passthrough at 0x101b45580>,
mapper: 'ValueMapper' = None,
choices: 'Iterable' = None
) → None
```
Expand All @@ -142,7 +142,7 @@ The name is mandatory.
- <b>`value`</b> (Any, optional): The initial value of the option. Defaults to None.
- <b>`default`</b> (Any, optional): The value returned when there is no defined value. Defaults to None.
- <b>`description`</b> (str, optional): A description for the option. Defaults to "".
- <b>`mapper`</b> (ConfigOptionMapper, optional): A mapper function for casting the value. Defaults to passthrough.
- <b>`mapper`</b> (ConfigOptionMapper, optional): A mapper function for casting the value. Defaults to None.
- <b>`choices`</b> (Iterable, optional): A list of possible values. Defaults to None.


Expand Down Expand Up @@ -242,7 +242,7 @@ The current value of the option.

---

<a href="../toolbox/config/config_option.py#L378"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../toolbox/config/config_option.py#L381"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `cast`

Expand All @@ -266,7 +266,7 @@ Casts and format a value to what is expected by the config option.

---

<a href="../toolbox/config/config_option.py#L182"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../toolbox/config/config_option.py#L185"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `copy`

Expand Down Expand Up @@ -298,7 +298,7 @@ print(name is name2) # False

---

<a href="../toolbox/config/config_option.py#L233"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../toolbox/config/config_option.py#L236"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `get`

Expand Down Expand Up @@ -333,7 +333,7 @@ print(name.get()) # "John"

---

<a href="../toolbox/config/config_option.py#L209"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../toolbox/config/config_option.py#L212"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `get_dict`

Expand Down Expand Up @@ -362,7 +362,7 @@ print(name.get_dict()) # {"name": "foo", "value": "bar", "default": None, ...}

---

<a href="../toolbox/config/config_option.py#L300"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../toolbox/config/config_option.py#L303"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `reset`

Expand All @@ -380,7 +380,7 @@ Resets the option to its default value.

---

<a href="../toolbox/config/config_option.py#L256"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../toolbox/config/config_option.py#L259"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `set`

Expand Down Expand Up @@ -429,7 +429,7 @@ print(name.get()) # "bob"

---

<a href="../toolbox/config/config_option.py#L316"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../toolbox/config/config_option.py#L319"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `set_default`

Expand Down Expand Up @@ -476,7 +476,7 @@ print(name.get()) # ""

---

<a href="../toolbox/config/config_option.py#L358"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../toolbox/config/config_option.py#L361"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `set_description`

Expand Down
9 changes: 3 additions & 6 deletions pydoc.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#!/bin/sh
rm -rf docs
lazydocs \
--ignored-modules toolbox.config.test \
--ignored-modules toolbox.data.test \
--ignored-modules toolbox.files.test \
--ignored-modules toolbox.logging.test \
--ignored-modules toolbox.testing.test \
--ignored-modules tests \
--overview-file=README.md \
--validate .
--validate \
.
rm docs/.pages
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "py-toolbox"
version = "0.7.0"
version = "0.8.0"
authors = [{ name = "Jean-Sébastien CONAN", email = "jsconan@gmail.com" }]
description = "A set of utilities for Python projects"
readme = "README.md"
Expand Down
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Test packages."""
1 change: 1 addition & 0 deletions tests/config/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Test package for the toolbox.config namespace."""
File renamed without changes.
1 change: 1 addition & 0 deletions tests/data/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Test package for the toolbox.data namespace."""
File renamed without changes.
1 change: 1 addition & 0 deletions tests/files/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Test package for the toolbox.files namespace."""
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions tests/logging/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Test package for the toolbox.logging namespace."""
File renamed without changes.
1 change: 1 addition & 0 deletions tests/testing/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Test package for the toolbox.testing namespace."""
File renamed without changes.
5 changes: 2 additions & 3 deletions toolbox/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
from typing import Any, Callable, Iterator

from toolbox.config.config_option import ConfigOption, create_options
from toolbox.data import passthrough


class Config:
Expand Down Expand Up @@ -373,7 +372,7 @@ def set_option(
value: Any = None,
default: Any = None,
description: str = None,
mapper: Callable = passthrough,
mapper: Callable = None,
choices: list = None,
) -> None:
"""Adds a configuration option.
Expand All @@ -387,7 +386,7 @@ def set_option(
description (str, optional): A description for the option.
Defaults to "".
mapper (ConfigOptionMapper, optional): A mapper function for casting the value.
Defaults to passthrough.
Defaults to None.
choices (Iterable, optional): A list of possible values.

Examples:
Expand Down
7 changes: 5 additions & 2 deletions toolbox/config/config_option.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(
value: Any = None,
default: Any = None,
description: str = "",
mapper: ValueMapper = passthrough,
mapper: ValueMapper = None,
choices: Iterable = None,
) -> None:
"""Creates a named configuration option.
Expand All @@ -82,7 +82,7 @@ def __init__(
description (str, optional): A description for the option.
Defaults to "".
mapper (ConfigOptionMapper, optional): A mapper function for casting the value.
Defaults to passthrough.
Defaults to None.
choices (Iterable, optional): A list of possible values.
Defaults to None.

Expand All @@ -105,6 +105,9 @@ def __init__(
if not name:
raise ValueError("The name is mandatory for a config option.")

if mapper is None:
mapper = passthrough

if not callable(mapper):
raise ValueError("A valid mapper is needed for casting the option's value.")

Expand Down
Empty file removed toolbox/config/test/__init__.py
Empty file.
Empty file removed toolbox/data/test/__init__.py
Empty file.
Empty file removed toolbox/files/test/__init__.py
Empty file.
Empty file removed toolbox/logging/test/__init__.py
Empty file.
Empty file removed toolbox/testing/test/__init__.py
Empty file.