Merge pull request #1347 from tahoe-lafs/4075-dependency-updates

Dependency updates and some improvements to typechecking
This commit is contained in:
meejah 2023-11-22 17:23:22 -07:00 committed by GitHub
commit 638d8d66c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 19 additions and 15 deletions

0
newsfragments/4075.minor Normal file
View File

View File

@ -11,6 +11,7 @@ from typing import (
Optional, Optional,
Union, Union,
List, List,
IO
) )
from twisted.python.filepath import FilePath from twisted.python.filepath import FilePath
@ -178,6 +179,7 @@ def load_grid_manager(config_path: Optional[FilePath]):
:raises: ValueError if the confguration is invalid or IOError if :raises: ValueError if the confguration is invalid or IOError if
expected files can't be opened. expected files can't be opened.
""" """
config_file: Union[IO[bytes], IO[str]]
if config_path is None: if config_path is None:
config_file = sys.stdin config_file = sys.stdin
else: else:

View File

@ -200,14 +200,14 @@ def read_config(basedir, portnumfile, generated_files: Iterable = (), _valid_con
config_path = FilePath(basedir).child("tahoe.cfg") config_path = FilePath(basedir).child("tahoe.cfg")
try: try:
config_str = config_path.getContent() config_bytes = config_path.getContent()
except EnvironmentError as e: except EnvironmentError as e:
if e.errno != errno.ENOENT: if e.errno != errno.ENOENT:
raise raise
# The file is missing, just create empty ConfigParser. # The file is missing, just create empty ConfigParser.
config_str = u"" config_str = u""
else: else:
config_str = config_str.decode("utf-8-sig") config_str = config_bytes.decode("utf-8-sig")
return config_from_string( return config_from_string(
basedir, basedir,

View File

@ -15,7 +15,7 @@ scheduler affinity or cgroups, but that's not the end of the world.
""" """
import os import os
from typing import TypeVar, Callable from typing import TypeVar, Callable, cast
from functools import partial from functools import partial
import threading import threading
from typing_extensions import ParamSpec from typing_extensions import ParamSpec
@ -24,8 +24,9 @@ from unittest import TestCase
from twisted.python.threadpool import ThreadPool from twisted.python.threadpool import ThreadPool
from twisted.internet.threads import deferToThreadPool from twisted.internet.threads import deferToThreadPool
from twisted.internet import reactor from twisted.internet import reactor
from twisted.internet.interfaces import IReactorFromThreads
_CPU_THREAD_POOL = ThreadPool(minthreads=0, maxthreads=os.cpu_count(), name="TahoeCPU") _CPU_THREAD_POOL = ThreadPool(minthreads=0, maxthreads=os.cpu_count() or 1, name="TahoeCPU")
if hasattr(threading, "_register_atexit"): if hasattr(threading, "_register_atexit"):
# This is a private API present in Python 3.8 or later, specifically # This is a private API present in Python 3.8 or later, specifically
# designed for thread pool shutdown. Since it's private, it might go away # designed for thread pool shutdown. Since it's private, it might go away
@ -64,7 +65,7 @@ async def defer_to_thread(f: Callable[P, R], *args: P.args, **kwargs: P.kwargs)
return f(*args, **kwargs) return f(*args, **kwargs)
# deferToThreadPool has no type annotations... # deferToThreadPool has no type annotations...
result = await deferToThreadPool(reactor, _CPU_THREAD_POOL, f, *args, **kwargs) result = await deferToThreadPool(cast(IReactorFromThreads, reactor), _CPU_THREAD_POOL, f, *args, **kwargs)
return result return result

View File

@ -874,6 +874,6 @@ def add_static_children(root: IResource):
for child in static_dir.iterdir(): for child in static_dir.iterdir():
child_path = child.name.encode("utf-8") child_path = child.name.encode("utf-8")
root.putChild(child_path, static.File( root.putChild(child_path, static.File(
temporary_file_manager.enter_context(as_file(child)) str(temporary_file_manager.enter_context(as_file(child)))
)) ))
weakref.finalize(root, temporary_file_manager.close) weakref.finalize(root, temporary_file_manager.close)

19
tox.ini
View File

@ -101,11 +101,7 @@ skip_install = true
deps = deps =
# Pin a specific version so we get consistent outcomes; update this # Pin a specific version so we get consistent outcomes; update this
# occasionally: # occasionally:
ruff == 0.0.287 ruff == 0.1.6
# towncrier doesn't work with importlib_resources 6.0.0
# https://github.com/twisted/towncrier/issues/528
# Will be fixed in first version of Towncrier that is larger than 2023.6.
importlib_resources < 6.0.0
towncrier towncrier
# On macOS, git inside of towncrier needs $HOME. # On macOS, git inside of towncrier needs $HOME.
passenv = HOME passenv = HOME
@ -137,8 +133,13 @@ deps =
types-pyOpenSSL types-pyOpenSSL
foolscap foolscap
# Upgrade when new releases come out: # Upgrade when new releases come out:
Twisted==23.8.0 Twisted==23.10.0
commands = mypy src commands =
# Different versions of Python have a different standard library, and we
# want to be compatible with all the variations. For speed's sake we only do
# the earliest and latest versions.
mypy --python-version=3.8 src
mypy --python-version=3.12 src
[testenv:draftnews] [testenv:draftnews]
@ -146,7 +147,7 @@ passenv = TAHOE_LAFS_*,PIP_*,SUBUNITREPORTER_*,USERPROFILE,HOMEDRIVE,HOMEPATH,CO
deps = deps =
# see comment in [testenv] about "certifi" # see comment in [testenv] about "certifi"
certifi certifi
towncrier==21.3.0 towncrier==23.11.0
commands = commands =
python -m towncrier --draft --config towncrier.toml python -m towncrier --draft --config towncrier.toml
@ -158,7 +159,7 @@ whitelist_externals =
deps = deps =
# see comment in [testenv] about "certifi" # see comment in [testenv] about "certifi"
certifi certifi
towncrier==21.3.0 towncrier==23.11.0
commands = commands =
python -m towncrier --yes --config towncrier.toml python -m towncrier --yes --config towncrier.toml
# commit the changes # commit the changes