Skip to content

Commit 009d64a

Browse files
Copilotjpn--
andauthored
Replace deprecated pkg_resources with importlib.resources (#1011)
* Initial plan * Replace deprecated pkg_resources with importlib.resources Co-authored-by: jpn-- <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: jpn-- <[email protected]>
1 parent f50a261 commit 009d64a

File tree

14 files changed

+29
-30
lines changed

14 files changed

+29
-30
lines changed

activitysim/abm/test/test_misc/setup_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# See full license in LICENSE.txt.
33
from __future__ import annotations
44

5+
import importlib.resources
56
import logging
67
import os
78

@@ -10,7 +11,6 @@
1011
import openmatrix as omx
1112
import pandas as pd
1213
import pandas.testing as pdt
13-
import pkg_resources
1414
import pytest
1515
import yaml
1616

@@ -32,7 +32,7 @@
3232

3333
def example_path(dirname):
3434
resource = os.path.join("examples", "prototype_mtc", dirname)
35-
return pkg_resources.resource_filename("activitysim", resource)
35+
return str(importlib.resources.files("activitysim").joinpath(resource))
3636

3737

3838
def setup_dirs(ancillary_configs_dir=None, data_dir=None):

activitysim/abm/test/test_misc/test_load_cached_accessibility.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# See full license in LICENSE.txt.
33
from __future__ import annotations
44

5+
import importlib.resources
56
import logging
67
import os
78

@@ -10,7 +11,6 @@
1011
import openmatrix as omx
1112
import pandas as pd
1213
import pandas.testing as pdt
13-
import pkg_resources
1414
import pytest
1515
import yaml
1616

@@ -34,7 +34,7 @@
3434

3535
def example_path(dirname):
3636
resource = os.path.join("examples", "prototype_mtc", dirname)
37-
return pkg_resources.resource_filename("activitysim", resource)
37+
return str(importlib.resources.files("activitysim").joinpath(resource))
3838

3939

4040
def close_handlers():

activitysim/abm/test/test_pipeline/test_pipeline.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
# See full license in LICENSE.txt.
33
from __future__ import annotations
44

5+
import importlib.resources
56
import logging
67
import os
78

89
import numpy as np
910
import openmatrix as omx
1011
import pandas as pd
1112
import pandas.testing as pdt
12-
import pkg_resources
1313
import pytest
1414

1515
from activitysim.core import random, tracing, workflow
@@ -34,7 +34,7 @@
3434

3535
def example_path(dirname):
3636
resource = os.path.join("examples", "prototype_mtc", dirname)
37-
return pkg_resources.resource_filename("activitysim", resource)
37+
return str(importlib.resources.files("activitysim").joinpath(resource))
3838

3939

4040
def setup_dirs(ancillary_configs_dir=None, data_dir=None):

activitysim/cli/create.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import zipfile
1212
from pathlib import Path
1313

14-
import pkg_resources
1514
import requests
1615
import yaml
1716

activitysim/examples/placeholder_multiple_zone/test/test_multiple_zone.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@
22

33
# ActivitySim
44
# See full license in LICENSE.txt.
5+
import importlib.resources
56
import os
67
import subprocess
78
import sys
89
from pathlib import Path
910

1011
import pandas as pd
11-
import pkg_resources
1212
import pytest
1313

1414
from activitysim.core import test, workflow
1515

1616

1717
def example_path(dirname):
1818
resource = os.path.join("examples", "placeholder_multiple_zone", dirname)
19-
return pkg_resources.resource_filename("activitysim", resource)
19+
return str(importlib.resources.files("activitysim").joinpath(resource))
2020

2121

2222
def mtc_example_path(dirname):
2323
resource = os.path.join("examples", "prototype_mtc", dirname)
24-
return pkg_resources.resource_filename("activitysim", resource)
24+
return str(importlib.resources.files("activitysim").joinpath(resource))
2525

2626

2727
def build_data():

activitysim/examples/production_semcog/test/test_semcog.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22

33
# ActivitySim
44
# See full license in LICENSE.txt.
5+
import importlib.resources
56
import os
67
import subprocess
78

89
import pandas as pd
9-
import pkg_resources
1010

1111
from activitysim.core.test._tools import assert_frame_substantively_equal
1212

1313

1414
def run_test_semcog(multiprocess=False):
1515
def example_path(dirname):
1616
resource = os.path.join("examples", "production_semcog", dirname)
17-
return pkg_resources.resource_filename("activitysim", resource)
17+
return str(importlib.resources.files("activitysim").joinpath(resource))
1818

1919
def test_path(dirname):
2020
return os.path.join(os.path.dirname(__file__), dirname)

activitysim/examples/prototype_arc/test/test_arc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22

33
# ActivitySim
44
# See full license in LICENSE.txt.
5+
import importlib.resources
56
import os
67
import subprocess
78
import sys
89

910
import pandas as pd
1011
import pandas.testing as pdt
11-
import pkg_resources
1212

1313
from activitysim.core.test import assert_frame_substantively_equal
1414

1515

1616
def _test_arc(recode=False, sharrow=False):
1717
def example_path(dirname):
1818
resource = os.path.join("examples", "prototype_arc", dirname)
19-
return pkg_resources.resource_filename("activitysim", resource)
19+
return str(importlib.resources.files("activitysim").joinpath(resource))
2020

2121
def test_path(dirname):
2222
return os.path.join(os.path.dirname(__file__), dirname)

activitysim/examples/prototype_marin/test/test_marin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22

33
# ActivitySim
44
# See full license in LICENSE.txt.
5+
import importlib.resources
56
import os
67
import subprocess
78
from pathlib import Path
89

910
import pandas as pd
1011
import pandas.testing as pdt
11-
import pkg_resources
1212

1313
from activitysim.core import test, workflow
1414

1515

1616
def example_path(dirname):
1717
resource = os.path.join("examples", "prototype_marin", dirname)
18-
return pkg_resources.resource_filename("activitysim", resource)
18+
return str(importlib.resources.files("activitysim").joinpath(resource))
1919

2020

2121
def _test_path(dirname):

activitysim/examples/prototype_mtc/test/test_mtc.py

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

33
# ActivitySim
44
# See full license in LICENSE.txt.
5+
import importlib.resources
56
import os
67
import subprocess
78
import sys
89
from pathlib import Path
910

1011
import pandas as pd
1112
import pandas.testing as pdt
12-
import pkg_resources
1313

1414
from activitysim.core import test, workflow
1515

1616

1717
def run_test_mtc(multiprocess=False, chunkless=False, recode=False, sharrow=False):
1818
def example_path(dirname):
1919
resource = os.path.join("examples", "prototype_mtc", dirname)
20-
return pkg_resources.resource_filename("activitysim", resource)
20+
return str(importlib.resources.files("activitysim").joinpath(resource))
2121

2222
def test_path(dirname):
2323
return os.path.join(os.path.dirname(__file__), dirname)

activitysim/examples/prototype_mtc_extended/sampling_scenarios.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from __future__ import annotations
22

33
import argparse
4+
import importlib.resources
45
import os
56
import shutil
67

78
import pandas as pd
8-
import pkg_resources
99
import yaml
1010

1111
from activitysim.cli.run import add_run_args, run
@@ -35,12 +35,12 @@ def integer_params(params):
3535

3636
def base_path(dirname):
3737
resource = os.path.join("examples", "placeholder_sandag_2_zone", dirname)
38-
return pkg_resources.resource_filename("activitysim", resource)
38+
return str(importlib.resources.files("activitysim").joinpath(resource))
3939

4040

4141
def extended_path(dirname):
4242
resource = os.path.join("examples", "placeholder_sandag_2_zone_extended", dirname)
43-
return pkg_resources.resource_filename("activitysim", resource)
43+
return str(importlib.resources.files("activitysim").joinpath(resource))
4444

4545

4646
def run_model():

0 commit comments

Comments
 (0)