Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test dt adapter #5524

Open
wants to merge 37 commits into
base: wip-NXDRIVE-2929-upgrade-python-from-3.9.5-to-3.12.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
c75e217
Bump platformdirs from 4.2.2 to 4.3.6 in /tools/deps (#5265)
dependabot[bot] Sep 27, 2024
106e3a6
Bump watchdog from 3.0.0 to 5.0.2 in /tools/deps (#5221)
dependabot[bot] Oct 1, 2024
405f6d9
Bump pyobjc-framework-cocoa from 10.1 to 10.3.1 in /tools/deps (#4988)
dependabot[bot] Oct 8, 2024
094f4de
Bump pyobjc-framework-fsevents from 10.1 to 10.3.1 in /tools/deps (#4…
dependabot[bot] Oct 9, 2024
9aa9228
NXDRIVE-2954: [Mac] Certificate needs to be renewed (#5347)
gitofanindya Oct 24, 2024
4a40d03
Bump send2trash from 1.7.1 to 1.8.3 in /tools/deps (#4775)
dependabot[bot] Oct 24, 2024
c5b58eb
Bump requests from 2.31.0 to 2.32.3 in /tools/deps (#4942)
dependabot[bot] Oct 28, 2024
c0fac40
NXDRIVE-2925: Ignore zero-byte files (#5372)
gitofanindya Nov 11, 2024
9805a47
Bump black from 23.12.1 to 24.10.0 in /tools/deps (#5386)
dependabot[bot] Nov 12, 2024
b4b5d33
NXDRIVE-2967: Upgrade the deprecated datetime adapter
gitofanindya Nov 19, 2024
d898aa3
Merge branch 'master' of https://github.com/nuxeo/nuxeo-drive into te…
gitofanindya Nov 19, 2024
ed3221c
updated test_utils
gitofanindya Nov 19, 2024
3ebc1c6
downgrading requests
gitofanindya Nov 20, 2024
36c10af
upgraded requests
gitofanindya Nov 20, 2024
4200605
Update utils.py
gitofanindya Nov 28, 2024
69d0baf
Update utils.py
gitofanindya Nov 28, 2024
dda1df2
Update utils.py
gitofanindya Nov 28, 2024
16485de
Update utils.py
gitofanindya Nov 29, 2024
569349a
Update test_options.py
gitofanindya Nov 29, 2024
1b9c085
Update test_proxy.py
gitofanindya Nov 29, 2024
997db2f
Update utils.py
gitofanindya Nov 29, 2024
3461608
Update conftest.py
gitofanindya Dec 2, 2024
59208b8
Update requirements.txt 1
gitofanindya Dec 18, 2024
ad685a0
Update requirements-tests.txt 1
gitofanindya Dec 18, 2024
55e58fa
Update requirements.txt 2
gitofanindya Dec 18, 2024
d31181b
Update requirements-tox.txt 1
gitofanindya Dec 18, 2024
a19ab90
Update requirements-tests.txt 2
gitofanindya Dec 18, 2024
92f345f
Update requirements-pip.txt 1
gitofanindya Dec 18, 2024
4bdd34d
Update requirements-bench.txt 1
gitofanindya Dec 18, 2024
b32ba20
Update direct_edit.py
gitofanindya Dec 18, 2024
3657983
Update direct_edit.py 2
gitofanindya Dec 18, 2024
9800c7b
Update requirements-tox.txt 3
gitofanindya Dec 18, 2024
bebf0ba
Update requirements-tests.txt 3
gitofanindya Dec 18, 2024
4f2536f
Update requirements-tests.txt 4
gitofanindya Dec 18, 2024
d2e136c
Update requirements-tox.txt 4
gitofanindya Dec 18, 2024
9d0ba23
Update requirements-tox.txt 4
gitofanindya Dec 18, 2024
a289429
Update requirements.txt 4
gitofanindya Dec 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ jobs:
if: matrix.os == 'macos-latest'
run: |
wget https://www.apple.com/appleca/AppleIncRootCertificate.cer
echo "${{ secrets.CERT_APP_MACOS }}" | base64 --decode > developerID_application.cer
echo "${{ secrets.CERT_APP_MACOS }}" | base64 --decode > developerID_application.p12
echo "${{ secrets.PRIV_APP_MACOS }}" | base64 --decode > nuxeo-drive.priv

#- name: "[macOS] Downloading Python"
Expand Down
24 changes: 24 additions & 0 deletions docs/changes/5.5.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Release date: `2024-xx-xx`

- [NXDRIVE-2909](https://jira.nuxeo.com/browse/NXDRIVE-2909): Set container title when defining the Folder type from Document Type Selection using Direct Transfer
- [NXDRIVE-2915](https://jira.nuxeo.com/browse/NXDRIVE-2915): Translate "Document type" and "container type" labels on Direct Transfer popup
- [NXDRIVE-2925](https://jira.nuxeo.com/browse/NXDRIVE-2925): Ignore zero-byte files

### Task Management
- [NXDRIVE-2](https://jira.nuxeo.com/browse/NXDRIVE-2):
Expand All @@ -27,6 +28,8 @@ Release date: `2024-xx-xx`

- [NXDRIVE-2970](https://jira.nuxeo.com/browse/NXDRIVE-2970): Fix security issue: urllib3's Proxy-Authorization request header isn't stripped during cross-origin redirects
- [NXDRIVE-2971](https://jira.nuxeo.com/browse/NXDRIVE-2971): Fix security issue: pyca/cryptography has a vulnerable OpenSSL included in cryptography wheels
- [NXDRIVE-2954](https://jira.nuxeo.com/browse/NXDRIVE-2954): [Mac] Certificate needs to be renewed
- [NXDRIVE-2976](https://hyland.atlassian.net/browse/NXDRIVE-2976): Fix security issue: Black vulnerable to Regular Expression Denial of Service (ReDoS)

## Tests

Expand All @@ -38,23 +41,44 @@ Release date: `2024-xx-xx`

## Minor Changes

- Upgraded `altgraph` from 0.17 to 0.17.4
- Upgraded `authlib` from 1.3.0 to 1.3.1
- Upgraded `black` from 23.12.1 to 24.10.0
- Upgraded `boto3` from 1.34.17 to 1.35.21
- Upgraded `botocore` from 1.34.17 to 1.35.21
- Upgraded `build` from 1.2.1 to 1.2.2
- Upgraded `cachetools` from 5.3.3 to 5.5.0
- Upgraded `certifi` from 2023.7.22 to 2024.7.4
- Upgraded `cryptography` from 42.0.5 to 43.0.1
- Upgraded `docutils` from 0.20.1 to 0.21.2
- Upgraded `faker` from 22.0.0 to 29.0.0
- Upgraded `filelock` from 3.14.0 to 3.16.1
- Upgraded `flake8` from 6.1.0 to 7.1.1
- Upgraded `future` from 0.18.3 to 1.0.0
- Upgraded `mypy` from 1.10.0 to 1.11.2
- Upgraded `types-python-dateutil` from 2.8.19.20240106 to 2.9.0.20240906
- Upgraded `typing-extensions` from 4.9.0 to 4.12.2
- Upgraded `pefile` from 2023.2.7 to 2024.8.26
- Upgraded `platformdirs` from 4.2.2 to 4.3.6
- Upgraded `pre-commit` from 2.16.0 to 3.8.0
- Upgraded `pycodestyle` from 2.11.1 to 2.12.1
- Upgraded `pycparser` from 2.21 to 2.22
- Upgraded `py-cpuinfo` from 8.0.0 to 9.0.0
- Upgraded `pyflakes` from 3.1.0 to 3.2.0
- Upgraded `pyobjc-core` from 10.1 to 10.3.1
- Upgraded `pyobjc-framework-cocoa` from 10.1 to 10.3.1
- Upgraded `pyobjc-framework-coreservices` from 10.1 to 10.3.1
- Upgraded `pyobjc-framework-scriptingbridge` from 10.1 to 10.3.1
- Upgraded `pyobjc-framework-fsevents` from 10.1 to 10.3.1
- Upgraded `pyobjc-framework-systemconfiguration` from 10.1 to 10.3.1
- Upgraded `pytest-benchmark` from 3.4.1 to 4.0.0
- Upgraded `python-dateutil` from 2.8.2 to 2.9.0.post0
- Upgraded `responses` from 0.24.1 to 0.25.3
- Upgraded `requests` from 2.31.0 to 2.32.3
- Upgraded `send2trash` from 1.7.1 to 1.8.3
- Upgraded `setuptools` from 69.5.1 to 72.1.0
- Upgraded `urllib3` from 1.26.12 to 1.26.19
- Upgraded `watchdog` from 3.0.0 to 5.0.2
- Upgraded `zipp` from 3.18.0 to 3.20.0

## Technical Changes
Expand Down
1 change: 1 addition & 0 deletions nxdrive/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
In this file we cannot use a relative import here, else Drive will not start when packaged.
See https://github.com/pyinstaller/pyinstaller/issues/2560
"""

import locale
import platform
import signal
Expand Down
1 change: 1 addition & 0 deletions nxdrive/behavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
Allow or disallow server deletions.

"""

from types import SimpleNamespace

Behavior = SimpleNamespace(server_deletion=True)
1 change: 1 addition & 0 deletions nxdrive/client/local/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" API to access local resources for synchronization. """

from .base import FileInfo, get

# Get the local client related to the current OS
Expand Down
6 changes: 3 additions & 3 deletions nxdrive/client/local/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import unicodedata
import uuid
from contextlib import suppress
from datetime import datetime
from datetime import datetime, timezone
from logging import getLogger
from pathlib import Path
from tempfile import mkdtemp
Expand Down Expand Up @@ -263,12 +263,12 @@ def get_info(self, ref: Path, /, *, check: bool = True) -> FileInfo:
stat_info = os_path.stat()
size = 0 if folderish else stat_info.st_size
try:
mtime = datetime.utcfromtimestamp(stat_info.st_mtime)
mtime = datetime.fromtimestamp(stat_info.st_mtime, tz=timezone.utc)
except (ValueError, OverflowError, OSError) as e:
log.warning(
f"{e} file path: {os_path}. st_mtime value: {stat_info.st_mtime}"
)
mtime = datetime.utcfromtimestamp(0)
mtime = datetime.fromtimestamp(0, tz=timezone.utc)

# TODO Do we need to load it every time ?
remote_ref = self.get_remote_id(ref)
Expand Down
1 change: 1 addition & 0 deletions nxdrive/client/uploader/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Uploader used by the Remote client for all upload stuff.
"""

import json
from abc import abstractmethod
from logging import getLogger
Expand Down
1 change: 1 addition & 0 deletions nxdrive/client/uploader/direct_transfer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Uploader used by the Direct Transfer feature.
"""

import json
from logging import getLogger
from pathlib import Path
Expand Down
1 change: 1 addition & 0 deletions nxdrive/client/uploader/sync.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Uploader used by the synchronization engine.
"""

from pathlib import Path
from typing import Any, Dict, Optional

Expand Down
12 changes: 10 additions & 2 deletions nxdrive/dao/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""
Query formatting in this file is based on http://www.sqlstyle.guide/
"""

from datetime import datetime, timezone
import sys
from contextlib import suppress
from logging import getLogger
Expand All @@ -18,14 +20,20 @@

log = getLogger(__name__)


class AutoRetryCursor(Cursor):
def adapt_datetime_iso(self, val):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: The strftime('%s') format specifier is not guaranteed to work on all platforms, particularly Windows

return datetime.fromtimestamp(val.strftime('%s'), tz=timezone.utc)
def execute(self, sql: str, parameters: Iterable[Any] = ()) -> Cursor:
count = 1
while True:
count += 1
try:
return super().execute(sql, parameters)
import sqlite3
# return super().execute(sql, parameters)
# new_param = tuple( datetime.fromtimestamp(param, tz=timezone.utc) if isinstance(param, datetime) else param for param in parameters )
new_param = tuple( sqlite3.register_adapter(param, self.adapt_datetime_iso) if isinstance(param, datetime) else param for param in parameters )

return super().execute(sql, new_param)
except OperationalError as exc:
log.info(
f"Retry locked database #{count}, {sql=}, {parameters=}",
Expand Down
1 change: 1 addition & 0 deletions nxdrive/dao/engine.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Query formatting in this file is based on http://www.sqlstyle.guide/
"""

import json
import os
import shutil
Expand Down
1 change: 1 addition & 0 deletions nxdrive/dao/manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Query formatting in this file is based on http://www.sqlstyle.guide/
"""

from logging import getLogger
from pathlib import Path
from sqlite3 import Cursor, IntegrityError, Row
Expand Down
6 changes: 3 additions & 3 deletions nxdrive/dao/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ def dump(database: Path, dump_file: Path, /) -> None:
"""

log.info(f"Dumping the database {database!r} into {dump_file!r}...")
with sqlite3.connect(str(database)) as con, dump_file.open(
mode="w", encoding="utf-8"
) as f:
con = sqlite3.connect(str(database))
with dump_file.open(mode="w", encoding="utf-8") as f:
for line in con.iterdump():
f.write(f"{line}\n")

# Force write of file to disk
f.flush()
fsync(f.fileno())
con.close()
Comment on lines +39 to +47
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Use context manager pattern for database connection to ensure proper cleanup

This ensures the connection is closed even if an exception occurs during the dump process.

Suggested change
con = sqlite3.connect(str(database))
with dump_file.open(mode="w", encoding="utf-8") as f:
for line in con.iterdump():
f.write(f"{line}\n")
# Force write of file to disk
f.flush()
fsync(f.fileno())
con.close()
with sqlite3.connect(str(database)) as con, dump_file.open(mode="w", encoding="utf-8") as f:
for line in con.iterdump():
f.write(f"{line}\n")
# Force write of file to disk
f.flush()
fsync(f.fileno())


log.info("Dump finished with success.")

Expand Down
1 change: 1 addition & 0 deletions nxdrive/direct_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1111,4 +1111,5 @@ def _get_ref(self, src_path: Path) -> Path:
ref = self.local.get_path(src_path)
if ref not in self._file_metrics:
self._file_metrics[ref] = defaultdict(int)
#testing...
return ref
4 changes: 1 addition & 3 deletions nxdrive/engine/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,9 +838,7 @@ def resume_transfer(
meth = (
self.dao.get_download
if nature == "download"
else self.dao.get_dt_upload
if is_direct_transfer
else self.dao.get_upload
else self.dao.get_dt_upload if is_direct_transfer else self.dao.get_upload
)
func = partial(meth, uid=uid) # type: ignore
self._resume_transfers(nature, func, is_direct_transfer=is_direct_transfer)
Expand Down
1 change: 1 addition & 0 deletions nxdrive/fatal_error.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Fatal error screen management using either Qt or OS-specific dialogs.
"""

import sys
from contextlib import suppress
from pathlib import Path
Expand Down
1 change: 1 addition & 0 deletions nxdrive/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
Enable or disable the synchronization features.

"""

from types import SimpleNamespace
from typing import List

Expand Down
1 change: 1 addition & 0 deletions nxdrive/gui/application.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" Main Qt application handling OS events and system tray UI. """

import os
import webbrowser
from contextlib import suppress
Expand Down
12 changes: 11 additions & 1 deletion nxdrive/gui/folders_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,9 @@ def _files_display(self) -> str:
txt += f" (+{self.overall_count - 1:,})"
return txt

def get_size(self, file_path: Path) -> bool:
return file_path.stat().st_size

def _process_additionnal_local_paths(self, paths: List[str], /) -> None:
"""Append more local paths to the upload queue."""
for local_path in paths:
Expand All @@ -647,10 +650,17 @@ def _process_additionnal_local_paths(self, paths: List[str], /) -> None:
# Save the path
if path.is_dir():
for file_path, size in get_tree_list(path):
if self.get_size(file_path) == 0:
# ignoring zero byte files [NXDRIVE-2925]
continue
self.paths[file_path] = size
else:
try:
self.paths[path] = path.stat().st_size
file_size = self.get_size(path)
if file_size == 0:
# ignoring zero byte files [NXDRIVE-2925]
continue
self.paths[path] = file_size
except OSError:
log.warning(f"Error calling stat() on {path!r}", exc_info=True)
continue
Expand Down
1 change: 1 addition & 0 deletions nxdrive/osi/darwin/pyNotificationCenter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" Python integration macOS notification center. """

from typing import TYPE_CHECKING, Dict

from CoreServices import (
Expand Down
1 change: 1 addition & 0 deletions nxdrive/qt/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Put here all PyQt constants used across the project.
"""

from .imports import (
QAbstractSocket,
QDialogButtonBox,
Expand Down
1 change: 1 addition & 0 deletions nxdrive/qt/imports.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Put here all PyQt imports used across the project.
"""

from PyQt5.QtCore import (
QT_VERSION_STR,
QAbstractListModel,
Expand Down
1 change: 1 addition & 0 deletions nxdrive/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
This state is set at the start of the application to know if it has crashed at the previous run.

"""

from types import SimpleNamespace

State = SimpleNamespace(about_to_quit=False, crash_details="", has_crashed=False)
1 change: 1 addition & 0 deletions nxdrive/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Most of functions are pure enough to be decorated with a LRU cache.
Each *maxsize* is adjusted depending of the heavy use of the decorated function.
"""

import os
import os.path
import re
Expand Down
1 change: 1 addition & 0 deletions tests/benchmarks/test_safe_filename.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
If is not the most efficient for small ASCII-only filenames,
but it is the best when there are non-ASCII characters.
"""

import pytest

FILENAMES = [
Expand Down
1 change: 1 addition & 0 deletions tests/cleanup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Cleanup old test users and workspaces."""

import env
from nuxeo.client import Nuxeo

Expand Down
4 changes: 0 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@ def no_warnings(recwarn):
continue
elif "Cryptography will be significantly faster" in message:
continue
elif "The default datetime adapter is deprecated as of Python 3.12" in message:
continue
elif "datetime.datetime" in message:
continue

warn = f"{warning.filename}:{warning.lineno} {message}"
print(warn, file=sys.stderr)
Expand Down
4 changes: 3 additions & 1 deletion tests/integration/windows/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ def test_argument_log_filename(exe, tmp, file):
assert log.is_file()


@pytest.mark.parametrize("folder", ["azerty", "$alice", "léa", "mi Kaël", "こん ツリ ^^"])
@pytest.mark.parametrize(
"folder", ["azerty", "$alice", "léa", "mi Kaël", "こん ツリ ^^"]
)
def test_argument_nxdrive_home(exe, tmp, folder):
path = tmp()
path.mkdir(parents=True, exist_ok=True)
Expand Down
1 change: 1 addition & 0 deletions tests/markers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Collection of pytest markers to ease test filtering."""

import os

import pytest
Expand Down
1 change: 1 addition & 0 deletions tests/old_functional/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" Common test utilities. """

import os
import sys
import tempfile
Expand Down
1 change: 1 addition & 0 deletions tests/old_functional/test_behavior.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Test application Behavior.
"""

from nxdrive.behavior import Behavior

from .. import ensure_no_exception
Expand Down
1 change: 1 addition & 0 deletions tests/old_functional/test_direct_transfer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Test the Direct Transfer feature in different scenarii.
"""

import logging
import re
from pathlib import Path
Expand Down
1 change: 1 addition & 0 deletions tests/old_functional/test_local_changes_when_offline.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Test if changes made to local file system when Drive is offline sync's back
later when Drive becomes online.
"""

import pytest

from nxdrive.constants import WINDOWS
Expand Down
1 change: 1 addition & 0 deletions tests/old_functional/test_local_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

See NXDRIVE-742.
"""

import hashlib
import os
from pathlib import Path
Expand Down
Loading
Loading