Skip to content

Commit

Permalink
Use miniver again
Browse files Browse the repository at this point in the history
  • Loading branch information
WillAyd committed Oct 29, 2024
1 parent 1c50f70 commit 0fcf0c3
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 10 deletions.
4 changes: 2 additions & 2 deletions dev/release/release_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ def set_python_dev_version_command(args):
_, last_dev_tag = find_last_dev_tag()
dev_distance = len(find_commits_since(last_dev_tag))

config_file = src_path("python", "meson.build")
version_file = src_path("python", "src", "nanoarrow", "_static_version.py")
file_regex_replace(
r'"([0-9]+\.[0-9]+\.[0-9]+)\.dev[0-9]+"',
f'"\\1.dev{dev_distance}"',
config_file,
version_file,
)


Expand Down
8 changes: 4 additions & 4 deletions dev/release/utils-prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ update_versions() {
git add DESCRIPTION
popd

pushd "${NANOARROW_DIR}/python/"
sed -i.bak -E "s/version = '.+'/version = '${python_version}'/" meson.build
rm meson.build.bak
git add meson.build
pushd "${NANOARROW_DIR}/python/src/nanoarrow"
sed -i.bak -E "s/version = \".+\"/version = \"${python_version}\"/" _static_version.py
rm _static_version.py.bak
git add _static_version.py
popd
}

Expand Down
2 changes: 1 addition & 1 deletion python/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
project(
'nanoarrow',
'c', 'cython',
version: '0.7.0.dev0',
version: run_command(['src/nanoarrow/_version.py', '--print'], check: true).stdout().strip(),
license: 'Apache-2.0',
meson_version: '>=1.2.0',
default_options: [
Expand Down
4 changes: 1 addition & 3 deletions python/src/nanoarrow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
Arrow C Data and Arrow C Stream interfaces.
"""

import importlib.metadata

from nanoarrow._utils import c_version
from nanoarrow.c_array import c_array_from_buffers, c_array
from nanoarrow.c_array_stream import c_array_stream
Expand Down Expand Up @@ -77,8 +75,8 @@
from nanoarrow.array import array, Array
from nanoarrow.array_stream import ArrayStream
from nanoarrow.visitor import nulls_as_sentinel, nulls_forbid, nulls_separate
from nanoarrow._version import __version__ # noqa: F401

__version__ = importlib.metadata.version("nanoarrow")

# Helps Sphinx automatically populate an API reference section
__all__ = [
Expand Down
25 changes: 25 additions & 0 deletions python/src/nanoarrow/_static_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
# This file is part of 'miniver': https://github.com/jbweston/miniver

# Replaced by version-bumping scripts at release time
version = "0.7.0.dev0"

# These values are only set if the distribution was created with 'git archive'
refnames = "$Format:%D$"
git_hash = "$Format:%h$"
52 changes: 52 additions & 0 deletions python/src/nanoarrow/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env python3

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
# This file is part of 'miniver': https://github.com/jbweston/miniver

import os

# No public API
__all__ = []

package_root = os.path.dirname(os.path.realpath(__file__))
package_name = os.path.basename(package_root)

STATIC_VERSION_FILE = "_static_version.py"


def get_version(version_file=STATIC_VERSION_FILE):
override = os.environ.get("SETUPTOOLS_SCM_PRETEND_VERSION")
if override is not None and override != "":
return override
version_info = get_static_version_info(version_file)
version = version_info["version"]
return version


def get_static_version_info(version_file=STATIC_VERSION_FILE):
version_info = {}
with open(os.path.join(package_root, version_file), "rb") as f:
exec(f.read(), {}, version_info)
return version_info


__version__ = get_version()

if __name__ == "__main__":
print(get_version())
2 changes: 2 additions & 0 deletions python/src/nanoarrow/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ endforeach

py_sources = [
'__init__.py',
'_static_version.py',
'_version.py',
'array.py',
'array_stream.py',
'c_array.py',
Expand Down

0 comments on commit 0fcf0c3

Please sign in to comment.