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

Add support for cython, depend on sagemath, instructions for PyPI #19

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion .travis-deploy-doc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if [[ "${TRAVIS_PULL_REQUEST}" == "false" && "${TRAVIS_BRANCH}" == "${DEPLOY_DOC
fi
chmod 600 .travis_ci_gh_pages_deploy_key
eval `ssh-agent -s`
ssh-add .travis_ci_gh_pages_deploy_key
ssh-add .travis_ci_gh_pages_deploy_key < /dev/null
rm -Rf gh-pages
git clone --depth 1 git@github.com:${DEPLOY_DOC_TO_REPOSITORY}.git --depth 1 --branch=gh-pages gh-pages
BUILT_DOCS_DIR=`cd docs/build/html && pwd`
Expand All @@ -25,3 +25,4 @@ if [[ "${TRAVIS_PULL_REQUEST}" == "false" && "${TRAVIS_BRANCH}" == "${DEPLOY_DOC
git push origin gh-pages
fi
fi
/usr/bin/killall python2
9 changes: 6 additions & 3 deletions .travis-install.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#! /bin/sh
#! /bin/bash
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved. This file is offered as-is,
# without any warranty.
set -e
SAGE_IMAGE=`python2 -c "import setup; print setup.get_all_version_names('${SAGE_SERVER}index.html',${SAGE_AGE}, distribution='${UBUNTU_VERSION}')"`
echo "Obtaining Sage image:"
echo $SAGE_IMAGE
cd $HOME
if [ ! -x SageMath/sage ] ; then
if [ ! -x SageMath/sage ] ; then
rm -f SageMath.tar.bz2
wget $SAGE_SERVER$SAGE_IMAGE -O SageMath.tar.bz2
wget ${SAGE_SERVER}${SAGE_IMAGE} -O SageMath.tar.bz2
tar xf SageMath.tar.bz2
fi
MAKE="make -j4"
Expand Down
9 changes: 4 additions & 5 deletions .travis-test.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#! /bin/sh
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved. This file is offered as-is,
# without any warranty.
set -e

mkdir -p $HOME/SageMath/build/pkgs
$HOME/SageMath/sage -pip install --upgrade -v -i https://pypi.python.org/pypi sagemath
$HOME/SageMath/sage -pip install --upgrade --no-index -v .
$HOME/SageMath/sage setup.py test
(cd docs && $HOME/SageMath/sage -sh -c "make html")
$HOME/SageMath/sage -pip uninstall .
$HOME/SageMath/sage -pip uninstall sage_sample
29 changes: 17 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved. This file is offered as-is,
# without any warranty.
language: python
python: 2.7
dist: xenial
matrix:
include:
- env: CACHE_NAME=7.6 DEPLOY_DOC_FROM_BRANCH=master DEPLOY_DOC_TO_DIRECTORY=/ SAGE_SERVER=http://mirrors.xmission.com/sage/ SAGE_IMAGE=linux/64bit/sage-7.6-Ubuntu_12.04-x86_64.tar.bz2
- env: CACHE_NAME=7.5.1 SAGE_SERVER=http://mirrors.xmission.com/sage/ SAGE_IMAGE=linux/64bit/sage-7.5.1-Ubuntu_12.04-x86_64.tar.bz2
- env: CACHE_NAME=latest DEPLOY_DOC_FROM_BRANCH=master DEPLOY_DOC_TO_REPOSITORY=mmasdeu/sage_sample
DEPLOY_DOC_TO_DIRECTORY=doc/html SAGE_SERVER=http://mirrors.xmission.com/sage/linux/64bit/
SAGE_AGE=0 UBUNTU_VERSION=Ubuntu_16.04-x86_64
- env: CACHE_NAME=older SAGE_SERVER=http://mirrors.xmission.com/sage/linux/64bit/ SAGE_AGE=1
UBUNTU_VERSION=Ubuntu_16.04-x86_64
allow_failures:
- env: CACHE_NAME=older SAGE_SERVER=http://mirrors.xmission.com/sage/linux/64bit/ SAGE_AGE=1
UBUNTU_VERSION=Ubuntu_16.04-x86_64

install:
- ./.travis-install.sh
- "./.travis-install.sh"
script:
- ./.travis-test.sh
- "./.travis-test.sh"
cache:
directories:
- $HOME/SageMath
- $HOME/.cache/matplotlib
- "$HOME/SageMath"
- "$HOME/.cache/matplotlib"
timeout: 1000
before_cache:
- rm -Rf $HOME/SageMath/logs $HOME/SageMath/.BUILDSTART
after_success:
- ./.travis-deploy-doc.sh
- "./.travis-deploy-doc.sh"
before_script:
- openssl aes-256-cbc -K $encrypted_f96cc3b3888c_key -iv $encrypted_f96cc3b3888c_iv
- openssl aes-256-cbc -K $encrypted_2f33c728c8dc_key -iv $encrypted_2f33c728c8dc_iv
-in .travis_ci_gh_pages_deploy_key.enc -out .travis_ci_gh_pages_deploy_key -d || true
Binary file modified .travis_ci_gh_pages_deploy_key.enc
Binary file not shown.
5 changes: 5 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
prune sage_sample
include VERSION
include sage_sample/*.py
include sage_sample/*.pyx

121 changes: 68 additions & 53 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
Sage Sample Package
===================

This package is designed as as simple `SageMath <http://www.sagemath.org>`_ package
This package is designed as a simple `SageMath <http://www.sagemath.org>`_ package
example to serve as a good practice reference for package developers. We follow
python recommendations and adapt them to the SageMath community. You can find more
advanced documentation on python package creation on
`How To Package Your Python Code <https://packaging.python.org/>`_.

This is still a work in progress. Once this example will have
stabilized, the plan is to make a
`cookie cutter <https://cookiecutter.readthedocs.io/en/latest/>`_
template out of it.

Installation
------------
Expand All @@ -17,22 +21,34 @@ Local install from source

Download the source from the git repository::

$ git clone https://github.com/nthiery/sage_sample.git
$ git clone https://github.com/sagemath/sage_sample.git

Change to the root directory and run::

$ sage -pip install --upgrade --no-index -v .

For convenience this package contains a [makefile](makefile) with this
and other often used commands. Should you wish too, you can use the
shorthand:
shorthand::

$ make install

Install from PyPI
^^^^^^^^^^^^^^^^^^

TODO: distribute on PyPI.
Create an account at https://pypi.python.org/pypi

Install ``twine`` in Sage::

$ sage -pip install --upgrade twine

Create the distribution (you can also use ``bdist`` instead to create the built distribution instead of the source one)::

$ python setup.py sdist

Upload to PyPI::

$ twine upload dist/* -r pypi

Usage
-----
Expand All @@ -47,7 +63,7 @@ Setup
------

All packaging setup is done through ``setup.py``. To create your own package
follow the strcuture of the file and change the parameters accordingly.
follow the structure of the file and change the parameters accordingly.

Source code
-----------
Expand All @@ -73,7 +89,7 @@ configured in ``setup.py`` to run the tests::

This is just calling ``sage -t`` with appropriate flags.

Shorthand:
Shorthand::

$ make test

Expand All @@ -86,19 +102,19 @@ The documentation of the package can be generated using Sage's
$ cd docs
$ sage -sh -c "make html"

Shorthand:
Shorthand::

$ make doc

For this to work on your own package, make sure you follow the same
structure as we do here:

* Create a ``docs`` folder containing the exact same ``Makefile`` and a ``source``
folder.
* Copy and paste the ``docs/source/conf.py`` file from this package and update
the few project specific variables at the beginning of the file.
* Create an ``index.rst`` file as well as a ``<module name>.rst`` file for each
module you want on the documentation.
* Create a ``docs`` folder containing the exact same ``Makefile`` and a ``source``
folder.
* Copy and paste the ``docs/source/conf.py`` file from this package and update
the few project specific variables at the beginning of the file.
* Create an ``index.rst`` file as well as a ``<module name>.rst`` file for each
module you want on the documentation.

Travis CI integration
---------------------
Expand All @@ -111,23 +127,22 @@ Travis CI system are included.
https://docs.travis-ci.com/user/for-beginners explains how to enable
automatic Travis CI builds for your GitHub-hosted project.

The scripts download and install binary releases (7.1-7.4) from a
The scripts download and install the last two binary releases from a
SageMath mirror. Edit ``.travis-install.sh`` if some optional or
experimental SageMath packages need to be installed prior to running
your package. Edit ``.travis.yml`` to change the list of SageMath
versions used.
your package.

Automatically deploying documentation to GitHub pages using Travis CI
---------------------------------------------------------------------

* First do the steps described above to enable Travis CI integration
of your GitHub-hosted project.
* If you don't already have GitHub pages for your project: Create and
checkout a branch ``gh-pages`` in your repository and put an empty
file ``.nojekyll`` in it. (See
https://help.github.com/articles/files-that-start-with-an-underscore-are-missing/)::
Commit it and push it to GitHub::
* First do the steps described above to enable Travis CI integration
of your GitHub-hosted project.

* If you don't already have GitHub pages for your project: Create and
checkout a branch ``gh-pages`` in your repository and put an empty
file ``.nojekyll`` in it (see
https://help.github.com/articles/files-that-start-with-an-underscore-are-missing/).
Then commit it and push it to GitHub::

$ git clone --single-branch --depth 1 https://github.com/USER/PROJECT.git gh-pages
$ cd gh-pages
Expand All @@ -138,58 +153,58 @@ Automatically deploying documentation to GitHub pages using Travis CI
$ git commit -m "Initial commit"
$ git push -u origin gh-pages
$ cd ..
* (Back in your working copy:) Generate a new ssh key pair with an
empty passphrase::

* (Back in your working copy:) Generate a new ssh key pair with an
empty passphrase::

$ ssh-keygen -t dsa -f .travis_ci_gh_pages_deploy_key

* Add the public ssh key (contents of the file
``.travis_ci_gh_pages_deploy_key.pub``) to your GitHub repository
as a deploy key (Settings/Deploy keys/Add deploy key).
Title: Key for deploying documentation to GitHub pages.
Check Allow write access.
* Add the public ssh key (contents of the file
``.travis_ci_gh_pages_deploy_key.pub``) to your GitHub repository
as a deploy key (Settings/Deploy keys/Add deploy key).
Title: Key for deploying documentation to GitHub pages.
Check Allow write access.

* Install the Travis CI command-line client from
https://github.com/travis-ci/travis.rb::
* Install the Travis CI command-line client from
https://github.com/travis-ci/travis.rb::

$ gem install travis
* Log in to Travis CI using your GitHub credentials::

* Log in to Travis CI using your GitHub credentials::

$ travis login
* Encrypt the private ssh key, add the decryption keys
as secure environment variables to Travis CI, and
add code to ``.travis.yml`` to decrypt it::

* Encrypt the private ssh key, add the decryption keys
as secure environment variables to Travis CI, and
add code to ``.travis.yml`` to decrypt it::

$ travis encrypt-file .travis_ci_gh_pages_deploy_key --add before_script

* Add the encrypted private ssh key to the repository::
* Add the encrypted private ssh key to the repository::

$ git add .travis_ci_gh_pages_deploy_key.enc

* Have git ignore the other keys (and the gh-pages directory)::
* Have git ignore the other keys (and the gh-pages directory)::

$ echo >> .gitignore
$ echo "/.travis_ci_gh_pages_deploy_key" >> .gitignore
$ echo "/.travis_ci_gh_pages_deploy_key.pub" >> .gitignore
$ echo "/gh-pages" >> .gitignore
$ git add .gitignore

* Optionally, edit ``.travis.yml`` to adjust variables ``DEPLOY_DOC_...``
* Optionally, edit ``.travis.yml`` to adjust variables ``DEPLOY_DOC_...``

* Commit all changes to GitHub. The Travis CI build should then run
automatically and deploy it::
* Commit all changes to GitHub. The Travis CI build should then run
automatically and deploy it::

$ git add .travis.yml
$ git commit -m "Deploy built documentation to GitHub"
$ git push
* The deployed documentation will be available at:
https://USER.github.io/PROJECT/
This can be customized by changing ``DEPLOY_DOC_TO_DIRECTORY=/``
to another directory in ``.travis.yml``
For example, setting ``DEPLOY_DOC_TO_DIRECTORY=doc/html`` will make
the deployed documentation available at:
https://USER.github.io/PROJECT/doc/html/

* The deployed documentation will be available at:
https://USER.github.io/PROJECT/
This can be customized by changing ``DEPLOY_DOC_TO_DIRECTORY=/``
to another directory in ``.travis.yml``
For example, setting ``DEPLOY_DOC_TO_DIRECTORY=doc/html`` will make
the deployed documentation available at:
https://USER.github.io/PROJECT/doc/html/
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sagemath >= 1.2.8
cython >= 0.26
3 changes: 3 additions & 0 deletions sage_sample/one_cython_file.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# A sample cython file
def quick_question(int a):
return a + 1
3 changes: 2 additions & 1 deletion sage_sample/ultimate_question.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
- Viviane Pons: initial implementation
"""
from sage.combinat.combinat import catalan_number
from one_cython_file import quick_question

def answer_to_ultimate_question():
r"""
Expand All @@ -42,4 +43,4 @@ def answer_to_ultimate_question():
sage: answer_to_ultimate_question() == 42
True
"""
return catalan_number(5)
return quick_question(catalan_number(5)) - 1
Loading