From e0e9bc270ff76a0c3979a62256b93a15dd5a3909 Mon Sep 17 00:00:00 2001 From: Martin Hjelmare Date: Mon, 14 Feb 2022 23:41:53 +0100 Subject: [PATCH] Add github actions (#369) --- .github/workflows/ci.yml | 30 +++++++++++++++++++++++ .travis.yml | 23 ------------------ pyicloud/base.py | 51 ++++++++++++++++++++++------------------ pyproject.toml | 2 +- requirements_all.txt | 1 + requirements_test.txt | 1 + tests/const_login.py | 4 +--- tox.ini | 23 ++++++++++++++---- 8 files changed, 80 insertions(+), 55 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..2347b79 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,30 @@ +name: CI + +on: + push: + branches: [master] + pull_request: + branches: [master] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: + - "3.6" + - "3.7" + - "3.8" + + steps: + - uses: actions/checkout@v2.4.0 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2.3.2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install tox tox-gh-actions + - name: Test with tox + run: tox diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 6d77029..0000000 --- a/.travis.yml +++ /dev/null @@ -1,23 +0,0 @@ -os: linux -dist: xenial - -language: python -python: - - 2.7 - - 3.4 - - 3.7 - - 3.8 -cache: - pip: true - -before_install: - - pip install -r requirements_all.txt - - pip install -e . -install: - - python setup.py install - - python setup.py sdist -before_script: - - pylint pyicloud tests - - ./scripts/check_format.sh -script: - - py.test diff --git a/pyicloud/base.py b/pyicloud/base.py index 814a9c7..e6b25a9 100644 --- a/pyicloud/base.py +++ b/pyicloud/base.py @@ -72,13 +72,7 @@ class PyiCloudSession(Session): if self.service.password_filter not in request_logger.filters: request_logger.addFilter(self.service.password_filter) - request_logger.debug( - "%s %s %s" % ( - method, - url, - kwargs.get("data", "") - ) - ) + request_logger.debug("%s %s %s" % (method, url, kwargs.get("data", ""))) has_retried = kwargs.get("retried") kwargs.pop("retried", None) @@ -103,11 +97,18 @@ class PyiCloudSession(Session): self.cookies.save(ignore_discard=True, ignore_expires=True) LOGGER.debug("Cookies saved to %s", self.service.cookiejar_path) - if not response.ok and (content_type not in json_mimetypes - or response.status_code in [421, 450, 500]): + if not response.ok and ( + content_type not in json_mimetypes + or response.status_code in [421, 450, 500] + ): try: + # pylint: disable=protected-access fmip_url = self.service._get_webservice_url("findme") - if has_retried is None and response.status_code == 450 and fmip_url in url: + if ( + has_retried is None + and response.status_code == 450 + and fmip_url in url + ): # Handle re-authentication for Find My iPhone LOGGER.debug("Re-authenticating Find My iPhone service") try: @@ -234,7 +235,7 @@ class PyiCloudService(object): if not path.exists(self._cookie_directory): mkdir(self._cookie_directory, 0o700) - LOGGER.debug("Using session file %s" % self.session_path) + LOGGER.debug("Using session file %s", self.session_path) self.session_data = {} try: @@ -258,12 +259,12 @@ class PyiCloudService(object): if path.exists(cookiejar_path): try: self.session.cookies.load(ignore_discard=True, ignore_expires=True) - LOGGER.debug("Read cookies from %s" % cookiejar_path) + LOGGER.debug("Read cookies from %s", cookiejar_path) except: # pylint: disable=bare-except # Most likely a pickled cookiejar from earlier versions. # The cookiejar will get replaced with a valid one after # successful authentication. - LOGGER.warning("Failed to read cookiejar %s" % cookiejar_path) + LOGGER.warning("Failed to read cookiejar %s", cookiejar_path) self.authenticate() @@ -286,18 +287,22 @@ class PyiCloudService(object): except PyiCloudAPIResponseException: LOGGER.debug("Invalid authentication token, will log in from scratch.") - if not login_successful and service != None: + if not login_successful and service is not None: app = self.data["apps"][service] - if "canLaunchWithOneFactor" in app and app["canLaunchWithOneFactor"] == True: - LOGGER.debug("Authenticating as %s for %s" % (self.user["accountName"], service)) + if "canLaunchWithOneFactor" in app and app["canLaunchWithOneFactor"]: + LOGGER.debug( + "Authenticating as %s for %s", self.user["accountName"], service + ) try: self._authenticate_with_credentials_service(service) login_successful = True - except: - LOGGER.debug("Could not log into service. Attempting brand new login.") + except Exception: + LOGGER.debug( + "Could not log into service. Attempting brand new login." + ) if not login_successful: - LOGGER.debug("Authenticating as %s" % self.user["accountName"]) + LOGGER.debug("Authenticating as %s", self.user["accountName"]) data = dict(self.user) @@ -354,7 +359,7 @@ class PyiCloudService(object): data = { "appName": service, "apple_id": self.user["accountName"], - "password": self.user["password"] + "password": self.user["password"], } try: @@ -408,7 +413,8 @@ class PyiCloudService(object): """Get path for session data file.""" return path.join( self._cookie_directory, - "".join([c for c in self.user.get("accountName") if match(r"\w", c)]) + '.session', + "".join([c for c in self.user.get("accountName") if match(r"\w", c)]) + + ".session", ) @property @@ -511,8 +517,7 @@ class PyiCloudService(object): try: self.session.get( - "%s/2sv/trust" % self.AUTH_ENDPOINT, - headers=headers, + "%s/2sv/trust" % self.AUTH_ENDPOINT, headers=headers, ) self._authenticate_with_token() return True diff --git a/pyproject.toml b/pyproject.toml index 7334c01..2dfcc69 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,4 +18,4 @@ exclude = ''' )/ | exceptions.py ) -''' \ No newline at end of file +''' diff --git a/requirements_all.txt b/requirements_all.txt index daefbd0..6fd2cbd 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1,2 +1,3 @@ -r requirements.txt -r requirements_test.txt +tox==3.24.5 diff --git a/requirements_test.txt b/requirements_test.txt index 3895e27..6fe2311 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -1,3 +1,4 @@ +black==19.10b0 pytest mock unittest2six diff --git a/tests/const_login.py b/tests/const_login.py index bb87eb6..8984fe6 100644 --- a/tests/const_login.py +++ b/tests/const_login.py @@ -16,9 +16,7 @@ A_DS_ID = "123456-12-12345678-1234-1234-1234-123456789012" + PERSON_ID WIDGET_KEY = "widget_key" + PERSON_ID # Data -AUTH_OK = { - "authType": "hsa2" -} +AUTH_OK = {"authType": "hsa2"} LOGIN_WORKING = { "dsInfo": { diff --git a/tox.ini b/tox.ini index 42ef6ea..ab61342 100644 --- a/tox.ini +++ b/tox.ini @@ -1,11 +1,24 @@ [tox] -envlist = py27, py33, py37, py38 -downloadcache = {toxworkdir}/_download/ +envlist = py36, py37, py38, lint +skip_missing_interpreters = True + +[gh-actions] +python = + 3.6: py36, lint + 3.7: py37 + 3.8: py38 [testenv] deps = -r{toxinidir}/requirements_all.txt - tox>=3.14.5 -sitepackages = False commands = - {envbindir}/py.test + {envbindir}/pytest + +[testenv:lint] +basepython = python3 +ignore_errors = True +commands = + black --check --fast . + pylint pyicloud tests +deps = + -r{toxinidir}/requirements_all.txt