Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkgs/sage-project-cookiecutter #37541

Draft
wants to merge 14 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkgs/sage-project-cookiecutter/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include VERSION.txt
109 changes: 109 additions & 0 deletions pkgs/sage-project-cookiecutter/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
=========================================================================================
Sage: Open Source Mathematics Software: Script for maintaining a SageMath-based project
=========================================================================================

About SageMath
--------------

"Creating a Viable Open Source Alternative to
Magma, Maple, Mathematica, and MATLAB"

Copyright (C) 2005-2024 The Sage Development Team

https://www.sagemath.org

SageMath fully supports all major Linux distributions, recent versions of macOS, and Windows (using Windows Subsystem for Linux).

The traditional and recommended way to install SageMath is from source via Sage-the-distribution (https://www.sagemath.org/download-source.html). Sage-the-distribution first builds a large number of open source packages from source (unless it finds suitable versions installed in the system) and then installs the Sage Library (sagelib, implemented in Python and Cython).


About this pip-installable source distribution
----------------------------------------------

Creating a user project
~~~~~~~~~~~~~~~~~~~~~~~

::

$ sage-project-cookiecutter create PROJECT-DIRECTORY

This creates configuration files:

- ``environment*.yml`` for local use with conda-forge in Linux, macOS
- ``.devcontainer/downstream-*/`` for use in dev container on Linux, macOS, Windows

It can also be invoked as follows::

$ pipx run cruft create https://github.com/mkoeppe/sage --checkout sagemath-environment-cookiecutter \
--directory="pkgs/sage-project-cookiecutter/sage_project_cookiecutter/user-project-template"

TODO: Update URL, remove --checkout ... before merging.

See https://cruft.github.io/cruft/ for available options.


Creating a pip-installable downstream package
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

::

$ sage-project-cookiecutter create --downstream-package PROJECT-DIRECTORY

Additionally creates:

- ``.github/workflows/``

It can also be invoked as follows::

$ pipx run cruft create https://github.com/mkoeppe/sage --checkout sagemath-environment-cookiecutter \
--directory="pkgs/sage-project-cookiecutter/sage_project_cookiecutter/downstream-package-template"


Adding Sage CI portability/integration testing infrastructure to an upstream project
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

::

$ sage-project-cookiecutter create --upstream-package PROJECT-DIRECTORY

Creates in the existing ``PROJECT-DIRECTORY``:

- ``.github/workflows/ci-sage.yml``
- ``.devcontainer/portability-*``
- ``.devcontainer/tox-docker-in-docker``

It can also be invoked as follows::

[alice@localhost PROJECT-DIRECTORY]$ (cd .. && pipx run cruft create \
https://github.com/mkoeppe/sage \
--checkout sagemath-environment-cookiecutter \
--directory="pkgs/sage-project-cookiecutter/sage_project_cookiecutter/upstream-package-template" \
--overwrite-if-exists)
[1/1] Name of the project (directory name to create) (my-sage-project): PROJECT-DIRECTORY


Creating a pip-installable upstream package of the SageMath organization
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

::

$ sage-project-cookiecutter create --sagemath-upstream-package PROJECT-DIRECTORY

Additionally creates:

- ``CODE_OF_CONDUCT.md``
- ``CONTRIBUTING.md``

It can also be invoked as follows::

$ pipx run cruft create https://github.com/mkoeppe/sage --checkout sagemath-environment-cookiecutter \
--directory="pkgs/sage-project-cookiecutter/sage_project_cookiecutter/sagemath-upstream-package-template"


Updating a project
~~~~~~~~~~~~~~~~~~

::

[alice@localhost PROJECT-DIRECTORY]$ pipx run cruft update \
--checkout sagemath-environment-cookiecutter
1 change: 1 addition & 0 deletions pkgs/sage-project-cookiecutter/VERSION.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10.3.rc2
48 changes: 48 additions & 0 deletions pkgs/sage-project-cookiecutter/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[build-system]
requires = ["setuptools>=61.2"]
build-backend = "setuptools.build_meta"

[project]
name = "sage-project-cookiecutter"
description = "Sage: Open Source Mathematics Software: Script for maintaining a SageMath-based project"
license = {text = "GNU General Public License (GPL) v2 or later"}
authors = [{name = "The Sage Developers", email = "sage-support@googlegroups.com"}]
classifiers = [
"Development Status :: 6 - Mature",
"Intended Audience :: Education",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)",
"Operating System :: POSIX",
"Operating System :: MacOS :: MacOS X",
"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",
"Topic :: Scientific/Engineering :: Mathematics",
]
urls = {Homepage = "https://www.sagemath.org"}
dependencies = [
"cookiecutter",
"cruft",
]
dynamic = ["version"]

[project.readme]
file = "README.rst"
content-type = "text/x-rst"

