Commit graph

3717 commits

Author SHA1 Message Date
Gregory Szorc 3957afc9c5 pyo3-build-config: conditionalize symbols on resolve-config feature
PR #1856 was buggy in that the `pyo3-build-config` crate didn't actually
work in library mode because `include_str!()` was attempting to resolve
missing files as part of populating some `const` values.

We could change the logic of these constants to make them lazy if
we wanted to support possibly getting access to the value. But the
simple solution is to conditionalize their presence on the crate
feature.

Test coverage for building and testing the crate in insolation with the
feature disabled has been added.

Various code has been conditionalized to avoid compiler warnings.

Also, it appears `cargo build|test -p pyo3-build-config
--no-default-features` still passes default features. This seems wrong
to me. But it is how my system behaves. Maybe it is an sccache bug?
I coded the new tests to `cd pyo3-build-config` first to work around.
2021-09-02 17:18:55 -07:00
David Hewitt afd4d46bdb
Merge pull request #1856 from indygreg/build-config-feature
pyo3-build-config: add a crate feature to control build script
2021-09-02 21:45:34 +01:00
David Hewitt 812c518c65
Merge pull request #1854 from davidhewitt/cargo-llvm-cov-0.1.5
ci: use cargo-llvm-cov 0.1.5
2021-09-02 21:19:44 +01:00
Gregory Szorc 1e951d5d8b pyo3-build-config: add a crate feature to control build script
I have a use case in PyOxidizer where I want to use the
pyo3-build-config crate as a library crate so I can access the
`InterpreterConfig` struct so I can read/write config files without
reinventing the wheel.

This is doable before this commit. But it requires that the
build environment have a Python interpreter. This is undesirable
for library usage.

This commit introduces a cargo feature flag to control whether the
build script does anything. The feature flag must be present for
the build script to resolve a config. The feature flag is enabled
by default for backwards compatibility. The pyo3 and pyo3-macros-backend
crates use this feature by default, for backwards compatibility and
because it is the reasonable default.

This is probably room to conditionalize some APIs and other behavior
based on this feature flag. But we stop short of doing that for
the time being.
2021-09-01 19:44:54 -07:00
David Hewitt 10039393c1 ci: use cargo-llvm-cov 0.1.5 2021-09-01 20:35:53 +01:00
David Hewitt 921c4410ce
Merge pull request #1849 from PyO3/pylist_apis
PyList: add more sequence APIs
2021-09-01 08:50:49 +01:00
David Hewitt 7d40461dcf
Merge pull request #1847 from davidhewitt/test-parse-sysconfigdata
pyo3-build-config: add test for parsing sysconfigdata
2021-09-01 08:50:29 +01:00
David Hewitt c6a268a339
Merge pull request #1852 from PyO3/revert-1838-pin-parking-lot-msrv
Revert "ci: pin parking_lot to 0.11.1 on MSRV"
2021-09-01 08:48:21 +01:00
David Hewitt a8ff8ddab4
Merge pull request #1853 from indygreg/build-flags-clone
pyo3-build-config: derive Clone on BuildFlags
2021-09-01 08:47:36 +01:00
Gregory Szorc 05815bf861 pyo3-build-config: derive Clone on BuildFlags
This isn't strictly necessary since you can `.0.clone()`. But it is
more ergonomic.
2021-08-31 18:47:58 -07:00
mejrs 5c4b5979a8
Revert "ci: pin parking_lot to 0.11.1 on MSRV" 2021-09-01 02:45:24 +02:00
David Hewitt 4a6ea17959 pyo3-build-config: add test for parsing sysconfigdata 2021-08-31 22:29:02 +01:00
David Hewitt 5e8d43c8bd
Merge pull request #1848 from indygreg/public-interpreter-config
pyo3-build-config: make InterpreterConfig public
2021-08-31 22:21:28 +01:00
David Hewitt 44c0287274
Merge pull request #1793 from indygreg/build-settings
Build configuration settings to facilitate complete link control
2021-08-31 22:20:50 +01:00
David Hewitt 868f668201
Merge pull request #1819 from indygreg/links-python
cargo: add `links = "python"`
2021-08-30 22:22:56 +01:00
David Hewitt e06f5b9592
Merge pull request #1850 from davidhewitt/fix-s390x
ci: check and fix s390x build
2021-08-30 22:20:54 +01:00
Gregory Szorc c9c606f7c6 build: enable suppression of cargo:rustc-link-* lines
PyOxidizer requires advanced control over the settings used to link
libpython. We recently implemented support for configuration files
defining explicit lines to emit from build scripts to give callers
control over what lines to emit from build scripts so use cases
like PyOxidizer's are feasible without hacks in PyO3's code base.

