Skip to content
New issue

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

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

Already on GitHub? # to your account

Last fixes before release #102

Merged
merged 3 commits into from
Dec 29, 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
8 changes: 5 additions & 3 deletions .github/workflows/actions/install_dependencies/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ inputs:
python_version:
required: true
type: string
default: "3.9"
default: "3.12"
poetry_version:
required: true
type: string
default: "1.3.1"
default: "1.8.1"

runs:
using: composite
Expand All @@ -25,10 +25,12 @@ runs:
virtualenvs-create: true
virtualenvs-in-project: false
installer-parallel: true
plugins: |
poetry-plugin-export
- uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python_version }}
cache: "poetry"
- name: Install Dependencies
run: poetry --no-interaction --no-cache install --no-root --with nox --with dev
run: poetry --no-interaction --no-cache install --no-root --with dev
shell: bash
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
with:
python_version: |
${{ matrix.python }}
3.9
3.12
- uses: ./.github/workflows/actions/run_nox_session
with:
nox_session: ${{ matrix.session }}
Expand All @@ -81,7 +81,7 @@ jobs:
with:
python_version: |
${{ matrix.python }}
3.9
3.12
- uses: ./.github/workflows/actions/run_nox_session
with:
nox_session: ${{ matrix.session }}
Expand Down
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
default_stages: [ commit ]
default_stages: [ pre-commit ]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
Expand All @@ -15,23 +15,23 @@ repos:
entry: poetry run black
language: system
types: [ python ]
stages: [ commit ]
stages: [ pre-commit ]
- id: lint
name: Linter (pylint)
entry: poetry run pylint
language: system
types: [ python ]
stages: [ commit ]
stages: [ pre-commit ]
- id: isort
name: Ordering imports (isort)
entry: poetry run isort
language: system
types: [ python ]
stages: [ commit ]
stages: [ pre-commit ]
- id: test
name: Unit tests (pytest)
entry: poetry run pytest
pass_filenames: false
language: system
types: [ python ]
stages: [ push ]
stages: [ pre-push ]
1 change: 1 addition & 0 deletions examples/stqdm_stop_and_retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
See : https://github.com/Wirg/stqdm/issues/64#issuecomment-1367536561
"""

from time import sleep

import streamlit as st
Expand Down
1 change: 0 additions & 1 deletion examples/stqdm_with_caching_and_speed.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
From : https://discuss.streamlit.io/t/stqdm-a-tqdm-like-progress-bar-for-streamlit/10097/20?u=wirg
"""


from time import sleep
from typing import List

Expand Down
19 changes: 9 additions & 10 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ def fix_deps_issues(streamlit_version: str) -> List[str]:
Fix issues with streamlit and stqdm deps to ease ci
"""
install_fixes: List[str] = []
# Used to avoid a compatibility issue between streamlit and protobuf
# https://discuss.streamlit.io/t/streamlit-run-with-protobuf-error/25632/5
if is_version_below((1, 12), streamlit_version):
install_fixes += ["protobuf<3.20"]

# https://discuss.streamlit.io/t/modulenotfounderror-no-module-named-altair-vegalite-v4/42921/13
altair_lower_than_5 = "altair<5"
Expand Down Expand Up @@ -107,12 +103,15 @@ def install_deps(session: nox.Session, constraint_groups: List[str], dependencie


PYTHON_ST_TQDM_VERSIONS = (
with_python_versions(["3.8", "3.9"], "~=1.11.0", "~=4.50.0")
+ with_python_versions(["3.8", "3.9"], "~=1.11.0", "~=4.66.1")
+ with_python_versions(["3.8", "3.9", "3.10"], "~=1.12.0", "~=4.66.1")
+ with_python_versions(["3.9", "3.10"], "~=1.20.0", LATEST)
+ with_python_versions(["3.11"], "~=1.29.0", LATEST)
+ with_python_versions(["3.9", "3.10", "3.11"], LATEST, LATEST)
# python = ">=3.10,<4.0" # current 3.13.1
# tqdm = ">=4.61" # current 4.67.1
# streamlit = ">=1.29.0" # current # 1.41.1
with_python_versions(["3.10", "3.11"], "~=1.29.0", "~=4.61")
+ with_python_versions(["3.10", "3.11"], "~=1.29.0", "~=4.66.1")
+ with_python_versions(["3.10", "3.11", "3.12"], "~=1.29.0", "~=4.66.1")
+ with_python_versions(["3.10", "3.11"], "~=1.29.0", LATEST)
+ with_python_versions(["3.11"], "~=1.41.1", LATEST)
+ with_python_versions(["3.10", "3.11", "3.12"], LATEST, LATEST)
)


Expand Down
2,086 changes: 1,023 additions & 1,063 deletions poetry.lock

Large diffs are not rendered by default.

28 changes: 13 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,29 @@ classifiers = [
]

[tool.poetry.dependencies]
# Drop 3.9.7 https://github.com/streamlit/streamlit/issues/5140#issuecomment-1213574499
python = ">=3.8,<4.0.0,!=3.9.7"
tqdm = ">=4.50"
streamlit = ">=1.11"
python = ">=3.10,<4.0"
tqdm = ">=4.61"
streamlit = ">=1.29.0"

[tool.poetry.group.dev.dependencies]
pre-commit = "^3.3.3"
pytest = "^7.4.0"
pytest-cov = "^4.1.0"
black = "^23.7.0"
click = ">=8.1" # Force for black compatibility
isort = "^5.12.0"
pylint = "^2.17.5"
pre-commit = "^4.0.1"
pytest = "^8.3.4"
pytest-cov = "^6.0.0"
black = "^24.10.0"
isort = "^5.13.2"
pylint = "^3.3.3"
nox = "^2023.4.22"
nox-poetry = "^1.0.3"
freezegun = "^1.4.0"
mypy = "^1.8.0"
freezegun = "^1.5.1"
mypy = "^1.14.0"
types-tqdm = "^4.66.0.5"
# Requirement added for compatibility between dev deps & some dependencies
# during the nox testing: streamlit_version='~=1.29.0'
packaging = "<24"
packaging = ">=1.16,<24"

[tool.black]
line-length = 127
target-version = ['py37', 'py38', 'py39', 'py310', 'py311']
target-version = ['py310', 'py311']

[tool.isort]
py_version=39
Expand Down
58 changes: 58 additions & 0 deletions stqdm/configuration_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,89 @@


class ScopeManager(Generic[ScopeConfig], metaclass=ABCMeta): # pylint: disable=invalid-name,inconsistent-mro
"""A Manager for handling scoped configurations `ScopeConfig` with a stack to maintain context states.

