Skip to content

Commit 7c47384

Browse files
committed
Finished implementing changes.
1 parent a3b1579 commit 7c47384

File tree

9 files changed

+125
-81
lines changed

9 files changed

+125
-81
lines changed

.travis-deploy-doc.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ if [[ "${TRAVIS_PULL_REQUEST}" == "false" && "${TRAVIS_BRANCH}" == "${DEPLOY_DOC
1010
fi
1111
chmod 600 .travis_ci_gh_pages_deploy_key
1212
eval `ssh-agent -s`
13-
ssh-add .travis_ci_gh_pages_deploy_key
13+
ssh-add .travis_ci_gh_pages_deploy_key < /dev/null
1414
rm -Rf gh-pages
1515
git clone --depth 1 [email protected]:${DEPLOY_DOC_TO_REPOSITORY}.git --depth 1 --branch=gh-pages gh-pages
1616
BUILT_DOCS_DIR=`cd docs/build/html && pwd`
@@ -25,3 +25,4 @@ if [[ "${TRAVIS_PULL_REQUEST}" == "false" && "${TRAVIS_BRANCH}" == "${DEPLOY_DOC
2525
git push origin gh-pages
2626
fi
2727
fi
28+
/usr/bin/killall python2

.travis-install.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
#! /bin/sh
1+
#! /bin/bash
22
# Copying and distribution of this file, with or without modification,
33
# are permitted in any medium without royalty provided the copyright
44
# notice and this notice are preserved. This file is offered as-is,
55
# without any warranty.
66
set -e
7+
SAGE_IMAGE=`python2 -c "import setup; print setup.get_all_version_names('${SAGE_SERVER}index.html',${SAGE_AGE})"`
8+
echo "Obtaining Sage image:"
9+
echo $SAGE_IMAGE
710
cd $HOME
8-
if [ ! -x SageMath/sage ] ; then
11+
if [ ! -x SageMath/sage ] ; then
912
rm -f SageMath.tar.bz2
10-
wget $SAGE_SERVER$SAGE_IMAGE -O SageMath.tar.bz2
13+
wget ${SAGE_SERVER}${SAGE_IMAGE} -O SageMath.tar.bz2
1114
tar xf SageMath.tar.bz2
1215
fi
1316
MAKE="make -j4"

.travis-test.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
#! /bin/sh
2-
# Copying and distribution of this file, with or without modification,
3-
# are permitted in any medium without royalty provided the copyright
4-
# notice and this notice are preserved. This file is offered as-is,
5-
# without any warranty.
62
set -e
7-
$HOME/SageMath/sage -pip install --upgrade --no-index -v sagemath # Check that Sage is installed
3+
4+
$HOME/SageMath/sage -pip install --upgrade -v -i https://pypi.python.org/pypi sagemath
85
$HOME/SageMath/sage -pip install --upgrade --no-index -v .
96
$HOME/SageMath/sage setup.py test
107
(cd docs && $HOME/SageMath/sage -sh -c "make html")

.travis.yml

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
1-
# Copying and distribution of this file, with or without modification,
2-
# are permitted in any medium without royalty provided the copyright
3-
# notice and this notice are preserved. This file is offered as-is,
4-
# without any warranty.
51
language: python
62
matrix:
73
include:
8-
- env: CACHE_NAME=7.6 DEPLOY_DOC_FROM_BRANCH=master DEPLOY_DOC_TO_REPOSITORY=username/sample_sage
9-
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
4+
- env: CACHE_NAME=latest DEPLOY_DOC_FROM_BRANCH=master DEPLOY_DOC_TO_REPOSITORY=mmasdeu/sage_sample
5+
DEPLOY_DOC_TO_DIRECTORY=doc/html SAGE_SERVER=http://mirrors.xmission.com/sage/linux/64bit/
6+
SAGE_AGE=0
7+
- env: CACHE_NAME=older SAGE_SERVER=http://mirrors.xmission.com/sage/linux/64bit/ SAGE_AGE=1
108
allow_failures:
11-
- 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
9+
- env: CACHE_NAME=older SAGE_SERVER=http://mirrors.xmission.com/sage/linux/64bit/ SAGE_AGE=1
10+
1211
install:
13-
- ./.travis-install.sh
12+
- "./.travis-install.sh"
1413
script:
15-
- ./.travis-test.sh
14+
- "./.travis-test.sh"
1615
cache:
1716
directories:
18-
- $HOME/SageMath
19-
- $HOME/.cache/matplotlib
17+
- "$HOME/SageMath"
18+
- "$HOME/.cache/matplotlib"
2019
timeout: 1000
2120
before_cache:
2221
- rm -Rf $HOME/SageMath/logs $HOME/SageMath/.BUILDSTART
2322
after_success:
24-
- ./.travis-deploy-doc.sh
23+
- "./.travis-deploy-doc.sh"
2524
before_script:
26-
- openssl aes-256-cbc -K $encrypted_f96cc3b3888c_key -iv $encrypted_f96cc3b3888c_iv
25+
- openssl aes-256-cbc -K $encrypted_2f33c728c8dc_key -iv $encrypted_2f33c728c8dc_iv
2726
-in .travis_ci_gh_pages_deploy_key.enc -out .travis_ci_gh_pages_deploy_key -d || true

.travis_ci_gh_pages_deploy_key.enc

0 Bytes
Binary file not shown.

MANIFEST.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
prune sage_sample
2+
include VERSION
3+
include sage_sample/*.py
4+
include sage_sample/*.pyx
5+

README.rst

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
Sage Sample Package
33
===================
44

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

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

1216
Installation
1317
------------
@@ -17,22 +21,34 @@ Local install from source
1721

1822
Download the source from the git repository::
1923

20-
$ git clone https://github.com/nthiery/sage_sample.git
24+
$ git clone https://github.com/sagemath/sage_sample.git
2125

2226
Change to the root directory and run::
2327

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

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

3034
$ make install
3135

3236
Install from PyPI
3337
^^^^^^^^^^^^^^^^^^
3438

35-
TODO: distribute on PyPI.
39+
Create an account at https://pypi.python.org/pypi
40+
41+
Install ``twine`` in Sage::
42+
43+
$ sage -pip install --upgrade twine
44+
45+
Create the distribution (you can also use ``bdist`` instead to create the built distribution instead of the source one)::
46+
47+
$ python setup.py sdist
48+
49+
Upload to PyPI::
50+
51+
$ twine upload dist/* -r pypi
3652

3753
Usage
3854
-----
@@ -73,7 +89,7 @@ configured in ``setup.py`` to run the tests::
7389

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

76-
Shorthand:
92+
Shorthand::
7793

7894
$ make test
7995

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

89-
Shorthand:
105+
Shorthand::
90106

91107
$ make doc
92108

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

96-
* Create a ``docs`` folder containing the exact same ``Makefile`` and a ``source``
97-
folder.
98-
* Copy and paste the ``docs/source/conf.py`` file from this package and update
99-
the few project specific variables at the beginning of the file.
100-
* Create an ``index.rst`` file as well as a ``<module name>.rst`` file for each
101-
module you want on the documentation.
112+
* Create a ``docs`` folder containing the exact same ``Makefile`` and a ``source``
113+
folder.
114+
* Copy and paste the ``docs/source/conf.py`` file from this package and update
115+
the few project specific variables at the beginning of the file.
116+
* Create an ``index.rst`` file as well as a ``<module name>.rst`` file for each
117+
module you want on the documentation.
102118

103119
Travis CI integration
104120
---------------------
@@ -111,11 +127,10 @@ Travis CI system are included.
111127
https://docs.travis-ci.com/user/for-beginners explains how to enable
112128
automatic Travis CI builds for your GitHub-hosted project.
113129

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

120135
Automatically deploying documentation to GitHub pages using Travis CI
121136
---------------------------------------------------------------------
@@ -125,9 +140,9 @@ Automatically deploying documentation to GitHub pages using Travis CI
125140

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

132147
$ git clone --single-branch --depth 1 https://github.com/USER/PROJECT.git gh-pages
133148
$ cd gh-pages

sage_sample/one_cython_file.pyx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# A sample cython file
2+
def quick_question(int a):
3+
return a + 1

setup.py

Lines changed: 62 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
## -*- encoding: utf-8 -*-
22
import os
33
import sys
4+
import re
5+
import urllib2
46
from setuptools import setup
57
from codecs import open # To open the README file with proper encoding
68
from setuptools.command.test import test as TestCommand # for tests
79
from distutils.command import build as build_module
810

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

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

37+
2738
# For the tests
2839
class SageTest(TestCommand):
2940
def run_tests(self):
30-
errno = os.system("sage -t --force-lib sage_sample")
41+
errno = os.system("sage -t --force-lib sage_sample sage_sample/*.pyx")
3142
if errno != 0:
3243
sys.exit(1)
3344

34-
# Cython modules
35-
ext_modules = [
36-
Extension('sage_sample.one_cython_file',
37-
sources = [os.path.join('sage_sample','one_cython_file.pyx')],
38-
include_dirs=sage_include_directories())
39-
]
45+
if __name__ == "__main__":
46+
47+
# The next block is needed if there are cython files
48+
from setuptools import Extension
49+
from Cython.Build import cythonize
50+
import Cython.Compiler.Options
51+
from sage.env import sage_include_directories
52+
53+
54+
# Cython modules
55+
ext_modules = [
56+
Extension('sage_sample.one_cython_file',
57+
sources = [os.path.join('sage_sample','one_cython_file.pyx')],
58+
include_dirs=sage_include_directories())
59+
]
4060

41-
# Specify the required Sage version
42-
sage_required_version = '>=7.6'
61+
# Specify the required Sage version
62+
sage_required_version = '>=7.5'
4363

44-
setup(
45-
name = "sage_sample",
46-
version = readfile("VERSION"), # the VERSION file is shared with the documentation
47-
description='An example of a basic sage package',
48-
long_description = readfile("README.rst"), # get the long description from the README
49-
url='https://github.com/sagemath/sage_sample',
50-
author='Matthias Koeppe, Sébastien Labbé, Viviane Pons, Nicolas M. Thiéry, ... with inspiration from many',
51-
author_email='[email protected]', # choose a main contact email
52-
license='GPLv2+', # This should be consistent with the LICENCE file
53-
classifiers=[
54-
# How mature is this project? Common values are
55-
# 3 - Alpha
56-
# 4 - Beta
57-
# 5 - Production/Stable
58-
'Development Status :: 4 - Beta',
59-
'Intended Audience :: Science/Research',
60-
'Topic :: Software Development :: Build Tools',
61-
'Topic :: Scientific/Engineering :: Mathematics',
62-
'License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)',
63-
'Programming Language :: Python :: 2.7',
64-
], # classifiers list: https://pypi.python.org/pypi?%3Aaction=list_classifiers
65-
keywords = "SageMath packaging",
66-
install_requires = ['sagemath'], # This ensures that Sage is installed
67-
packages = ['sage_sample'],
68-
ext_modules = cytonize(ext_modules), # This line is only needed if there are cython files present
69-
cmdclass = {'build': build, 'test': SageTest} # adding a special setup command for tests
70-
)
64+
setup(
65+
name = "sage_sample",
66+
version = readfile("VERSION"), # the VERSION file is shared with the documentation
67+
description='An example of a basic sage package',
68+
long_description = readfile("README.rst"), # get the long description from the README
69+
url='https://github.com/sagemath/sage_sample',
70+
author='Matthias Koeppe, Sébastien Labbé, Viviane Pons, Nicolas M. Thiéry, ... with inspiration from many',
71+
author_email='[email protected]', # choose a main contact email
72+
license='GPLv2+', # This should be consistent with the LICENCE file
73+
classifiers=[
74+
# How mature is this project? Common values are
75+
# 3 - Alpha
76+
# 4 - Beta
77+
# 5 - Production/Stable
78+
'Development Status :: 4 - Beta',
79+
'Intended Audience :: Science/Research',
80+
'Topic :: Software Development :: Build Tools',
81+
'Topic :: Scientific/Engineering :: Mathematics',
82+
'License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)',
83+
'Programming Language :: Python :: 2.7',
84+
], # classifiers list: https://pypi.python.org/pypi?%3Aaction=list_classifiers
85+
keywords = "SageMath packaging",
86+
install_requires = ['sagemath'], # This ensures that Sage is installed
87+
packages = ['sage_sample'],
88+
ext_modules = cythonize(ext_modules), # This line is only needed if there are cython files present
89+
include_package_data = True,
90+
cmdclass = {'build': build, 'test': SageTest} # adding a special setup command for tests
91+
)

0 commit comments

Comments
 (0)