[tool.setuptools]
packages = [
"sage_project",
]
include-package-data = false

[tools.setuptools.package-data]
"sage_project_cookiecutter" = [
"template*/**"
]

[tool.setuptools.dynamic]
version = {file = ["VERSION.txt"]}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"package_directory": "my-package-directory",
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"project_name": "my-sage-project",
"__prompts__": {
"project_name": "Name of the project (directory name to create)"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: Run Sage CI

## This GitHub Actions workflow provides:
##
## - portability testing, by building and testing this project on many platforms
## (Linux variants, macOS)
##
## - continuous integration, by building and testing other software
## that depends on this project.
##
## It runs on every pull request and push of a tag to the GitHub repository.
##
## The testing can be monitored in the "Actions" tab of the GitHub repository.
##
## After all jobs have finished (or are canceled) and a short delay,
## tar files of all logs are made available as "build artifacts".
##
## This GitHub Actions workflow uses the portability testing framework
## of SageMath (https://www.sagemath.org/). For more information, see
## https://doc.sagemath.org/html/en/developer/portability_testing.html

## The workflow consists of two jobs:
##
## - First, it builds a source distribution of the project
## and generates a script "update-pkgs.sh". It uploads them
## as a build artifact named upstream.
##
## - Second, it checks out a copy of the SageMath source tree.
## It downloads the upstream artifact and replaces the project's
## package in the SageMath distribution by the newly packaged one
## from the upstream artifact, by running the script "update-pkgs.sh".
## Then it builds a small portion of the Sage distribution.
##
## Many copies of the second step are run in parallel for each of the tested
## systems/configurations.

on:
pull_request:
push:
tags:
- '*'
workflow_dispatch:
# Allow to run manually

concurrency:
group: {{"${{"}} github.workflow {{"}}"}}-{{"${{"}} github.head_ref || github.run_id {{"}}"}}
cancel-in-progress: true

env:
# Ubuntu packages to install so that the project's "make dist" can succeed
DIST_PREREQ: python3-pip
# Name of this project in the Sage distribution
SPKG: {{cookiecutter.project_name}}
REMOVE_PATCHES: "*"

jobs:

dist:
runs-on: ubuntu-latest
steps:
- name: Check out {{"${{"}} env.SPKG {{"}}"}}
uses: actions/checkout@v3
with:
path: build/pkgs/{{"${{"}} env.SPKG {{"}}"}}/src
- name: Install prerequisites
run: |
sudo DEBIAN_FRONTEND=noninteractive apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get install $DIST_PREREQ
python3 -m pip install --user build
- name: Run make dist, prepare upstream artifact
run: |
(cd build/pkgs/{{"${{"}} env.SPKG {{"}}"}}/src && python3 -m build --sdist) \
&& mkdir -p upstream && cp build/pkgs/{{"${{"}} env.SPKG {{"}}"}}/src/dist/*.tar.gz upstream/{{"${{"}} env.SPKG {{"}}"}}-git.tar.gz \
&& echo "sage-package create {{"${{"}} env.SPKG {{"}}"}} --version git --tarball {{"${{"}} env.SPKG {{"}}"}}-git.tar.gz --type=optional" > upstream/update-pkgs.sh \
&& if [ -n "{{"${{"}} env.REMOVE_PATCHES {{"}}"}}" ]; then echo "(cd ../build/pkgs/{{"${{"}} env.SPKG {{"}}"}}/patches && rm -f {{"${{"}} env.REMOVE_PATCHES {{"}}"}}; :)" >> upstream/update-pkgs.sh; fi \
&& ls -l upstream/
- uses: actions/upload-artifact@v3
with:
path: upstream
name: upstream

linux:
uses: sagemath/sage/.github/workflows/docker.yml@develop
with:
# Sage distribution packages to build
targets: SAGE_CHECK=no SAGE_CHECK_PACKAGES={{cookiecutter.project_name}} {{cookiecutter.project_name}}
# Standard setting: Test the current beta release of Sage:
sage_repo: sagemath/sage
sage_ref: develop
upstream_artifact: upstream
# Docker targets (stages) to tag
docker_targets: "with-targets"
docker_push_repository: ghcr.io/{{"${{"}} github.repository {{"}}"}}/{{cookiecutter.project_name}}
needs: [dist]

macos:
uses: sagemath/sage/.github/workflows/macos.yml@develop
with:
# Sage distribution packages to build
targets: SAGE_CHECK=no SAGE_CHECK_PACKAGES={{cookiecutter.project_name}} {{cookiecutter.project_name}}
# Standard setting: Test the current beta release of Sage:
sage_repo: sagemath/sage
sage_ref: develop
upstream_artifact: upstream
needs: [dist]
Loading
Loading