Commit Graph

631 Commits

Author SHA1 Message Date
Paul Ganssle 26c5397618
Implement Debug for PyObject in Python 2
For whatever reason I cannot build rustapi_module without this, and
rather than figure out the core problem, I figured that, for symmetry,
it makes sense to just implement Debug for PyObject.
2018-08-21 18:33:32 -04:00
Paul Ganssle cf3b1d2cc3
Remove leading __ from private cache objects
These were basically cargo culted from lazy_static's implementation, but
they are not idiomatic or necessary to indicate that these are private
variables.
2018-08-21 18:33:32 -04:00
Paul Ganssle a271ba9ed9
Use unified implementation for ffi::datetime
In the future we can make ffi::object, ffi::pycapsule, etc as
crate-public, but importing the specific symbols is a light touch way to
do this.
2018-08-21 18:33:32 -04:00
Paul Ganssle 3357fabb35
Remove 'Component' from ComponentAccess Traits 2018-08-21 18:33:32 -04:00
Paul Ganssle f68d0932f4
Unwrap PyDateTime_CAPI function fields
Because the PyDateTime_CAPI is always accessed via a lazy-initialized
static reference, it is not necessary to handle the case where the
functions on the C struct have not been initialized.
2018-08-21 18:33:32 -04:00
Paul Ganssle bcc27bd522
Change datetime constructors to use Rust Option
This makes it cleaner to call PyTime::new and PyDateTime::new from Rust
without needing to retrieve a Python None.
2018-08-21 18:33:32 -04:00
Paul Ganssle bcc42315ff
Inline parameter typecasts
Clippy complains about the one-letter variables, but it's preferable to
do the typecasts in-line anyway.
2018-08-21 18:33:31 -04:00
Paul Ganssle 94bd0d7b6d
Relax constraints on PyDateTimeAPI initialization
As noted in the comments, using call_once to initialize the
PyDateTimeAPI singleton is causing deadlocks with the GIL; these
deadlocks can be avoided by falling back on CPython's own locking
behavior.
2018-08-21 18:33:28 -04:00
konstin 771d59b913 Fix another bunch of clippy lints 2018-08-21 23:51:13 +02:00
Paul Ganssle 12c20a75d9
Move datetime interface to exclusively use functions 2018-08-21 14:29:36 -04:00
Paul Ganssle ee658de1fb
Run rustfmt after datetime changes
Most of the datetime related changes were made before pyo3 switched to
using rustfmt, so I ran rustfmt only on the final commit to make it
easier to rewrite history as necessary (for fixups and whatnot).
2018-08-21 14:29:36 -04:00
Paul Ganssle 996c2baec8
Add preliminary Python 2 support to datetime bindings
The bounds checking tests are xfail because the datetime "fast path"
constructor didn't do bounds checking until bpo-29100 was resolved in
CPython commit b67f0967386a9c90411, which was merged for Python 3.6.

This functionality should be simple to backport to earlier versions in a
future commit.

BPO issue:
https://bugs.python.org/issue29100

