diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 06d140da..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 @@ -25,19 +25,20 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - 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 --upgrade build wheel setuptools setuptools_scm 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 . - 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 + python -m build -nwsx .; + pip install ./dist/*.whl; + 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/.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..bbdce584 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,39 @@ +[build-system] +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/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..f4161c73 --- /dev/null +++ b/scripts/get_package_name.py @@ -0,0 +1,54 @@ +#!/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 extractFromPEP621(pyproject) -> None: + project = pyproject.get("project", None) + if isinstance(project, dict): + return project.get("name", None) + + return None + + +def getPackageName(rootDir: Path) -> str: + tomlPath = Path(rootDir / "pyproject.toml") + + with tomlPath.open("rb") as f: + pyproject = tomli.load(f) + + fromPEP621 = extractFromPEP621(pyproject) + if fromPEP621: + return fromPEP621 + + +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..77b8fc14 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 +# 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.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' -)