From 867d8ee49e7a7d71f50224765ea9fe36113ac273 Mon Sep 17 00:00:00 2001 From: ed Date: Sun, 7 May 2023 14:37:57 +0000 Subject: [PATCH] replace setup.py with pyproject.toml + misc cleanup --- copyparty/res/__init__.py | 0 docs/devnotes.md | 13 ++-- pyproject.toml | 144 +++++++++++++++++++++++++++++++++++ scripts/make-pypi-release.sh | 39 +++++----- setup.py | 5 ++ 5 files changed, 178 insertions(+), 23 deletions(-) create mode 100644 copyparty/res/__init__.py create mode 100644 pyproject.toml diff --git a/copyparty/res/__init__.py b/copyparty/res/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/docs/devnotes.md b/docs/devnotes.md index 703757f5..f04c0a5d 100644 --- a/docs/devnotes.md +++ b/docs/devnotes.md @@ -228,6 +228,8 @@ pip install mutagen # audio metadata pip install pyftpdlib # ftp server pip install impacket # smb server -- disable Windows Defender if you REALLY need this on windows pip install Pillow pyheif-pillow-opener pillow-avif-plugin # thumbnails +pip install pyvips # faster thumbnails +pip install psutil # better cleanup of stuck metadata parsers on windows pip install black==21.12b0 click==8.0.2 bandit pylint flake8 isort mypy # vscode tooling ``` @@ -264,19 +266,20 @@ uses the included prebuilt webdeps if you downloaded a [release](https://github.com/9001/copyparty/releases) source tarball from github (for example [copyparty-1.6.15.tar.gz](https://github.com/9001/copyparty/releases/download/v1.6.15/copyparty-1.6.15.tar.gz) so not the autogenerated one) you can build it like so, ```bash -python3 setup.py install --user +python3 -m pip install --user -U build setuptools wheel jinja2 strip_hints +bash scripts/run-tests.sh python3 # optional +python3 -m build ``` -or if you're packaging it for a linux distro (nice), maybe something like +if you are unable to use `build`, you can use the old setuptools approach instead, ```bash -bash scripts/run-tests.sh python3 # optional +python3 setup.py install --user setuptools wheel jinja2 python3 setup.py build +# you now have a wheel which you can install. or extract and repackage: python3 setup.py install --skip-build --prefix=/usr --root=$HOME/pe/copyparty ``` -if you have a very recent python where `setup.py install` finally got obliterated, see [the arch pkg](https://github.com/9001/copyparty/blob/hovudstraum/contrib/package/arch/PKGBUILD) for the current workaround until copyparty finally migrates to the toml meme - ## complete release diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..dbc75b9e --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,144 @@ +[project] +name = "copyparty" +description = """ + Portable file server with accelerated resumable uploads, \ + deduplication, WebDAV, FTP, zeroconf, media indexer, \ + video thumbnails, audio transcoding, and write-only folders""" +readme = "README.md" +authors = [{ name = "ed", email = "copyparty@ocv.me" }] +license = { text = "MIT" } +requires-python = ">=3.3" +dependencies = ["Jinja2"] +dynamic = ["version"] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.3", + "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.5", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: Implementation :: CPython", + "Programming Language :: Python :: Implementation :: Jython", + "Programming Language :: Python :: Implementation :: PyPy", + "Environment :: Console", + "Environment :: No Input/Output (Daemon)", + "Intended Audience :: End Users/Desktop", + "Intended Audience :: System Administrators", + "Topic :: Communications :: File Sharing", + "Topic :: Internet :: File Transfer Protocol (FTP)", + "Topic :: Internet :: WWW/HTTP :: HTTP Servers", +] + +[project.urls] +"Source Code" = "https://github.com/9001/copyparty" +"Bug Tracker" = "https://github.com/9001/copyparty/issues" +"Demo Server" = "https://a.ocv.me/pub/demo/" + +[project.optional-dependencies] +thumbnails = ["Pillow"] +thumbnails2 = ["pyvips"] +audiotags = ["mutagen"] +ftpd = ["pyftpdlib"] +ftps = ["pyftpdlib", "pyopenssl"] + +[project.scripts] +copyparty = "copyparty.__main__:main" +"up2k.py" = "copyparty.web.a.up2k:main" +"partyfuse.py" = "copyparty.web.a.partyfuse:main" + +# ===================================================================== + +[build-system] +requires = ["setuptools", "wheel"] +build-backend = "setuptools.build_meta" +# requires = ["hatchling"] +# build-backend = "hatchling.build" + +[tool.hatch.version] +source = "code" +path = "copyparty/__version__.py" + +[tool.setuptools.dynamic] +version = { attr = "copyparty.__version__.__version__" } + +[tool.setuptools.packages.find] +include = ["copyparty*"] + +[tool.setuptools.package-data] +copyparty = [ + "res/COPYING.txt", + "res/insecure.pem", + "web/*.gz", + "web/*.html", + "web/a/*.bat", + "web/dd/*.png", + "web/deps/*.gz", + "web/deps/*.woff*", +] + +# ===================================================================== + +[tool.black] +required-version = '21.12b0' +target-version = ['py27'] + +[tool.isort] +profile = "black" +include_trailing_comma = true +force_sort_within_sections = true + +[tool.bandit] +skips = ["B104", "B110", "B112"] + +# ===================================================================== + +[tool.pylint.MAIN] +py-version = "3.11" +jobs = 2 + +[tool.pylint."MESSAGES CONTROL"] +disable = [ + "missing-module-docstring", + "missing-class-docstring", + "missing-function-docstring", + "import-outside-toplevel", + "wrong-import-position", + "raise-missing-from", + "bare-except", + "broad-exception-raised", + "broad-exception-caught", + "invalid-name", + "line-too-long", + "too-many-lines", + "consider-using-f-string", + "pointless-string-statement", +] + +[tool.pylint.FORMAT] +expected-line-ending-format = "LF" + +# ===================================================================== + +[tool.mypy] +python_version = "3.11" +files = ["copyparty"] +show_error_codes = true +show_column_numbers = true +pretty = true +strict = true +local_partial_types = true +strict_equality = true +warn_unreachable = true +ignore_missing_imports = true +follow_imports = "silent" + +[[tool.mypy.overrides]] +no_implicit_reexport = false diff --git a/scripts/make-pypi-release.sh b/scripts/make-pypi-release.sh index 1fcbe0fe..cc67db1c 100755 --- a/scripts/make-pypi-release.sh +++ b/scripts/make-pypi-release.sh @@ -73,14 +73,17 @@ pydir="$( } function have() { - python -c "import $1; $1; $1.__version__" + python -c "import $1; $1; getattr($1,'__version__',0)" } function load_env() { . buildenv/bin/activate have setuptools have wheel + have build have twine + have jinja2 + have strip_hints } load_env || { @@ -88,19 +91,32 @@ load_env || { deactivate || true rm -rf buildenv python3 -m venv buildenv - (. buildenv/bin/activate && pip install twine wheel) + (. buildenv/bin/activate && pip install \ + setuptools wheel build twine jinja2 strip_hints ) load_env } +# cleanup +rm -rf unt build/pypi + # grab licenses scripts/genlic.sh copyparty/res/COPYING.txt -# remove type hints to support python < 3.9 +# clean-ish packaging env rm -rf build/pypi mkdir -p build/pypi -cp -pR setup.py README.md LICENSE copyparty contrib bin scripts/strip_hints build/pypi/ +cp -pR pyproject.toml README.md LICENSE copyparty contrib bin scripts/strip_hints build/pypi/ tar -c docs/lics.txt scripts/genlic.sh build/*.txt | tar -xC build/pypi/ cd build/pypi + +# delete junk +find -name '*.pyc' -delete +find -name __pycache__ -delete +find -name py.typed -delete +find -type f \( -name .DS_Store -or -name ._.DS_Store \) -delete +find -type f -name ._\* | while IFS= read -r f; do cmp <(printf '\x00\x05\x16') <(head -c 3 -- "$f") && rm -f -- "$f"; done + +# remove type hints to support python < 3.9 f=../strip-hints-0.1.10.tar.gz [ -e $f ] || (url=https://files.pythonhosted.org/packages/9c/d4/312ddce71ee10f7e0ab762afc027e07a918f1c0e1be5b0069db5b0e7542d/strip-hints-0.1.10.tar.gz; @@ -136,20 +152,7 @@ rm -rf contrib (cd copyparty/web && make -j$(nproc) && rm Makefile) # build -./setup.py clean2 -./setup.py sdist bdist_wheel --universal +python3 -m build [ "$mode" == t ] && twine upload -r pypitest dist/* [ "$mode" == u ] && twine upload -r pypi dist/* - -cat <