Skip to content

Commit

Permalink
Add binder.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
kwankyu committed Dec 2, 2023
1 parent b281350 commit cd97a1b
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 20 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/binder-dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Dockerfile for binder
# Reference: https://mybinder.readthedocs.io/en/latest/tutorials/dockerfile.html

# Pull the Sage docker image
FROM ghcr.io/sagemath/sage/sage-ubuntu-focal-standard-with-targets:dev

USER root

# These lines are here to remove warnings
ENV DEBIAN_FRONTEND noninteractive
ENV DEBCONF_NOWARNINGS="yes"

# Install jupyterlab to the system
RUN apt-get update
RUN apt-get install -y apt-utils
RUN apt-get install -y python3-pip
RUN python3 -m pip install --no-warn-script-location jupyterlab

# Disable annoying pupup for Jupyter news
RUN jupyter labextension disable "@jupyterlab/apputils-extension:announcements"

# Create user "alice" whose uid is 1000
ARG NB_USER=alice
ARG NB_UID=1000
ENV NB_USER alice
ENV NB_UID 1000
ENV HOME /home/${NB_USER}
RUN adduser --disabled-password --gecos "Default user" --uid ${NB_UID} ${NB_USER}

# Prepare for building Sage
ENV PR_REPO https://github.com/REPO_NAME
ENV PR_BRANCH BRANCH_NAME
ENV BINDER_BRANCH sagemath-environment
RUN apt-get install -y git

# Build Sage incrementally
WORKDIR /sage
RUN export PATH="/sage/build/bin:$PATH"
RUN git config --global user.email ${NB_USER}@wonderland
RUN git config --global user.name ${NB_USER}
RUN git config --global --add safe.directory $(pwd)
RUN pwd
COPY .gitignore /sage/.gitignore
RUN if [ ! -d .git ]; then git init && git add -A; fi
RUN git fetch ${PR_REPO} ${PR_BRANCH}
RUN git checkout -f -b ${BINDER_BRANCH} FETCH_HEAD
RUN ./bootstrap && ./configure --enable-build-as-root && make -j4