However, the default logic in `emit_link_config()` may not be
appropriate in scenarios where link settings are provided via this
"extra lines" mechanism. The default logic may prohibit use of or
interfere with desired settings provided externally.

This commit defines a new field on the interpreter config that
suppresses the emission of the default link control logic from the
`pyo3` build script. It effectively gives advanced consumers like
PyOxidizer full control over link logic while minimally polluting
PyO3's build logic.

I thought about implementing this control as a crate feature. But
given the expected target audience size of ~1, I thought a crate
feature was too visible for a power user feature and decided to
implement it via the configuration file.
2021-08-30 10:01:36 -07:00
Gregory Szorc 04c77e35c5 build: support emitting arbitrary lines from pyo3 build script
PyOxidizer needs to do some... questionable things with regards to
configuring how the Python interpreter is linked. The way I solved this
problem for the `cpython` / `python3-sys` crates was by adding a bunch
of crate features to control what `cargo:` lines were emitted by the
build scripts. This added a lot of complexity to the those crates for
a target audience of ~1.

Now that PyO3 has support for config files to control settings, this
provides a richer mechanism than crate features to influence the build
script.

This commit defines a new field on the `InterpreterConfig` struct to
hold an arbitrary list of strings/lines that should be emitted by
the build script. This field is only every populated when parsing config
files and it is only read by pyo3's build script to `println!()`
additional values.

My intended use case for this is to have PyOxidizer effectively control
the interpreter link settings via the config file (at my own peril)
while having minimal impact on the maintainability of PyO3's code base.
Given the complexity of the link hacks employed, you probably don't want
this polluting pyo3's code base.
2021-08-30 09:52:11 -07:00
Gregory Szorc 82d9b44f5e cargo: add links = "python"
PyOxidizer has crates depending on `pyo3` that would like to access
the `pyo3` crate configuration. (This use case isn't unique to
PyOxidizer.)

Cargo has a facility for enabling the build scripts of dependent
crates to access _exported_ variables via `DEP_` environment
variables. However, this only works if the exporting crate defines a
`links` key in its Cargo manifest. See
https://doc.rust-lang.org/cargo/reference/build-scripts.html#the-links-manifest-key.

While `pyo3`'s build script doesn't yet export the variables that
PyOxidizer will need, a prerequisite to making this work is adding
the `links` key. Since this change could introduce unintended
side-effects, it warrants being made in its own commit, which is
why we're making this change outside of #1793.

