SyntaxError on `poe test` when using `streamlit`
Closed this issue · 2 comments
Error
The error occurs when running poe test
on a Python 3.12 project that imports streamlit
.
⬢ [Docker] ❯ poe test
Poe => coverage run
=========================================================================================================================================================================== test session starts ============================================================================================================================================================================
platform linux -- Python 3.12.3, pytest-8.1.1, pluggy-1.5.0 -- /opt/my-package-env/bin/python
cachedir: .pytest_cache
rootdir: /workspaces/my-package
configfile: pyproject.toml
testpaths: src, tests
plugins: typeguard-4.2.1, mock-3.14.0, xdist-3.5.0
collected 0 items / 1 error
run-last-failure: None
================================================================================================================================================================================== ERRORS ==================================================================================================================================================================================
__________________________________________________________________________________________________________________________________________________________________ ERROR collecting src/my_package/app.py __________________________________________________________________________________________________________________________________________________________________
/opt/my-package-env/lib/python3.12/site-packages/_pytest/python.py:520: in importtestmodule
mod = import_path(
/opt/my-package-env/lib/python3.12/site-packages/_pytest/pathlib.py:584: in import_path
importlib.import_module(module_name)
/usr/local/lib/python3.12/importlib/__init__.py:90: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1387: in _gcd_import
???
<frozen importlib._bootstrap>:1360: in _find_and_load
???
<frozen importlib._bootstrap>:1331: in _find_and_load_unlocked
???
<frozen importlib._bootstrap>:935: in _load_unlocked
???
/opt/my-package-env/lib/python3.12/site-packages/typeguard/_importhook.py:98: in exec_module
super().exec_module(module)
<frozen importlib._bootstrap_external>:995: in exec_module
???
<frozen importlib._bootstrap>:488: in _call_with_frames_removed
???
src/my_package/app.py:3: in <module>
import streamlit as st
/opt/my-package-env/lib/python3.12/site-packages/streamlit/__init__.py:69: in <module>
from streamlit.delta_generator import (
/opt/my-package-env/lib/python3.12/site-packages/streamlit/delta_generator.py:49: in <module>
from streamlit.elements.arrow import ArrowMixin
/opt/my-package-env/lib/python3.12/site-packages/streamlit/elements/arrow.py:22: in <module>
from streamlit.elements.lib.column_config_utils import (
/opt/my-package-env/lib/python3.12/site-packages/streamlit/elements/lib/column_config_utils.py:23: in <module>
from streamlit.elements.lib.column_types import ColumnConfig, ColumnType
E File "/opt/my-package-env/lib/python3.12/site-packages/streamlit/elements/lib/column_types.py", line 488
E """Configure a link column in ``st.dataframe`` or ``st.data_editor``.
E ^^^
E SyntaxError: invalid escape sequence '\.'
------------------------------------------------------------------------------------------------------------------------------------------------------ generated xml file: /workspaces/my-package/reports/pytest.xml -------------------------------------------------------------------------------------------------------------------------------------------------------
========================================================================================================================================================================= short test summary info ==========================================================================================================================================================================
ERROR src/my_package/app.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================================================================================================================================================= 1 error in 0.83s =============================================================================================================================================================================
Error: Sequence aborted after failed subtask 'test[0]'
Steps to reproduce
Tested inside WSL2 on Windows 11 version 23H2.
Delete all existing poetry-cookicutter
Docker containers and images.
Clone the repo to a local folder:
git clone git@github.com:radix-ai/poetry-cookiecutter.git
Open it with VSCode:
code .
Run VSCode command: Dev Containers: Rebuild Without Cache and Reopen in Container
.
The poetry-cookiecutter
dev container builds and opens.
Once completely initialized, open VSCode's bash terminal: Terminal: Create New Terminal
.
Scaffold a new Python 3.12 package project using cruft:
cruft create -f https://github.com/radix-ai/poetry-cookiecutter
Choose the following cookiecutter values. Here reported in the generated .cruft.json
:
{
"template": "https://github.com/radix-ai/poetry-cookiecutter",
"commit": "8ab7ee0accff3b9cb0e470bfc925858fc04d1e97",
"checkout": null,
"context": {
"cookiecutter": {
"project_type": "package",
"project_name": "My Package",
"project_description": "A Python package that reticulates splines.",
"project_url": "https://github.com/user/my-package",
"author_name": "John Smith",
"author_email": "john@example.com",
"python_version": "3.12",
"development_environment": "strict",
"with_conventional_commits": "1",
"with_fastapi_api": "0",
"with_typer_cli": "0",
"continuous_integration": "GitHub",
"private_package_repository_name": "",
"private_package_repository_url": "",
"__docker_image": "python:$PYTHON_VERSION-slim",
"__docstring_style": "NumPy",
"__project_name_kebab_case": "my-package",
"__project_name_snake_case": "my_package",
"_template": "https://github.com/radix-ai/poetry-cookiecutter"
}
},
"directory": null
}
Exit the dev container and close VSCode.
Copy the scaffolded project to another local folder:
cd ..
cp -r poetry-cookiecutter/my-package ./
Navigate to the scaffolded project folder and open it with VSCode:
cd my-package/
code .
Build the project's dev container: run VSCode command: Dev Containers: Rebuild Without Cache and Reopen in Container
.
Once completely initialized, open VSCode's bash terminal: Terminal: Create New Terminal
.
Add Streamlit as a dependency:
poetry add streamlit
Create a Python file that imports streamlit
:
In src/my_package/app.py
:
"""A Streamlit app."""
import streamlit as st
Init a git repo:
git init
Run code linting:
poe lint
Run tests:
poe test
Hi, @vanolucas, thanks for submitting this issue! It looks like it's a known issue on Streamlit side in combination with the strict configuration of pytest
which is enabled with development_environment=strict
.
I see that there's a fix merged already so I expect it to no longer be an issue in the next streamlit
release. As a temporary workaround, I'd recommend switching to the simple
development environment or remove the line filterwarnings = ["error", "ignore::DeprecationWarning"]
in the pyproject.toml
which causes pytest
to fail on warnings.