Skip to content

Commit

Permalink
cargo update, build and tooling misc
Browse files Browse the repository at this point in the history
  • Loading branch information
ijl committed Nov 23, 2023
1 parent 399b36a commit ffb5a17
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
CC: "clang"
CFLAGS: "-O2 -fno-plt -flto=thin"
LDFLAGS: "-O2 -flto=thin -fuse-ld=lld -Wl,--as-needed"
RUSTFLAGS: "-C linker=clang -C link-arg=-fuse-ld=lld"
RUSTFLAGS: "-C linker=clang -C linker-plugin-lto -C link-arg=-fuse-ld=lld"
CARGO_UNSTABLE_SPARSE_REGISTRY: "true"
container:
image: quay.io/pypa/manylinux_2_28_x86_64:latest
Expand Down
36 changes: 18 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ci/azure-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ steps:
maturin build --release --strip --features=no-panic,yyjson --interpreter $(interpreter) --target=universal2-apple-darwin
env:
CC: "clang"
LDFLAGS: "-O2 -flto=thin -fuse-ld=lld -Wl,--as-needed"
LDFLAGS: "-O2 -flto=thin -Wl,--as-needed"
CFLAGS: "-O2 -fno-plt -flto=thin"
CFLAGS_x86_64_apple_darwin: "-O2 -fno-plt -flto=thin -march=x86-64-v2 -mtune=generic"
CFLAGS_aarch64_apple_darwin: "-O2 -fno-plt -flto=thin -mcpu=apple-m1 -mtune=generic"
Expand Down
10 changes: 8 additions & 2 deletions ci/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ build-std-features = ["panic_immediate_abort"]

[target.x86_64-apple-darwin]
linker = "clang"
rustflags = ["-C", "target-cpu=x86-64-v2", "-Z", "tune-cpu=generic"]
rustflags = [
"-C", "linker-plugin-lto",
"-C", "target-cpu=x86-64-v2",
]

[target.aarch64-apple-darwin]
linker = "clang"
rustflags = ["-C", "target-cpu=apple-m1"]
rustflags = [
"-C", "linker-plugin-lto",
"-C", "target-cpu=apple-m1",
]

[target.armv7-unknown-linux-gnueabihf]
rustflags = ["-C", "opt-level=s"]
Expand Down
4 changes: 2 additions & 2 deletions integration/wsgi.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

from datetime import datetime
from datetime import datetime, timezone
from uuid import uuid4

from flask import Flask
Expand All @@ -9,7 +9,7 @@

app = Flask(__name__)

NOW = datetime.utcnow()
NOW = datetime.now(timezone.utc)


@app.route("/")
Expand Down
13 changes: 7 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,21 @@ include = [
{ format = "sdist", path = "include/**/*" },
]


[tool.black]
line-length = 88
target-version = ["py38"]
include = ".pyi?$"

[tool.ruff]
line-length = 88
target-version = "py38"

select = [
"I",
]

ignore = [
"E501", # line too long
"F601", # Dictionary key literal ... repeated
]

[tool.ruff.lint.isort]
known-first-party = ["orjson"]