CPython commit:
b67f096738
2018-08-21 14:29:36 -04:00
Paul Ganssle cd6f7295a1
Add type checking FFI bindings 2018-08-21 14:29:36 -04:00
Paul Ganssle f701bccbdf
Add PyTime component accessors 2018-08-21 14:29:36 -04:00
Paul Ganssle ecf3aaafb2
Add PyDateTime component accessors 2018-08-21 14:29:35 -04:00
Paul Ganssle 0b39452276
Add accessors to PyDateTime_Date 2018-08-21 14:29:35 -04:00
Paul Ganssle 08e7e0f55a
Add PyDelta component accessors
Adds the PyDateTime_DELTA_GET_{comp} accessors and bindings to them in
the PyDelta object.
2018-08-21 14:29:35 -04:00
Paul Ganssle f47697e2b5
Refactor pyobject_* macros
See 8c26020015 for general change.
2018-08-21 14:29:35 -04:00
Paul Ganssle f5e0785654
Add time_with_fold 2018-08-21 14:29:35 -04:00
Paul Ganssle c49bbe4549
Add PyDateTime::from_timestamp 2018-08-21 14:29:34 -04:00
Paul Ganssle 7256bc85b7
Add PyDate::from_timestamp 2018-08-21 14:29:34 -04:00
Paul Ganssle e8d6a4bcc0
Version qualify PyDateTimeAPI 2018-08-21 14:29:34 -04:00
Paul Ganssle 8d781cb03f
Add datetime.timedelta 2018-08-21 14:29:34 -04:00
Paul Ganssle f45362943d
Add datetime.time 2018-08-21 14:29:34 -04:00
Paul Ganssle d7b90c1b3a
Add datetime.datetime and switch to PyResult<Py<T>> 2018-08-21 14:29:34 -04:00
Paul Ganssle 496b879525
Add objects/datetime.rs 2018-08-21 14:29:33 -04:00
Paul Ganssle 2b74cdbd57
Add initial bindings for datetime.h 2018-08-21 14:29:31 -04:00
konstin 82129c70b4 Added an explenation that the GIL can temporarily be released even while holding a GILGuard 2018-08-20 22:56:24 +02:00
konstin db4a2d9017 Get rid of the pyobject_extract macro 2018-08-20 22:53:43 +02:00
konstin 991a8b94d2 More nightly fixes 2018-08-19 20:42:17 +02:00
konstin b12b65cfae Cleanup 2018-08-19 20:06:47 +02:00
kngwyu ff2871f325 Remove unnecessary feature gates from doc tests 2018-08-14 18:29:15 +09: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
konstin d9d1650fc4 Fix #197 - Remove tuple to dict conversions 2018-07-30 22:52:36 +02:00
konstin 27633da3b1
Merge pull request #191 from milesgranger/master
Python::run should return PyObjectRef result
2018-07-30 17:49:57 +02:00
Miles Granger a13b79459f Return PyObjectRef result from Python::run 2018-07-29 22:00:36 +02:00
kngwyu 5e1ce01251 Enable generics parameter in pyobject_native_type! 2018-07-28 14:46:00 +09:00
konstin 2627fa8a08 0.3.2 2018-07-22 21:36:18 +02:00
konstin ff70f45071 (Hopefully) get travis to build the guide for tags 2018-07-18 23:28:14 +02:00
konstin 3adcac6e61 Replace concat_idents with mashup 2018-07-18 23:17:05 +02:00
konstin 7d4381fc5d Fixed scoping bug in pyobject_native_type that would break rust-numpy 2018-07-18 14:06:17 +02:00
konstin d59bebcc38 Upgrade from proc_macro to use_extern_macros 2018-07-18 13:08:05 +02:00
konstin eb613c64d9 Add repr(transparent) where applicable 2018-07-13 18:10:09 +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 68c14a5707 Merge branch 'master' of https://github.com/PyO3/pyo3 2018-07-03 21:55:43 +02:00
konstin 28d6c9986c Fix clippy errors 2018-07-03 21:32:16 +02:00
konstin 43eb5fa490 Rename prepare_pyo3_library to init_once 2018-07-03 21:12:57 +02:00
konstin 6645708e4f Get rid of #[py*] methods 2018-07-03 20:42:02 +02:00
kngwyu 7d7c1ede49 Modify pyobject_native_type to take expr
To use deref(*) expression
2018-07-02 16:31:36 +09:00
kngwyu 41f4d1d673 $crate::std to ::std
So that we can use these macros in outer crates
2018-07-02 00:06:08 +09:00
kngwyu 70e1879d59 Make python pub 2018-07-02 00:06:01 +09:00
kngwyu 3ec49b586f Modify pyobject_native_type to take path instead of ident
So that we can use this macro outside this crate.
2018-07-01 23:51:56 +09:00
konstin f9ff7cd465 Ignore test because of a docmatic bug
See https://github.com/assert-rs/docmatic/issues/4
2018-06-15 15:59:22 +02:00
konstin 1301394264 Fix c string conversion in python 2 2018-06-15 15:57:59 +02:00
konstin 7a52bf647c Apply fixes by Philip Molloy 2018-06-14 16:03:05 +02:00
konstin 54b09c704b Fix -Z minimal-versions 2018-06-06 21:18:42 +02:00
kngwyu 66183d4683 Move common functions and macros from num2&num3 to num_common 2018-06-06 01:31:40 +09:00
kngwyu 0b964b503f Rename args of _PyLong_FromByteArray/_PyLong_AsByteArray 2018-06-05 23:03:53 +09:00
kngwyu 9ffbae30ab Add 128bit integer support for python2 2018-06-02 22:10:13 +09:00
kngwyu a87ddeab21 Add 128bit integer support for python3 2018-06-02 22:08:29 +09:00
kngwyu 4795a35143 impl IntoPyDictPointer for IntoIterator<Item=(K, V)>
this commit has 2 purposes:
1. Avoid duplication of implementation(for BTreeMap & HashMap)
2. Enable conversion from Vec<(K, V)> to PyDict
2018-05-30 16:26:23 +09:00
Kevin Phillips 9544adaf1d Marked from_code on PyModule to only work with Python 3. It could work with Python 2 if you call, for example, Py_CompileStringFlags and pass std::prt::null_mut() as the last argument and when calling PyImport_ExecCodeModuleEx passing mutable pointers for the first and last arguments. I also added a test for this to test_module.rs 2018-05-21 16:03:21 +02:00
Kevin Phillips 1b1121e558 Added a function to PyModule to load a module from a string of Python 2018-05-21 16:03:20 +02:00
konstin c42b71bc55 Fix python2 2018-05-19 17:42:40 +02:00
konstin 314a4a2b3e Some more documentation work 2018-05-19 17:27:26 +02:00
konstin 46b9bd6a9f
Merge pull request #155 from PyO3/pyobject_macros
Refactor and Export Pyobject_* macros
2018-05-13 14:54:57 +02:00
konstin 5717463daf
Merge pull request #154 from konstin/capybara
Relax return types and add functions
2018-05-12 20:43:40 +02:00
Martin Larralde 416a7fd8d3
Export PyUnicode in Python3 as well 2018-05-08 12:54:21 +02:00
konstin d445d60e0a Export PyUnicode to fix #141 2018-05-08 10:42:17 +02:00
konstin cb5bae2c90 Export pyobejct_* macros
This is required for interaction with other native python extensions, e.g. numpy