This helps handling `scope` context manager and has a default configuration (specific level-0 scope).
This is a generic class made to handle `Mapping`s. Those will be tqdm + stqdm configurations parameters.

Attributes:
default_config (ScopeConfig): The default configuration. This is a specific scope (level-0 scope).
By default, it does not behave in the same way as other scope.
It's argument are kept unless overridden by the latest scope in the stack.
_scope_stack (List[ScopeConfig]): A list that tracks all active scope configurations.
"""

def __init__(self, default_config: ScopeConfig) -> None:
"""Initializes the ScopeManager with a default configuration.

Args:
default_config (ScopeConfig): The default configuration dictionary.

Raises:
TypeError: If the default_config is not an instance of Mapping.
"""
if not isinstance(default_config, Mapping):
raise TypeError("Default config is not an instance of Mapping.")
self.default_config: ScopeConfig = default_config
self._scope_stack: List[ScopeConfig] = []

def set_default_config(self, default_config: ScopeConfig) -> None:
"""Sets the default configuration of the ScopeManager.

Args:
default_config (ScopeConfig): The configuration to set as default.
"""
self.default_config = default_config

def get_default_config(self) -> ScopeConfig:
"""Retrieves the current default configuration.

Returns:
ScopeConfig: The default configuration.
"""
return self.default_config

@contextmanager
def scope(self, scope_config: ScopeConfig) -> Iterator[ScopeConfig]:
"""A context manager that temporarily adds a new configuration to the stack.

Args:
scope_config (ScopeConfig): The temporary configuration for the scope.

Yields:
ScopeConfig: The provided configuration.
"""
self._scope_stack.append(scope_config)
try:
yield scope_config
finally:
self._scope_stack.pop()

def get_current_scope_config(self) -> ScopeConfig:
"""Retrieves the configuration of the current scope.

Returns:
ScopeConfig: The active scope configuration if any, otherwise an empty dictionary.
"""
if self._scope_stack:
return self._scope_stack[-1]
return {}

def use_current_default_if_config_not_provided(self, config: ScopeConfig) -> ScopeConfig:
"""Merges the provided configuration with the defaults and the current scope configuration.

This is the logic that implements the default merge for configurations.
The new config is the latest provided values in order:
- default_config (less important)
- latest scope
- current_config (stqdm call params) (most important)
It ignores all the intermediary scopes.

Args:
config (ScopeConfig): The configuration to merge with defaults and current scope.

Returns:
ScopeConfig: The resulting configuration after merging.
"""
# This typing is probably wrong, but in our case, we will be using a TypedDict and it should be ok
return cast(ScopeConfig, {**self.get_default_config(), **self.get_current_scope_config(), **config})
Loading
Loading