Skip to content

Commit bd6be16

Browse files
authored
Deprecate pkg_resources (#81)
* Deprecate pkg_resources * Fix error * Add support for Python 3.13
1 parent 7621262 commit bd6be16

6 files changed

Lines changed: 6138 additions & 3770 deletions

File tree

.github/workflows/py-check.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ jobs:
1818
fail-fast: false
1919
matrix:
2020
os: [ubuntu-latest]
21-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
21+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
2222
include:
2323
- os: macos-latest
24-
python-version: "3.11"
24+
python-version: "3.12"
2525
- os: windows-latest
26-
python-version: "3.11"
26+
python-version: "3.12"
2727

2828
env:
2929
SDKROOT: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@ Tool names in the **whitebox** Python package can be called either using the sna
123123
.. code:: python
124124
125125
import os
126-
import pkg_resources
126+
from importlib_resources import files
127127
import whitebox
128128
129129
wbt = whitebox.WhiteboxTools()
130130
print(wbt.version())
131131
print(wbt.help())
132132
133133
# identify the sample data directory of the package
134-
data_dir = os.path.dirname(pkg_resources.resource_filename("whitebox", 'testdata/'))
134+
data_dir = str(files("whitebox").joinpath("testdata"))
135135
136136
wbt.set_working_dir(data_dir)
137137
wbt.verbose = False

docs/usage.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ For example:
1111
.. code:: python
1212
1313
import os
14-
import pkg_resources
14+
from importlib_resources import files
1515
import whitebox
1616
1717
wbt = whitebox.WhiteboxTools()
1818
print(wbt.version())
1919
print(wbt.help())
2020
2121
# identify the sample data directory of the package
22-
data_dir = os.path.dirname(pkg_resources.resource_filename("whitebox", 'testdata/'))
22+
data_dir = str(files("whitebox").joinpath("testdata"))
2323
2424
wbt.set_working_dir(data_dir)
2525
wbt.verbose = False

examples/whitebox.ipynb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,6 @@
249249
"**Tool names in the whitebox Python package can be called either using the snake_case or CamelCase convention (e.g. lidar_info or LidarInfo). The example below uses snake_case.** "
250250
]
251251
},
252-
{
253-
"cell_type": "code",
254-
"execution_count": null,
255-
"metadata": {},
256-
"outputs": [],
257-
"source": []
258-
},
259252
{
260253
"cell_type": "code",
261254
"execution_count": null,
@@ -264,10 +257,11 @@
264257
},
265258
"outputs": [],
266259
"source": [
267-
"import os, pkg_resources\n",
260+
"import os\n",
261+
"from importlib_resources import files\n",
268262
"\n",
269263
"# identify the sample data directory of the package\n",
270-
"data_dir = os.path.dirname(pkg_resources.resource_filename(\"whitebox\", 'testdata/'))\n",
264+
"data_dir = str(files(\"whitebox\").joinpath(\"testdata\"))\n",
271265
"\n",
272266
"# set whitebox working directory\n",
273267
"wbt.set_working_dir(data_dir)\n",

whitebox/download_wbt.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def download_wbt(linux_musl=False, reset=False, verbose=True):
1515
import tarfile
1616
import shutil
1717
import urllib.request
18-
import pkg_resources
18+
import importlib.resources
1919
import webbrowser
2020

2121
if os.environ.get("WBT_PATH", None) is not None:
@@ -25,8 +25,9 @@ def download_wbt(linux_musl=False, reset=False, verbose=True):
2525
package_name = "whitebox"
2626
# Get package directory
2727
pkg_dir = os.path.dirname(
28-
pkg_resources.resource_filename(package_name, "whitebox_tools.py")
28+
importlib.resources.files(package_name) / "whitebox_tools.py"
2929
)
30+
3031
exe_dir = os.path.join(
3132
pkg_dir, "WBT"
3233
) # Get directory of WhiteboxTools executable file

0 commit comments

Comments
 (0)