Commit Graph

199 Commits

Author SHA1 Message Date
David Hewitt 370652eba8 examples: maturin and setuptools_rust examples 2021-04-03 11:59:41 +01:00
David Hewitt fe74160a7d pyo3_benchmarks: benchmarks as separate Python example 2021-03-01 19:12:39 +00:00
David Hewitt 29a525b327 pyfunction: refactor argument extraction 2021-03-01 17:49:46 +00:00
winxton 5498b7ee3c Fix wordcount example docs 2021-02-24 13:41:45 -05:00
David Hewitt b2675b11fe rust 1.50: clippy and lint fixes 2021-02-11 22:03:34 +00:00
David Hewitt 0da12bd0dc ci: deny clippy warnings for examples 2020-12-31 22:11:48 +00:00
David Hewitt 126a74842f rustapi_module: move issue_219 regression test 2020-11-10 14:23:08 +00:00
David Hewitt 33b8aba3bb examples: simplify tox instructions 2020-11-10 12:50:41 +00:00
Yuji Kanagawa 3b3ba4e3ab
Merge pull request #1152 from PyO3/abi3
Complete abi3 support
2020-10-27 23:30:36 +09:00
Arnav Jindal 042337b423
Update lib.rs 2020-10-21 19:37:23 +05:30
Arnav Jindal a3d0c86c1c
Docs: Fixed example word_count 2020-10-21 12:36:36 +05:30
Alex Gaynor 90a825d0c2 Merge branch 'master' into abi3-merge-master 2020-10-19 14:32:49 -04:00
David Hewitt afd9b823d2 Drop support for Python 3.5 2020-10-18 19:02:27 +01:00
Alex Gaynor aabad7cf7f Assorted updates to the abi3 branch from review 2020-10-11 19:51:27 -04:00
Alex Gaynor 140790b15f Merge branch 'master' into abi3-merge-master 2020-10-10 10:11:49 -04:00
kngwyu 2e22066feb Do not test PyPy on Windows 2020-10-08 16:29:50 +09:00
Alex Gaynor 5bfb4674b1 Merge branch 'master' into abi3-merge-master 2020-09-10 17:01:13 -04:00
kngwyu 7a4c5e2960 Merge branch 'master' into abi3 2020-09-10 00:48:20 +09:00
Sebastian Pütz 22881a3c2f Change add_function, ensure static docstrings.
Change add_function to take `&PyCFunction` instead of a wrapper
fn and ensure that dostrings of functions are `&'static str`.
2020-09-09 12:37:37 +02:00
Sebastian Pütz 3214249010 Make python function wrapper creation fallible.
Wrapping a function can fail if we can't get the module name.

Based on suggestion by @kngwyu
2020-09-03 15:48:32 +02:00
Sebastian Pütz 5bbca1a052 Set the module of `#[pyfunction]`s.
Previously neither the module nor the name of the module of
pyfunctions were registered. This commit passes the module and
its name when creating a new pyfunction.

PyModule::add_function and PyModule::add_module have been added and are
set to replace `add_wrapped` in a future release. `add_wrapped` is kept
for compatibility reasons during the transition.

