Skip to content

Commit 30acdff

Browse files
committed
[none] Project utility improvement
- Replaced the deprecated license info in `pyproject.toml` with a viable solution - Improved repo url hanlding in the `process_md_doc.py` script - Aligned Makefile targets to use colorized info logs and suppress unnecessary command output - Added the `upload-test` Makefile target for uploading the project to testpypi
1 parent e4c21d2 commit 30acdff

File tree

4 files changed

+61
-24
lines changed

4 files changed

+61
-24
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2024 Jakub Musiał
3+
Copyright (c) 2024-2025 Jakub Musiał
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Makefile

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
PY := python3
22
PYM := $(PY) -m
33

4+
COLOR_RESET := \033[0m
5+
COLOR_GREEN := \033[1;32m
6+
COLOR_CYAN := \033[1;33m
7+
COLOR_CYAN := \033[1;36m
8+
COLOR_RED := \033[1;31m
9+
410
.PHONY: \
511
prepare-venv \
612
clean-venv \
@@ -17,47 +23,78 @@ PYM := $(PY) -m
1723
upload
1824

1925
prepare-venv:
26+
@echo "$(COLOR_CYAN)> Creating virtual environment...$(COLOR_RESET)"; \
2027
$(PYM) venv venv && \
21-
. venv/bin/activate && \
22-
pip install -r requirements-dev.txt
28+
echo "$(COLOR_CYAN)> Installing dev dependencies...$(COLOR_RESET)"; \
29+
. venv/bin/activate && pip install -r requirements-dev.txt > /dev/null
2330

2431
clean-venv:
32+
@echo "$(COLOR_CYAN)> Removing virtual environment...$(COLOR_RESET)"; \
2533
rm -rf venv/
2634

27-
source-venv:
28-
. venv/bin/activate
29-
3035
tests-simple:
36+
@echo "$(COLOR_CYAN)> Running tests (simple) ...$(COLOR_RESET)"; \
3137
$(PYM) pytest test/
3238

33-
# tox will generate the coverage report
3439
tests-tox:
40+
@echo "$(COLOR_CYAN)> Running tests (tox)...$(COLOR_RESET)"; \
3541
$(PYM) tox
3642

3743
clean-tests:
44+
@echo "$(COLOR_CYAN)> Cleaning test artifacts...$(COLOR_RESET)"; \
3845
rm -rf .pytest_cache/ .tox/
3946

4047
clean-cov:
48+
@echo "$(COLOR_CYAN)> Cleaning coverage files...$(COLOR_RESET)"; \
4149
rm -rf .coverage*
4250

43-
build:
44-
$(PY) scripts/preprocess_md_doc.py
45-
$(PYM) build
46-
4751
clean-build:
52+
@echo "$(COLOR_CYAN)> Cleaning build artifacts...$(COLOR_RESET)"; \
4853
rm -rf build/ dist/ *.egg-info README_pypi.md
4954

55+
build: clean-build
56+
@ALL_TAGS=$$(git tag | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$$' | sort -V); \
57+
LATEST_TAG=$$(echo "$$ALL_TAGS" | tail -n 1); \
58+
echo "$(COLOR_CYAN)> Latest git tag: $(COLOR_YELLOW)$$LATEST_TAG$(COLOR_RESET)"; \
59+
PY_VERSION=$$(sed -n 's/^version *= *"\([^"]*\)".*$$/\1/p' pyproject.toml); \
60+
echo "$(COLOR_CYAN)> Current version (pyproject.toml): $(COLOR_CYAN)$$PY_VERSION$(COLOR_RESET)"; \
61+
if [ "$${LATEST_TAG#v}" != "$$PY_VERSION" ]; then \
62+
echo "$(COLOR_RED)> ERROR: Git tag ($$LATEST_TAG) and pyproject version ($$PY_VERSION) do not match.$(COLOR_RESET)"; \
63+
exit 1; \
64+
fi; \
65+
echo "$(COLOR_CYAN)> Processing project README...$(COLOR_RESET)"; \
66+
$(PY) scripts/process_md_doc.py --version $$LATEST_TAG > /dev/null; \
67+
echo "$(COLOR_CYAN)> Building the distribution...$(COLOR_RESET)"; \
68+
$(PYM) build > /dev/null; \
69+
BUILD_EXIT_CODE=$$?; \
70+
if [ $$BUILD_EXIT_CODE -eq 0 ]; then \
71+
echo "$(COLOR_GREEN)> Build complete.$(COLOR_RESET)"; \
72+
else \
73+
echo "$(COLOR_RED)> Build failed.$(COLOR_RESET)"; \
74+
exit $$BUILD_EXIT_CODE; \
75+
fi
76+
5077
ruff:
51-
$(PYM) ruff format && ruff check --fix
78+
@echo "$(COLOR_CYAN)> Running formatter...$(COLOR_RESET)"; \
79+
$(PYM) ruff format; \
80+
echo "$(COLOR_CYAN)> Running linter...$(COLOR_RESET)"; \
81+
$(PYM) ruff check --fix
5282

5383
clean-ruff:
84+
@echo "$(COLOR_CYAN)> Cleaning ruff cache...$(COLOR_RESET)"; \
5485
rm -rf .ruff_cache/
5586

5687
clean-all: clean-venv clean-tests clean-cov clean-build clean-ruff
5788

5889
install:
59-
$(PYM) pip uninstall -y pypformat || true
60-
$(PYM) pip install .
90+
@echo "$(COLOR_CYAN)> Reinstalling local package...$(COLOR_RESET)"; \
91+
$(PYM) pip uninstall -y pypformat > /dev/null || true; \
92+
$(PYM) pip install . > /dev/null
6193

62-
upload: build
94+
upload: clean-build build
95+
@echo "$(COLOR_CYAN)> Uploading distribution to pypi...$(COLOR_RESET)"; \
6396
$(PYM) twine upload dist/*
97+
98+
upload-test: clean-build build
99+
@echo "$(COLOR_CYAN)> Uploading distribution to testpypi...$(COLOR_RESET)"; \
100+
$(PYM) twine upload --repository testpypi dist/*

pyproject.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ build-backend = "setuptools.build_meta"
55

66
[project]
77
name = "pypformat"
8-
version = "1.2.2"
8+
version = "1.2.3"
99
description = "Python pretty formatting package"
1010
authors = [
1111
{name = "SpectraL519"}
1212
]
1313
readme = {file = "README_pypi.md", content-type = "text/markdown; charset=UTF-8; variant=GFM"}
14-
license = {file = "LICENSE"}
14+
license = "MIT"
15+
license-files = ["LICENSE"]
1516
requires-python = ">= 3.9"
1617
dependencies = ["colored==2.2.*"]
1718
keywords = ["string", "format", "formatting", "pretty", "print"]
@@ -21,8 +22,6 @@ classifiers = [
2122
"Intended Audience :: Developers",
2223
"Topic :: Software Development :: Libraries :: Python Modules",
2324

24-
"License :: OSI Approved :: MIT License",
25-
2625
"Programming Language :: Python :: 3",
2726
"Programming Language :: Python :: 3.9",
2827
"Programming Language :: Python :: 3.10",

scripts/preprocess_md_doc.py renamed to scripts/process_md_doc.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
from pathlib import Path
44

55

6-
def preprocess_md_doc(input_file: Path, output_file: Path, repo_url: str):
6+
def process_md_doc(input_file: Path, output_file: Path, version: str):
77
with open(input_file, "r", encoding="utf-8") as f:
88
content = f.read()
99

10+
repo_url = f"https://github.com/SpectraL519/pypformat/blob/{version}"
11+
1012
updated_content = re.sub(
1113
r"\[([^\]]+)\]\((?!http)(.*?)\)",
1214
lambda match: f"[{match.group(1)}]({repo_url}/{match.group(2).lstrip('./')})",
@@ -30,14 +32,13 @@ def parse_args():
3032
help="Path to the output README file.",
3133
)
3234
parser.add_argument(
33-
"-r",
34-
"--repo-url",
35+
"-v",
36+
"--version",
3537
type=str,
36-
default="https://github.com/SpectraL519/repo/blob/master",
3738
help="Base URL of the repository.",
3839
)
3940
return vars(parser.parse_args())
4041

4142

4243
if __name__ == "__main__":
43-
preprocess_md_doc(**parse_args())
44+
process_md_doc(**parse_args())

0 commit comments

Comments
 (0)