Skip to content

Commit

Permalink
ENH: Add runtime & compiled PROJ versions
Browse files Browse the repository at this point in the history
  • Loading branch information
snowman2 committed Aug 27, 2024
1 parent 2a27805 commit faeba97
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 14 deletions.
1 change: 1 addition & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ extension-pkg-whitelist=pyproj._crs,
pyproj._geod,
pyproj._context,
pyproj._compat,
pyproj._version,
pyproj.database,
pyproj.list

Expand Down
1 change: 1 addition & 0 deletions docs/history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Latest
- DEP: Minimum PROJ version 9.2 (pull #1394)
- ENH: Add :meth:`CRS.is_deprecated` and :meth:`CRS.get_non_deprecated` (pull #1383)
- PERF: thread local context (issue #1133)
- ENH: Add runtime & compiled PROJ versions (discussion #1420)

3.6.1
------
Expand Down
12 changes: 9 additions & 3 deletions pyproj/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
from pyproj._show_versions import ( # noqa: F401 pylint: disable=unused-import
show_versions,
)
from pyproj._version import ( # noqa: F401 pylint: disable=unused-import
PROJ_COMPILED_VERSION,
PROJ_COMPILED_VERSION_STR,
PROJ_VERSION,
PROJ_VERSION_STR,
)
from pyproj.crs import CRS # noqa: F401 pylint: disable=unused-import
from pyproj.database import ( # noqa: F401 pylint: disable=unused-import
get_authorities,
Expand All @@ -62,7 +68,6 @@
from pyproj.transformer import ( # noqa: F401 pylint: disable=unused-import
Transformer,
itransform,
proj_version_str,
transform,
)

Expand All @@ -82,8 +87,9 @@
"get_units_map",
"show_versions",
]
__proj_version__ = proj_version_str

__proj_version__ = PROJ_VERSION_STR
proj_version_str = PROJ_VERSION_STR
__proj_compiled_version__ = PROJ_COMPILED_VERSION_STR
try:
pyproj.network.set_ca_bundle_path()
except DataDirError as err:
Expand Down
3 changes: 2 additions & 1 deletion pyproj/_show_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def _get_proj_info():

blob = [
("pyproj", pyproj.__version__),
("PROJ", pyproj.__proj_version__),
("PROJ (runtime)", pyproj.__proj_version__),
("PROJ (compiled)", pyproj.__proj_compiled_version__),
("data dir", data_dir),
("user_data_dir", pyproj.datadir.get_user_data_dir()),
("PROJ DATA (recommended version)", get_database_metadata("PROJ_DATA.VERSION")),
Expand Down
3 changes: 0 additions & 3 deletions pyproj/_transformer.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ from typing import Any, NamedTuple
from pyproj._crs import _CRS, AreaOfUse, Base, CoordinateOperation
from pyproj.enums import ProjVersion, TransformDirection

proj_version_str: str
PROJ_VERSION: tuple[int, int, int]

class AreaOfInterest(NamedTuple):
west_lon_degree: float
south_lat_degree: float
Expand Down
3 changes: 0 additions & 3 deletions pyproj/_transformer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ from pyproj.aoi import AreaOfInterest
from pyproj.enums import ProjVersion, TransformDirection, WktVersion
from pyproj.exceptions import ProjError

# version number string for PROJ
proj_version_str = f"{PROJ_VERSION_MAJOR}.{PROJ_VERSION_MINOR}.{PROJ_VERSION_PATCH}"
PROJ_VERSION = (PROJ_VERSION_MAJOR, PROJ_VERSION_MINOR, PROJ_VERSION_PATCH)
_AUTH_CODE_RE = re.compile(r"(?P<authority>\w+)\:(?P<code>\w+)")


Expand Down
4 changes: 4 additions & 0 deletions pyproj/_version.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
PROJ_VERSION: tuple[int, int, int]
PROJ_VERSION_STR: str
PROJ_COMPILED_VERSION: tuple[int, int, int]
PROJ_COMPILED_VERSION_STR: str
7 changes: 7 additions & 0 deletions pyproj/_version.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include "proj.pxi"

cdef PJ_INFO _PROJ_INFO = proj_info()
PROJ_VERSION = (_PROJ_INFO.major, _PROJ_INFO.minor, _PROJ_INFO.patch)
PROJ_VERSION_STR = f"{_PROJ_INFO.major}.{_PROJ_INFO.minor}.{_PROJ_INFO.patch}"
PROJ_COMPILED_VERSION = (PROJ_VERSION_MAJOR, PROJ_VERSION_MINOR, PROJ_VERSION_PATCH)
PROJ_COMPILED_VERSION_STR = f"{PROJ_VERSION_MAJOR}.{PROJ_VERSION_MINOR}.{PROJ_VERSION_PATCH}"
14 changes: 14 additions & 0 deletions pyproj/proj.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ cdef extern from "proj.h" nogil:
PJ *proj_create (PJ_CONTEXT *ctx, const char *definition)
PJ *proj_normalize_for_visualization(PJ_CONTEXT *ctx, const PJ* obj)

ctypedef struct PJ_INFO:
int major # Major release number
int minor # Minor release number
int patch # Patch level
const char *release # Release info. Version + date
const char *version # Full version number
const char *searchpath # Paths where init and grid files are
# looked for. Paths are separated by
# semi-colons on Windows, and colons
# on non-Windows platforms.
const char *const *paths
size_t path_count
PJ_INFO proj_info()

ctypedef struct PJ_PROJ_INFO:
const char *id
const char *description
Expand Down
1 change: 0 additions & 1 deletion pyproj/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
AreaOfInterest,
_Transformer,
_TransformerGroup,
proj_version_str,
)
from pyproj.datadir import get_user_data_dir
from pyproj.enums import ProjVersion, TransformDirection, WktVersion
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ def get_extension_modules():
Extension("pyproj.list", ["pyproj/list.pyx"], **ext_options),
Extension("pyproj._network", ["pyproj/_network.pyx"], **ext_options),
Extension("pyproj._sync", ["pyproj/_sync.pyx"], **ext_options),
Extension("pyproj._version", ["pyproj/_version.pyx"], **ext_options),
],
quiet=True,
compile_time_env={
Expand Down
3 changes: 2 additions & 1 deletion test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def test_main__verbose(input_command, option, tmpdir):
input_command + [option], stderr=subprocess.STDOUT
).decode("utf-8")
assert "pyproj:" in output
assert "PROJ:" in output
assert "PROJ (compiled):" in output
assert "PROJ (runtime):" in output
assert "data dir" in output
assert "user_data_dir" in output
assert "System" in output
Expand Down
6 changes: 4 additions & 2 deletions test/test_show_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
def test_get_proj_info():
pyproj_info = _get_proj_info()
assert "pyproj" in pyproj_info
assert "PROJ" in pyproj_info
assert "PROJ (runtime)" in pyproj_info
assert "PROJ (compiled)" in pyproj_info
assert "data dir" in pyproj_info
assert "user_data_dir" in pyproj_info
assert "PROJ DATA (recommended version)" in pyproj_info
Expand Down Expand Up @@ -41,6 +42,7 @@ def test_show_versions_with_proj(capsys):
out, err = capsys.readouterr()
assert "System" in out
assert "python" in out
assert "PROJ" in out
assert "PROJ (runtime)" in out
assert "PROJ (compiled)" in out
assert "data dir" in out
assert "Python deps" in out

0 comments on commit faeba97

Please sign in to comment.