Depending on whether a `PyModule` or `Python` is the argument for the
Python function-wrapper, the module will be registered with the function.
2020-09-03 14:49:28 +02:00
Alex Gaynor 400462063d Proof of concept of using PEP384s PyType_Spec 2020-09-02 16:54:39 -04:00
David Hewitt 4ed9748b45 Rename exceptions to PyException etc; reintroduce deprecated ones 2020-07-18 06:02:57 +01:00
kngwyu 016800ba4d Use travis's pypy binary instead of anaconda 2020-06-27 19:45:31 +09:00
David Hewitt 9f9137c6e4 Add ability to return from `__next__` / `__anext__` 2020-06-23 15:26:28 +01:00
kngwyu f053bc3881 Fix dealloc implementation to collectly use subtype's tp_free 2020-06-22 10:58:00 +09:00
kngwyu b70ee9a5ad Use subclass correctly in tp_new 2020-06-22 01:38:13 +09:00
Alexander Niederbühl d2c7645bad Add benchmark for Python threaded word count
Add benchmark where the sequential Rust version of the word count is
executed twice to demonstrate parallelism with Python threads.  Also
slightly simplify the benchmark functions.
2020-06-05 20:22:20 +02:00
Alexander Niederbühl bafe269dde Set debug to `False` in word-count example 2020-06-05 16:40:29 +02:00
Alexander Niederbühl de9aae1e82 Use string slices as function arguments
Also use the same names as parameters.
2020-06-05 16:40:29 +02:00
Alexander Niederbühl 4c55fa6b38 Remove unnecessary wrapping of test function 2020-06-05 16:40:29 +02:00
Alexander Niederbühl eb73105625 Make benchmarks more comparable 2020-06-05 16:40:29 +02:00
Alexander Niederbühl bcf48c0bd2 Fix clippy lints 2020-06-05 13:53:01 +02:00
Yuji Kanagawa b3566bc7d9
Merge pull request #830 from oconnor663/maxsize
use struct.calcsize("P") rather than platform.machine()
2020-03-29 16:07:57 +09:00
Jack O'Connor d2c07a87d2 xfail a couple of datetime tests on Python 3.5 + macOS 2020-03-29 15:38:42 +09:00
Jack O'Connor 9e23476221 avoid using platform.architecture() to detect 32-bit-ness in datetime tests
Same reasoning as the previous commit.
2020-03-26 14:01:18 -04:00
kngwyu 5280a281c9 Remove GILPool::new_no_pointer 2020-03-26 19:45:32 +09:00
Alexander Niederbühl 0a84c201f7 Revert "Disable segfaulty subclassing by default"
This reverts commit 5096f936dc.
2020-01-12 01:22:32 +01:00
Alexander Niederbühl 3dc5b86f22 Add subclassing testcase which previously caused a segfault
Add a testcase from #407. Both test cases don't segfault after the
change to the #[pyclass] system in #683.

Closes #407
2020-01-11 18:24:50 +01:00
kngwyu acb1120c55 Fix examples with the new #[new] API 2019-12-22 23:59:28 +09:00
kngwyu dadeb17c3a Fix Windows test 2019-11-17 16:34:55 +09:00
Alexander Niederbühl defa43015a Fix handling of invalid utf-8 sequences in PyString::to_string_lossy 2019-10-24 22:45:32 +02:00
Alexander Niederbühl 7aaef51ab0 Define limits for datetime tests as datetime literals 2019-10-21 16:50:43 +02:00
Alexander Niederbühl ffe4e2f20a Make datetime range for tests smaller 2019-10-19 18:28:53 +02:00
Alexander Niederbühl 8cdc0b42dd Fix minimum and maximum for datetime tests
Depending on the local timezone one could get

  ValueError: year 0 is out of range