# Make sure the contents of the notebooks directory are in ${HOME}
COPY notebooks/* ${HOME}/
RUN chown -R ${NB_UID} ${HOME}

# Install jupyterlab to Sage
RUN /sage/sage -pip install --no-warn-script-location jupyterlab

# Install Sage package
# RUN /sage/sage -i <spkg-name>

# Switch to the user
USER ${NB_USER}

# This is where kernels are installed
RUN mkdir -p $(jupyter --data-dir)/kernels

# Install sagemath kernel
RUN ln -s /sage/venv/share/jupyter/kernels/sagemath $(jupyter --data-dir)/kernels

# Start in the home directory of the user
WORKDIR /home/${NB_USER}
46 changes: 46 additions & 0 deletions .github/workflows/binder.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Create Binder branch

# How to use this workflow
#
# (1) Go to your forked Sage repo
# (2) In the Actions tab, find "Create Binder branch" workflow
# (3) Run the workflow with your PR branch named say "contribution"
# (4) Wait for the workflow run to finish
# (5) In the Code tab, select the new "contribution-binder" branch
# (6) Find the Binder badge in README.md
# (7) Copy the Binder badge from README.md (in edit mode)
# (8) Paste the Binder badge into the description of your PR in the sagemath/sage repo
# (9) Click the Binder badge to start creating the Binder environment
# (10) Leave it open and come back after an hour.
# (11) The Binder badge is now ready for reviewers of your PR

on: workflow_dispatch

jobs:
create-branch:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Create binder branch
run: |
set -ex
REPO_NAME=${{ github.repository }}
BRANCH_NAME=${GITHUB_REF#refs/heads/}
BINDER_REPO_NAME=${REPO_NAME}
BINDER_BRANCH_NAME=${BRANCH_NAME}-binder
cp .github/workflows/binder-dockerfile Dockerfile
sed -i 's/REPO_NAME/'$(echo "${REPO_NAME}" | sed 's/\//\\\//g')'/' Dockerfile
sed -i 's/BRANCH_NAME/'$(echo "${BRANCH_NAME}" | sed 's/\//\\\//g')'/' Dockerfile
sed -i 's/sagemath\/sage-binder-env\/master/'$(echo "${BINDER_REPO_NAME}/${BINDER_BRANCH_NAME}" | sed 's/\//\\\//g')'/' README.md
if [ ! -d .git ]; then git init; fi
if [ ! -d notebooks ]; then mkdir notebooks && touch notebooks/my_favorite_notebooks.md; fi
git config --global user.email alice@wonderland
git config --global user.name Alice
git config --global --add safe.directory $(pwd)
git checkout -b $BINDER_BRANCH_NAME
git add -A
git commit -a -m "Binder environment for '${BRANCH_NAME}' branch"
git push -f origin $BINDER_BRANCH_NAME
47 changes: 27 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
<div>
<a href="https://sagemath.org">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="src/doc/common/static/logo_sagemath_white.svg">
<img src="src/doc/common/static/logo_sagemath_black.svg" height="60" align="left">
</picture>
</a>
<em>"Creating a Viable Open Source Alternative to
Magma, Maple, Mathematica, and MATLAB"</em>
</div>

# Sage: Open Source Mathematical Software
#

> "Creating a Viable Open Source Alternative to
> Magma, Maple, Mathematica, and MATLAB"
> Copyright (C) 2005-2023 The Sage Development Team
https://www.sagemath.org

[Sage Documentation](https://doc.sagemath.org/html/en/index.html)

The Sage Library is free software released under the
GNU General Public Licence GPLv2+, and included packages
have [compatible software licenses](./COPYING.txt).
[Over 800 people](https://www.sagemath.org/development-map.html)
have contributed code to Sage. In many cases, documentation
for modules and functions list the authors.
Sage is open source mathematical software released under the GNU General Public
Licence GPLv2+, and includes packages that have [compatible software licenses](./COPYING.txt).
[People all around the globe](https://www.sagemath.org/development-map.html) have contributed to the
development of Sage. [Full documentation](https://doc.sagemath.org/html/en/index.html) is available online.

Table of Contents
-----------------
Expand All @@ -44,6 +37,12 @@ Table of Contents
Getting Started
---------------

Those who are impatient may use the Binder badge

[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/sagemath/sage-binder-env/master)

for an instant computing environment with Sage. Otherwise read on.

The [Sage Installation Guide](https://doc.sagemath.org/html/en/installation/index.html)
provides a decision tree that guides you to the type of installation
that will work best for you. This includes building from source,
Expand Down Expand Up @@ -81,7 +80,7 @@ The preferred way to run Sage on Windows is using the [Windows Subsystem for
Linux](https://docs.microsoft.com/en-us/windows/wsl/faq), a.k.a. WSL, which allows
you to install a standard Linux distribution such as Ubuntu within
your Windows. Make sure you allocate WSL sufficient RAM; 5GB is known to work, while
2GB might be not enough for building Sage from source.
2GB might be not enough for building Sage from source.
Then all instructions for installation in Linux apply.

As an alternative, you can also run Linux on Windows using Docker ([see
Expand Down Expand Up @@ -428,18 +427,18 @@ in the Installation Guide.
or JupyterLab installation, as described in [section
"Launching SageMath"](https://doc.sagemath.org/html/en/installation/launching.html)
in the installation manual.

Alternative Installation using PyPI
---------------

For installation of `sage` in python using `pip` you need to install `sagemath-standard`. First, activate your python virtual environment and follow these steps:

$ python3 -m pip install sage_conf
$ ls $(sage-config SAGE_SPKG_WHEELS)
$ python3 -m pip install $(sage-config SAGE_SPKG_WHEELS)/*.whl
$ python3 -m pip install $(sage-config SAGE_SPKG_WHEELS)/*.whl
$ python3 -m pip install sagemath-standard

You need to install `sage_conf`, a wheelhouse of various python packages. You can list the wheels using `ls $(sage-config SAGE_SPKG_WHEELS)`. After manual installation of these wheels, you can install the sage library, `sagemath-standard`.
You need to install `sage_conf`, a wheelhouse of various python packages. You can list the wheels using `ls $(sage-config SAGE_SPKG_WHEELS)`. After manual installation of these wheels, you can install the sage library, `sagemath-standard`.

**NOTE:** You can find `sage` and `sagemath` pip packages but with these packages, you will encounter `ModuleNotFoundError`.

Expand Down Expand Up @@ -647,3 +646,11 @@ Sources are in unmodified (as far as possible) tarballs in the
information, patches, and build scripts are in the accompanying
`build/pkgs/<packagename>` directory. This directory is
part of the Sage git repository.

<p align="center">
Copyright (C) 2005-2023 The Sage Development Team
</p>
<p align="center">
https://www.sagemath.org
</p>

0 comments on commit cd97a1b

Please sign in to comment.