From 2868326411bec6cfd1e30f3e8f96394f7cbc4817 Mon Sep 17 00:00:00 2001 From: Maxwell G Date: Fri, 23 Feb 2024 01:12:17 +0000 Subject: [PATCH 1/4] Use setuptools_scm to generate package version Fixes: https://github.com/NikitaBeloglazov/clipman/issues/8 --- .git_archival.txt | 4 ++++ .gitattributes | 1 + pyproject.toml | 6 ++++-- src/clipman/__version__.py | 16 ++++++++++++---- 4 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 .git_archival.txt create mode 100644 .gitattributes diff --git a/.git_archival.txt b/.git_archival.txt new file mode 100644 index 0000000..8fb235d --- /dev/null +++ b/.git_archival.txt @@ -0,0 +1,4 @@ +node: $Format:%H$ +node-date: $Format:%cI$ +describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$ +ref-names: $Format:%D$ diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..00a7b00 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +.git_archival.txt export-subst diff --git a/pyproject.toml b/pyproject.toml index 1f9c2bf..9f98bb2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,10 @@ [build-system] -requires = ["setuptools>=61.0"] +requires = ["setuptools>=61.0", "setuptools_scm"] build-backend = "setuptools.build_meta" [project] name = "clipman" -version = "!!{PLACEHOLDER}!!" # PLEASE RUN tags_marker.py BEFORE PACKAGING +dynamic = ["version"] authors = [ {name="NikitaBeloglazov", email="nnikita.beloglazov@gmail.com"}, ] @@ -28,3 +28,5 @@ classifiers = [ [project.urls] "Homepage" = "https://github.com/NikitaBeloglazov/clipman" "Bug Tracker" = "https://github.com/NikitaBeloglazov/clipman/issues" + +[tool.setuptools_scm] diff --git a/src/clipman/__version__.py b/src/clipman/__version__.py index 8994925..efac672 100644 --- a/src/clipman/__version__.py +++ b/src/clipman/__version__.py @@ -1,7 +1,15 @@ """ Created for storing version number. -The version number will be placed here based on the tag in Github using the tags_marker.py script. - -Having "!!{PLACEHOLDER}!!" in final releases is NOT allowed. """ -__version__="!!{PLACEHOLDER}!!" + +# Dynamically determine __version__ from package metadata + +from importlib.metadata import PackageNotFoundError, version + +try: + __version__ = version("clipman") +except PackageNotFoundError: + # Fallback for when running from the source directory + __version__ = "0.0.0+unknown" + +__all__ = ("__version__",) From 4f71580278de4d085e63e5f892f3ca6c7b261e0a Mon Sep 17 00:00:00 2001 From: Nikita Beloglazov <77229847+NikitaBeloglazov@users.noreply.github.com> Date: Fri, 23 Feb 2024 04:28:37 +0200 Subject: [PATCH 2/4] Delete uneeded files --- .git_archival.txt | 4 ---- .gitattributes | 1 - 2 files changed, 5 deletions(-) delete mode 100644 .git_archival.txt delete mode 100644 .gitattributes diff --git a/.git_archival.txt b/.git_archival.txt deleted file mode 100644 index 8fb235d..0000000 --- a/.git_archival.txt +++ /dev/null @@ -1,4 +0,0 @@ -node: $Format:%H$ -node-date: $Format:%cI$ -describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$ -ref-names: $Format:%D$ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 00a7b00..0000000 --- a/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -.git_archival.txt export-subst From 7f1b4dc7d20784b9e9e3d26f287c7660d337613f Mon Sep 17 00:00:00 2001 From: Nikita Beloglazov <77229847+NikitaBeloglazov@users.noreply.github.com> Date: Fri, 23 Feb 2024 04:31:28 +0200 Subject: [PATCH 3/4] Add some configs for tool.setuptools_scm, rework __version__.py --- pyproject.toml | 10 +++++++++- src/clipman/__version__.py | 19 +++++++------------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 9f98bb2..753a5fa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "clipman" -dynamic = ["version"] +dynamic = ["version"] # setuptools_scm authors = [ {name="NikitaBeloglazov", email="nnikita.beloglazov@gmail.com"}, ] @@ -30,3 +30,11 @@ classifiers = [ "Bug Tracker" = "https://github.com/NikitaBeloglazov/clipman/issues" [tool.setuptools_scm] +# DO NOT add numbers to version. I decide which version I need to post +version_scheme = "release-branch-semver" + +# get only tag, 3.2.0, not an 3.2.0.dev17+g2868326.d20240223abcdefghijklmnopqrstuvwxyz +git_describe_command = "git describe --tags main" + +# overwrites an fallback template +version_file = "src/clipman/__version__.py" diff --git a/src/clipman/__version__.py b/src/clipman/__version__.py index efac672..b64b331 100644 --- a/src/clipman/__version__.py +++ b/src/clipman/__version__.py @@ -1,15 +1,10 @@ """ Created for storing version number. -""" - -# Dynamically determine __version__ from package metadata - -from importlib.metadata import PackageNotFoundError, version +The version number will be placed here based on the tag in Github using the setuptools_scm. +This file must be overwritten -try: - __version__ = version("clipman") -except PackageNotFoundError: - # Fallback for when running from the source directory - __version__ = "0.0.0+unknown" - -__all__ = ("__version__",) +Having 0.0.0 in final releases is NOT allowed. +If you see this comment, setuptools_scm was not started +""" +__version__ = version = '0.0.0' +__version_tuple__ = version_tuple = (0, 0, 0) From 74f64f42207f578dd99ffdd0b23d7aca36796018 Mon Sep 17 00:00:00 2001 From: Nikita Beloglazov <77229847+NikitaBeloglazov@users.noreply.github.com> Date: Fri, 23 Feb 2024 04:33:30 +0200 Subject: [PATCH 4/4] Clean up old files --- .github/workflows/python-publish.yml | 2 - tags_marker.py | 80 ---------------------------- 2 files changed, 82 deletions(-) delete mode 100644 tags_marker.py diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 3846e31..0bc122d 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -35,8 +35,6 @@ jobs: run: | python -m pip install --upgrade pip pip install build - - name: Mark version - run: python3 tags_marker.py - name: Build package run: python -m build - name: Store the distribution packages diff --git a/tags_marker.py b/tags_marker.py deleted file mode 100644 index dfcf268..0000000 --- a/tags_marker.py +++ /dev/null @@ -1,80 +0,0 @@ -# -*- coding: utf-8 -*- -""" - * Copyright (C) 2023 Nikita Beloglazov - * - * This file is part of github.com/NikitaBeloglazov/clipman. - * - * NikitaBeloglazov/clipman is free software; you can redistribute it and/or - * modify it under the terms of the Mozilla Public License 2.0 - * published by the Mozilla Foundation. - * - * NikitaBeloglazov/clipman is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY. - * - * You should have received a copy of the Mozilla Public License 2.0 - * along with NikitaBeloglazov/clipman - * If not, see https://mozilla.org/en-US/MPL/2.0. - -- = - = - * Module Decsription: - In short, all it does is find the latest release number using git, - and replace the special placeholders (!!{PLACEHOLDER}!!) - with the latest release version number that it finds. - - This module is mostly designed for automatic assembly. - - [!!] Works only if the folder has the git system initialized. - (In simple, `git clone` and `.git` folder is required) - - # TODO?: Change this file name -""" - -# - DEBUG - -#import os -#os.system("tree -a") -#os.system("git fetch --tags") -#print(subprocess.check_output("git tag -n9", shell=True, encoding="UTF-8")) - -import subprocess - -# - Get current tag -tag = subprocess.check_output("git describe --tags", shell=True, encoding="UTF-8") -print("[TAG MARKER] git response: " + tag) - -# - Clear tag from junk, you need to get numbers with dots only -tag = tag.replace("\n", "").replace("v", "") -if tag.find("-") > 1: - tag = tag[0:tag.find("-")] -print("[TAG MARKER] FOUND TAG: " + tag) - -# - Mark pyproject.toml -print("[TAG MARKER] MARKING VERSION IN pyproject.toml") -with open('pyproject.toml', 'r+', encoding="utf-8") as file: - # Reading the contents of a file - content = file.read() - # Replace the desired part of the text using the replace method - new_content = content.replace('!!{PLACEHOLDER}!!', tag) - # Move the file pointer to the beginning (0) to overwrite - file.seek(0) - # Write the changed content back to the file - file.write(new_content) - # Trim the file if the new content is shorter than the old one to remove the remaining data - file.truncate() -print("[TAG MARKER] DONE") - -# - Mark src/clipman/__version__.py -print("[TAG MARKER] MARKING VERSION IN src/clipman/__version__.py") -with open('src/clipman/__version__.py', 'r+', encoding="utf-8") as file: - # Reading the contents of a file - content = file.read() - # Replace the desired part of the text using the replace method - new_content = content.replace('!!{PLACEHOLDER}!!', tag) - # Move the file pointer to the beginning (0) to overwrite - file.seek(0) - # Write the changed content back to the file - file.write(new_content) - # Trim the file if the new content is shorter than the old one to remove the remaining data - file.truncate() -print("[TAG MARKER] DONE") - -print("[TAG MARKER] Marking complete")