-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade project, testing with nox, replace VisibleDeprecationWarning (#…
…106)
- Loading branch information
1 parent
362b73e
commit f7bb29b
Showing
17 changed files
with
247 additions
and
97 deletions.
There are no files selected for viewing
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,35 @@ | ||
name: Deploy | ||
|
||
on: | ||
workflow_dispatch: | ||
release: | ||
types: [published] | ||
pull_request: | ||
paths: | ||
- .github/workflows/deploy.yml | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
|
||
environment: | ||
name: pypi | ||
url: https://pypi.org/p/numba-stats | ||
permissions: | ||
id-token: write | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 # needed by setuptools_scm | ||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.12' | ||
|
||
- run: python -m pip install --upgrade pip build | ||
- run: python -m build | ||
- run: python -m pip install --prefer-binary $(echo dist/*.whl)'[test]' | ||
- run: python -m pytest | ||
|
||
- uses: pypa/gh-action-pypi-publish@release/v1 | ||
if: github.event_name == 'push' && contains(github.event.ref, '/tags/') |
This file was deleted.
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
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 |
---|---|---|
|
@@ -15,3 +15,4 @@ venv | |
*.egg-info | ||
.vscode | ||
bench/*.svg | ||
.nox |
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
This file was deleted.
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
This file was deleted.
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
""" | ||
Noxfile to orchestrate tests and computing coverage. | ||
Pass extra arguments to pytest after -- | ||
""" | ||
|
||
import nox | ||
import sys | ||
|
||
sys.path.append(".") | ||
import python_releases | ||
|
||
nox.needs_version = ">=2024.3.2" | ||
nox.options.default_venv_backend = "uv|virtualenv" | ||
|
||
ENV = { | ||
"COVERAGE_CORE": "sysmon", # faster coverage on Python 3.12 | ||
} | ||
|
||
PYPROJECT = nox.project.load_toml("pyproject.toml") | ||
MINIMUM_PYTHON = PYPROJECT["project"]["requires-python"].strip(">=") | ||
LATEST_PYTHON = str(python_releases.latest()) | ||
|
||
nox.options.sessions = ["test", "maxtest"] | ||
|
||
# running in parallel with pytest-xdist does not make the tests faster | ||
|
||
|
||
@nox.session(reuse_venv=True) | ||
def test(session: nox.Session) -> None: | ||
"""Run all tests.""" | ||
session.install("-e.[test]") | ||
session.run("pytest", *session.posargs) | ||
|
||
|
||
@nox.session(python=LATEST_PYTHON, reuse_venv=True) | ||
def maxtest(session: nox.Session) -> None: | ||
"""Run the unit and regular tests.""" | ||
session.install("-e.[test]") | ||
session.run("pytest", *session.posargs, env=ENV) | ||
|
||
|
||
# Python-3.12 provides coverage info faster | ||
@nox.session(python="3.12", reuse_venv=True) | ||
def cov(session: nox.Session) -> None: | ||
"""Run covage and place in 'htmlcov' directory.""" | ||
session.install("-e.[test]") | ||
session.run("coverage", "run", "-m", "pytest", env=ENV) | ||
session.run("coverage", "html", "-d", "htmlcov") | ||
session.run("coverage", "report", "-m") |
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 |
---|---|---|
|
@@ -2,8 +2,47 @@ | |
requires = ["setuptools>=42", "setuptools_scm[toml]>=3.4"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[project] | ||
name = "numba-stats" | ||
dynamic = ["version"] | ||
requires-python = ">=3.9" | ||
dependencies = ["numba>=0.53", "numpy>=1.20", "scipy>=1.5"] | ||
authors = [{ name = "Hans Dembinski", email = "[email protected]" }] | ||
readme = "README.md" | ||
description = "Numba-accelerated implementations of scipy probability distributions and others used in particle physics" | ||
license = { text = "MIT" } | ||
classifiers = [ | ||
# complete classifier list: http://pypi.python.org/pypi?%3Aaction=list_classifiers | ||
'Development Status :: 5 - Production/Stable', | ||
'Intended Audience :: Science/Research', | ||
"License :: OSI Approved :: MIT License", | ||
"Operating System :: OS Independent", | ||
"Programming Language :: Python :: 3", | ||
'Programming Language :: Python :: 3', | ||
'Programming Language :: Python :: 3 :: Only', | ||
'Programming Language :: Python :: 3.9', | ||
'Programming Language :: Python :: 3.10', | ||
'Programming Language :: Python :: 3.11', | ||
'Programming Language :: Python :: 3.12', | ||
'Programming Language :: Python :: Implementation :: CPython', | ||
] | ||
|
||
[project.urls] | ||
repository = "https://github.com/hdembinski/numba-stats" | ||
|
||
[project.optional-dependencies] | ||
test = [ | ||
"pytest>=6", | ||
"pytest-cov>=5", | ||
"pytest-benchmark>=4", | ||
"pydocstyle>=6", | ||
"coverage>=6", | ||
] | ||
|
||
[tool.setuptools.packages.find] | ||
where = ["src"] | ||
|
||
[tool.setuptools_scm] | ||
write_to = "src/numba_stats/_version.py" | ||
|
||
[tool.pytest.ini_options] | ||
minversion = "6.0" | ||
|
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,64 @@ | ||
"""Get the latest Python release which is online.""" | ||
|
||
import urllib.request | ||
import re | ||
from html.parser import HTMLParser | ||
import gzip | ||
from packaging.version import Version | ||
|
||
|
||
class PythonVersionParser(HTMLParser): | ||
"""Specialized HTMLParser to get Python version number.""" | ||
|
||
def __init__(self): | ||
"""Initialize parser state.""" | ||
super().__init__() | ||
self.versions = set() | ||
self.found_version = False | ||
|
||
def handle_starttag(self, tag, attrs): | ||
"""Look for the right tag and store result in an attribute.""" | ||
if tag == "a": | ||
for attr in attrs: | ||
if attr[0] == "href" and "/downloads/release/python-" in attr[1]: | ||
self.found_version = True | ||
return | ||
|
||
def handle_data(self, data): | ||
"""Extract Python version from entry.""" | ||
if self.found_version: | ||
self.found_version = False | ||
match = re.search(r"Python (\d+\.\d+)", data) | ||
if match: | ||
self.versions.add(Version(match.group(1))) | ||
|
||
|
||
def versions(): | ||
"""Get all Python release versions.""" | ||
req = urllib.request.Request("https://www.python.org/downloads/") | ||
req.add_header("Accept-Encoding", "gzip") | ||
|
||
with urllib.request.urlopen(req) as response: | ||
raw = response.read() | ||
if response.info().get("Content-Encoding") == "gzip": | ||
raw = gzip.decompress(raw) | ||
html = raw.decode("utf-8") | ||
|
||
parser = PythonVersionParser() | ||
parser.feed(html) | ||
|
||
return parser.versions | ||
|
||
|
||
def latest(): | ||
"""Return version of latest Python release.""" | ||
return max(versions()) | ||
|
||
|
||
def main(): | ||
"""Print all discovered release versions.""" | ||
print(" ".join(str(x) for x in sorted(versions()))) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.