Skip to content

Commit ecd0f2a

Browse files
committed
fixed untracked files
1 parent a149f77 commit ecd0f2a

17 files changed

+998
-0
lines changed

.gitignore

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
test.py
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
env/
12+
build/
13+
develop-eggs/
14+
dist/
15+
downloads/
16+
eggs/
17+
.eggs/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
*.egg-info/
23+
.installed.cfg
24+
*.egg
25+
26+
# PyInstaller
27+
# Usually these files are written by a python script from a template
28+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
29+
*.manifest
30+
*.spec
31+
32+
# Installer logs
33+
pip-log.txt
34+
pip-delete-this-directory.txt
35+
36+
# Unit test / coverage reports
37+
htmlcov/
38+
.tox/
39+
.coverage
40+
.coverage.*
41+
.cache
42+
nosetests.xml
43+
coverage.xml
44+
*,cover
45+
46+
# Translations
47+
*.mo
48+
*.pot
49+
50+
# Django stuff:
51+
*.log
52+
53+
# Sphinx documentation
54+
docs/_build/
55+
56+
# PyBuilder
57+
target/
58+
59+
# Generated by Cython
60+
primesieve/*.cpp
61+
primesieve/array/*.cpp
62+
primesieve/numpy/*.cpp

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "lib/primesieve"]
2+
path = lib/primesieve
3+
url = https://github.com/kimwalisch/primesieve

.travis.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Our .travis.yml is a slightly modified version of:
2+
# https://github.com/joerick/cibuildwheel#example-setup
3+
4+
language: python
5+
jobs:
6+
include:
7+
# perform a linux build
8+
- services: docker
9+
env:
10+
- BUILD_SOURCE_DISTRIBUTION="true"
11+
- services: docker
12+
# and a mac build
13+
- os: osx
14+
# PyPy 7.3.2 needs macOS >= 10.14
15+
osx_image: xcode10.2
16+
language: shell
17+
# and a windows build
18+
- os: windows
19+
language: shell
20+
before_install:
21+
- choco install python --version 3.8.0
22+
- export PATH="/c/Python38:/c/Python38/Scripts:$PATH"
23+
# make sure it's on PATH as 'python3'
24+
- ln -s /c/Python38/python.exe /c/Python38/python3.exe
25+
26+
env:
27+
global:
28+
# Skip building Python 2.7 and PyPy (jit)
29+
- CIBW_SKIP="cp27-* pp*"
30+
# TWINE_PASSWORD is set to a PyPI API token in Travis settings
31+
- TWINE_USERNAME=__token__
32+
33+
install:
34+
- python3 -m pip install --upgrade setuptools cython numpy pytest cibuildwheel==1.6.4
35+
36+
script:
37+
- |
38+
if [ "$BUILD_SOURCE_DISTRIBUTION" = "true" ]
39+
then
40+
python3 setup.py install
41+
pytest
42+
pushd ..
43+
python3 -c "import primesieve;print(primesieve.n_primes(10))"
44+
popd
45+
python3 setup.py sdist
46+
export UPLOAD_FILES=dist/*.tar.gz
47+
else
48+
# For the CIBW environment variables we need to use python instead of python3.
49+
# This way we use the CIBW python version.
50+
export CIBW_BEFORE_BUILD="python -m pip install --upgrade cython numpy"
51+
export CIBW_TEST_REQUIRES="pytest numpy"
52+
export CIBW_TEST_COMMAND='pytest {project} && python -c "import primesieve;print(primesieve.n_primes(10))"'
53+
python3 -m cibuildwheel --output-dir wheelhouse
54+
export UPLOAD_FILES=wheelhouse/*.whl
55+
fi
56+
57+
# Unfortunately failures in after_success currently do not cause the
58+
# build to fail, see https://github.com/travis-ci/travis-ci/issues/758.
59+
# I think we could switch to "deploy:" to get the desired behavior.
60+
after_success:
61+
# Because of a bug in Travis we have to pin keyring here,
62+
# see: https://github.com/kimwalisch/primesieve-python/issues/44.
63+
# Try removing this workaround in 2022 (remove "keyring==21.4.0").
64+
- python3 -m pip install twine keyring==21.4.0
65+
66+
# All commits are uploaded to https://test.pypi.org in order to
67+
# ensure that releases will be uploaded to PyPI without any issues.
68+
- python3 -m twine upload -p $TEST_TOKEN --repository-url https://test.pypi.org/legacy/ --skip-existing --verbose $UPLOAD_FILES;
69+
70+
# If the release was tagged, upload to PyPI.
71+
- if [[ $TRAVIS_TAG ]]; then python3 -m twine upload -p $PYPI_TOKEN --skip-existing --verbose $UPLOAD_FILES; fi

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 - 2017 Mirth Hickford
4+
Copyright (c) 2015 - 2019 Kim Walisch
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.

MANIFEST.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
include README.md
2+
include LICENSE
3+
graft lib

README.md

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
# primesieve-python
2+
3+
[![Build Status](https://travis-ci.org/kimwalisch/primesieve-python.svg?branch=master)](https://travis-ci.org/kimwalisch/primesieve-python) [![PyPI](https://img.shields.io/pypi/v/primesieve.svg)](https://pypi.python.org/pypi/primesieve)
4+
5+
# Summary
6+
7+
Python bindings for the [primesieve](https://github.com/kimwalisch/primesieve)
8+
C++ library.
9+
10+
Generates primes orders of magnitude faster than any pure Python code!
11+
12+
**Features:**
13+
14+
* Get an array of primes
15+
* Iterate over primes using little memory
16+
* Find the nth prime
17+
* Count/print primes and [prime k-tuplets](https://en.wikipedia.org/wiki/Prime_k-tuple)
18+
* Multi-threaded for counting primes and finding the nth prime
19+
* NumPy support
20+
21+
# Prerequisites
22+
23+
We provide primesieve wheels (distribution packages) for Windows, macOS
24+
and Linux for x86 and x64 CPUs. For other operating systems and/or CPUs
25+
you need to have installed a C++ compiler.
26+
27+
```bash
28+
# Ubuntu/Debian
29+
sudo apt install g++ python-dev
30+
31+
# Fedora
32+
sudo dnf install gcc-c++ python-devel
33+
34+
# macOS
35+
xcode-select --install
36+
```
37+
38+
# Installation
39+
40+
```bash
41+
# Python 3.5 or later
42+
pip install primesieve
43+
44+
# For Python 2.7 use:
45+
pip install "primesieve<=1.4.4"
46+
```
47+
48+
# Conda Installation
49+
50+
[![TravisCI](https://travis-ci.org/conda-forge/python-primesieve-feedstock.svg?branch=master)](https://travis-ci.org/conda-forge/python-primesieve-feedstock)
51+
[![AppVeyor](https://ci.appveyor.com/api/projects/status/github/conda-forge/python-primesieve-feedstock?svg=True)](https://ci.appveyor.com/project/conda-forge/python-primesieve-feedstock/branch/master)
52+
[![Circle CI](https://circleci.com/gh/conda-forge/python-primesieve-feedstock.svg?style=shield)](https://circleci.com/gh/conda-forge/python-primesieve-feedstock)
53+
[![Anaconda-Server Badge](https://anaconda.org/conda-forge/python-primesieve/badges/downloads.svg)](https://anaconda.org/conda-forge/python-primesieve)
54+
55+
You don't need to install a C++ compiler when installing python-primesieve using Conda.
56+
57+
```
58+
conda install -c conda-forge python-primesieve
59+
```
60+
61+
# Usage examples
62+
63+
```Python
64+
>>> from primesieve import *
65+
66+
# Get an array of the primes <= 40
67+
>>> primes(40)
68+
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]
69+
70+
# Get an array of the primes between 100 and 120
71+
>>> primes(100, 120)
72+
[101, 103, 107, 109, 113]
73+
74+
# Get an array of the first 10 primes
75+
>>> n_primes(10)
76+
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
77+
78+
# Get an array of the first 10 primes >= 1000
79+
>>> n_primes(10, 1000)
80+
[1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061]
81+
82+
# Get the 10th prime
83+
>>> nth_prime(10)
84+
29
85+
86+
# Count the primes below 10**9
87+
>>> count_primes(10**9)
88+
50847534
89+
```
90+
91+
Here is a [list of all available functions](primesieve/_primesieve.pyx).
92+
93+
# Iterating over primes
94+
95+
Instead of generating a large array of primes and then do something
96+
with the primes it is also possible to simply iterate over the primes
97+
which uses less memory.
98+
99+
```Python
100+
""">>> import primesieve
101+
102+
it = primesieve.Iterator()
103+
prime = it.next_prime()
104+
105+
# Iterate over the primes below 10000
106+
while prime < 10000:
107+
print prime
108+
prime = it.next_prime()
109+
110+
# Set iterator start number to 100
111+
it.skipto(100)
112+
prime = it.prev_prime()
113+
114+
# Iterate backwards over the primes below 100
115+
while prime > 0:
116+
print prime
117+
prime = it.prev_prime()"""
118+
119+
from primesieve import primes_range
120+
121+
# iterate over the primes in range between 100 and 10^7
122+
# 100 < prime <= 10^7
123+
for prime in primes_range(100,10e7):
124+
125+
# do something with the prime
126+
...
127+
128+
```
129+
130+
# NumPy support
131+
132+
Using the ```primesieve.numpy``` module you can generate an array of
133+
primes using native C++ performance!
134+
135+
In comparison the ```primesieve``` module generates an array of primes
136+
about 3 times slower mostly because the conversion of the C primes
137+
array into a python array is quite slow.
138+
139+
```Python
140+
>>> from primesieve.numpy import *
141+
142+
# Generate a numpy array with the primes below 100
143+
>>> primes(100)
144+
array([ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59,
145+
61, 67, 71, 73, 79, 83, 89, 97])
146+
147+
# Generate a numpy array with the first 100 primes
148+
>>> n_primes(100)
149+
array([ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41,
150+
43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101,
151+
103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167,
152+
173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239,
153+
241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313,
154+
317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397,
155+
401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467,
156+
479, 487, 491, 499, 503, 509, 521, 523, 541])
157+
```
158+
159+
# Development
160+
161+
You need to have installed a C++ compiler, see [Prerequisites](#prerequisites).
162+
163+
```bash
164+
# Install prerequisites
165+
pip install cython pytest numpy
166+
167+
# Clone repository
168+
git clone --recursive https://github.com/kimwalisch/primesieve-python
169+
170+
cd primesieve-python
171+
172+
# Build and install primesieve-python
173+
pip install . --upgrade
174+
175+
# Run tests
176+
pytest
177+
```
178+
179+
# How to do a new release
180+
181+
* You need to be a maintainer of the [primesieve-python](https://github.com/kimwalisch/primesieve-python) repo.
182+
* You need to be a maintainer of the [primesieve pypi](https://pypi.org/project/primesieve) project.
183+
* Compare ```.travis.yml``` with [cibuildwheel#example-setup](https://github.com/joerick/cibuildwheel#example-setup) and update ```.travis.yml``` if needed.
184+
* Update the supported Python versions in ```setup.py``` (we support the same versions as [cibuildwheel](https://pypi.org/project/cibuildwheel)).
185+
* Increment the primesieve-python version in ```setup.py```. Ideally this should be the last commit before the release as this uploads the new primesieve wheels to [https://test.pypi.org](https://test.pypi.org/project/primesieve/#files).
186+
* Check if all primesieve wheels (Windows, macOS, Linux) have been uploaded to [https://test.pypi.org](https://test.pypi.org/project/primesieve/#files).
187+
* If not, read the [Travis CI logs](https://travis-ci.org/github/kimwalisch/primesieve-python) and fix the bugs.
188+
* Finally, do a new release on GitHub.

primesieve/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from primesieve._primesieve import *

0 commit comments

Comments
 (0)