Skip to content

Commit

Permalink
lint job, build maintenance
Browse files Browse the repository at this point in the history
  • Loading branch information
ijl committed Feb 28, 2023
1 parent 251e56a commit c5a1c8a
Show file tree
Hide file tree
Showing 19 changed files with 65 additions and 68 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: lint
on: push
jobs:
lint:
runs-on: ubuntu-22.04
steps:
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- run: curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain=stable --profile=default -y
- run: pip install -U autoflake isort black mypy types-python-dateutil types-pytz types-simplejson types-ujson

- uses: actions/checkout@v3

- run: cargo fmt
- run: ./script/lint

- run: git diff --exit-code
13 changes: 4 additions & 9 deletions .github/workflows/linux-cross.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
name: linux-cross
on:
push:
branches:
- '*'
tags:
- '*'
on: push
jobs:
linux-cross:
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -33,7 +28,7 @@ jobs:
LDFLAGS: "-O2 -flto -Wl,--as-needed"
CARGO_UNSTABLE_SPARSE_REGISTRY: "true"
with:
maturin-version: v0.14.12
maturin-version: v0.14.14
target: ${{ matrix.target.arch }}
rust-toolchain: nightly-2023-02-03
rustup-components: rust-src
Expand All @@ -54,7 +49,7 @@ jobs:
run: |
PYTHON=python${{ matrix.python.version }}
$PYTHON -m venv venv
venv/bin/pip install -U pip
venv/bin/pip install -U pip wheel
venv/bin/pip install -r test/requirements.txt
venv/bin/pip install orjson --no-index --find-links dist/ --force-reinstall
venv/bin/python -m pytest -s -rxX -v test
Expand All @@ -75,7 +70,7 @@ jobs:
name: wheels
- uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: "3.11"
- run: pip install "maturin>=0.14,<0.15"
- name: deploy
run: maturin upload --skip-existing --username "$MATURIN_USERNAME" *.whl
Expand Down
7 changes: 1 addition & 6 deletions .github/workflows/manylinux2014.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
name: manylinux2014
on:
push:
branches:
- '*'
tags:
- '*'
on: push
jobs:
manylinux2014:
runs-on: ubuntu-22.04
Expand Down
7 changes: 1 addition & 6 deletions .github/workflows/manylinux_2_28.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
name: manylinux_2_28
on:
push:
branches:
- '*'
tags:
- '*'
on: push
jobs:
manylinux_2_28:
runs-on: ubuntu-22.04
Expand Down
13 changes: 4 additions & 9 deletions .github/workflows/musllinux.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
name: musllinux
on:
push:
branches:
- '*'
tags:
- '*'
on: push
jobs:
musllinux:
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -35,7 +30,7 @@ jobs:
LDFLAGS: "-O2 -flto -Wl,--as-needed"
CARGO_UNSTABLE_SPARSE_REGISTRY: "true"
with:
maturin-version: v0.14.12
maturin-version: v0.14.14
rust-toolchain: nightly-2023-02-03
rustup-components: rust-src
target: ${{ matrix.platform.target }}
Expand All @@ -62,7 +57,7 @@ jobs:
PYTHON=python${{ matrix.python.version }}
$PYTHON -m venv venv
venv/bin/pip install -U pip
venv/bin/pip install -U pip wheel
venv/bin/pip install -r test/requirements.txt
venv/bin/pip install orjson --no-index --find-links dist/ --force-reinstall
venv/bin/python -m pytest -s -rxX -v test
Expand All @@ -83,7 +78,7 @@ jobs:
name: wheels
- uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: "3.11"
- run: pip install "maturin>=0.14,<0.15"
- name: deploy
run: maturin upload --skip-existing --username "$MATURIN_USERNAME" *.whl
Expand Down
8 changes: 4 additions & 4 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-sdist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ steps:
displayName: ensure toolchain
- bash: PATH=$(path) $(interpreter) -m pip install --user --upgrade pip "maturin>=0.14,<0.15" wheel
displayName: build dependencies
- bash: PATH=$(path) $(interpreter) -m pip install --user -r test/requirements.txt -r integration/requirements.txt mypy==0.991
- bash: PATH=$(path) $(interpreter) -m pip install --user -r test/requirements.txt -r integration/requirements.txt mypy
displayName: test dependencies
- bash: PATH=$(path) maturin sdist
displayName: package sdist
Expand Down
2 changes: 1 addition & 1 deletion script/lint
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ script/pysort script/pynumpy script/pynonstr script/pycorrectness script/graph"
autoflake --in-place --recursive --remove-all-unused-imports --ignore-init-module-imports .
isort ${to_lint}
black ${to_lint}
mypy --ignore-missing-imports ./bench/*.py ./pysrc/orjson/__init__.pyi ./test/*.py
mypy --ignore-missing-imports --check-untyped-defs ./bench/*.py ./pysrc/orjson/__init__.pyi ./test/*.py
2 changes: 1 addition & 1 deletion script/pytest
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh -e

pytest -s -rxX test
pytest -s -rxX --random-order test
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
#![cfg_attr(feature = "intrinsics", feature(core_intrinsics))]
#![cfg_attr(feature = "optimize", feature(optimize_attribute))]
#![allow(unused_unsafe)]
#![allow(non_camel_case_types)]
#![allow(clippy::explicit_auto_deref)]
#![allow(clippy::missing_safety_doc)]
#![allow(clippy::redundant_field_names)]
#![allow(clippy::uninlined_format_args)] // MSRV 1.66
#![allow(clippy::unnecessary_unwrap)]
#![allow(clippy::upper_case_acronyms)]
#![allow(clippy::zero_prefixed_literal)]
#![allow(non_camel_case_types)]

#[macro_use]
mod util;
Expand Down
2 changes: 1 addition & 1 deletion src/str/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn find_str_kind(buf: &str, num_chars: usize) -> PyUnicodeKind {
}

pub fn unicode_from_str(buf: &str) -> *mut pyo3_ffi::PyObject {
if buf.len() == 0 {
if buf.is_empty() {
ffi!(Py_INCREF(EMPTY_UNICODE));
unsafe { EMPTY_UNICODE }
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/str/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ pub struct PyCompactUnicodeObject {
}

#[cfg(not(Py_3_12))]
const STATE_ASCII: u32 = 0b00000000000000000000000001000000;
const STATE_ASCII: u32 = 1 << 6;
#[cfg(not(Py_3_12))]
const STATE_COMPACT: u32 = 0b00000000000000000000000000100000;
const STATE_COMPACT: u32 = 1 << 5;

#[cfg(Py_3_12)]
const STATE_ASCII: u32 = 0b00000000000000000000000000100000;
const STATE_ASCII: u32 = 1 << 5;

#[cfg(Py_3_12)]
const STATE_COMPACT: u32 = 0b00000000000000000000000000010000;
const STATE_COMPACT: u32 = 1 << 4;

const STATE_COMPACT_ASCII: u32 = STATE_COMPACT | STATE_ASCII;

Expand Down
10 changes: 5 additions & 5 deletions test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,16 @@ def test_default_positional(self):
dumps() positional arg
"""
with pytest.raises(TypeError):
orjson.dumps(__obj={})
orjson.dumps(__obj={}) # type: ignore
with pytest.raises(TypeError):
orjson.dumps(zxc={})
orjson.dumps(zxc={}) # type: ignore

def test_default_unknown_kwarg(self):
"""
dumps() unknown kwarg
"""
with pytest.raises(TypeError):
orjson.dumps({}, zxc=default)
orjson.dumps({}, zxc=default) # type: ignore

def test_default_empty_kwarg(self):
"""
Expand All @@ -145,14 +145,14 @@ def test_default_twice(self):
dumps() default twice
"""
with pytest.raises(TypeError):
orjson.dumps({}, default, default=default)
orjson.dumps({}, default, default=default) # type: ignore

def test_option_twice(self):
"""
dumps() option twice
"""
with pytest.raises(TypeError):
orjson.dumps({}, None, orjson.OPT_NAIVE_UTC, option=orjson.OPT_NAIVE_UTC)
orjson.dumps({}, None, orjson.OPT_NAIVE_UTC, option=orjson.OPT_NAIVE_UTC) # type: ignore

def test_option_mixed(self):
"""
Expand Down
8 changes: 4 additions & 4 deletions test/test_circular.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def test_circular_dict(self):
"""
dumps() circular reference dict
"""
obj = {}
obj = {} # type: ignore
obj["obj"] = obj
with pytest.raises(orjson.JSONEncodeError):
orjson.dumps(obj)
Expand All @@ -19,16 +19,16 @@ def test_circular_list(self):
"""
dumps() circular reference list
"""
obj = []
obj.append(obj)
obj = [] # type: ignore
obj.append(obj) # type: ignore
with pytest.raises(orjson.JSONEncodeError):
orjson.dumps(obj)

def test_circular_nested(self):
"""
dumps() circular reference nested dict, list
"""
obj = {}
obj = {} # type: ignore
obj["list"] = [{"obj": obj}]
with pytest.raises(orjson.JSONEncodeError):
orjson.dumps(obj)
13 changes: 7 additions & 6 deletions test/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

try:
import zoneinfo

_ = zoneinfo.ZoneInfo("Europe/Amsterdam")
except Exception: # ImportError,ZoneInfoNotFoundError
zoneinfo = None # type: ignore
Expand All @@ -25,7 +26,7 @@
try:
from dateutil import tz
except ImportError:
tz = None
tz = None # type: ignore


AMSTERDAM_1937_DATETIMES = (
Expand Down Expand Up @@ -267,7 +268,7 @@ def test_datetime_pendulum_positive(self):
3,
4,
0,
tzinfo=pendulum.timezone("Asia/Shanghai"),
tzinfo=pendulum.timezone("Asia/Shanghai"), # type: ignore
)
]
)
Expand Down Expand Up @@ -306,7 +307,7 @@ def test_datetime_pendulum_negative_dst(self):
3,
4,
0,
tzinfo=pendulum.timezone("America/New_York"),
tzinfo=pendulum.timezone("America/New_York"), # type: ignore
)
]
)
Expand Down Expand Up @@ -375,7 +376,7 @@ def test_datetime_pendulum_negative_non_dst(self):
3,
4,
0,
tzinfo=pendulum.timezone("America/New_York"),
tzinfo=pendulum.timezone("America/New_York"), # type: ignore
)
]
)
Expand Down Expand Up @@ -444,7 +445,7 @@ def test_datetime_pendulum_partial_hour(self):
3,
4,
0,
tzinfo=pendulum.timezone("Australia/Adelaide"),
tzinfo=pendulum.timezone("Australia/Adelaide"), # type: ignore
)
]
)
Expand All @@ -469,7 +470,7 @@ def test_datetime_partial_second_pendulum_supported(self):
0,
27,
87,
tzinfo=pendulum.timezone("Europe/Amsterdam"),
tzinfo=pendulum.timezone("Europe/Amsterdam"), # type: ignore
)
]
)
Expand Down
1 change: 0 additions & 1 deletion test/test_non_str_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,6 @@ def test_dict_keys_tuple(self):
orjson.dumps(obj, option=orjson.OPT_NON_STR_KEYS)

def test_dict_keys_unknown(self):
obj = {frozenset(): True}
with pytest.raises(orjson.JSONEncodeError):
orjson.dumps({frozenset(): True}, option=orjson.OPT_NON_STR_KEYS)

Expand Down
7 changes: 3 additions & 4 deletions test/test_ujson.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_encodeDictWithUnicodeKeys(self):
orjson.dumps(val)

def test_encodeArrayOfNestedArrays(self):
val = [[[[]]]] * 20
val = [[[[]]]] * 20 # type: ignore
output = orjson.dumps(val)
assert val == orjson.loads(output)
assert val == orjson.loads(output)
Expand Down Expand Up @@ -152,7 +152,7 @@ def testEncodeSymbols(self):
assert s == decoded

def test_encodeArrayInArray(self):
val = [[[[]]]]
val = [[[[]]]] # type: ignore
output = orjson.dumps(val)

assert val == orjson.loads(output)
Expand Down Expand Up @@ -219,8 +219,7 @@ def test_encodeFalseConversion(self):
assert val == orjson.loads(output)

def test_encodeToUTF8(self):
val = b"\xe6\x97\xa5\xd1\x88"
val = val.decode("utf-8")
val = b"\xe6\x97\xa5\xd1\x88".decode("utf-8")
enc = orjson.dumps(val)
dec = orjson.loads(enc)
assert enc == orjson.dumps(val)
Expand Down
4 changes: 2 additions & 2 deletions test/test_uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ def test_uuid_immutable(self):
"""
val = uuid.uuid4()
with pytest.raises(TypeError):
val.int = 1
val.int = 1 # type: ignore
with pytest.raises(TypeError):
val.int = None
val.int = None # type: ignore

def test_uuid_int(self):
"""
Expand Down
5 changes: 2 additions & 3 deletions test/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@

def read_fixture_bytes(filename, subdir=None):
if subdir is None:
parts = (dirname, filename)
path = Path(dirname, filename)
else:
parts = (dirname, subdir, filename)
path = Path(*parts)
path = Path(dirname, subdir, filename)
if path.suffix == ".xz":
contents = lzma.decompress(path.read_bytes())
else:
Expand Down

0 comments on commit c5a1c8a

Please sign in to comment.