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

add type hints #165

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
6b757ef
add type hints
honglei Jul 3, 2023
855342f
fix indent error in ftpbench.py/bytes_per_second
honglei Jul 4, 2023
c85b9c4
ftpbench.py now use python3
honglei Jul 4, 2023
9c46f22
follow PEP8
honglei Jul 4, 2023
d4704d7
use autopep8 to fix PEP8
honglei Jul 4, 2023
9f4c632
fix PEP8 line length
honglei Jul 4, 2023
37bfebc
remove white space in line
honglei Jul 4, 2023
15790b5
Update ci.yml
honglei Jul 4, 2023
349b373
type hints use Python3.10+
honglei Jul 8, 2023
fb0b52f
solve flake8 warning
honglei Jul 8, 2023
4e95b2f
autopep8
honglei Jul 8, 2023
bf52d09
aioftp need Python3.10+
honglei Jul 8, 2023
c17a281
future-annotations-import-pep-563
honglei Jul 8, 2023
d80d734
ignore flake8 q000: double quotes found but single quotes preferred
honglei Jul 10, 2023
69c4b85
add missing type hints in client.py
honglei Jul 10, 2023
39df58d
add missing test for `SIZE`(rfc3659)
honglei Jul 10, 2023
e7a7b2b
match flake8
honglei Jul 10, 2023
5b75298
add test for 'SIZE'
honglei Jul 14, 2023
9398c6a
remove not used code
honglei Jul 14, 2023
cea2871
Update test_file.py
honglei Jul 14, 2023
fa13c7d
Merge branch 'aio-libs:master' into master
honglei Jul 14, 2023
3cfddf7
for pass mypy
honglei Aug 8, 2023
ebda8da
Merge branch 'master' of https://github.com/honglei/aioftp
honglei Aug 8, 2023
e2b61f1
black it.
honglei Aug 8, 2023
539cc52
line<=79
honglei Aug 8, 2023
22aaa3b
ci.yml add mypy
honglei Aug 8, 2023
28f8500
Update ci.yml
honglei Aug 8, 2023
4994839
fix mypy import error
honglei Aug 8, 2023
dbe5133
black
honglei Aug 8, 2023
feeafec
fix StreamThrottle
honglei Aug 8, 2023
5155e91
update linters
pohmelie Aug 12, 2023
b6ec758
partial work
honglei Aug 13, 2023
0cc53ff
ruff it
honglei Aug 13, 2023
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
3 changes: 3 additions & 0 deletions .black.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[tool.black]
line-length = 120
target-version = ['py311']
64 changes: 37 additions & 27 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,53 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.x'
- run: |
pip install flake8
flake8 aioftp tests
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.11'
- name: black
run: |
pip install black
black --config .black.toml --diff --check .
- name: ruff
run: |
pip install ruff
ruff check .
- name: mypy
run: |
pip install mypy
mypy

tests:
needs: lint
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10']
python-version: ['3.11']
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- run: |
pip install -e ./[tests]
pytest
- uses: codecov/codecov-action@v2
if: github.ref == 'refs/heads/master'
with:
fail_ci_if_error: true
verbose: true
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- run: |
pip install -e ./[dev]
pytest
- uses: codecov/codecov-action@v2
if: github.ref == 'refs/heads/master'
with:
fail_ci_if_error: true
verbose: true
token: ${{ secrets.CODECOV_TOKEN }}

deploy:
needs: tests
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: casperdcl/deploy-pypi@v2
with:
password: ${{ secrets.PYPI_TOKEN }}
build: true
skip_existing: true
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: casperdcl/deploy-pypi@v2
with:
password: ${{ secrets.PYPI_TOKEN }}
build: true
skip_existing: true
16 changes: 16 additions & 0 deletions .mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[mypy]
files = aioftp
strict = true
ignore_missing_imports = true
allow_subclassing_any = true
allow_untyped_calls = true
pretty = true
show_error_codes = true
implicit_reexport = true
allow_untyped_decorators = true
warn_unused_ignores = false
warn_return_any = false
namespace_packages = true

[mypy-tests.*]
ignore_errors = true
48 changes: 48 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks

.python-linters: &python-linters
pass_filenames: false
language: system
types: [python]

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
hooks:
- id: check-ast
- id: trailing-whitespace
- id: end-of-file-fixer

- repo: https://github.com/asottile/add-trailing-comma
rev: v2.1.0
hooks:
- id: add-trailing-comma

- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.1.0
hooks:
- id: pretty-format-yaml
args:
- --autofix
- --preserve-quotes
- --indent=2

- repo: local
hooks:
- <<: *python-linters
id: black
name: Format with Black
entry: black
args: ["--config", ".black.toml", "."]

- <<: *python-linters
id: ruff
name: Check with ruff
entry: ruff
args: ["check", "--fix", "."]

- <<: *python-linters
id: mypy
name: Validate types with MyPy
entry: mypy
File renamed without changes.
4 changes: 4 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
line-length = 120
target-version = "py311"
select = ["E", "W", "F", "Q", "UP", "I", "ASYNC"]
exclude = ["docs"]
4 changes: 3 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,14 @@ pyftpdlib 1.5.2
Dependencies
------------

- Python 3.7+
- Python 3.11+

0.13.0 is the last version which supports python 3.5.3+

0.16.1 is the last version which supports python 3.6+

0.21.4 is the last version which supports python 3.7-3.10

License
-------

Expand Down
25 changes: 12 additions & 13 deletions aioftp/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
"""ftp client/server for asyncio"""
# flake8: noqa

from .client import *
from .common import *
from .errors import *
from .pathio import *
from .server import *
from aioftp.client import *
from aioftp.common import *
from aioftp.errors import *
from aioftp.pathio import *
from aioftp.server import *
from aioftp.client import __all__ as client_all
from aioftp.server import __all__ as server_all
from aioftp.errors import __all__ as errors_all
from aioftp.common import __all__ as common_all
from aioftp.pathio import __all__ as pathio_all


__version__ = "0.21.4"
version = tuple(map(int, __version__.split(".")))

__all__ = (
client.__all__ +
server.__all__ +
errors.__all__ +
common.__all__ +
pathio.__all__ +
("version", "__version__")
)
__all__ = client_all + server_all + errors_all + common_all + pathio_all + ("version", "__version__")
47 changes: 29 additions & 18 deletions aioftp/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
"""Simple aioftp-based server with one user (anonymous or not)"""
import argparse
import asyncio
import contextlib
Expand All @@ -10,24 +9,36 @@
parser = argparse.ArgumentParser(
prog="aioftp",
usage="%(prog)s [options]",
description="Simple aioftp-based server with one user (anonymous or not)."
description="Simple aioftp-based server with one user (anonymous or not).",
)
parser.add_argument("--user", metavar="LOGIN", dest="login", help="user name to login")
parser.add_argument("--pass", metavar="PASSWORD", dest="password", help="password to login")
parser.add_argument(
"-d",
metavar="DIRECTORY",
dest="home",
help="the directory to share (default current directory)",
)
parser.add_argument(
"-q",
"--quiet",
action="store_true",
help="set logging level to 'ERROR' instead of 'INFO'",
)
parser.add_argument("--user", metavar="LOGIN", dest="login",
help="user name to login")
parser.add_argument("--pass", metavar="PASSWORD", dest="password",
help="password to login")
parser.add_argument("-d", metavar="DIRECTORY", dest="home",
help="the directory to share (default current directory)")
parser.add_argument("-q", "--quiet", action="store_true",
help="set logging level to 'ERROR' instead of 'INFO'")
parser.add_argument("--memory", action="store_true", help="use memory storage")
parser.add_argument("--host", default=None,
help="host for binding [default: %(default)s]")
parser.add_argument("--port", type=int, default=2121,
help="port for binding [default: %(default)s]")
parser.add_argument("--family", choices=("ipv4", "ipv6", "auto"),
default="auto",
help="Socket family [default: %(default)s]")
parser.add_argument("--host", default=None, help="host for binding [default: %(default)s]")
parser.add_argument(
"--port",
type=int,
default=2121,
help="port for binding [default: %(default)s]",
)
parser.add_argument(
"--family",
choices=("ipv4", "ipv6", "auto"),
default="auto",
help="Socket family [default: %(default)s]",
)

args = parser.parse_args()
print(f"aioftp v{aioftp.__version__}")
Expand All @@ -40,7 +51,7 @@
)
if args.memory:
user = aioftp.User(args.login, args.password, base_path="/")
path_io_factory = aioftp.MemoryPathIO
path_io_factory: type[aioftp.MemoryPathIO] | type[aioftp.PathIO] = aioftp.MemoryPathIO
else:
if args.home:
user = aioftp.User(args.login, args.password, base_path=args.home)
Expand Down
Loading