From 3a73707abd48c9df214646d57204cff854bbe98b Mon Sep 17 00:00:00 2001 From: Laurent Franceschetti Date: Thu, 17 Oct 2024 06:41:48 +0200 Subject: [PATCH] Migrate to pyproject.toml - change update_pypi.sh accordingly --- CHANGELOG.md | 9 ++++-- _setup.py | 75 ++++++++++++++++++++++++++++++++++++++++++++++++ pyproject.toml | 58 +++++++++++++++++++++++++++++++++++++ setup.py | 77 +++++--------------------------------------------- update_pypi.sh | 42 +++++++++++++++++---------- 5 files changed, 174 insertions(+), 87 deletions(-) create mode 100644 _setup.py create mode 100644 pyproject.toml diff --git a/CHANGELOG.md b/CHANGELOG.md index 93e14e5..0a106a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,14 @@ -# Changelog: mkdocs-macros +# Changelog: Mkdocs-Dacros -All notable changes to this project will be documented in this file. +All notable changes to this project are documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 1.3.7, 2024-10-17 +* Added: complete test framework, using pytest and Mkdocs-Test (#244) + A number of automated test cases are implemented. +* Changed: move from setup.py to pyproject.toml (#250) + ## 1.2.0, 2024-09-15 * Added: three hooks `register_variables/macros/filters` to facilitate cooperation with other MkDocs plugins. diff --git a/_setup.py b/_setup.py new file mode 100644 index 0000000..553059f --- /dev/null +++ b/_setup.py @@ -0,0 +1,75 @@ +# -------------------------------------------- +# Setup file for the package +# +# Laurent Franceschetti (c) 2018-2020 +# THIS IS THE OLD VERSION, kept for reference purposes +# -------------------------------------------- + +import os +from setuptools import setup, find_packages + + +# -------------------- +# Initialization +# -------------------- + +VERSION_NUMBER = '1.3.7' + +# required if you want to run document/test +# pip install 'mkdocs-macros-plugin[test]' +TEST_REQUIRE = ['mkdocs-macros-test', 'mkdocs-material>=6.2', + 'mkdocs-include-markdown-plugin', 'mkdocs-test'] + +# -------------------- +# Setup +# -------------------- + + +def read_file(fname): + "Read a local file" + return open(os.path.join(os.path.dirname(__file__), fname), encoding="utf-8").read() + + +setup( + name='mkdocs-macros-plugin', + version=VERSION_NUMBER, + description="Unleash the power of MkDocs with macros and variables", + long_description=read_file('README.md'), + long_description_content_type='text/markdown', + keywords='mkdocs python markdown macros', + url='https://github.com/fralau/mkdocs_macros_plugin', + author='Laurent Franceschbetti', + author_email='info@settlenext.com', + license='MIT', + python_requires='>=3.8', + install_requires=[ + 'mkdocs>=0.17', + 'jinja2', + 'termcolor', + 'pyyaml', + 'hjson', + 'pathspec', + 'python-dateutil', + 'packaging', + 'super-collections' + ], + extras_require={ + 'test': TEST_REQUIRE, + }, + classifiers=[ + 'Development Status :: 5 - Production/Stable', + 'Intended Audience :: Developers', + 'Intended Audience :: Information Technology', + 'License :: OSI Approved :: MIT License', + 'Programming Language :: Python', + 'Programming Language :: Python :: 3 :: Only', + 'Programming Language :: Python :: 3.5', + ], + include_package_data=True, + packages=find_packages(exclude=['*.tests']), + entry_points={ + 'mkdocs.plugins': [ + 'macros = mkdocs_macros.plugin:MacrosPlugin', + ] + } +) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..54ce588 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,58 @@ +[project] +name = "mkdocs-macros-plugin" + +# This version number is the REFERENCE for the rest of the project, +# particularly for update_pypi.sh +version = "1.3.6" + +description = "Unleash the power of MkDocs with macros and variables" +readme = "README.md" +license = { text = "MIT" } +requires-python = ">=3.8" +authors = [ + { name = "Laurent Franceschetti", email = "info@settlenext.com" }, +] +keywords = [ + "macros", + "markdown", + "mkdocs", + "python", +] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "Intended Audience :: Information Technology", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.5", +] +dependencies = [ + "hjson", + "jinja2", + "mkdocs>=0.17", + "packaging", + "pathspec", + "python-dateutil", + "pyyaml", + "super-collections", + "termcolor", +] + +[tool.setuptools] +packages = { find = { exclude = ["*.tests"] } } + +[project.optional-dependencies] +test = [ + "mkdocs-include-markdown-plugin", + "mkdocs-macros-test", + "mkdocs-material>=6.2", + "mkdocs-test", +] + +[project.entry-points."mkdocs.plugins"] +macros = "mkdocs_macros.plugin:MacrosPlugin" + +[project.urls] +Homepage = "https://github.com/fralau/mkdocs_macros_plugin" + diff --git a/setup.py b/setup.py index 5e63ab3..813f280 100644 --- a/setup.py +++ b/setup.py @@ -1,74 +1,11 @@ -# -------------------------------------------- -# Setup file for the package -# -# Laurent Franceschetti (c) 2018-2020 -# -------------------------------------------- - -import os -from setuptools import setup, find_packages - - -# -------------------- -# Initialization -# -------------------- - -VERSION_NUMBER = '1.3.6' - -# required if you want to run document/test -# pip install 'mkdocs-macros-plugin[test]' -TEST_REQUIRE = ['mkdocs-macros-test', 'mkdocs-material>=6.2', - 'mkdocs-include-markdown-plugin', 'mkdocs-test'] - -# -------------------- -# Setup -# -------------------- - - -def read_file(fname): - "Read a local file" - return open(os.path.join(os.path.dirname(__file__), fname), encoding="utf-8").read() +""" +Installation using setup.py is no longer supported. +Use `python -m pip install .` instead. +""" +from setuptools import setup +# Fake reference so GitHub still considers it a real package for statistics purposes. setup( name='mkdocs-macros-plugin', - version=VERSION_NUMBER, - description="Unleash the power of MkDocs with macros and variables", - long_description=read_file('README.md'), - long_description_content_type='text/markdown', - keywords='mkdocs python markdown macros', - url='https://github.com/fralau/mkdocs_macros_plugin', - author='Laurent Franceschbetti', - author_email='info@settlenext.com', - license='MIT', - python_requires='>=3.8', - install_requires=[ - 'mkdocs>=0.17', - 'jinja2', - 'termcolor', - 'pyyaml', - 'hjson', - 'pathspec', - 'python-dateutil', - 'packaging', - 'super-collections' - ], - extras_require={ - 'test': TEST_REQUIRE, - }, - classifiers=[ - 'Development Status :: 5 - Production/Stable', - 'Intended Audience :: Developers', - 'Intended Audience :: Information Technology', - 'License :: OSI Approved :: MIT License', - 'Programming Language :: Python', - 'Programming Language :: Python :: 3 :: Only', - 'Programming Language :: Python :: 3.5', - ], - include_package_data=True, - packages=find_packages(exclude=['*.tests']), - entry_points={ - 'mkdocs.plugins': [ - 'macros = mkdocs_macros.plugin:MacrosPlugin', - ] - } -) +) \ No newline at end of file diff --git a/update_pypi.sh b/update_pypi.sh index 30e5333..275a21a 100755 --- a/update_pypi.sh +++ b/update_pypi.sh @@ -1,8 +1,10 @@ # ------------------------------------------------------------- # update the package on pypi +# 2024-10-12 # # Tip: if you don't want to retype pypi's username every time # define it as an environment variable (TWINE_USERNAME) +# # ------------------------------------------------------------- function warn { GREEN='\033[0;32m' @@ -10,25 +12,35 @@ function warn { echo -e "${GREEN}$1${NORMAL}" } -setup="python3 setup.py" -package_name=$($setup --name) -package_version=v$($setup --version) # add a 'v' in front (git convention) +function get_value { + # get the value from the config file (requires the Python toml package) + toml get --toml-path pyproject.toml $1 +} + +# Clean the subdirs, for safety and to guarantee integrity +# ./cleanup.sh -warn "UPDATE PACKAGE $package_name ($package_version) ON PYPI:" -warn "Cleaning up..." -rm -rf dist -rm -rf build -warn "Recreating wheels..." -$setup sdist bdist_wheel 1>/dev/null -# update version (just in case): -package_version=v$($setup --version) # add a 'v' in front (git convention) -warn "---" -warn "Upload to Pypi..." -if twine upload --repository-url https://upload.pypi.org/legacy/ dist/* ; then +# Check for changes in the files compared to the repository +if ! git diff --quiet; then + warn "Won't do it: there are changes in the repository. Please commit first!" + exit 1 +fi + +# get the project inform +package_name=$(get_value project.name) +package_version=v$(get_value project.version) # add a 'v' in front (git convention) + +# update Pypi +warn "Rebuilding $package_name..." +rm -rf build dist *.egg-info # necessary to guarantee integrity +python3 -m build +if twine upload dist/* ; then + git push # just in case warn "... create tag $package_version, and push to remote git repo..." git tag $package_version git push --tags warn "Done ($package_version)!" else warn "Failed ($package_version)!" -fi + exit 1 +fi \ No newline at end of file