Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24406 from charris/backport-24196
MAINT: Remove versioneer
- Loading branch information
Showing
24 changed files
with
169 additions
and
2,987 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import os | ||
import textwrap | ||
|
||
|
||
def init_version(): | ||
init = os.path.join(os.path.dirname(__file__), '../../pyproject.toml') | ||
data = open(init).readlines() | ||
|
||
version_line = next( | ||
line for line in data if line.startswith('version =') | ||
) | ||
|
||
version = version_line.strip().split(' = ')[1] | ||
version = version.replace('"', '').replace("'", '') | ||
|
||
return version | ||
|
||
|
||
def git_version(version): | ||
# Append last commit date and hash to dev version information, | ||
# if available | ||
|
||
import subprocess | ||
import os.path | ||
|
||
try: | ||
p = subprocess.Popen( | ||
['git', 'log', '-1', '--format="%H %aI"'], | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
cwd=os.path.dirname(__file__), | ||
) | ||
except FileNotFoundError: | ||
pass | ||
else: | ||
out, err = p.communicate() | ||
if p.returncode == 0: | ||
git_hash, git_date = ( | ||
out.decode('utf-8') | ||
.strip() | ||
.replace('"', '') | ||
.split('T')[0] | ||
.replace('-', '') | ||
.split() | ||
) | ||
|
||
# Only attach git tag to development versions | ||
if 'dev' in version: | ||
version += f'+git{git_date}.{git_hash[:7]}' | ||
else: | ||
git_hash = '' | ||
|
||
return version, git_hash | ||
|
||
|
||
if __name__ == "__main__": | ||
import argparse | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument('--write', help="Save version to this file") | ||
parser.add_argument( | ||
'--meson-dist', | ||
help='Output path is relative to MESON_DIST_ROOT', | ||
action='store_true' | ||
) | ||
args = parser.parse_args() | ||
|
||
version, git_hash = git_version(init_version()) | ||
|
||
# For NumPy 2.0, this should only have one field: `version` | ||
template = textwrap.dedent(f''' | ||
version = "{version}" | ||
__version__ = version | ||
full_version = version | ||
git_revision = "{git_hash}" | ||
release = 'dev' not in version and '+' not in version | ||
short_version = version.split("+")[0] | ||
''') | ||
|
||
if args.write: | ||
outfile = args.write | ||
if args.meson_dist: | ||
outfile = os.path.join( | ||
os.environ.get('MESON_DIST_ROOT', ''), | ||
outfile | ||
) | ||
|
||
# Print human readable output path | ||
relpath = os.path.relpath(outfile) | ||
if relpath.startswith('.'): | ||
relpath = outfile | ||
|
||
with open(outfile, 'w') as f: | ||
print(f'Saving version to {relpath}') | ||
f.write(template) | ||
else: | ||
print(version) |
Oops, something went wrong.