2019-10-19 17:56:39 +02:00
Samuele Maci 25564e115a Trigger garbage collection before and after calling the rust binding 2019-10-11 18:46:21 +02:00
Samuele Maci 9ff41fcd3b Rename BytesExtractor method names to reflect their actions 2019-10-11 17:59:48 +02:00
Samuele Maci 681996da38 Add assertions around memory_diff in test_pybuffer_doesnot_leak_memory 2019-10-11 16:10:19 +02:00
kngwyu f1bb043b70 Temporaly skip test_buf_and_str for PyPY 2019-09-23 19:25:27 +09:00
kngwyu 05a1a097a9 Remove mem::forget from PyBuffer::release 2019-09-14 16:56:11 +09:00
kngwyu e911828b79 Add a test to detect memory leak of bytes->vec conversion 2019-09-07 17:59:19 +09:00
Yuji Kanagawa 5eb7656a5e
Merge branch 'master' into examples-debug 2019-09-07 11:53:00 +09:00
konstin 73947d84b4
Format examples with black (#590) 2019-09-06 01:16:09 +02:00
konstin 94f6248d87 Compile examples in debug mode 2019-09-05 13:13:06 +02:00
konstin 5096f936dc Disable segfaulty subclassing by default
See https://github.com/PyO3/pyo3/issues/220 and https://github.com/PyO3/pyo3/issues/407 for details on those segfaults
2019-08-05 11:52:47 +02:00
Alexander Niederbühl f22708f140 datetime tests: Remove Python 2 compatibility 2019-07-15 08:13:03 +02:00
Alexander Niederbühl ad0a068a38 Add minimal datetime as testcase which should pass on all platforms 2019-07-15 08:08:51 +02:00
Alexander Niederbühl f642f19167 Increase MIN_DATETIME_FROM_TIMESTAMP for windows
Otherwise test_datetime_from_timestamp will give an OSError. This seems
to be a similar problem as https://bugs.python.org/issue29097
2019-07-15 08:07:14 +02:00
Martin Larralde 99fdafbb88 Allow setting the module name for a pyclass (#499)
* Add `MODULE` const value to `PyTypeInfo` trait

* Allow setting module name in `pyclass` macro arguments

* Add `$module` argument to `pyobject_native_type` macro in `pyo3::types`

* Set the right module for builtin types in `pyo3::types`

* Add `module` argument to example `word_count.WordCounter` class

* Add `module` argument of `pyclass` macro to guide

* Reformat code using `rustfmt`

* Add tests and entry in CHANGELOG.md for `module` argument in `pyclass`

* Make `$module` parameter in `pyobject_native_type` optional

* Make `pyobject_native_type` declare module as `Some("builtins")` by default
2019-06-03 12:18:44 +09:00
kngwyu e4287e4e47 Fix datetime example 2019-05-26 00:39:06 +09:00
Azat Ibrakov 134c129edc Fix installing in 'venv' and datetime tests on Windows (#472)
* Add failing test

* Complete formatting

* Fix commands execution

* Fix commands execution for Linux

* Extract virtual environment creation/removing into separate functions

* Complete error messages

* Complete examples building

* Use 'venv' independent path

* Call script by dotted path instead of 'source' call

* Add Travis CI script

* Rename variable: 'exec_prefix' -> 'base_prefix'

* Add AppVeyor script

* Remove Rust test

* Complete shell script mode

* Complete path to powershell script

* Use 'pushd'/'popd' instead of 'cd'

* Complete powershell script

* Complete shell script

* Fix setup

* Use 'tox-venv' plugin for 'venv' stdlib module support

* Remove additional 'venv' testing

* Use global environment instead of calling 'set'

* Use 'tox' for AppVeyor, extract commands into 'setup' & 'test' scripts

* Add updating of 'pip' & 'setuptools'

* Add moving in/back from examples directories

* Complete 'pip'/'setuptools' updating

* Complete requirements

* Complete 'word-count' example configuration

* Simplify 'setup' script

* Complete 'rustapi_module' example tests

* Revert formatting

* Complete examples configuration

* Remove redundant annotations

* Add entry in changelog
2019-05-12 22:20:17 +09:00
Georg Brandl cdabf9e1a5 Make more constructors return &PyX instead of Py<PyX>
fixes #405
2019-05-06 10:33:31 +02:00
Paul Ganssle b9a2d2c89f
Update word-count to support PEP 517 sdists 2019-04-25 07:06:29 -04:00
Paul Ganssle 789c0b842b
Add build backend to pyproject.toml
Adding a build-backend key forces PEP 517 with pip >= 19.0, and so it
was left off while there was no PEP 517 support. Now that we have some
tentative PEP 517 support, we can explicitly add this key.
2019-04-25 07:06:29 -04:00
Paul Ganssle f42ee00980
Update tox configuration for PEP 517
This drops "usedevelop", which does an editable installation of the
directory in favor of an isolated PEP 517/518 build environment. The
minimum version of tox has been bumped to one that has PEP 518 support.
2019-04-25 07:06:29 -04:00
Paul Ganssle c3fee87dee
Add custom sdist command to modify Cargo.toml
This enables PEP 517 builds from an sdist, and should fix `tox` builds
using `pip >= 19.0`. This does not fix pip installing the directory;
pinning to `pip < 19.0` is still the best strategy for that.
2019-04-25 07:06:26 -04:00
Omer BenAmram f8bf258602 Support rust extensions for PyPy via cpyext (#393)
* wip

* removed stuff

* removed another change

* implemented minimum amouth of ifdefs to make pypy3 hello world to compile

* implemented minimum amount of ifdefs to make pypy3 hello world to compile

* hacking on build.rs

* compiler is happy!

* few todos remain

* extracted build logic to seperate module

* added pypy test

* finally fixed pypy structs

* removed some todos

* test should now be machine independent

* fixed all pypy3 symbols

* added pypy feature

* removed `is_pypy`

* added pypy2 declerations also

* fix for cpython2

* improved libpypy detection

* added all pypy2 macros

* fixed errneous type

* more fixes

* fix python2 string macros

* modsupport symbol

* fix

* fixed and added many symbols

* fixes

* remove dup

* remove mac-specific config

* fix all name mangling macros

* unite imports

* missing symbol

* fix pybool

* implemented another missing symbol

* it works

* fix merge conflict

* uncomment non default features

* cargo.toml

* Cargo fmt

* small merge fixes

* use newer build version

* whoops

* fix build script

* more build hacks

* some random hiccups

* small fixes

* it builds!

* it builds and runs

* revert everything in FFI2

* revert changes to ffi2

* check python3 for pypy

* tiny fix

* revert ffi2 for real

* revert weird formatting changes

* bring back missing feature

* tiny error

* fix py3.7 issue

* add pypy3.5 6.0 to travis

* remove dbg!

* another tiny fix

* removed some useless annotations, and fixed inlines annotations

* removed `pretty_assertions`

* removed pypy feature from cargo.toml

* fix for Py_CompileStringFlags

* tox runs word_count!

* __dict__ changes are not supported for PyPy

* fix 3.7 and copy comment

* fix test script 😳

* transfer ownership of strings to cpython when possible

* remove cstr! macro

* added missing nuls

* as_bytes() -> b’’ string

* symbol removed by mistake

* properly shim pypy date time API, some tests are passing!

* extension_module tests now not crashing! (some still skipped)

* maybe travis has new pypy version?

* small error on windows (build script)

* fix conditional compilation

* try to make tests run on travis..

* invert condition

* added pytest-faulthandler to facilitate debugging

* correctly name dir

* use full paths

* say —yes to conda

* fix

* syntax error

* change PATH

* fixed a terrible bug with PyTypeObjects in PyPy

* fix PyTypeObject defs

* re-enabled tests!

* all tests are passing!

* make the fix ad-hoc for now

* removed build module

* revert changes that cause an additional GC bug

* prevented buggy test from failing pypy

* removed unused comment

* don’t run coverage on pypy

* removed some erroneous symbols from function calls which are actually macros

* restore py37 pyunicode missing def

* use only `link_name` in PyPy specific declarations

* only setup PyPy when testing against PyPy

* annotation that was eaten during merge

* remove change to  comment by mistake + unnecessary changes to cargo.toml

* xfail dates test only on pypy

* changed comment to be a little more helpful

* cleaned up some warnings

* Update src/ffi3/ceval.rs

Co-Authored-By: omerbenamram <omerbenamram@gmail.com>

* @konstin PR notes

* rustfmt

* some documentation

* if configured via env var only, default to cpython

* remove extra unsafe

* refer users to guide for pypy

* Update guide/src/pypy.md

Co-Authored-By: omerbenamram <omerbenamram@gmail.com>

* Update guide/src/pypy.md

Co-Authored-By: omerbenamram <omerbenamram@gmail.com>

* @konstin applied patch

* check that pypy at least build

* search explicitly for libpypy

* added note about some known unsupported features

* use ld_version

* export PYTHON_SYS_EXECUTABLE to `cargo build` test

* inverted if

* always link pypy dynamically

* remove unused imports

* Apply @kngwyu’s suggestion

* fix tox configuration

* try conda virtualenv

* try to simply not install python at all inside pypy environment

* setup pypy before using “python"

* use system_site_packages

* revert change to .travis

* moved cpyext datetime documentation to module level, and revised it.

* Update src/ffi/datetime.rs

Co-Authored-By: omerbenamram <omerbenamram@gmail.com>

* rustfmt

* Update src/ffi/datetime.rs

Co-Authored-By: omerbenamram <omerbenamram@gmail.com>

* kept only notes that are relevant to users.

* invert if

* use bash and not sh
2019-04-23 13:18:42 +02:00
ijl 2bb0d05a30 Drop support for python2 2019-03-29 12:37:26 +00:00
Alisa Dammer 0ec6603b7a
Remove unrequired encoding header
This is not required anymore for Python 3.
2019-03-03 18:14:12 +01:00
konstin 6cd07c369c Simpler new and clippy fixes 2019-02-23 18:38:00 +01:00
konstin d02f7c3aa5 Big proc macro refactoring
* Removed a lot of clutter, unified some code
 * Started using syn::parse::Parse for pyfunction attributes 
 * No more newlines between imports
 * Renamed `#[prop(get, set)]` to `#[pyo3(get, set)]`
 * `#[pyfunction]` now supports the same arguments as `#[pyfn()]`
 * Some macros now emit proper spanned errors instead of panics.
2019-02-18 20:07:56 +01:00
konstin 6cb098ee12 Replace py.init_[ref|mut] with Py[Ref|Mut]::new 2019-02-13 21:52:21 +01:00
konstin 1a489d2829 Make the init methods use a value instead of a function 2019-02-13 13:59:47 +01:00
konstin c868cc3e4b Fix test 2019-02-01 16:31:18 +01:00
konstin 56f2257e90 rust 2018 fixes 2019-02-01 16:23:34 +01:00
konstin ae8a37cd0a Allow 0..n pymethod blocks without specialization 2019-02-01 16:23:34 +01:00
konstin 936f0153e8 Migrate to rust 2018 2019-02-01 14:23:29 +01:00
Joar Wandborg 8e4d23e470
Pass posargs to pytest command, skip redundant install 2019-01-09 22:00:29 +01:00
konstin b9f9580751
Fix #314 2018-12-28 20:29:12 +01:00
konstin 9c8c5a6063 Rename #[pymodinit] to #[pymodule] 2018-11-15 19:43:29 +01:00
konstin 863ffb161f Add wrap_module macro 2018-11-15 19:43:29 +01:00
kngwyu 1081ba9447 Fix import module name in test_dict_iter 2018-11-13 11:50:13 +09:00
kngwyu 3b01b8f6ba Review fixes 2018-11-13 00:53:06 +09:00
kngwyu 34099b33f8 Fix PyDictIterator's segfault(for #159) 2018-11-13 00:25:54 +09:00
konstin 57afb51604 Remove PyToken completely; Fixes #94 2018-11-12 14:42:21 +01:00
konstin d2ba436d6d Remove the unnecessary type parameter PyObjectAlloc 2018-11-12 14:37:06 +01:00
konstin c77049541a Fix CI
black requires 3.6+ to be installed
2018-11-11 18:13:33 +01:00
konstin 9f45efebaf Format 2018-11-11 12:25:53 +01:00
konstin a9b05711b0 Add test to fix #220 2018-11-11 12:24:24 +01:00
kngwyu bd6f923f43 Fix #240 2018-11-09 13:11:47 +09:00
Yuji Kanagawa ecae8544f4
Merge pull request #262 from kngwyu/pganssle-tzinfo_subclass_introspection
Skip failing test of #239
2018-11-08 18:34:46 +09:00
kngwyu 9ae2f1f7f5 Skip failing test 2018-11-08 18:13:44 +09:00
konstin 4da9110489 Add tox config for word-count 2018-10-09 18:21:52 +02:00
Hanaasagi 92119d195a remove meaningless __future__.absolute_import 2018-10-09 23:26:28 +09:00
Hanaasagi eb6e7a2c2a use pytest directlly instead of python -m pytest 2018-10-09 23:24:36 +09:00
Paul Ganssle 7abd436a0d
Add tests for othermod
This adds othermod to the rustapi_module extension and tests the
contents of the module.
2018-09-29 10:28:32 -04:00
Paul Ganssle f847974c06
Add failing test for TzClass introspection
Currently accesing `tzi.__class__` causes a segmentation fault
2018-09-28 18:10:50 -04:00
Paul Ganssle 2fa3b942f2 Add failing test to create tzinfo subclass
Currently this fails at import time with undefined symbol:
PyDateTime_TZInfoType
2018-09-28 23:56:57 +09:00
konstin ed2739829f Fix the other part from #231 2018-09-27 01:44:17 +02:00
konstin 78a5053b22 Fix #231 2018-09-27 01:11:31 +02:00