Skip to content

Commit

Permalink
Add binder.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
kwankyu committed Sep 11, 2023
1 parent 4103129 commit 7cca95a
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 18 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/binder-dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# 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-optional: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

# Create user "alice" whose uid is 1000
ARG NB_USER=alice
ARG NB_UID=1000
ENV NB_USER ${NB_USER}
ENV NB_UID ${NB_UID}
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
RUN apt-get install -y git

# Build Sage
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 FETCH_HEAD
RUN ./bootstrap && ./configure --enable-build-as-root && make -j4

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

# Switch to the user
USER ${NB_USER}

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

# 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}
32 changes: 32 additions & 0 deletions .github/workflows/binder.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Create Binder branch

on: workflow_dispatch

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

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

- 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 "Init"
git push origin $BINDER_BRANCH_NAME
43 changes: 25 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
<div align="center">
<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

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.

Getting Started
---------------

For the impatient, here is the Binder badge for instant computing environment with Sage:

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

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 @@ -61,7 +60,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 @@ -401,18 +400,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 @@ -620,3 +619,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 7cca95a

Please sign in to comment.