1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
# SPDX-FileCopyrightText: 2022 The meson-python developers
#
# SPDX-License-Identifier: MIT
import argparse
import os
def write_version_info(path):
# A real project would call something to generate this
dummy_version = '1.0.0'
dummy_hash = '013j2fiejqea'
if os.environ.get('MESON_DIST_ROOT'):
path = os.path.join(os.environ.get('MESON_DIST_ROOT'), path)
with open(path, 'w') as file:
file.write(f'__version__="{dummy_version}"\n')
file.write(
f'__git_version__="{dummy_hash}"\n'
)
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
'-o', '--outfile', type=str, help='Path to write version info to'
)
args = parser.parse_args()
if not args.outfile.endswith('.py'):
raise ValueError(
f'Output file must be a Python file. '
f'Got: {args.outfile} as filename instead'
)
write_version_info(args.outfile)
main()
|