Skip to content

Commit

Permalink
Use union types for top-level init files
Browse files Browse the repository at this point in the history
  • Loading branch information
mojaveazure committed Dec 17, 2024
1 parent 30a0df3 commit 1e06649
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
7 changes: 4 additions & 3 deletions apis/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
# Based on ideas from https://github.com/pybind/cmake_example
# The `bld` script here is reused for pip install, CI, and local builds.

from __future__ import annotations

import ctypes
import os
import pathlib
import platform
import shutil
import subprocess
import sys
from typing import Optional

import setuptools.command.bdist_wheel
import setuptools.command.build_ext
Expand All @@ -43,8 +44,8 @@
# tiledb_dir and tiledbsoma_dir may be specified by either environment variable
# or command-line argument. If both are provided, the latter wins.

tiledb_dir: Optional[pathlib.Path] = None
tiledbsoma_dir: Optional[pathlib.Path] = None
tiledb_dir: pathlib.Path | None = None
tiledbsoma_dir: pathlib.Path | None = None
no_tiledb_dep: bool = False

args = sys.argv[:]
Expand Down
18 changes: 10 additions & 8 deletions apis/python/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
git tag -s v1.0
"""

from __future__ import annotations

__author__ = (
"Douglas Creager <[email protected]>",
"Michal Nazarewicz <[email protected]>",
Expand All @@ -75,7 +77,7 @@
from datetime import date
from os.path import basename, dirname, join, relpath
from subprocess import DEVNULL, CalledProcessError, check_output
from typing import List, Optional
from typing import List

GIT_RELPATH = "apis/python/version.py"
RELEASE_VERSION_FILE = join(dirname(__file__), "RELEASE-VERSION")
Expand All @@ -95,7 +97,7 @@ def err(*args, **kwargs):

def lines(
*cmd, drop_trailing_newline: bool = True, stderr=DEVNULL, **kwargs
) -> Optional[List[str]]:
) -> List[str] | None:
"""Run a command, return its stdout as a list of lines.
Strip each line's trailing newline, and drop the last line if it's empty, by default.
Expand All @@ -114,7 +116,7 @@ def lines(
return lns


def line(*cmd, **kwargs) -> Optional[str]:
def line(*cmd, **kwargs) -> str | None:
"""Verify a command produces exactly one line of stdout, and return it, otherwise `None`."""
lns = lines(*cmd, **kwargs)
if lns is None:
Expand All @@ -125,13 +127,13 @@ def line(*cmd, **kwargs) -> Optional[str]:
return lns[0]


def get_latest_tag() -> Optional[str]:
def get_latest_tag() -> str | None:
"""Return the most recent local Git tag of the form `[0-9].*.*` (or `None` if none exist)."""
tags = lines("git", "tag", "--list", "--sort=v:refname", "[0-9].*.*")
return tags[-1] if tags else None


def get_latest_remote_tag(remote: str) -> Optional[str]:
def get_latest_remote_tag(remote: str) -> str | None:
"""Return the most recent Git tag of the form `[0-9].*.*`, from a remote Git repository."""
tags = lines("git", "ls-remote", "--tags", "--sort=v:refname", remote, "[0-9].*.*")
if not tags:
Expand All @@ -148,7 +150,7 @@ def get_sha_base10() -> int:
return int(sha, 16)


def get_default_remote() -> Optional[str]:
def get_default_remote() -> str | None:
"""Find a Git remote to parse a most recent release tag from.
- If the current branch tracks a remote branch, use that remote
Expand All @@ -171,7 +173,7 @@ def get_default_remote() -> Optional[str]:
return None


def get_git_version() -> Optional[str]:
def get_git_version() -> str | None:
"""Construct a PEP440-compatible version string that encodes various Git state.
- If `git describe` returns a plain release tag, use that.
Expand Down Expand Up @@ -245,7 +247,7 @@ def get_git_version() -> Optional[str]:
return ver


def read_release_version() -> Optional[str]:
def read_release_version() -> str | None:
try:
with open(RELEASE_VERSION_FILE) as fd:
ver = fd.readline().strip()
Expand Down

0 comments on commit 1e06649

Please sign in to comment.