diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..64d0914 --- /dev/null +++ b/.gitignore @@ -0,0 +1,20 @@ +__pycache__/ +*.py[cod] +*.sage.pyc +*.sage.py +*.egg-info/ +.sage/ +.sage-cache/ +.pytest_cache/ +.mypy_cache/ +.coverage +htmlcov/ +dist/ +build/ +.venv/ +.venv-*/ +.env +.envrc +.DS_Store +.idea/ +.vscode/ diff --git a/LICENSE b/LICENSE index c7ffc1a..37425bf 100644 --- a/LICENSE +++ b/LICENSE @@ -1 +1,4 @@ -"THE BEER-WARE LICENSE" (Revision 42): wrote this file. As long as you retain this notice you can do whatever you want with this stuff. If we meet some day, and you think this stuff is worth it, you can buy me a beer in return Poul-Henning Kamp +"THE BEER-WARE LICENSE" (Revision 42): +Eloi Torrents wrote this project. As long as you retain this notice you can do whatever you want with this stuff. If we meet some day, and you think this stuff is worth it, you can buy me a beer in return. + +-- Eloi Torrents diff --git a/README.md b/README.md index 8d56294..77a729c 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,26 @@ -# SageMath_package_template +# SageMath Package Template +A lightweight template that shows how to structure a SageMath package and ship a couple of runnable demos. + +## Quick start +- Install the package in editable mode with `sage -pip install -e .` +- Run the elliptic curve demo: `sage -python elliptic_curve_demo.py` + +## Just shortcuts +- `just prepare` – create the Sage-aware virtualenv and install the package editable +- `just run` – execute the elliptic curve demo inside that virtualenv +- `just test` – run the unit tests with Sage's Python + +## Running tests +Use Sage's Python so Sage-specific imports resolve correctly when you run the bundled unittest suite: + +```bash +sage -python -m unittest discover -s tests -t . +``` + +## Project layout +- `demo_package/` – minimal package source code +- `elliptic_curve_demo.py` – Python entry point using SageMath +- `tests/` – example unittest-based tests + +Feel free to copy this template, rename the package, and extend the demos for your own SageMath projects. diff --git a/demo_package/__init__.py b/demo_package/__init__.py new file mode 100644 index 0000000..65642f0 --- /dev/null +++ b/demo_package/__init__.py @@ -0,0 +1,5 @@ +"""Demo package exposing helper utilities.""" + +from .utils import greet + +__all__ = ["greet"] diff --git a/demo_package/utils.py b/demo_package/utils.py new file mode 100644 index 0000000..19c7797 --- /dev/null +++ b/demo_package/utils.py @@ -0,0 +1,6 @@ +"""Utility functions for the demo package.""" + + +def greet(name: str) -> str: + """Return a friendly greeting for the provided name.""" + return f"Hello, {name}!" diff --git a/elliptic_curve_demo.py b/elliptic_curve_demo.py new file mode 100644 index 0000000..4aef343 --- /dev/null +++ b/elliptic_curve_demo.py @@ -0,0 +1,34 @@ +#!/usr/bin/env sage -python +from sage.all import EllipticCurve + +from demo_package import greet + + +def describe_curve() -> None: + """Construct an elliptic curve and print basic arithmetic information.""" + E = EllipticCurve([0, 0, 0, -1, 1]) # y^2 = x^3 - x + 1 + print(f"Elliptic curve E: {E}") + print(f"Discriminant: {E.discriminant()}") + print(f"j-invariant: {E.j_invariant()}") + + rank = E.rank() + print(f"Rank: {rank}") + + generators = E.gens() + if generators: + P = generators[0] + print(f"Generator: {P}") + for n in range(1, 6): + multiple = n * P + print(f"{n} * P = {multiple}") + else: + print("Curve has no generators over Q.") + + +def main() -> None: + print(greet("Sage enthusiast")) + describe_curve() + + +if __name__ == "__main__": + main() diff --git a/justfile b/justfile new file mode 100644 index 0000000..b81b107 --- /dev/null +++ b/justfile @@ -0,0 +1,18 @@ +SAGE_PY := "sage -python" + +# Create the Sage-aware virtual environment and install this package editable. +prepare: + if [ ! -d .venv ]; then {{SAGE_PY}} -m venv --system-site-packages .venv; fi + .venv/bin/pip install --no-build-isolation -e . + +# Upgrade pip inside the managed virtual environment. +update: prepare + .venv/bin/python -m pip install --upgrade pip + +# Run the elliptic curve demo using the virtual environment. +run: prepare + .venv/bin/python elliptic_curve_demo.py + +# Execute the unit test suite. +test: prepare + .venv/bin/python -m unittest discover -s tests -t . diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..b44fb6a --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,37 @@ +[build-system] +requires = ["setuptools>=64", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "demo-sage-package" +version = "0.1.0" +description = "Demo package used alongside SageMath elliptic-curve computations" +readme = "README.md" +requires-python = ">=3.10" +authors = [ + { name = "Eloi Torrents", email = "eloitor@duck.com" } +] +keywords = ["sagemath", "template", "mathematics"] +license = { file = "LICENSE" } +classifiers = [ + "Intended Audience :: Science/Research", + "License :: Other/Proprietary License", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Topic :: Scientific/Engineering :: Mathematics" +] + +[project.urls] +Documentation = "https://git.32bit.cafe/eloitor/SageMath_package_template" +Source = "https://git.32bit.cafe/eloitor/SageMath_package_template" +Issues = "https://git.32bit.cafe/eloitor/SageMath_package_template/issues" + +[tool.setuptools] +include-package-data = true + +[tool.setuptools.packages.find] +where = ["."] +include = ["demo_package*"] + diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_utils.py b/tests/test_utils.py new file mode 100644 index 0000000..9b99438 --- /dev/null +++ b/tests/test_utils.py @@ -0,0 +1,12 @@ +import unittest + +from demo_package import greet + + +class GreetTests(unittest.TestCase): + def test_returns_expected_greeting(self) -> None: + self.assertEqual(greet("Ada"), "Hello, Ada!") + + +if __name__ == "__main__": + unittest.main()