-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically calculate template snakebids version
- Based first on latest version from pypi, falling back to dependency version
- Loading branch information
Showing
7 changed files
with
145 additions
and
167 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,9 +12,7 @@ authors = [ | |
"Jason Kai <[email protected]>", | ||
] | ||
license = "MIT" | ||
packages = [ | ||
{ include = "snakebids" } | ||
] | ||
packages = [{ include = "snakebids" }] | ||
exclude = ["snakebids/tests/**"] | ||
|
||
[tool.poetry-dynamic-versioning] | ||
|
@@ -26,12 +24,11 @@ bump = true | |
|
||
[tool.poetry-dynamic-versioning.substitution] | ||
files = [ | ||
'snakebids/project_template/cookiecutter.json', | ||
'snakebids/__init__.py' | ||
'snakebids/__init__.py', | ||
] | ||
patterns = [ | ||
"(^\\s+\"snakebids_version\":\\s*\")[^'\"]*(\")", | ||
"(^__version__\\s*(?::.*?)?=\\s*['\"])[^'\"]*(['\"])" | ||
"(^__version__\\s*(?::.*?)?=\\s*['\"])[^'\"]*(['\"])", | ||
] | ||
|
||
[tool.poetry.dependencies] | ||
|
@@ -42,7 +39,6 @@ snakemake = [ | |
{ version = ">=7.18.2", python = ">=3.11" }, | ||
] | ||
PyYAML = "^6" | ||
cookiecutter = "^2.1.1" | ||
typing-extensions = ">=3.10.0" | ||
attrs = ">=21.2.0,<24" | ||
boutiques = "^0.5.25" | ||
|
@@ -57,15 +53,18 @@ importlib-resources = ">=5.12.0,<7" | |
# on the python version being used. | ||
numpy = [ | ||
{ version = "<=1.24.4", python = "<3.9" }, | ||
{ version = ">=1.23.2", python = ">=3.11" } | ||
{ version = ">=1.23.2", python = ">=3.11" }, | ||
] | ||
# Use minimum of 1.10.0 because of security vulnerability | ||
scipy = [ | ||
{ version = ">=1.10.0,<=1.10.1", python = "<3.9" }, | ||
{ version = ">=1.10.0", python = ">=3.9" } | ||
{ version = ">=1.10.0", python = ">=3.9" }, | ||
] | ||
# minimum 8.2.0 to use post-copy mesages | ||
copier = ">=8.2.0" | ||
jinja2-time = ">=0.2.0" | ||
# minimum 2.31.0 because of security vulnerability | ||
requests = ">=2.31.0" | ||
|
||
[tool.poetry.group.dev.dependencies] | ||
black = "^23.1.0" | ||
|
@@ -88,6 +87,7 @@ ruff = "^0.0.285" | |
pytest-xdist = "^3.3.1" | ||
pytest-split = "^0.8.1" | ||
tomli = "^2.0.1" | ||
requests-mock = "^1.11.0" | ||
|
||
[tool.poetry.scripts] | ||
snakebids = "snakebids.admin:main" | ||
|
@@ -133,11 +133,11 @@ reportImportCycles = false | |
|
||
[tool.ruff] | ||
select = [ | ||
"E", # pycodestyle error | ||
"F", # pyflakes | ||
"PL", # pylint | ||
"RUF", # ruff | ||
"UP", #pyupgrade | ||
"E", # pycodestyle error | ||
"F", # pyflakes | ||
"PL", # pylint | ||
"RUF", # ruff | ||
"UP", #pyupgrade | ||
"T100", # debugger | ||
] | ||
ignore = ["PLR0913"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from __future__ import annotations | ||
|
||
import importlib.metadata as impm | ||
import re | ||
|
||
import jinja2.parser | ||
import requests | ||
from jinja2.ext import Extension | ||
|
||
|
||
class SnakebidsVersionExtension(Extension): | ||
def __init__(self, env: jinja2.Environment): | ||
env.globals["snakebids_version"] = self._lookup_version() # type: ignore | ||
super().__init__(env) | ||
|
||
def _lookup_version(self): | ||
request = requests.get("https://pypi.org/pypi/snakebids/json") | ||
version_regex = re.compile(r"\d+\.\d+\.\d+") | ||
try: | ||
request.raise_for_status() | ||
version = request.json()["info"]["version"] | ||
if not re.fullmatch(version_regex, version): | ||
raise TypeError() | ||
return version | ||
except (requests.HTTPError, KeyError, TypeError): | ||
version = impm.version("snakebids") | ||
if version == "0.0.0" or not re.fullmatch(version_regex, version): | ||
return None | ||
return version |
Oops, something went wrong.