From 6aea0a337dae0e0045b14bc76343256f7abe46da Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Tue, 21 Jul 2020 20:12:30 +0300 Subject: [PATCH 1/4] Packagify Pushover --- pushover.py => pushover/__init__.py | 0 cli.py => pushover/cli.py | 0 setup.py | 4 ++-- 3 files changed, 2 insertions(+), 2 deletions(-) rename pushover.py => pushover/__init__.py (100%) rename cli.py => pushover/cli.py (100%) diff --git a/pushover.py b/pushover/__init__.py similarity index 100% rename from pushover.py rename to pushover/__init__.py diff --git a/cli.py b/pushover/cli.py similarity index 100% rename from cli.py rename to pushover/cli.py diff --git a/setup.py b/setup.py index 639b9a5..41df87a 100644 --- a/setup.py +++ b/setup.py @@ -15,8 +15,8 @@ url="https://github.com/Thibauth/python-pushover", author="Thibaut Horel", author_email="thibaut.horel+pushover@gmail.com", - py_modules=["pushover", "cli"], - entry_points={"console_scripts": ["pushover = cli:main"]}, + packages=["pushover"], + entry_points={"console_scripts": ["pushover = pushover.cli:main"]}, install_requires=["requests>=1.0"], use_2to3=True, license="GNU GPLv3", From b591f99be2c58f0319aff53413ca896a8169c443 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Tue, 21 Jul 2020 20:57:53 +0300 Subject: [PATCH 2/4] Add Python bytecode + .egg-info to gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index dc84959..10e4c8e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ +*.egg-info +*.py[cod] build/ - From 5d0010cf271124959ee0672875d617dced4618de Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Tue, 21 Jul 2020 20:59:54 +0300 Subject: [PATCH 3/4] Be Python2+3 compatible without 2to3 Using `use_2to3` makes it hard to use `pip install -e .`; see https://github.com/spacetelescope/webbpsf/issues/234 --- pushover/__init__.py | 8 ++++---- pushover/cli.py | 10 +++++++--- setup.py | 1 - 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/pushover/__init__.py b/pushover/__init__.py index 97a9d5f..109126b 100644 --- a/pushover/__init__.py +++ b/pushover/__init__.py @@ -83,7 +83,7 @@ def __init__(self, payload): if payload.get("priority", 0) == 2: self.url = RECEIPT_URL + self.answer["receipt"] self.status["done"] = False - for param, when in MessageRequest.params.iteritems(): + for param, when in MessageRequest.params.items(): self.status[param] = False self.status[when] = 0 @@ -108,7 +108,7 @@ def poll(self): """ if not self.status["done"]: r = Request("get", self.url + ".json", {"token": self.payload["token"]}) - for param, when in MessageRequest.params.iteritems(): + for param, when in MessageRequest.params.items(): self.status[param] = bool(r.answer[param]) self.status[when] = int(r.answer[when]) for param in ["acknowledged_by", "acknowledged_by_device"]: @@ -201,7 +201,7 @@ def message(self, user, message, **kwargs): """ payload = {"message": message, "user": user, "token": self.token} - for key, value in kwargs.iteritems(): + for key, value in kwargs.items(): if key not in Pushover.message_keywords: raise ValueError("{0}: invalid message parameter".format(key)) elif key == "timestamp" and value is True: @@ -225,7 +225,7 @@ def glance(self, user, **kwargs): """ payload = {"user": user, "token": self.token} - for key, value in kwargs.iteritems(): + for key, value in kwargs.items(): if key not in Pushover.glance_keywords: raise ValueError("{0}: invalid glance parameter".format(key)) else: diff --git a/pushover/cli.py b/pushover/cli.py index 73ebfc9..cff806c 100644 --- a/pushover/cli.py +++ b/pushover/cli.py @@ -1,4 +1,8 @@ -from ConfigParser import RawConfigParser, NoSectionError, NoOptionError +try: + import configparser +except ImportError: # Python 2 + import ConfigParser as configparser + from argparse import ArgumentParser, RawDescriptionHelpFormatter import os from pushover import Pushover @@ -6,7 +10,7 @@ def read_config(config_path): config_path = os.path.expanduser(config_path) - config = RawConfigParser() + config = configparser.RawConfigParser() params = {"users": {}} files = config.read(config_path) if not files: @@ -18,7 +22,7 @@ def read_config(config_path): user["user_key"] = config.get(name, "user_key") try: user["device"] = config.get(name, "device") - except NoOptionError: + except configparser.NoOptionError: user["device"] = None params["users"][name] = user return params diff --git a/setup.py b/setup.py index 41df87a..3ffb299 100644 --- a/setup.py +++ b/setup.py @@ -18,6 +18,5 @@ packages=["pushover"], entry_points={"console_scripts": ["pushover = pushover.cli:main"]}, install_requires=["requests>=1.0"], - use_2to3=True, license="GNU GPLv3", ) From ddd6a6ce6251a0ff63c0ba928dfd317d51f0f3f6 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Tue, 21 Jul 2020 21:24:04 +0300 Subject: [PATCH 4/4] Add very basic tox flake8 test with GitHub CI --- .github/workflows/python.yml | 27 +++++++++++++++++++++++++++ .gitignore | 3 ++- setup.py | 7 ++----- tox.ini | 4 ++++ 4 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/python.yml create mode 100644 tox.ini diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml new file mode 100644 index 0000000..5f3bcc7 --- /dev/null +++ b/.github/workflows/python.yml @@ -0,0 +1,27 @@ +name: Python package + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [2.7, 3.7] + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install + run: | + python -m pip install --upgrade pip + pip install tox + - name: Run tox + run: tox --skip-missing-interpreters \ No newline at end of file diff --git a/.gitignore b/.gitignore index 10e4c8e..d738bfb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.egg-info *.py[cod] -build/ +.tox +build/ \ No newline at end of file diff --git a/setup.py b/setup.py index 3ffb299..24bc707 100644 --- a/setup.py +++ b/setup.py @@ -2,16 +2,13 @@ from setuptools import setup +long_description = "\n".join([open(f).read() for f in ("README.rst", "AUTHORS.rst", "CHANGES.rst")]) setup( name="python-pushover", version="1.0", description="Comprehensive bindings and command line utility for the " "Pushover notification service", - long_description=open("README.rst").read() - + "\n" - + open("AUTHORS.rst").read() - + "\n" - + open("CHANGES.rst").read(), + long_description=long_description, url="https://github.com/Thibauth/python-pushover", author="Thibaut Horel", author_email="thibaut.horel+pushover@gmail.com", diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..feef3ab --- /dev/null +++ b/tox.ini @@ -0,0 +1,4 @@ +[testenv] +deps = flake8 +commands = + flake8 pushover setup.py --ignore=E501 --count --max-complexity=10 --statistics