Skip to content

Commit bc47d46

Browse files
committed
Remove duplicate read_text without orjson
If orjson was not present, the `_json_loads` method on `StacIO` would try to read the text again, which would lead to the read text method being called with json (bad). This slipped through CI because one of the requirements-dev.txt dependencies installs orjson, so the non-orjson case wasn't being tested. This commit also includes a new build job to install+test without requirements-dev.txt to try and protect against regression. Also includes a scripts comment fix to s/yapf/black, and a comment to make pylance ignore a missing orjson import. I didn't update the docs re the yapf->black switch b/c @lossyrob said that some other folks were working on the docs upgrades.
1 parent 5158a4c commit bc47d46

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,14 @@ jobs:
3939
token: ${{ secrets.CODECOV_TOKEN }}
4040
file: ./coverage.xml
4141
fail_ci_if_error: false
42+
vanilla:
43+
runs-on: ubuntu-latest
44+
steps:
45+
- uses: actions/checkout@v2
46+
- uses: actions/setup-python@v2
47+
with:
48+
python-version: "3.8"
49+
- name: Install without orjson
50+
run: pip install '.[validation]'
51+
- name: Run unittests
52+
run: python -m unittest discover tests

.style.yapf

Lines changed: 0 additions & 2 deletions
This file was deleted.

pystac/stac_io.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
# Use orjson if available
2525
try:
26-
import orjson
26+
import orjson # type: ignore
2727
except ImportError:
2828
orjson = None
2929

@@ -77,7 +77,7 @@ def _json_loads(self, txt: str, source: Union[str, "Link_Type"]) -> Dict[str, An
7777
if orjson is not None:
7878
return orjson.loads(txt)
7979
else:
80-
return json.loads(self.read_text(txt))
80+
return json.loads(txt)
8181

8282
def _json_dumps(
8383
self, json_dict: Dict[str, Any], source: Union[str, "Link_Type"]

scripts/format

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fi
99
function usage() {
1010
echo -n \
1111
"Usage: $(basename "$0")
12-
Format code with yapf
12+
Format code with black
1313
"
1414
}
1515

tests/test_stac_io.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import unittest
22
import warnings
33

4+
import pystac
45
from pystac.stac_io import STAC_IO
56
from tests.utils import TestCases
67

@@ -18,3 +19,8 @@ def test_stac_io_issues_warnings(self):
1819
# Verify some things
1920
self.assertEqual(len(w), 1)
2021
self.assertTrue(issubclass(w[-1].category, DeprecationWarning))
22+
23+
def test_read_text(self):
24+
_ = pystac.read_file(
25+
TestCases.get_path("data-files/collections/multi-extent.json")
26+
)

0 commit comments

Comments
 (0)