From bf8e70c1ff7ae34279e68c348a1c1454853d0277 Mon Sep 17 00:00:00 2001 From: Georges Toth Date: Tue, 19 Dec 2023 18:21:12 +0100 Subject: [PATCH] migrate setup.py to pyproject.toml; use setuptools-scm; fixes #357 --- .gitignore | 1 + CHANGELOG.md | 1 + RELEASE-HOWTO.md | 12 +++++-- caldav/__init__.py | 3 +- caldav/davclient.py | 8 +++-- caldav/elements/base.py | 8 +++-- caldav/lib/url.py | 7 +++- caldav/objects.py | 9 +++-- pyproject.toml | 55 ++++++++++++++++++++++++++++ setup.py | 80 ++--------------------------------------- setup.cfg => tox.ini | 0 11 files changed, 95 insertions(+), 89 deletions(-) create mode 100644 pyproject.toml rename setup.cfg => tox.ini (100%) diff --git a/.gitignore b/.gitignore index 0ebf7f30..ca48debb 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,4 @@ tests/conf_private.py .tox .eggs .venv +caldav/_version.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 8574bb78..c4aae042 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ This project should more or less adhere to [Semantic Versioning](https://semver. * Initial work at integrating typing information. Details in https://github.com/python-caldav/caldav/pull/358 * Remove dependency on pytz. Details in https://github.com/python-caldav/caldav/issues/231 +* Use setuptools-scm / pyproject.toml (modern packaging). Details in https://github.com/python-caldav/caldav/pull/364 ## [1.3.9] - 2023-12-12 diff --git a/RELEASE-HOWTO.md b/RELEASE-HOWTO.md index 1fdf0c97..0c364da8 100644 --- a/RELEASE-HOWTO.md +++ b/RELEASE-HOWTO.md @@ -15,12 +15,18 @@ I have no clue on the proper procedures for doing releases, and I keep on doing * For minor and major releases, look through the github issues, anything urgent there that should be fixed prior to doing a new release? * Write up some release notes. (I typically keep a short summary of the changes in the CHANGELOG, and use that as the release notes). * Verify that we're on the right branch - `git checkout master`. (`master` may not always be right - sometimes we may want to use a dedicated branch connected to the release-series, i.e. `v1.3`) -* Change the version number in `caldav/__init__.py`. * Commit the changes (typically `CHANGELOG.md`, `__init__.py`, documentation): `git commit -am "preparing for releasing v${VERSION}` * Create a tag: `git tag -as v${VERSION}` - use the release notes in the tag message. * Make a clone: `git clone caldav/ caldav-release ; cd caldav-release ; git checkout v${VERSION}` * Run tests (particularly the style check): `pytest` and `tox -e style`. -* Double-verify that the version-number in `__init__.py` is correct: `grep version caldav/__init__.py` * Push the code to github: `cd ~/caldav ; git push ; git push --tags` * Some people relies on the github release system for finding releases - go to https://github.com/python-caldav/caldav/releases/new, choose the new tag, copy the version number and the release notes in. -* The most important part - push to pypi: `cd ~/caldav-release ; python setup.py sdist bdist_wheel ; python -m twine upload dist/*` +* The most important part - push to pypi: + ``` + cd ~/caldav-release + python3 -m venv venv + . venv/bin/activate + pip install -U pip build twine + python -m build + python -m twine upload dist/* + ``` diff --git a/caldav/__init__.py b/caldav/__init__.py index 6c117346..74543994 100644 --- a/caldav/__init__.py +++ b/caldav/__init__.py @@ -3,8 +3,7 @@ import vobject.icalendar -__version__ = "1.3.9" - +from ._version import __version__ from .davclient import DAVClient from .objects import * diff --git a/caldav/davclient.py b/caldav/davclient.py index eeea9bd6..628b0e60 100644 --- a/caldav/davclient.py +++ b/caldav/davclient.py @@ -9,7 +9,6 @@ from urllib.parse import unquote import requests -import typing_extensions from caldav.elements import dav from caldav.lib import error from caldav.lib.python_utilities import to_normal_str @@ -35,6 +34,11 @@ else: from collections.abc import Iterable, Mapping +if sys.version_info < (3, 11): + from typing_extensions import Self +else: + from typing import Self + class DAVResponse: """ @@ -434,7 +438,7 @@ def __init__( self._principal = None - def __enter__(self) -> typing_extensions.Self: + def __enter__(self) -> Self: return self def __exit__( diff --git a/caldav/elements/base.py b/caldav/elements/base.py index e91f0a3a..e2b1862c 100644 --- a/caldav/elements/base.py +++ b/caldav/elements/base.py @@ -11,14 +11,18 @@ from caldav.lib.python_utilities import to_unicode from lxml import etree from lxml.etree import _Element -from typing_extensions import Self -from typing_extensions import TypeAlias + if sys.version_info < (3, 9): from typing import Iterable else: from collections.abc import Iterable +if sys.version_info < (3, 11): + from typing_extensions import Self +else: + from typing import Self + class BaseElement: children: Optional[List[Self]] = None diff --git a/caldav/lib/url.py b/caldav/lib/url.py index e5790b42..9dbba958 100644 --- a/caldav/lib/url.py +++ b/caldav/lib/url.py @@ -1,5 +1,6 @@ #!/usr/bin/env python # -*- encoding: utf-8 -*- +import sys import typing import urllib.parse from typing import Union @@ -12,7 +13,11 @@ from caldav.lib.python_utilities import to_normal_str from caldav.lib.python_utilities import to_unicode -from typing_extensions import Self + +if sys.version_info < (3, 11): + from typing_extensions import Self +else: + from typing import Self class URL: diff --git a/caldav/objects.py b/caldav/objects.py index 7aeddbc3..6f54a627 100644 --- a/caldav/objects.py +++ b/caldav/objects.py @@ -35,8 +35,6 @@ class hierarchy into a separate file) from dateutil.rrule import rrulestr from lxml import etree from lxml.etree import _Element -from typing_extensions import Literal -from typing_extensions import Self from vobject.base import VBase from .elements.base import BaseElement @@ -66,6 +64,7 @@ class hierarchy into a separate file) from typing import Callable, Container, Iterator, Sequence from typing import Iterable from typing_extensions import DefaultDict + from typing_extensions import Literal else: from collections.abc import Callable from collections.abc import Container @@ -73,6 +72,12 @@ class hierarchy into a separate file) from collections.abc import Iterator from collections.abc import Sequence from collections import defaultdict as DefaultDict + from typing import Literal + +if sys.version_info < (3, 11): + from typing_extensions import Self +else: + from typing import Self _CC = TypeVar("_CC", bound="CalendarObjectResource") log = logging.getLogger("caldav") diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..68de6c4b --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,55 @@ +[build-system] +requires = ["setuptools>=64", "setuptools-scm[toml]>=7.0"] +build-backend = "setuptools.build_meta" + +[project] +name = "caldav" +authors = [{ name = "Cyril Robert", email = "cyril@hippie.io" }] +license = { text = "GPL" } +description = "CalDAV (RFC4791) client library" +keywords = [] +readme = "README.md" +classifiers = [ + "Development Status :: 4 - Beta", + "Intended Audience :: Developers", + "License :: OSI Approved :: GNU General Public License (GPL)", + "License :: OSI Approved :: Apache Software License", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Topic :: Office/Business :: Scheduling", + "Topic :: Software Development :: Libraries :: Python Modules", +] +urls = { Homepage = "https://github.com/python-caldav/caldav" } +dependencies = [ + "vobject", + "lxml", + "requests", + "icalendar", + "recurring-ical-events>=2.0.0", + "typing_extensions;python_version<'3.11'", +] +dynamic = ["version"] + +[project.optional-dependencies] +test = [ + "pytest", + "pytest-coverage", + "coverage", + "sphinx", + "backports.zoneinfo;python_version<'3.9'", + "tzlocal", + "xandikos==0.2.8;python_version<'3.9'", + "dulwich==0.20.50;python_version<'3.9'", + "xandikos;python_version>='3.9'", +] + +[tool.setuptools_scm] +write_to = "caldav/_version.py" + +[tool.setuptools] +py-modules = ["caldav"] +include-package-data = true + +[tool.setuptools.packages.find] +exclude = ["tests"] +namespaces = false diff --git a/setup.py b/setup.py index 71b04944..1b5eca22 100755 --- a/setup.py +++ b/setup.py @@ -1,78 +1,4 @@ -#!/usr/bin/python -# -*- encoding: utf-8 -*- -import ast -import re -import sys +# -*- coding: utf-8 -*- +import setuptools -from setuptools import find_packages -from setuptools import setup - -## I believe it's good practice to keep the version number -## available as package.__version__ - -## It is defitively good practice not to have to maintain the -## version number several places. - -# However, there seems to be no "best current practice" on how -## to set up version number in the setup.py file? - -## I've copied the following from the icalendar library: -_version_re = re.compile(r"__version__\s+=\s+(.*)") -with open("caldav/__init__.py", "rb") as f: - version = str( - ast.literal_eval(_version_re.search(f.read().decode("utf-8")).group(1)) - ) - -if __name__ == "__main__": - ## TODO: consider if automated testing with radicale in addition to - ## xandikos would yield any benefits. - test_packages = [ - "pytest", - "pytest-coverage", - "coverage", - "sphinx", - "backports.zoneinfo;python_version<'3.9'", - "tzlocal", - "xandikos==0.2.8;python_version<'3.9'", - "dulwich==0.20.50;python_version<'3.9'", - "xandikos;python_version>='3.9'", - ] - - setup( - name="caldav", - version=version, - py_modules=[ - "caldav", - ], - description="CalDAV (RFC4791) client library", - long_description=open("README.md").read(), - classifiers=[ - "Development Status :: 4 - Beta", - "Intended Audience :: Developers", - "License :: OSI Approved :: GNU General " "Public License (GPL)", - "License :: OSI Approved :: Apache Software License", - "Operating System :: OS Independent", - "Programming Language :: Python", - "Topic :: Office/Business :: Scheduling", - "Topic :: Software Development :: Libraries " ":: Python Modules", - ], - keywords="", - author="Cyril Robert", - author_email="cyril@hippie.io", - url="https://github.com/python-caldav/caldav", - license="GPL", - packages=find_packages(exclude=["tests"]), - include_package_data=True, - zip_safe=False, - install_requires=[ - "vobject", - "lxml", - "requests", - "icalendar", - "recurring-ical-events>=2.0.0", - "typing_extensions", - ], - extras_require={ - "test": test_packages, - }, - ) +setuptools.setup() diff --git a/setup.cfg b/tox.ini similarity index 100% rename from setup.cfg rename to tox.ini