From f3c255280198731d7cb28c7688347eef5fc1cbfe Mon Sep 17 00:00:00 2001 From: Tom Gross Date: Fri, 3 Jan 2025 10:38:05 +0100 Subject: [PATCH] Documentation --- .github/workflows/pcloud-test.yml | 1 + CHANGES.rst | 4 ++-- CONTRIBUTORS.rst | 8 -------- README.rst | 20 ++++++++++++++++++++ pyproject.toml | 4 +--- src/pcloud/oauth2.py | 7 +++++++ src/pcloud/tests/conftest.py | 12 +++++++++--- src/pcloud/tests/test_oauth2.py | 5 +++-- 8 files changed, 43 insertions(+), 18 deletions(-) delete mode 100644 CONTRIBUTORS.rst diff --git a/.github/workflows/pcloud-test.yml b/.github/workflows/pcloud-test.yml index 0c483d2..50d3b44 100644 --- a/.github/workflows/pcloud-test.yml +++ b/.github/workflows/pcloud-test.yml @@ -29,6 +29,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip + pip install pytest-rerunfailures==15.0 pytest-cov==6.0.0 pytest-timeout==2.3.1 pip install -e ".[test]" playwright install - name: Lint with flake8 diff --git a/CHANGES.rst b/CHANGES.rst index b6dedc7..f4b5ceb 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,8 +4,8 @@ Changelog 1.5 (unreleased) ---------------- -- Nothing changed yet. - +- Use `pyproject.toml` instead of `setup.py` [tomgross] +- Document `eapi`-endpoint for fs.opener [tomgross] 1.4 (2024-12-29) ---------------- diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst deleted file mode 100644 index 71aff6a..0000000 --- a/CONTRIBUTORS.rst +++ /dev/null @@ -1,8 +0,0 @@ -Contributors -============ - -- Tom Gross, itconsense@gmail.com -- Massimo Vannucci (blasterspike) -- Yennick Schepers (yennicks) -- olokelo -- qo4on diff --git a/README.rst b/README.rst index ccabb71..cf8c731 100644 --- a/README.rst +++ b/README.rst @@ -81,12 +81,21 @@ b) from data: >>> img.save(bio, format='jpeg') >>> pc.uploadfile(data=bio.getvalue(), filename="image.jpg", path='/path-to-pcloud-dir') +PyFilesystem integration +++++++++++++++++++++++++ + Usage of PyFilesystem with opener >>> from fs import opener >>> opener.open_fs('pcloud://email%40example.com:SecretPassword@/') +Opener of eapi endpoint + + >>> from fs import opener + >>> opener.open_fs('pcloud+eapi://email%40example.com:SecretPassword@/') + + Copying files from Linux to pCloud using PyFilesystem >>> from fs import opener, copy @@ -145,3 +154,14 @@ License ======= The project is licensed under MIT (see LICENSE). + +Contributors +============ + +- Tom Gross, itconsense@gmail.com +- Massimo Vannucci (blasterspike) +- Yennick Schepers (yennicks) +- olokelo +- qo4on + +.. include:: CHANGES.rst diff --git a/pyproject.toml b/pyproject.toml index 9563d4e..8c0904c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,6 +5,7 @@ package = "pcloud" name = "pcloud" version = "1.5.dev0" description = "A client library for pCloud" +readme = "README.rst" authors = [ { name = "Tom Gross", email = "itconsense@gmail.com" } ] @@ -40,9 +41,6 @@ dependencies = [ test = [ "pytest==8.3.4", "pytest-sugar==1.0.0", - "pytest-timeout==2.3.1", - "pytest-cov==6.0.0", - "pytest-rerunfailures==15.0", "wheel==0.45.1", "flake8==7.1.1", "fs==2.4.16", diff --git a/src/pcloud/oauth2.py b/src/pcloud/oauth2.py index bb44510..c4c9e21 100644 --- a/src/pcloud/oauth2.py +++ b/src/pcloud/oauth2.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +import logging +import socket import _thread import time @@ -8,6 +10,9 @@ from urllib.parse import urlparse from webbrowser import open_new +log = logging.getLogger("pcloud") +log.setLevel(logging.INFO) + PORT = 65432 REDIRECT_URL = f"http://localhost:{PORT}/" @@ -63,10 +68,12 @@ def get_access_token(self): def start_server(): http_server.handle_request() + log.info(f"Start token server {PORT}") _thread.start_new_thread(start_server, ()) self.open_browser() while not (http_server.access_token and http_server.pc_hostname): time.sleep(1) self.close_browser() http_server.server_close() + log.info(f"Teardown token server {PORT}") return http_server.access_token, http_server.pc_hostname diff --git a/src/pcloud/tests/conftest.py b/src/pcloud/tests/conftest.py index 3b5b89d..1e0441b 100644 --- a/src/pcloud/tests/conftest.py +++ b/src/pcloud/tests/conftest.py @@ -1,8 +1,14 @@ +import logging +import pytest + from pcloud.tests.server import MockHandler from pcloud.tests.server import MockServer -import pytest + from threading import Thread +log = logging.getLogger("pcloud") +log.setLevel(logging.INFO) + PORT = 5023 @@ -11,9 +17,9 @@ def start_mock_server(): """Start a mock server on port 5023""" httpd = MockServer(("", PORT), MockHandler) httpd_thread = Thread(target=httpd.serve_forever, daemon=True) + log.info(f"Start mock server at port {PORT}") httpd_thread.start() - print("start") yield start_mock_server - print("teardown") + log.info(f"Teardown mock server from port {PORT}") httpd.shutdown() httpd_thread.join() diff --git a/src/pcloud/tests/test_oauth2.py b/src/pcloud/tests/test_oauth2.py index 31c7a5b..275221c 100644 --- a/src/pcloud/tests/test_oauth2.py +++ b/src/pcloud/tests/test_oauth2.py @@ -19,6 +19,7 @@ class PlaywrightTokenHandler(TokenHandler): """ def open_browser(self): + with sync_playwright() as p: # set headless to `False` for debugging purposes self.browser = p.firefox.launch(headless=True) @@ -30,9 +31,9 @@ def open_browser(self): log.info(self.auth_url) page.goto(self.auth_url) page.get_by_placeholder("Email").fill(os.environ.get("PCLOUD_USERNAME")) - page.get_by_text("Continue", exact=True).click() + page.locator("[type=submit]").click() page.get_by_placeholder("Password").fill(os.environ.get("PCLOUD_PASSWORD")) - page.get_by_text("Log in", exact=True).click() + page.locator("[type=submit]").click() expect(page.get_by_text("You may now close this window.")).to_be_visible()