Skip to content

Commit

Permalink
Add some tags_marker.py documentation (fixes #8), add comments, remov…
Browse files Browse the repository at this point in the history
…e debug messages
  • Loading branch information
NikitaBeloglazov committed Feb 7, 2024
1 parent 6365663 commit c3120b7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "clipman"
version = "!!{PLACEHOLDER}!!"
version = "!!{PLACEHOLDER}!!" # PLEASE RUN tags_marker.py BEFORE PACKAGING
authors = [
{name="NikitaBeloglazov", email="nnikita.beloglazov@gmail.com"},
]
Expand Down
54 changes: 45 additions & 9 deletions tags_marker.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,55 @@
# -*- coding: utf-8 -*-
"""
* Copyright (C) 2023 Nikita Beloglazov <nnikita.beloglazov@gmail.com>
*
* 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
import os

os.system("tree -a")
os.system("git fetch --tags")
print(subprocess.check_output("git tag -n9", shell=True, encoding="UTF-8"))
# - 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")
# Open the file for reading and writing (the 'r+' mode provides both read and write access)
with open('pyproject.toml', 'r+') as file:
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
Expand All @@ -27,8 +62,9 @@
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+') as file:
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
Expand All @@ -41,4 +77,4 @@
file.truncate()
print("[TAG MARKER] DONE")

print("[TAG MARKER] Work finished")
print("[TAG MARKER] Marking complete")

0 comments on commit c3120b7

Please sign in to comment.