I _think_ this change should be mostly safe: the `links` key is
effectively metadata advertising that a crate links against a named
library. The only side-effects setting it has is to enable the
aforementioned `DEP_` environment variables in build scripts and
enforcing a limitation that only a single crate may link against the
same native library. I believe the only potential for this change
to cause problems is if there are multiple crates with `links =
"python"` entries. I'm not aware of any other crates that advertise
`links = "python"`: even `python3-sys` / `cpython` use `links =
"python3"` so this change should not prevent dual use of `pyo3` and
`cpython` in the same build.
2021-08-30 09:47:54 -07:00
Gregory Szorc 62e134242d pyo3-build-config: make interpreter config and references types public
PyOxidizer will want to create interpreter config files. Rather
than reinvent the logic for reading/writing these files, I think
it makes sense to consume the `pyo3-build-config` crate so we can
use the `InterpreterConfig` type directly. But the symbol needs
to be public to allow us to do that. And in order to allow direct
construction, we need to make all the types referenced by its fields
public as well.
2021-08-30 09:45:37 -07:00
David Hewitt a20864a903 ci: test and fix s390x build 2021-08-30 13:50:44 +01:00
Georg Brandl af46bf3bc6 PyList/Tuple: add more sequence APIs
See #1845
2021-08-30 12:19:31 +02:00
David Hewitt b7c62b8a53
Merge pull request #1846 from davidhewitt/changelog-release-0.14.4
changelog: updates for 0.14.4
2021-08-30 08:19:53 +01:00
David Hewitt f4c834f5fc
Merge pull request #1843 from PyO3/pymethods_hygiene
more macro hygiene cleanup: test #[pymethods] and more arg parsing and protos
2021-08-29 11:26:10 +01:00
David Hewitt 5119bad580 changelog: updates for 0.14.4 2021-08-29 08:07:44 +01:00
Georg Brandl 381eb9c501
Apply suggestions from code review
Co-authored-by: mejrs <59372212+mejrs@users.noreply.github.com>
2021-08-29 08:30:05 +02:00
David Hewitt 95a11d0725
Merge pull request #1842 from PyO3/frompyobject_hygiene
more macro hygiene cleanup: test the FromPyObject derive macro
2021-08-29 07:15:16 +01:00
David Hewitt 604b28451b
Merge pull request #1841 from PyO3/exception_hygiene
more macro hygiene cleanup: test the exception macros
2021-08-29 07:14:36 +01:00
David Hewitt 3219c89f10
Merge pull request #1746 from davidhewitt/doc-attributes-1.54
pyo3-macros-backend: support macros inside doc attributes
2021-08-29 07:12:58 +01:00
David Hewitt f76535fd07 pyo3-macros-backend: support macros inside doc attributes 2021-08-28 22:47:20 +01:00
Georg Brandl 6f75fc8eb7 more macro hygiene cleanup: test #[pymethods] and more arg parsing and protos 2021-08-28 18:05:32 +02:00
Georg Brandl 585487c3c1 more macro hygiene cleanup: test the FromPyObject derive macro 2021-08-28 16:42:29 +02:00
Georg Brandl b795cb2c14 class: hygiene cleanup 2021-08-28 15:47:28 +02:00
Georg Brandl db00a34a56 more macro hygiene cleanup: test the exception macros 2021-08-28 15:45:49 +02:00
David Hewitt 3fa97f9086
Merge pull request #1840 from hongquan/feature/more-specific-oserror
Convert io::Error to more specific Python OSError
2021-08-28 14:28:30 +01:00
David Hewitt a6d6367241
Merge pull request #1837 from davidhewitt/more-proc-macro-hygiene
pyo3-macros-backend: more tests for macro hygiene
2021-08-28 14:14:47 +01:00
Nguyễn Hồng Quân b721a45ff9 Convert io::Error to more specific Python OSError 2021-08-28 17:25:35 +07:00
David Hewitt 313610993a pyo3-macros-backend: more tests for macro hygiene 2021-08-28 10:28:27 +01:00
David Hewitt 667865e2d7
Merge pull request #1838 from davidhewitt/pin-parking-lot-msrv
ci: pin parking_lot to 0.11.1 on MSRV
2021-08-28 08:59:59 +01:00
David Hewitt 99f95a2eaf ci: pin parking_lot to 0.11.1 on MSRV 2021-08-28 08:17:28 +01:00
David Hewitt cf0e8a6435
Merge pull request #1830 from deantvv/ffi-cleanup-0825
ffi cleanup: pystrtod to pythonrun
2021-08-28 07:23:47 +01:00
David Hewitt 9c03227a20
Merge pull request #1833 from davidhewitt/changelog-function-brackets
changelog: remove function parentheses
2021-08-27 22:57:41 +01:00
David Hewitt 86dacd47c7
ffi: add some PyPy cfgs 2021-08-27 22:57:02 +01:00
Dean Li a8cc9c37d5
fixup! ffi: cleanup pythonrun 2021-08-27 23:54:27 +08:00
Dean Li 73220565c1
update changelog 2021-08-27 23:36:59 +08:00
Dean Li 72b8ffc588
ffi: cleanup pythonrun
Move multiple limited api to cpython. Many API in `pythonrun` are
removed in python 3.10.

There is also some function and macro share the same name (documented
below) in cpython, which I choose to skip macro definition.
- PyRun_String
- PyRun_AnyFile
- PyRun_AnyFileEx
- PyRun_AnyFileFlags
2021-08-27 23:36:58 +08:00
Dean Li d62f568ffb
ffi: cleanup pystrtod 2021-08-27 22:50:01 +08:00
messense 868c591c18
Merge pull request #1834 from davidhewitt/pystring-data-big-endian
pystring: disable `PyString::data` on big-endian targets
2021-08-27 09:41:57 +08:00
David Hewitt 755dd221e7 pystring: disable PyString::data on big-endian targets 2021-08-26 19:29:58 +01:00
David Hewitt 4a50a26c87 changelog: remove function parentheses 2021-08-26 18:59:07 +01:00