From 06897c7a637a2ba9f5d6fadcef5dbd9f7cfcc27a Mon Sep 17 00:00:00 2001 From: KOLANICH Date: Sun, 16 Jan 2022 11:42:36 +0300 Subject: [PATCH 1/2] Moved the metadata into `setup.cfg`. Added `pyproject.toml`. Version is now populated automatically from git tags using `setuptools_scm`. Deleted `bumpversion.sh`. Fixed some missing metadata fields. Fixed the scripts to work with `pyproject.toml` and cleaned them up. --- .github/workflows/python-package.yml | 4 ++- .gitignore | 3 ++ .travis.yml | 5 +++- Makefile | 2 +- adb_shell/__init__.py | 2 +- pyproject.toml | 7 +++++ scripts/bumpversion.sh | 35 ---------------------- scripts/get_package_name.py | 45 ++++++++++++++++++++++++++++ scripts/get_package_name.sh | 22 -------------- scripts/get_version.py | 15 ++++++++++ scripts/get_version.sh | 26 ---------------- scripts/git_retag.sh | 6 +--- scripts/git_tag.sh | 6 +--- scripts/rename_package.sh | 6 ++-- setup.cfg | 29 ++++++++++++++++++ setup.py | 24 --------------- 16 files changed, 113 insertions(+), 124 deletions(-) create mode 100644 pyproject.toml delete mode 100755 scripts/bumpversion.sh create mode 100755 scripts/get_package_name.py delete mode 100755 scripts/get_package_name.sh create mode 100755 scripts/get_version.py delete mode 100755 scripts/get_version.sh create mode 100644 setup.cfg delete mode 100644 setup.py diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 06d140da..7de5d54b 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -25,10 +25,12 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip + python -m pip install --upgrade build wheel setuptools setuptools_scm if python --version 2>&1 | grep -q "Python 2"; then pip install mock rsa==4.0 libusb1==1.9.3; fi python -m pip install flake8 pylint coveralls cryptography libusb1>=1.0.16 pycryptodome if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - pip install . + python -m build -nwsx .; + pip install ./dist/*.whl; if python --version 2>&1 | grep -q "Python 3.7" || python --version 2>&1 | grep -q "Python 3.8" || python --version 2>&1 | grep -q "Python 3.9" || python --version 2>&1 | grep -q "Python 3.10"; then pip install aiofiles; fi - name: Lint with pylint and flake8 run: | diff --git a/.gitignore b/.gitignore index db3f3ee1..c56a99bc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# Autogenerated version file +/adb_shell/version.py + # Python files *.idea *.pyc diff --git a/.travis.yml b/.travis.yml index 0795ead3..08014b8a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,10 @@ addons: - swig - libusb-1.0-0-dev install: - - pip install . + - pip install --upgrade pip + - pip install --upgrade build + - python -m build -nwx . + - pip install ./dist/*.whl - pip install flake8 pylint coveralls cryptography libusb1>=1.0.16 pycryptodome - python --version 2>&1 | grep -q "Python 2" && pip install mock || true - if python --version 2>&1 | grep -q "Python 3.7" || python --version 2>&1 | grep -q "Python 3.8" || python --version 2>&1 | grep -q "Python 3.9"; then pip install aiofiles; fi diff --git a/Makefile b/Makefile index 1c78665c..a7ee5bb2 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ release: rm -rf dist rm -rf build scripts/git_tag.sh - python setup.py sdist bdist_wheel + python -m build -nwsx twine upload dist/* .PHONY: docs diff --git a/adb_shell/__init__.py b/adb_shell/__init__.py index 3c1eda4d..3762de84 100644 --- a/adb_shell/__init__.py +++ b/adb_shell/__init__.py @@ -7,4 +7,4 @@ """ -__version__ = '0.4.2' +from .version import __version__ # noqa: F401 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..4a6dd2b5 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,7 @@ +[build-system] +requires = ["setuptools>=44", "wheel", "setuptools_scm[toml]>=3.4.3"] +build-backend = "setuptools.build_meta" + +[tool.setuptools_scm] +write_to = "adb_shell/version.py" +write_to_template = "'''Generated by setuptools_scm'''\n__version__ = '{version}'\n" diff --git a/scripts/bumpversion.sh b/scripts/bumpversion.sh deleted file mode 100755 index 7ee2b92b..00000000 --- a/scripts/bumpversion.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash - -# Make sure there is only 1 argument passed -if [ "$#" -ne 1 ]; then - echo "You must provide a new version" - exit 1 -fi - -# Make sure the new version is not empty -if [ -z "$1" ]; then - echo "You must provide a non-empty version" - exit 1 -fi - -# get the directory of this script -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" - -# get the package name -PACKAGE=$($DIR/get_package_name.sh) - -# get the current version -VERSION=$($DIR/get_version.sh) - -# Announce the version bump -echo "Bumping the version from $VERSION to $1" - -# __init__.py -sed -i "s|__version__ = '$VERSION'|__version__ = '$1'|g" $DIR/../$PACKAGE/__init__.py - -# setup.py -sed -i "s|version='$VERSION',|version='$1',|g" $DIR/../setup.py - -# conf.py -sed -i "s|version = '$VERSION'|version = '$1'|g" $DIR/../docs/source/conf.py -sed -i "s|release = '$VERSION'|release = '$1'|g" $DIR/../docs/source/conf.py diff --git a/scripts/get_package_name.py b/scripts/get_package_name.py new file mode 100755 index 00000000..4a8b6497 --- /dev/null +++ b/scripts/get_package_name.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 +import sys +import typing +from pathlib import Path + +import tomli + +__license__ = "Unlicense" +__copyright__ = """ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means. + +In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to +""" + + +def getPackageName(rootDir: Path) -> str: + from setuptools.config import read_configuration + + setupCfg = read_configuration(Path(rootDir / "setup.cfg")) + try: + return setupCfg["metadata"]["name"] + except KeyError: + return None + + +def main(): + if len(sys.argv) > 1: + p = sys.argv[1] + else: + p = "." + pn = getPackageName(Path(p)) + if pn: + print(pn, file=sys.stdout) + else: + print("Package name could not be determined", file=sys.stderr) + + +if __name__ == "__main__": + main() diff --git a/scripts/get_package_name.sh b/scripts/get_package_name.sh deleted file mode 100755 index b81914c9..00000000 --- a/scripts/get_package_name.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -set -e - -# get the directory of this script -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" - -RSTRIP="'*" -LSTRIP="*'" - -# get the package name -PACKAGE_LINE=$(grep 'name=' $DIR/../setup.py || echo '') -PACKAGE_TEMP=${PACKAGE_LINE%$RSTRIP} -PACKAGE=${PACKAGE_TEMP##$LSTRIP} - -# Make sure `PACKAGE` is not empty -if [ -z "$PACKAGE" ]; then - echo "Package name could not be determined" >&2 - exit 1 -fi - -echo "$PACKAGE" diff --git a/scripts/get_version.py b/scripts/get_version.py new file mode 100755 index 00000000..7d8766cf --- /dev/null +++ b/scripts/get_version.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python3 +import sys + +__license__ = "Unlicense" + +if __name__ == "__main__": + import setuptools_scm + + v = setuptools_scm.get_version(local_scheme="no-local-version").rsplit(".", 1) + if not v: + print("Version could not be determined", file=sys.stderr) + sys.exit(1) + if v[-1].startswith("dev"): + v = v[:-1] + print(".".join(v)) diff --git a/scripts/get_version.sh b/scripts/get_version.sh deleted file mode 100755 index b17f9606..00000000 --- a/scripts/get_version.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -set -e - -# get the directory of this script -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" - -RSTRIP="'*" -LSTRIP="*'" - -# get the package name -PACKAGE=$($DIR/get_package_name.sh) - -# get the current version -VERSION_LINE=$(grep '__version__' "$DIR/../$PACKAGE/__init__.py" || echo '') -VERSION_TEMP=${VERSION_LINE%"'"} - -VERSION=${VERSION_TEMP##$LSTRIP} - -# Make sure `VERSION` is not empty -if [ -z "$VERSION" ]; then - echo "Version could not be determined" >&2 - exit 1 -fi - -echo "$VERSION" diff --git a/scripts/git_retag.sh b/scripts/git_retag.sh index 1433f6d9..e325b833 100755 --- a/scripts/git_retag.sh +++ b/scripts/git_retag.sh @@ -3,12 +3,8 @@ # get the directory of this script DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" -# get the package name -PACKAGE=$($DIR/get_package_name.sh) - # get the current version -VERSION=$($DIR/get_version.sh) - +VERSION=$(python3 $DIR/get_version.py) # Announce the tag echo "Re-tagging v$VERSION" diff --git a/scripts/git_tag.sh b/scripts/git_tag.sh index c8c8d569..37c3d7b0 100755 --- a/scripts/git_tag.sh +++ b/scripts/git_tag.sh @@ -3,12 +3,8 @@ # get the directory of this script DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" -# get the package name -PACKAGE=$($DIR/get_package_name.sh) - # get the current version -VERSION=$($DIR/get_version.sh) - +VERSION=$(python3 $DIR/get_version.py) # Announce the tag echo "Creating tag v$VERSION" diff --git a/scripts/rename_package.sh b/scripts/rename_package.sh index b4487fc4..ec9cd2a0 100755 --- a/scripts/rename_package.sh +++ b/scripts/rename_package.sh @@ -18,7 +18,7 @@ fi DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" # get the current package name -PACKAGE=$($DIR/get_package_name.sh) +PACKAGE=$(python3 $DIR/get_package_name.py) # Announce the renaming echo "Renaming from '$PACKAGE' to '$1'" @@ -32,8 +32,8 @@ sed -i "s|$PACKAGE|$1|g" $DIR/../Doxyfile # Makefile sed -i "s|$PACKAGE|$1|g" $DIR/../Makefile -# setup.py -sed -i "s|$PACKAGE|$1|g" $DIR/../setup.py +# setup.cfg +sed -i "s|$PACKAGE|$1|g" $DIR/../setup.cfg # docs/Makefile sed -i "s|$PACKAGE|$1|g" $DIR/../docs/Makefile diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 00000000..d19569f9 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,29 @@ +[metadata] +name = adb_shell +author = Jeff Irion +author_email = jefflirion@users.noreply.github.com +description = A Python implementation of ADB with shell and FileSync functionality. +license = Apache-2.0 +keywords = adb, android +url = https://github.com/JeffLIrion/adb_shell +long_description = file: README.rst +long_description_content_type = text/x-rst +classifiers = + Operating System :: OS Independent + License :: OSI Approved :: Apache Software License + Programming Language :: Python :: 3 + Programming Language :: Python :: 2 + +[options] +install_requires = cryptography; pyasn1; rsa +packages = adb_shell, adb_shell.auth, adb_shell.transport + +[options.extras_require] +usb = libusb1>=1.0.16 +async = aiofiles>=0.4.0 +testing = pycryptodome; libusb1>=1.0.16 + +[tool.setuptools] + +[distutils.bdist_wheel] +universal = 1 diff --git a/setup.py b/setup.py deleted file mode 100644 index c0c4d273..00000000 --- a/setup.py +++ /dev/null @@ -1,24 +0,0 @@ -from setuptools import setup - -with open('README.rst') as f: - readme = f.read() - -setup( - name='adb_shell', - version='0.4.2', - description='A Python implementation of ADB with shell and FileSync functionality.', - long_description=readme, - keywords=['adb', 'android'], - url='https://github.com/JeffLIrion/adb_shell', - author='Jeff Irion', - author_email='jefflirion@users.noreply.github.com', - packages=['adb_shell', 'adb_shell.auth', 'adb_shell.transport'], - install_requires=['cryptography', 'pyasn1', 'rsa'], - tests_require=['pycryptodome', 'libusb1>=1.0.16'], - extras_require = {'usb': ['libusb1>=1.0.16'], 'async': ['aiofiles>=0.4.0']}, - classifiers=['Operating System :: OS Independent', - 'License :: OSI Approved :: Apache Software License', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 2'], - test_suite='tests' -) From cf90408fcc184295eda3debc121b91d75ebad395 Mon Sep 17 00:00:00 2001 From: KOLANICH Date: Fri, 6 May 2022 13:41:26 +0300 Subject: [PATCH 2/2] Moved the metadata from `setup.cfg` into `PEP 621`-compliant `pyproject.toml`. Dropped wheel building support on unsupported versions of `python`, because `setuptools` available for this versions doesn't support `PEP 621`. --- .github/workflows/python-package.yml | 15 ++++++------ pyproject.toml | 34 +++++++++++++++++++++++++++- scripts/get_package_name.py | 21 ++++++++++++----- scripts/rename_package.sh | 4 ++-- setup.cfg | 29 ------------------------ 5 files changed, 57 insertions(+), 46 deletions(-) delete mode 100644 setup.cfg diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 7de5d54b..73177b4c 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['2.7', '3.5', '3.6', '3.7', '3.8', '3.9', '3.10'] + python-version: ['3.7', '3.8', '3.9', '3.10'] steps: - uses: actions/checkout@v2 @@ -26,20 +26,19 @@ jobs: run: | python -m pip install --upgrade pip python -m pip install --upgrade build wheel setuptools setuptools_scm - if python --version 2>&1 | grep -q "Python 2"; then pip install mock rsa==4.0 libusb1==1.9.3; fi python -m pip install flake8 pylint coveralls cryptography libusb1>=1.0.16 pycryptodome - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi python -m build -nwsx .; pip install ./dist/*.whl; - if python --version 2>&1 | grep -q "Python 3.7" || python --version 2>&1 | grep -q "Python 3.8" || python --version 2>&1 | grep -q "Python 3.9" || python --version 2>&1 | grep -q "Python 3.10"; then pip install aiofiles; fi + pip install aiofiles - name: Lint with pylint and flake8 run: | - if python --version 2>&1 | grep -q "Python 2" || python --version 2>&1 | grep -q "Python 3.5" || python --version 2>&1 | grep -q "Python 3.6"; then flake8 adb_shell/ --exclude="adb_shell/adb_device_async.py,adb_shell/transport/base_transport_async.py,adb_shell/transport/tcp_transport_async.py" && pylint --ignore="adb_device_async.py,base_transport_async.py,tcp_transport_async.py" adb_shell/; fi - if python --version 2>&1 | grep -q "Python 3.7" || python --version 2>&1 | grep -q "Python 3.8" || python --version 2>&1 | grep -q "Python 3.9" || python --version 2>&1 | grep -q "Python 3.10"; then flake8 adb_shell/ && pylint adb_shell/; fi + flake8 adb_shell + pylint adb_shell - name: Test with unittest env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} COVERALLS_SERVICE_NAME: github run: | - if python --version 2>&1 | grep -q "Python 2" || python --version 2>&1 | grep -q "Python 3.5" || python --version 2>&1 | grep -q "Python 3.6" ; then for synctest in $(cd tests && ls test*.py | grep -v async); do python -m unittest discover -s tests/ -t . -p "$synctest" || exit 1; done; fi - if python --version 2>&1 | grep -q "Python 3.7" || python --version 2>&1 | grep -q "Python 3.8" || python --version 2>&1 | grep -q "Python 3.9" || python --version 2>&1 | grep -q "Python 3.10"; then coverage run --source adb_shell -m unittest discover -s tests/ -t . && coverage report -m && coveralls; fi + coverage run --source adb_shell -m unittest discover -s tests/ -t . + coverage report -m + coveralls diff --git a/pyproject.toml b/pyproject.toml index 4a6dd2b5..bbdce584 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,39 @@ [build-system] -requires = ["setuptools>=44", "wheel", "setuptools_scm[toml]>=3.4.3"] +requires = ["setuptools>=61.2.0", "wheel", "setuptools_scm[toml]>=3.4.3"] build-backend = "setuptools.build_meta" +[project] +name = "adb_shell" +authors = [{name = "Jeff Irion", email = "jefflirion@users.noreply.github.com"}] +description = "A Python implementation of ADB with shell and FileSync functionality." +license = {text = "Apache-2.0"} +keywords = ["adb", "android"] +readme = "README.rst" +classifiers = [ + "Operating System :: OS Independent", + "License :: OSI Approved :: Apache Software License", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 2", +] +urls = {Homepage = "https://github.com/JeffLIrion/adb_shell"} +dependencies = ["cryptography", "pyasn1", "rsa"] +dynamic = ["version"] + +[project.optional-dependencies] +usb = ["libusb1>=1.0.16"] +async = ["aiofiles>=0.4.0"] +testing = ["pycryptodome", "libusb1>=1.0.16"] + +[tool.setuptools] +packages = [ + "adb_shell", + "adb_shell.auth", + "adb_shell.transport", +] + [tool.setuptools_scm] write_to = "adb_shell/version.py" write_to_template = "'''Generated by setuptools_scm'''\n__version__ = '{version}'\n" + +[tool.distutils.bdist_wheel] +universal = 1 diff --git a/scripts/get_package_name.py b/scripts/get_package_name.py index 4a8b6497..f4161c73 100755 --- a/scripts/get_package_name.py +++ b/scripts/get_package_name.py @@ -19,14 +19,23 @@ """ +def extractFromPEP621(pyproject) -> None: + project = pyproject.get("project", None) + if isinstance(project, dict): + return project.get("name", None) + + return None + + def getPackageName(rootDir: Path) -> str: - from setuptools.config import read_configuration + tomlPath = Path(rootDir / "pyproject.toml") + + with tomlPath.open("rb") as f: + pyproject = tomli.load(f) - setupCfg = read_configuration(Path(rootDir / "setup.cfg")) - try: - return setupCfg["metadata"]["name"] - except KeyError: - return None + fromPEP621 = extractFromPEP621(pyproject) + if fromPEP621: + return fromPEP621 def main(): diff --git a/scripts/rename_package.sh b/scripts/rename_package.sh index ec9cd2a0..77b8fc14 100755 --- a/scripts/rename_package.sh +++ b/scripts/rename_package.sh @@ -32,8 +32,8 @@ sed -i "s|$PACKAGE|$1|g" $DIR/../Doxyfile # Makefile sed -i "s|$PACKAGE|$1|g" $DIR/../Makefile -# setup.cfg -sed -i "s|$PACKAGE|$1|g" $DIR/../setup.cfg +# pyproject.toml +sed -i "s|$PACKAGE|$1|g" $DIR/../pyproject.toml # docs/Makefile sed -i "s|$PACKAGE|$1|g" $DIR/../docs/Makefile diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index d19569f9..00000000 --- a/setup.cfg +++ /dev/null @@ -1,29 +0,0 @@ -[metadata] -name = adb_shell -author = Jeff Irion -author_email = jefflirion@users.noreply.github.com -description = A Python implementation of ADB with shell and FileSync functionality. -license = Apache-2.0 -keywords = adb, android -url = https://github.com/JeffLIrion/adb_shell -long_description = file: README.rst -long_description_content_type = text/x-rst -classifiers = - Operating System :: OS Independent - License :: OSI Approved :: Apache Software License - Programming Language :: Python :: 3 - Programming Language :: Python :: 2 - -[options] -install_requires = cryptography; pyasn1; rsa -packages = adb_shell, adb_shell.auth, adb_shell.transport - -[options.extras_require] -usb = libusb1>=1.0.16 -async = aiofiles>=0.4.0 -testing = pycryptodome; libusb1>=1.0.16 - -[tool.setuptools] - -[distutils.bdist_wheel] -universal = 1