[tool.mypy]
python_version = "3.8"
3 changes: 0 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
-r bench/requirements.txt
-r integration/requirements.txt
-r test/requirements.txt
autoflake
black
isort
maturin
mypy
ruff
Expand Down
2 changes: 1 addition & 1 deletion script/develop
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ rm -f target/wheels/*
export CC="clang"
export CFLAGS="-O2 -fno-plt -flto=thin"
export LDFLAGS="${CFLAGS} -fuse-ld=lld -Wl,--as-needed"
export RUSTFLAGS="-C linker=clang -C link-arg=-fuse-ld=lld"
export RUSTFLAGS="-C linker=clang -C linker-plugin-lto -C link-arg=-fuse-ld=lld"

maturin build "$@"

Expand Down
4 changes: 1 addition & 3 deletions script/lint
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ to_lint="./bench/*.py ./pysrc/orjson/__init__.pyi ./test/*.py script/pydataclass
script/pysort script/pynumpy script/pynonstr script/pycorrectness script/graph integration/init
integration/wsgi.py integration/typestubs.py integration/thread"

autoflake --in-place --recursive --remove-all-unused-imports --ignore-init-module-imports .
isort ${to_lint}
ruff ${to_lint} --fix
black ${to_lint}
ruff format ${to_lint}
mypy --ignore-missing-imports --check-untyped-defs ./bench/*.py ./pysrc/orjson/__init__.pyi ./test/*.py
4 changes: 1 addition & 3 deletions script/pynumpy
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ elif kind == "int32":
elif kind == "uint8":
array = numpy.random.randint(((2**8) - 1), size=(100000, 100), dtype=numpy.uint8)
elif kind == "uint16":
array = numpy.random.randint(
((2**16) - 1), size=(100000, 100), dtype=numpy.uint16
)
array = numpy.random.randint(((2**16) - 1), size=(100000, 100), dtype=numpy.uint16)
else:
print("usage: pynumpy (bool|int16|int32|float64|int8|uint8|uint16)")
sys.exit(1)
Expand Down
3 changes: 0 additions & 3 deletions src/deserialize/yyjson.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,7 @@ fn parse_yy_object(elem: *mut yyjson_val) -> NonNull<pyo3_ffi::PyObject> {
return nonnull!(ffi!(PyDict_New()));
}
let mut key = unsafe_yyjson_get_first(elem);
#[cfg(not(Py_3_13))]
let dict = ffi!(_PyDict_NewPresized(len as isize));
#[cfg(Py_3_13)]
let dict = ffi!(PyDict_New());
for _ in 0..=len - 1 {
let val = key.add(1);
let key_str = str_from_slice!((*key).uni.str_ as *const u8, unsafe_yyjson_get_len(key));
Expand Down
34 changes: 17 additions & 17 deletions src/typeref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,9 @@ unsafe fn look_up_json_exc() -> *mut PyObject {

#[cold]
#[cfg_attr(feature = "optimize", optimize(size))]
unsafe fn look_up_numpy_type(numpy_module: *mut PyObject, np_type: &str) -> *mut PyTypeObject {
let mod_dict = PyObject_GenericGetDict(numpy_module, null_mut());
let ptr = PyMapping_GetItemString(mod_dict, np_type.as_ptr() as *const c_char);
unsafe fn look_up_numpy_type(numpy_module_dict: *mut PyObject, np_type: &str) -> *mut PyTypeObject {
let ptr = PyMapping_GetItemString(numpy_module_dict, np_type.as_ptr() as *const c_char);
Py_XDECREF(ptr);
Py_XDECREF(mod_dict);
ptr as *mut PyTypeObject
}

Expand All @@ -253,21 +251,23 @@ pub fn load_numpy_types() -> Box<Option<NonNull<NumpyTypes>>> {
PyErr_Clear();
return Box::new(None);
}
let numpy_module_dict = PyObject_GenericGetDict(numpy, null_mut());
let types = Box::new(NumpyTypes {
array: look_up_numpy_type(numpy, "ndarray\0"),
float32: look_up_numpy_type(numpy, "float32\0"),
float64: look_up_numpy_type(numpy, "float64\0"),
int8: look_up_numpy_type(numpy, "int8\0"),
int16: look_up_numpy_type(numpy, "int16\0"),
int32: look_up_numpy_type(numpy, "int32\0"),
int64: look_up_numpy_type(numpy, "int64\0"),
uint16: look_up_numpy_type(numpy, "uint16\0"),
uint32: look_up_numpy_type(numpy, "uint32\0"),
uint64: look_up_numpy_type(numpy, "uint64\0"),
uint8: look_up_numpy_type(numpy, "uint8\0"),
bool_: look_up_numpy_type(numpy, "bool_\0"),
datetime64: look_up_numpy_type(numpy, "datetime64\0"),
array: look_up_numpy_type(numpy_module_dict, "ndarray\0"),
float32: look_up_numpy_type(numpy_module_dict, "float32\0"),
float64: look_up_numpy_type(numpy_module_dict, "float64\0"),
int8: look_up_numpy_type(numpy_module_dict, "int8\0"),
int16: look_up_numpy_type(numpy_module_dict, "int16\0"),
int32: look_up_numpy_type(numpy_module_dict, "int32\0"),
int64: look_up_numpy_type(numpy_module_dict, "int64\0"),
uint16: look_up_numpy_type(numpy_module_dict, "uint16\0"),
uint32: look_up_numpy_type(numpy_module_dict, "uint32\0"),
uint64: look_up_numpy_type(numpy_module_dict, "uint64\0"),
uint8: look_up_numpy_type(numpy_module_dict, "uint8\0"),
bool_: look_up_numpy_type(numpy_module_dict, "bool_\0"),
datetime64: look_up_numpy_type(numpy_module_dict, "datetime64\0"),
});
Py_XDECREF(numpy_module_dict);
Py_XDECREF(numpy);
Box::new(Some(nonnull!(Box::<NumpyTypes>::into_raw(types))))
}
Expand Down

0 comments on commit ffb5a17

Please sign in to comment.