Skip to content

Commit 087b20c

Browse files
authored
Do a safer/better job of parsing dependency versions (#66)
* Close #65: do a safer/better job of parsing dependency versions * Attempt to fix python 3.7 install error * Drop python 3.7, start running tests on python 3.11 * Start a CHANGELOG
1 parent e77db6c commit 087b20c

File tree

4 files changed

+38
-7
lines changed

4 files changed

+38
-7
lines changed

.github/workflows/pytest.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ubuntu-latest
1414
strategy:
1515
matrix:
16-
python-version: [3.7, 3.8, 3.9, "3.10"]
16+
python-version: [3.8, 3.9, "3.10", "3.11"]
1717
fail-fast: false
1818

1919
steps:

CHANGELOG.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Change Log for Shiny (for Python)
2+
3+
All notable changes to Shiny for Python will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [UNRELEASED]
9+
10+
### Bug fixes
11+
12+
* Closed #65: get shinywidgets working with ipywidgets 8.0.3.
13+
14+
## [0.1.2] - 2022-07-27
15+
16+
Initial release of shinywidgets

setup.cfg

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ classifiers =
1515
Intended Audience :: Developers
1616
License :: OSI Approved :: MIT License
1717
Natural Language :: English
18-
Programming Language :: Python :: 3.7
1918
Programming Language :: Python :: 3.8
2019
Programming Language :: Python :: 3.9
2120
Programming Language :: Python :: 3.10
@@ -25,7 +24,7 @@ project_urls =
2524
Source Code = https://github.com/rstudio/py-shinywidgets/
2625

2726
[options]
28-
python_requires = >=3.7
27+
python_requires = >=3.8
2928
packages = find:
3029
test_suite = tests
3130
include_package_data = True

shinywidgets/_dependencies.py

+20-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def libembed_dependency() -> List[HTMLDependency]:
4242
# stuff we need to render widgets outside of the notebook.
4343
HTMLDependency(
4444
name="ipywidget-libembed-amd",
45-
version=as_version(__html_manager_version__),
45+
version=parse_version_safely(__html_manager_version__),
4646
source={"package": "shinywidgets", "subdir": "static"},
4747
script={"src": "libembed-amd.js"},
4848
),
@@ -93,7 +93,7 @@ def require_dependency(w: Widget, session: Session) -> Optional[HTMLDependency]:
9393
)
9494
return None
9595

96-
version = as_version(getattr(w, "_model_module_version", "1.0"))
96+
version = parse_version_safely(getattr(w, "_model_module_version", "1.0"))
9797
source = HTMLDependencySource(subdir=module_dir)
9898

9999
dep = HTMLDependency(module_name, version, source=source)
@@ -156,5 +156,21 @@ def widget_pkg(w: object) -> str:
156156
return w.__module__.split(".")[0]
157157

158158

159-
def as_version(v: str) -> str:
160-
return re.sub("\\D*", "", str(packaging.version.parse(v)))
159+
def parse_version(v: str) -> str:
160+
# version could be in node-semver format
161+
# which is not compatible with packaging.version.parse
162+
# so we strip out the leading non-numeric characters
163+
# e.g., ^1.2.3 -> 1.2.3
164+
ver = re.sub("^\\D+", "", v)
165+
return str(packaging.version.parse(ver))
166+
167+
168+
# parsing can fail if the version is something like "*",
169+
# but it doesn't seem vital that we obtain the _actual_ version
170+
# since this only gets the version of the HTMLManager and module
171+
# dependencies, which should be unique within a given session
172+
def parse_version_safely(v: str) -> str:
173+
try:
174+
return parse_version(v)
175+
except Exception:
176+
return "0.0"

0 commit comments

Comments
 (0)