Skip to content

Commit

Permalink
Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
tomgross committed Jan 6, 2025
1 parent 2fbec29 commit 9e924f6
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 18 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pcloud-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
----------------
Expand Down
8 changes: 0 additions & 8 deletions CONTRIBUTORS.rst

This file was deleted.

20 changes: 20 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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@/')
<pCloudFS>

Opener of eapi endpoint

>>> from fs import opener
>>> opener.open_fs('pcloud+eapi://email%40example.com:SecretPassword@/')
<pCloudFS>

Copying files from Linux to pCloud using PyFilesystem

>>> from fs import opener, copy
Expand Down Expand Up @@ -145,3 +154,14 @@ License
=======

The project is licensed under MIT (see LICENSE).

Contributors
============

- Tom Gross, [email protected]
- Massimo Vannucci (blasterspike)
- Yennick Schepers (yennicks)
- olokelo
- qo4on

.. include:: CHANGES.rst
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]" }
]
Expand Down Expand Up @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions src/pcloud/oauth2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
import logging
import socket
import _thread
import time

Expand All @@ -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}/"
Expand Down Expand Up @@ -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
12 changes: 9 additions & 3 deletions src/pcloud/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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()
5 changes: 3 additions & 2 deletions src/pcloud/tests/test_oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()


Expand Down

0 comments on commit 9e924f6

Please sign in to comment.