Skip to content

Commit

Permalink
Automatically calculate template snakebids version
Browse files Browse the repository at this point in the history
- Based first on latest version from pypi, falling back to dependency
  version
  • Loading branch information
pvandyken committed Sep 25, 2023
1 parent 70f198c commit 58cd9bd
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 167 deletions.
171 changes: 31 additions & 140 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 14 additions & 14 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ authors = [
"Jason Kai <[email protected]>",
]
license = "MIT"
packages = [
{ include = "snakebids" }
]
packages = [{ include = "snakebids" }]
exclude = ["snakebids/tests/**"]

[tool.poetry-dynamic-versioning]
Expand All @@ -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]
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"]
Expand Down
29 changes: 29 additions & 0 deletions snakebids/jinja2_ext/snakebids_version.py
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
Loading

0 comments on commit 58cd9bd

Please sign in to comment.