From 8bd420394ee5843d2ccac0ad03287a9e0ef896f2 Mon Sep 17 00:00:00 2001 From: facelessuser Date: Fri, 21 Oct 2022 19:59:22 -0600 Subject: [PATCH 1/2] Use hatchling for build --- .github/workflows/build.yml | 12 +++--- .github/workflows/deploy.yml | 12 ++---- MANIFEST.in | 15 -------- hatch_build.py | 51 +++++++++++++++++++++++++ pyproject.toml | 49 ++++++++++++++++++++++-- setup.cfg | 2 - setup.py | 74 ------------------------------------ tox.ini | 3 +- 8 files changed, 109 insertions(+), 109 deletions(-) delete mode 100644 MANIFEST.in create mode 100644 hatch_build.py delete mode 100644 setup.cfg delete mode 100644 setup.py diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 369d2d9..cd7924e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -37,7 +37,7 @@ jobs: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} if: "!endsWith(matrix.python-version, '-dev')" - uses: actions/setup-python@v1 + uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - name: Set up development Python ${{ matrix.python-version }} @@ -47,7 +47,7 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | - python -m pip install --upgrade pip setuptools tox coverage codecov + python -m pip install --upgrade pip build tox coverage codecov - name: Test run: | python -m tox @@ -74,12 +74,12 @@ jobs: steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v1 + uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | - python -m pip install --upgrade pip setuptools tox + python -m pip install --upgrade pip build tox - name: Lint run: | python -m tox @@ -98,12 +98,12 @@ jobs: steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v1 + uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | - python -m pip install --upgrade pip setuptools tox + python -m pip install --upgrade pip build tox - name: Install Aspell run: | sudo apt-get install aspell aspell-en diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 01ae866..a024caf 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -7,23 +7,19 @@ on: jobs: pypi: - strategy: - matrix: - distribution: [bdist_wheel, sdist] - runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: actions/setup-python@v1 + - uses: actions/setup-python@v2 with: python-version: '3.10' - name: Package run: | - pip install --upgrade setuptools wheel - python setup.py ${{ matrix.distribution }} + pip install --upgrade build + python -m build -s -w - name: Publish - uses: pypa/gh-action-pypi-publish@v1.0.0a0 + uses: pypa/gh-action-pypi-publish@release/v1 with: user: __token__ password: ${{ secrets.PYPI_TOKEN }} diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 9d825cc..0000000 --- a/MANIFEST.in +++ /dev/null @@ -1,15 +0,0 @@ -recursive-include materialx *.py -recursive-include tests *.py -recursive-include requirements *.txt -recursive-exclude site * -include .dictionary -include .pyspelling.yml -include setup.py -include setup.cfg -include tox.ini -include .coveragerc -include LICENSE.md -include README.md -include changelog.md -include MANIFEST.in -include pyproject.toml diff --git a/hatch_build.py b/hatch_build.py new file mode 100644 index 0000000..b623866 --- /dev/null +++ b/hatch_build.py @@ -0,0 +1,51 @@ +"""Dynamically define some metadata.""" +import os +from hatchling.metadata.plugin.interface import MetadataHookInterface + + +def get_version_dev_status(root): + """Get version_info without importing the entire module.""" + + import importlib.util + + path = os.path.join(root, "materialx", "__meta__.py") + spec = importlib.util.spec_from_file_location("__meta__", path) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module.__version_info__._get_dev_status() + + +def get_requirements(root): + """Load list of dependencies.""" + + install_requires = [] + with open(os.path.join(root, "requirements", "project.txt")) as f: + for line in f: + if not line.startswith("#"): + install_requires.append(line.strip()) + return install_requires + + +class CustomMetadataHook(MetadataHookInterface): + """Our metadata hook.""" + + def update(self, metadata): + """See https://ofek.dev/hatch/latest/plugins/metadata-hook/ for more information.""" + + metadata["dependencies"] = get_requirements(self.root) + metadata["classifiers"] = [ + f"Development Status :: {get_version_dev_status(self.root)}", + "Environment :: Console", + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Topic :: Internet :: WWW/HTTP :: Dynamic Content", + "Topic :: Software Development :: Libraries :: Python Modules", + "Topic :: Text Processing :: Filters", + "Topic :: Text Processing :: Markup :: HTML", + ] diff --git a/pyproject.toml b/pyproject.toml index 285367a..0e3916d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,50 @@ [build-system] requires = [ - "setuptools>=42", - "wheel" + "hatchling>=0.21.1", ] +build-backend = "hatchling.build" -build-backend = "setuptools.build_meta" +[project] +name = "mkdocs-material-extensions" +description = "Extension pack for Python Markdown and MkDocs Material." +readme = "README.md" +license = "MIT" +requires-python = ">=3.7" +authors = [ + { name = "Isaac Muse", email = "Isaac.Muse@gmail.com" }, +] +keywords = [ + "extensions", + "markdown", +] +dynamic = [ + "classifiers", + "dependencies", + "version", +] + +[project.urls] +Homepage = "https://github.com/facelessuser/mkdocs-material-extensions'" + +[tool.hatch.version] +source = "code" +path = "materialx/__meta__.py" + +[tool.hatch.build.targets.sdist] +include = [ + "/requirements/*.txt", + "/materialx/**/*.py", + "/tests/**/*.py", + "/.pyspelling.yml", + "/.coveragerc", + "/tox.ini", + "/LICENSE.md", + "/changelog.md" +] + +[tool.hatch.build.targets.wheel] +include = [ + "/materialx", +] + +[tool.hatch.metadata.hooks.custom] diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 21934a2..0000000 --- a/setup.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[metadata] -license_file = LICENSE.md diff --git a/setup.py b/setup.py deleted file mode 100644 index c90fee1..0000000 --- a/setup.py +++ /dev/null @@ -1,74 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -"""Setup mkdocs-material-extensions.""" - -from setuptools import setup, find_packages -import os - - -def get_version(): - """Get version and version_info without importing the entire module.""" - - import importlib.util - - path = os.path.join(os.path.dirname(__file__), 'materialx', '__meta__.py') - spec = importlib.util.spec_from_file_location("__meta__", path) - module = importlib.util.module_from_spec(spec) - spec.loader.exec_module(module) - vi = module.__version_info__ - return vi._get_canonical(), vi._get_dev_status() - - -def get_requirements(req): - """Load list of dependencies.""" - - install_requires = [] - with open(req) as f: - for line in f: - if not line.startswith("#"): - install_requires.append(line.strip()) - return install_requires - - -def get_description(): - """Get long description.""" - - with open("README.md", 'r') as f: - desc = f.read() - return desc - - -VER, DEVSTATUS = get_version() - - -setup( - name='mkdocs-material-extensions', - version=VER, - keywords='markdown extensions', - description='Extension pack for Python Markdown.', - long_description=get_description(), - long_description_content_type='text/markdown', - author='Isaac Muse', - author_email='Isaac.Muse@gmail.com', - python_requires='>=3.7', - url='https://github.com/facelessuser/mkdocs-material-extensions', - packages=find_packages(exclude=['tools', 'test*']), - install_requires=get_requirements("requirements/project.txt"), - license='MIT License', - classifiers=[ - 'Development Status :: %s' % DEVSTATUS, - 'Environment :: Console', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: MIT License', - 'Operating System :: OS Independent', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', - 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', - 'Topic :: Software Development :: Libraries :: Python Modules', - 'Topic :: Text Processing :: Filters', - 'Topic :: Text Processing :: Markup :: HTML', - ] -) diff --git a/tox.ini b/tox.ini index ed7d62e..f6e7e92 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,7 @@ [tox] +isolated_build = true envlist = - {py36,py37,py38,py39}, lint, documents + {py37,py38,py39,py310}, lint, documents [testenv] passenv = LANG From aeef097f89c96a18794457ff9b265baa95b0c5cc Mon Sep 17 00:00:00 2001 From: facelessuser Date: Fri, 21 Oct 2022 20:19:41 -0600 Subject: [PATCH 2/2] Update changelog and update __meta__ --- changelog.md | 1 + materialx/__meta__.py | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/changelog.md b/changelog.md index 51f194e..b95e82d 100644 --- a/changelog.md +++ b/changelog.md @@ -3,6 +3,7 @@ ## 1.1.0 - **NEW**: Drop Python 3.6 and officially support 3.10. +- **NEW**: Cache emoji table to reduce build times. ## 1.0.3 diff --git a/materialx/__meta__.py b/materialx/__meta__.py index b801651..ef18c51 100644 --- a/materialx/__meta__.py +++ b/materialx/__meta__.py @@ -69,9 +69,9 @@ class Version(namedtuple("Version", ["major", "minor", "micro", "release", "pre" Version(1, 0, 0, "final") 1.0 Version(1, 2, 0, "final") 1.2 Version(1, 2, 3, "final") 1.2.3 - Version(1, 2, 0, ".dev-alpha", pre=4) 1.2a4 - Version(1, 2, 0, ".dev-beta", pre=4) 1.2b4 - Version(1, 2, 0, ".dev-candidate", pre=4) 1.2rc4 + Version(1, 2, 0, "alpha", pre=4) 1.2a4 + Version(1, 2, 0, "beta", pre=4) 1.2b4 + Version(1, 2, 0, "candidate", pre=4) 1.2rc4 Version(1, 2, 0, "final", post=1) 1.2.post1 Version(1, 2, 3, ".dev") 1.2.3.dev0 Version(1, 2, 3, ".dev", dev=1) 1.2.3.dev1 @@ -113,12 +113,12 @@ def __new__(cls, major, minor, micro, release="final", pre=0, post=0, dev=0): elif dev: raise ValueError("Version is not a development release.") - return super(Version, cls).__new__(cls, major, minor, micro, release, pre, post, dev) + return super().__new__(cls, major, minor, micro, release, pre, post, dev) def _is_pre(self): """Is prerelease.""" - return self.pre > 0 + return bool(self.pre > 0) def _is_dev(self): """Is development.""" @@ -128,7 +128,7 @@ def _is_dev(self): def _is_post(self): """Is post.""" - return self.post > 0 + return bool(self.post > 0) def _get_dev_status(self): # pragma: no cover """Get development status string.""" @@ -139,7 +139,7 @@ def _get_canonical(self): """Get the canonical output string.""" # Assemble major, minor, micro version and append `pre`, `post`, or `dev` if needed.. - if self.micro == 0: + if self.micro == 0 and self.major != 0: ver = "{}.{}".format(self.major, self.minor) else: ver = "{}.{}.{}".format(self.major, self.minor, self.micro) @@ -153,11 +153,14 @@ def _get_canonical(self): return ver -def parse_version(ver, pre=False): +def parse_version(ver): """Parse version into a comparable Version tuple.""" m = RE_VER.match(ver) + if m is None: + raise ValueError("'{}' is not a valid version".format(ver)) + # Handle major, minor, micro major = int(m.group('major')) minor = int(m.group('minor')) if m.group('minor') else 0