Fixes #153
2018-05-07 23:47:23 +02:00
konstin 8c26020015 Refactor pyobject_* macros 2018-05-07 23:45:24 +02:00
konstin 858a124374 Merge master 2018-05-05 15:50:04 +02:00
konstin afcc87e82c Feature gate try_from
This was discovered https://github.com/PyO3/pyo3/issues/5#issuecomment-386579894
2018-05-05 14:43:37 +02:00
konstin 57048bc5fc Merge branch 'master' into capybara 2018-05-02 19:32:56 +02:00
konstin 15204bab56 Better way to add functions to modules 2018-05-02 19:26:54 +02:00
Martin Larralde cc352dade3 Fix `exception` tests failing with Python 2 2018-05-02 13:54:59 +02:00
Martin Larralde b80b85539b Remove occurrences of `py::methods` and `py::class` 2018-05-01 23:17:42 +02:00
konstin 0880ac166c Merge master 2018-05-01 20:41:35 +02:00
konstin d0c42dfcc1 Fix compilation on nightly 2018-05-01 15:44:38 +02:00
konstin 6113428746 Allow defining functions outside of the module declarations
This commit consists of
 * a proc macro to convert rust functions into python functions (`#[function]`),
 * a macro to register a function in a module (`add_function_to_module!`)
 * Documenting both the old and the new way in the book
2018-04-30 23:17:09 +02:00
konstin 1c0eac2690 Minor changes 2018-04-09 00:00:20 +02:00
konstin 45bb09b3e8 Relax return type requirements
Allows returning essentially arbitrary types by wrapping them into a PyResult. This is done with a conversion trait that specializes for PyResult.
2018-04-06 17:22:09 +02:00
Alexey Popravka e66c5ebb83 use PyTryFrom explicitly 2018-03-29 17:36:05 +03:00
Vlad Shcherbina 2aedbffcd0 Fix typos 2018-03-15 14:41:16 +03:00
Ethan Smith 5cc6dc74d4
conditionally include Python3.6 items 2018-03-01 14:46:27 -08:00
Ethan Smith 6c25a753b8
Add PEP 523 frame eval API things 2018-03-01 13:36:16 -08:00
Roy Wellington Ⅳ 11e2163bb4 Fix minor typos in example code 2018-02-22 22:22:37 -08:00
Martin Larralde e58cd1c585 Fix wrong macro being tagged with `macro_export` 2018-02-21 22:44:56 +01:00
Nikolay Kim 995ec109c3
Merge pull request #116 from althonos/master
Allow importing exceptions from nested modules
2018-02-21 10:35:11 -08:00
Nikolay Kim 057660e546 fix python3.7 support 2018-02-21 10:29:14 -08:00
Martin Larralde cce9d0de56 Allow importing exceptions from nested modules 2018-02-21 19:16:17 +01:00
Nikolay Kim d50d1fb7ea enable python3.7 builds 2018-02-21 10:06:48 -08:00
Nikolay Kim 0b9557a245 call_method*() crashes when the method does not exist #113 2018-02-21 09:39:06 -08:00
Nikolay Kim b7a8d25338 const fns that we use are stable now 2018-02-21 09:23:58 -08:00
Nikolay Kim 438f4bf091 ignore some python code in doc strings 2018-02-21 09:23:52 -08:00
Vlad Shcherbina a59e1dc8ad Fix unused_parens warnings
I left the parentheses in place to keep the resemblance
to the original C macros.
2018-02-12 14:36:05 +03:00
Vlad Shcherbina a5d3ed0939 Add tests that string/float to int conversions raise TypeError #108 2018-02-11 19:09:15 +03:00