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 bdfcaa0
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 55 deletions.
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.

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
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 bdfcaa0

Please sign in to comment.