Commit Graph

191 Commits

Author SHA1 Message Date
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
konstin 05874d3f1a Fix tests 2018-09-27 01:11:31 +02:00
konstin c1cb5ca74f Use `::std` to fix #233 2018-09-27 00:55:45 +02:00
konstin 302c099a76 Big refactoring to shrink the prelude 2018-09-21 23:34:28 +02:00
konstin 0372360811 Add test for #219 2018-09-17 19:47:23 +02:00
Paul Ganssle 265a6802d7
Enable extension-module 2018-08-21 18:33:34 -04:00
Paul Ganssle c69634e0fd
Remove use_extern_macros, which is now stable 2018-08-21 18:33:34 -04:00
Paul Ganssle a05a78f7e0
Use smallest types for Py{Date}{Time} constructors
Because it's unlikely that anything other than the `year` parameter will
change in the C Python API, the rest can be restricted to their logical
ranges, which improves the compile-time error checking.
2018-08-21 18:33:33 -04:00
Paul Ganssle 5d5689f95b
Switch Py{Date}{Time} constructor parameters to i32
While the valid ranges for the constructor parameters is the same when
expressed as either u32 or i32, since the Python API uses i32 in their
public interface, we won't have to make any changes to the signatures if
the Python behavior changes (e.g. supporting negative years) without
their API changing.
2018-08-21 18:33:33 -04:00
Paul Ganssle 113de1bcd3
Drop setup_requires from rustapi_module
The PEP 518 way to do this is with pyproject.toml. tox doesn't support
PEP 518 yet, but we get around that by using pip install -e . as part of
the tox build until PEP 518 support arrives in tox.
2018-08-21 18:33:33 -04:00
Paul Ganssle 078bea4345
Move rustapi_module into examples
This is really a test module, but the Rust convention is to put
something like this under examples/, and when it lands, we can take
advantage of "Project-based Examples for Cargo Projects" - RFC link
at https://github.com/rust-lang/rfcs/pull/2517
2018-08-21 18:33:33 -04:00
konstin 991a8b94d2 More nightly fixes 2018-08-19 20:42:17 +02:00
konstin d0ed68414a Many small improvements 2018-08-04 19:56:59 +02:00
konstin fe8a719ee1 Rustfmt all the things ✔️ 2018-07-30 23:05:10 +02:00
konstin 83db765889 Refactoring 2018-07-30 22:56:25 +02:00
dependabot[bot] 026b32e64c
Update rayon requirement to 1.0
Updates the requirements on [rayon](https://github.com/rayon-rs/rayon) to permit the latest version.
- [Release notes](https://github.com/rayon-rs/rayon/releases)
- [Changelog](https://github.com/rayon-rs/rayon/blob/master/RELEASES.md)
- [Commits](https://github.com/rayon-rs/rayon/commits/v1.0.2)

Signed-off-by: dependabot[bot] <support@dependabot.com>
2018-07-27 15:16:28 +00:00
konstin 2627fa8a08 0.3.2 2018-07-22 21:36:18 +02:00
konstin d59bebcc38 Upgrade from proc_macro to use_extern_macros 2018-07-18 13:08:05 +02:00
konstin 2ffa302a8d Fix module name in word_count_cls 2018-07-10 00:30:44 +02:00
konstin fe931a594f #[pymodinit] now uses the function name as default module name 2018-07-10 00:13:02 +02:00
konstin 4013d40897 Add `py` prefix to the proc macros and move them into the root module
This is important because `proc_macro_path_invoc` isn't going to be stabilized soon.
2018-07-08 23:33:48 +02:00
konstin 562d417517 Fix bug which made code generation dependend on argument ordering 2018-07-06 12:56:40 +02:00
konstin 6645708e4f Get rid of #[py*] methods 2018-07-03 20:42:02 +02:00
konstin fd6ab73924 Upgrade to syn 0.14: Useful error messages 🎉 2018-06-15 22:41:16 +02:00
konstin 373d0cf5f4 rustfmt the examples 2018-06-15 21:23:18 +02:00
konstin f2be73c4f3 Fix tests 2018-06-14 16:20:55 +02:00
konstin 76510bdd0e Refactoring
This is actually a failed bugfix attempt, but still useful
2018-06-13 18:02:45 +02:00
konstin 319afe1f76 Small documentation improvements 2018-05-17 23:59:38 +02:00
konstin d0c42dfcc1 Fix compilation on nightly 2018-05-01 15:44:38 +02:00
James Johnson 8844502775 Syntax error in README changes.
see #126
2018-02-26 15:05:31 -06:00
James Johnson a923f8b5d3 Synchronizes word-count-cls example README and code.
see #126
2018-02-26 15:03:29 -06:00
Nikolay Kim 96ad2efddf do not use workspaces 2018-01-19 10:18:57 -08:00
Nikolay Kim c39a1d7e94 Add examples to workspace 2018-01-19 10:10:32 -08:00
Nikolay Kim 050397b723 mark method that work with raw pointer unsafe 2017-12-26 13:41:27 -08:00
Nikolay Kim e5bf656cbc revert pycls changes; fix word-cound-cls example 2017-11-18 07:20:03 -10:00
Nikolay Kim 9d56fd279a enable const_align_of future 2017-11-18 07:07:45 -10:00
Nikolay Kim c44e23f4b9 add prelude mod 2017-07-31 10:42:55 -07:00
Nikolay Kim dcaa3130d9 make word count example with class 2017-07-27 13:09:56 -07:00
Nikolay Kim 823054052d update word count example 2017-07-26 09:18:50 -07:00
messense 43a5d6f1b4 Test and benchmark word-count example (#60)
* Test and benchmark word-count example

* Optimize rust word_count
2017-07-26 12:37:36 +08:00
Nikolay Kim 9aa05daf08 fix name 2017-07-23 10:54:52 -07:00
messense 54a87aacdf
Add a word count example 2017-07-23 13:32:18 +08:00
Nikolay Kim 3bb7a64db5 drop python27 2017-05-12 19:59:20 -07:00
Daniel Grunwald f6ed2bbae9 Fix #10: Windows support.
We keep the #[link] attributes in #[cfg_attr(windows)] so that we don't require a nightly Rust build on non-Windows platforms.
This can be simplified once RFC 1717 is available in a stable rust version.

This commit also increases the minimum Rust version to 1.13.
2016-12-17 15:46:52 +01:00
Daniel Grunwald 0a270a0583 Put Python argument at beginning of argument list.
Closes #33.
2015-10-26 23:52:18 +01:00
Daniel Grunwald 44611991c3 Remove 'p lifetime from PyObject (#15)
Since the `Python` token no longer is a part of `PyObject`,
lots of methods now require the token as additional argument.

This [breaking-change] breaks everything!
2015-10-25 17:55:29 +01:00
gentoo90 a785ba87a9 Add an example of calling a python function from rust 2015-07-27 21:56:59 +03:00
Daniel Grunwald 1e5605036e Update documentation 2015-04-19 00:39:04 +02:00
Daniel Grunwald 5a303789b9 Don't export cstr! macro 2015-04-18 22:20:19 +02:00
Daniel Grunwald f8e24a870c Add support for exposing rust functions to python 2015-04-18 20:17:25 +02:00