Skip to content

Commit a3b1579

Browse files
committed
Added support for cython, also added dependency on sagemath package.
1 parent 4735dc0 commit a3b1579

File tree

5 files changed

+70
-41
lines changed

5 files changed

+70
-41
lines changed

.travis-test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# notice and this notice are preserved. This file is offered as-is,
55
# without any warranty.
66
set -e
7+
$HOME/SageMath/sage -pip install --upgrade --no-index -v sagemath # Check that Sage is installed
78
$HOME/SageMath/sage -pip install --upgrade --no-index -v .
89
$HOME/SageMath/sage setup.py test
910
(cd docs && $HOME/SageMath/sage -sh -c "make html")

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
language: python
66
matrix:
77
include:
8-
- 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
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
10+
allow_failures:
911
- 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
1012
install:
1113
- ./.travis-install.sh

README.rst

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Setup
4747
------
4848

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

5252
Source code
5353
-----------
@@ -120,14 +120,14 @@ versions used.
120120
Automatically deploying documentation to GitHub pages using Travis CI
121121
---------------------------------------------------------------------
122122

123-
* First do the steps described above to enable Travis CI integration
124-
of your GitHub-hosted project.
125-
126-
* If you don't already have GitHub pages for your project: Create and
127-
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::
123+
* First do the steps described above to enable Travis CI integration
124+
of your GitHub-hosted project.
125+
126+
* If you don't already have GitHub pages for your project: Create and
127+
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::
131131

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

145145
$ ssh-keygen -t dsa -f .travis_ci_gh_pages_deploy_key
146146

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

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

156156
$ gem install travis
157-
158-
* Log in to Travis CI using your GitHub credentials::
157+
158+
* Log in to Travis CI using your GitHub credentials::
159159

160160
$ travis login
161-
162-
* Encrypt the private ssh key, add the decryption keys
163-
as secure environment variables to Travis CI, and
164-
add code to ``.travis.yml`` to decrypt it::
161+
162+
* Encrypt the private ssh key, add the decryption keys
163+
as secure environment variables to Travis CI, and
164+
add code to ``.travis.yml`` to decrypt it::
165165

166166
$ travis encrypt-file .travis_ci_gh_pages_deploy_key --add before_script
167167

168-
* Add the encrypted private ssh key to the repository::
168+
* Add the encrypted private ssh key to the repository::
169169

170170
$ git add .travis_ci_gh_pages_deploy_key.enc
171171

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

174174
$ echo >> .gitignore
175175
$ echo "/.travis_ci_gh_pages_deploy_key" >> .gitignore
176176
$ echo "/.travis_ci_gh_pages_deploy_key.pub" >> .gitignore
177177
$ echo "/gh-pages" >> .gitignore
178178
$ git add .gitignore
179179

180-
* Optionally, edit ``.travis.yml`` to adjust variables ``DEPLOY_DOC_...``
180+
* Optionally, edit ``.travis.yml`` to adjust variables ``DEPLOY_DOC_...``
181181

182-
* Commit all changes to GitHub. The Travis CI build should then run
183-
automatically and deploy it::
182+
* Commit all changes to GitHub. The Travis CI build should then run
183+
automatically and deploy it::
184184

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

sage_sample/ultimate_question.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- Viviane Pons: initial implementation
2424
"""
2525
from sage.combinat.combinat import catalan_number
26+
from one_cython_file import quick_question
2627

2728
def answer_to_ultimate_question():
2829
r"""
@@ -42,4 +43,4 @@ def answer_to_ultimate_question():
4243
sage: answer_to_ultimate_question() == 42
4344
True
4445
"""
45-
return catalan_number(5)
46+
return quick_question(catalan_number(5)) - 1

setup.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,43 @@
44
from setuptools import setup
55
from codecs import open # To open the README file with proper encoding
66
from setuptools.command.test import test as TestCommand # for tests
7+
from distutils.command import build as build_module
78

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
814

915
# Get information from separate files (README, VERSION)
1016
def readfile(filename):
1117
with open(filename, encoding='utf-8') as f:
1218
return f.read()
1319

20+
# Check the right Sage version
21+
class build(build_module.build):
22+
def run(self):
23+
from sagemath.check_version import check_version
24+
check_version(sage_required_version)
25+
build_module.build.run(self)
26+
1427
# For the tests
1528
class SageTest(TestCommand):
1629
def run_tests(self):
1730
errno = os.system("sage -t --force-lib sage_sample")
1831
if errno != 0:
1932
sys.exit(1)
2033

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+
]
40+
41+
# Specify the required Sage version
42+
sage_required_version = '>=7.6'
43+
2144
setup(
2245
name = "sage_sample",
2346
version = readfile("VERSION"), # the VERSION file is shared with the documentation
@@ -40,6 +63,8 @@ def run_tests(self):
4063
'Programming Language :: Python :: 2.7',
4164
], # classifiers list: https://pypi.python.org/pypi?%3Aaction=list_classifiers
4265
keywords = "SageMath packaging",
66+
install_requires = ['sagemath'], # This ensures that Sage is installed
4367
packages = ['sage_sample'],
44-
cmdclass = {'test': SageTest} # adding a special setup command for tests
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
4570
)

0 commit comments

Comments
 (0)