Skip to content

Commit

Permalink
Finished implementing changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
mmasdeu committed Jul 31, 2017
1 parent a3b1579 commit 7c47384
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 81 deletions.
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})"`
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
7 changes: 2 additions & 5 deletions .travis-test.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#! /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
$HOME/SageMath/sage -pip install --upgrade --no-index -v sagemath # Check that Sage is installed

$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")
Expand Down
25 changes: 12 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
# 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
matrix:
include:
- env: CACHE_NAME=7.6 DEPLOY_DOC_FROM_BRANCH=master DEPLOY_DOC_TO_REPOSITORY=username/sample_sage
DEPLOY_DOC_TO_DIRECTORY=doc/html SAGE_SERVER=http://mirrors.xmission.com/sage/ SAGE_IMAGE=linux/64bit/sage-7.6-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
- env: CACHE_NAME=older SAGE_SERVER=http://mirrors.xmission.com/sage/linux/64bit/ SAGE_AGE=1
allow_failures:
- 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=older SAGE_SERVER=http://mirrors.xmission.com/sage/linux/64bit/ SAGE_AGE=1

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

51 changes: 33 additions & 18 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 Down Expand Up @@ -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,11 +127,10 @@ 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
---------------------------------------------------------------------
Expand All @@ -125,9 +140,9 @@ Automatically deploying documentation to GitHub pages using Travis CI

* 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::
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 Down
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
103 changes: 62 additions & 41 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
## -*- encoding: utf-8 -*-
import os
import sys
import re
import urllib2
from setuptools import setup
from codecs import open # To open the README file with proper encoding
from setuptools.command.test import test as TestCommand # for tests
from distutils.command import build as build_module

# The next block is needed if there are cython files
from setuptools import Extension
from Cython.Build import cythonize
import Cython.Compiler.Options
from sage.env import sage_include_directories
# Obtain the different Sage versions
def get_all_version_names(mirror_url, idx = None, distribution = 'Ubuntu_16.04-x86_64'):
if idx is None:
idx = 0
else:
idx = int(idx)
site = urllib2.urlopen(mirror_url).read()
ans = re.findall('(sage-([0-9]*(?:\.[0-9]*)*)-%s.tar.bz2)'%distribution, site)
all_version_names = []
for fname, ver in ans:
if fname not in all_version_names:
all_version_names.append(fname)
return all_version_names[idx]

# Get information from separate files (README, VERSION)
def readfile(filename):
Expand All @@ -24,47 +34,58 @@ def run(self):
check_version(sage_required_version)
build_module.build.run(self)


# For the tests
class SageTest(TestCommand):
def run_tests(self):
errno = os.system("sage -t --force-lib sage_sample")
errno = os.system("sage -t --force-lib sage_sample sage_sample/*.pyx")
if errno != 0:
sys.exit(1)

# Cython modules
ext_modules = [
Extension('sage_sample.one_cython_file',
sources = [os.path.join('sage_sample','one_cython_file.pyx')],
include_dirs=sage_include_directories())
]
if __name__ == "__main__":

# The next block is needed if there are cython files
from setuptools import Extension
from Cython.Build import cythonize
import Cython.Compiler.Options
from sage.env import sage_include_directories


# Cython modules
ext_modules = [
Extension('sage_sample.one_cython_file',
sources = [os.path.join('sage_sample','one_cython_file.pyx')],
include_dirs=sage_include_directories())
]

# Specify the required Sage version
sage_required_version = '>=7.6'
# Specify the required Sage version
sage_required_version = '>=7.5'

setup(
name = "sage_sample",
version = readfile("VERSION"), # the VERSION file is shared with the documentation
description='An example of a basic sage package',
long_description = readfile("README.rst"), # get the long description from the README
url='https://github.com/sagemath/sage_sample',
author='Matthias Koeppe, Sébastien Labbé, Viviane Pons, Nicolas M. Thiéry, ... with inspiration from many',
author_email='viviane.pons@lri.fr', # choose a main contact email
license='GPLv2+', # This should be consistent with the LICENCE file
classifiers=[
# How mature is this project? Common values are
# 3 - Alpha
# 4 - Beta
# 5 - Production/Stable
'Development Status :: 4 - Beta',
'Intended Audience :: Science/Research',
'Topic :: Software Development :: Build Tools',
'Topic :: Scientific/Engineering :: Mathematics',
'License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)',
'Programming Language :: Python :: 2.7',
], # classifiers list: https://pypi.python.org/pypi?%3Aaction=list_classifiers
keywords = "SageMath packaging",
install_requires = ['sagemath'], # This ensures that Sage is installed
packages = ['sage_sample'],
ext_modules = cytonize(ext_modules), # This line is only needed if there are cython files present
cmdclass = {'build': build, 'test': SageTest} # adding a special setup command for tests
)
setup(
name = "sage_sample",
version = readfile("VERSION"), # the VERSION file is shared with the documentation
description='An example of a basic sage package',
long_description = readfile("README.rst"), # get the long description from the README
url='https://github.com/sagemath/sage_sample',
author='Matthias Koeppe, Sébastien Labbé, Viviane Pons, Nicolas M. Thiéry, ... with inspiration from many',
author_email='viviane.pons@lri.fr', # choose a main contact email
license='GPLv2+', # This should be consistent with the LICENCE file
classifiers=[
# How mature is this project? Common values are
# 3 - Alpha
# 4 - Beta
# 5 - Production/Stable
'Development Status :: 4 - Beta',
'Intended Audience :: Science/Research',
'Topic :: Software Development :: Build Tools',
'Topic :: Scientific/Engineering :: Mathematics',
'License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)',
'Programming Language :: Python :: 2.7',
], # classifiers list: https://pypi.python.org/pypi?%3Aaction=list_classifiers
keywords = "SageMath packaging",
install_requires = ['sagemath'], # This ensures that Sage is installed
packages = ['sage_sample'],
ext_modules = cythonize(ext_modules), # This line is only needed if there are cython files present
include_package_data = True,
cmdclass = {'build': build, 'test': SageTest} # adding a special setup command for tests
)

0 comments on commit 7c47384

Please sign in to comment.