Skip to content

Commit

Permalink
BUG: get_data_dir support for conda Windows enviroments
Browse files Browse the repository at this point in the history
  • Loading branch information
snowman2 committed Mar 6, 2022
1 parent 8f0e1f7 commit e7c4896
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Latest
- BUG: Reorder deps in show_versions for setuptools issue (issue #1017)
- BUG: remove CustomConstructorCRS @abstractmethod decorator (pull #1018)
- BUG: Correct type annotation for AreaofUse.bounds (issue #1012)
- BUG: :func:`pyproj.datadir.get_data_dir` support for conda Windows (issue #1029)

3.3.0
-------
Expand Down
3 changes: 3 additions & 0 deletions pyproj/datadir.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def get_data_dir() -> str:
internal_datadir = Path(__file__).absolute().parent / "proj_dir" / "share" / "proj"
proj_lib_dirs = os.environ.get("PROJ_LIB", "")
prefix_datadir = Path(sys.prefix, "share", "proj")
conda_windows_prefix_datadir = Path(sys.prefix, "Library", "share", "proj")

def valid_data_dir(potential_data_dir):
if (
Expand All @@ -98,6 +99,8 @@ def valid_data_dirs(potential_data_dirs):
_VALIDATED_PROJ_DATA = proj_lib_dirs
elif valid_data_dir(prefix_datadir):
_VALIDATED_PROJ_DATA = str(prefix_datadir)
elif valid_data_dir(conda_windows_prefix_datadir):
_VALIDATED_PROJ_DATA = str(conda_windows_prefix_datadir)
else:
proj_exe = shutil.which("proj", path=sys.prefix)
if proj_exe is None:
Expand Down
10 changes: 10 additions & 0 deletions test/test_datadir.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ def test_get_data_dir__from_prefix(tmp_path):
assert get_data_dir() == str(proj_dir)


def test_get_data_dir__from_prefix__conda_windows(tmp_path):
with proj_env(), patch.dict(os.environ, {}, clear=True), patch(
"pyproj.datadir.Path.absolute", return_value=_INVALID_PATH
), patch("pyproj.datadir.sys.prefix", str(tmp_path)):
proj_dir = tmp_path / "Library" / "share" / "proj"
proj_dir.mkdir(parents=True)
create_projdb(proj_dir)
assert get_data_dir() == str(proj_dir)


def test_get_data_dir__from_path(tmp_path):
with proj_env(), patch.dict(os.environ, {}, clear=True), patch(
"pyproj.datadir.Path.absolute", return_value=_INVALID_PATH
Expand Down

0 comments on commit e7c4896

Please sign in to comment.