Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolCat467 committed Oct 31, 2023
2 parents fc28bbf + 6c50dc2 commit 928865c
Show file tree
Hide file tree
Showing 152 changed files with 5,360 additions and 3,074 deletions.
4 changes: 3 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ parallel=True

[report]
precision = 1
skip_covered = True
exclude_lines =
pragma: no cover
abc.abstractmethod
if TYPE_CHECKING:
if TYPE_CHECKING.*:
if _t.TYPE_CHECKING:
if t.TYPE_CHECKING:
@overload
class .*\bProtocol\b.*\):
raise NotImplementedError

partial_branches =
pragma: no branch
Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ jobs:
strategy:
fail-fast: false
matrix:
# pypy-3.10 is failing, see https://github.com/python-trio/trio/issues/2678
python: ['3.8', '3.9', '3.10', 'pypy-3.9-nightly'] #, 'pypy-3.10-nightly']
# pypy 3.9 and 3.10 are failing, see https://github.com/python-trio/trio/issues/2678 and https://github.com/python-trio/trio/issues/2776 respectively
python: ['3.8', '3.9', '3.10'] #, 'pypy-3.9-nightly', 'pypy-3.10-nightly']
arch: ['x86', 'x64']
lsp: ['']
lsp_extract_file: ['']
Expand Down Expand Up @@ -96,11 +96,16 @@ jobs:
matrix:
python: ['pypy-3.9', 'pypy-3.10', '3.8', '3.9', '3.10', '3.11', '3.12-dev', 'pypy-3.9-nightly', 'pypy-3.10-nightly']
check_formatting: ['0']
no_test_requirements: ['0']
extra_name: ['']
include:
- python: '3.8'
check_formatting: '1'
extra_name: ', check formatting'
# separate test run that doesn't install test-requirements.txt
- python: '3.8'
no_test_requirements: '1'
extra_name: ', no test-requirements'
continue-on-error: >-
${{
(
Expand Down Expand Up @@ -129,6 +134,7 @@ jobs:
run: ./ci.sh
env:
CHECK_FORMATTING: '${{ matrix.check_formatting }}'
NO_TEST_REQUIREMENTS: '${{ matrix.no_test_requirements }}'
- if: always()
uses: codecov/codecov-action@v3
with:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ pyvenv.cfg
nosetests.xml
coverage.xml

# Temp file during Mypy processing
mypy_annotate.dat

# Translations
*.mo

Expand Down
38 changes: 17 additions & 21 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
ci:
autofix_commit_msg: "[pre-commit.ci] auto fixes from pre-commit.com hooks"
autofix_prs: false
autoupdate_commit_msg: "[pre-commit.ci] pre-commit autoupdate"
autoupdate_schedule: weekly
submodules: false

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -9,31 +16,20 @@ repos:
- id: check-merge-conflict
- id: mixed-line-ending
- id: check-case-conflict
- id: sort-simple-yaml
files: .pre-commit-config.yaml
- repo: https://github.com/psf/black
rev: 23.7.0
rev: 23.10.1
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/pycqa/flake8
rev: 6.1.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.3
hooks:
- id: flake8
additional_dependencies:
- "flake8-pyproject==1.2.3"
- id: ruff
types: [file]
types_or: [python, pyi]
types_or: [python, pyi, toml]
args: ["--show-fixes"]
- repo: https://github.com/codespell-project/codespell
rev: v2.2.5
rev: v2.2.6
hooks:
- id: codespell

ci:
autofix_commit_msg: "[pre-commit.ci] auto fixes from pre-commit.com hooks"
autofix_prs: true
autoupdate_commit_msg: "[pre-commit.ci] pre-commit autoupdate"
autoupdate_schedule: weekly
skip: [black,isort]
submodules: false
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ demonstration of implementing the "Happy Eyeballs" algorithm in an
older library versus Trio.

**Cool, but will it work on my system?** Probably! As long as you have
some kind of Python 3.8-or-better (CPython or [currently maintained versions of
PyPy3](https://doc.pypy.org/en/latest/faq.html#which-python-versions-does-pypy-implement)
some kind of Python 3.8-or-better (CPython or `currently maintained versions of
PyPy3 <https://doc.pypy.org/en/latest/faq.html#which-python-versions-does-pypy-implement>`__
are both fine), and are using Linux, macOS, Windows, or FreeBSD, then Trio
will work. Other environments might work too, but those
are the ones we test on. And all of our dependencies are pure Python,
Expand Down
79 changes: 69 additions & 10 deletions check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,112 @@

set -ex

ON_GITHUB_CI=true
EXIT_STATUS=0

# If not running on Github's CI, discard the summaries
if [ -z "${GITHUB_STEP_SUMMARY+x}" ]; then
GITHUB_STEP_SUMMARY=/dev/null
ON_GITHUB_CI=false
fi

# Test if the generated code is still up to date
echo "::group::Generate Exports"
python ./trio/_tools/gen_exports.py --test \
|| EXIT_STATUS=$?
echo "::endgroup::"

# Autoformatter *first*, to avoid double-reporting errors
# (we'd like to run further autoformatters but *after* merging;
# see https://forum.bors.tech/t/pre-test-and-pre-merge-hooks/322)
# autoflake --recursive --in-place .
# pyupgrade --py3-plus $(find . -name "*.py")
echo "::group::Black"
if ! black --check setup.py trio; then
echo "* Black found issues" >> "$GITHUB_STEP_SUMMARY"
EXIT_STATUS=1
black --diff setup.py trio
echo "::endgroup::"
echo "::error:: Black found issues"
else
echo "::endgroup::"
fi

if ! isort --check setup.py trio; then
# Run ruff, configured in pyproject.toml
echo "::group::Ruff"
if ! ruff check .; then
echo "* ruff found issues." >> "$GITHUB_STEP_SUMMARY"
EXIT_STATUS=1
isort --diff setup.py trio
if $ON_GITHUB_CI; then
ruff check --output-format github --diff .
else
ruff check --diff .
fi
echo "::endgroup::"
echo "::error:: ruff found issues"
else
echo "::endgroup::"
fi

# Run flake8, configured in pyproject.toml
flake8 trio/ || EXIT_STATUS=$?

# Run mypy on all supported platforms
mypy trio --platform linux || EXIT_STATUS=$?
mypy trio --platform darwin || EXIT_STATUS=$? # tests FreeBSD too
mypy trio --platform win32 || EXIT_STATUS=$?
# MYPY is set if any of them fail.
MYPY=0
echo "::group::Mypy"
# Cleanup previous runs.
rm -f mypy_annotate.dat
# Pipefail makes these pipelines fail if mypy does, even if mypy_annotate.py succeeds.
set -o pipefail
mypy trio --show-error-end --platform linux | python ./trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat --platform Linux \
|| { echo "* Mypy (Linux) found type errors." >> "$GITHUB_STEP_SUMMARY"; MYPY=1; }
# Darwin tests FreeBSD too
mypy trio --show-error-end --platform darwin | python ./trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat --platform Mac \
|| { echo "* Mypy (Mac) found type errors." >> "$GITHUB_STEP_SUMMARY"; MYPY=1; }
mypy trio --show-error-end --platform win32 | python ./trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat --platform Windows \
|| { echo "* Mypy (Windows) found type errors." >> "$GITHUB_STEP_SUMMARY"; MYPY=1; }
set +o pipefail
# Re-display errors using Github's syntax, read out of mypy_annotate.dat
python ./trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat
# Then discard.
rm -f mypy_annotate.dat
echo "::endgroup::"
# Display a big error if we failed, outside the group so it can't be collapsed.
if [ $MYPY -ne 0 ]; then
echo "::error:: Mypy found type errors."
EXIT_STATUS=1
fi

# Check pip compile is consistent
echo "::group::Pip Compile - Tests"
pip-compile test-requirements.in
echo "::endgroup::"
echo "::group::Pip Compile - Docs"
pip-compile docs-requirements.in
echo "::endgroup::"

if git status --porcelain | grep -q "requirements.txt"; then
echo "::error::requirements.txt changed."
echo "::group::requirements.txt changed"
echo "* requirements.txt changed" >> "$GITHUB_STEP_SUMMARY"
git status --porcelain
git --no-pager diff --color *requirements.txt
git --no-pager diff --color ./*requirements.txt
EXIT_STATUS=1
echo "::endgroup::"
fi

codespell || EXIT_STATUS=$?

echo "::group::Pyright interface tests"
python trio/_tests/check_type_completeness.py --overwrite-file || EXIT_STATUS=$?
if git status --porcelain trio/_tests/verify_types*.json | grep -q "M"; then
echo "Type completeness changed, please update!"
echo "* Type completeness changed, please update!" >> "$GITHUB_STEP_SUMMARY"
echo "::error::Type completeness changed, please update!"
git --no-pager diff --color trio/_tests/verify_types*.json
EXIT_STATUS=1
fi

pyright trio/_tests/type_tests || EXIT_STATUS=$?
echo "::endgroup::"

# Finally, leave a really clear warning of any issues and exit
if [ $EXIT_STATUS -ne 0 ]; then
cat <<EOF
Expand All @@ -71,4 +129,5 @@ in your local checkout.
EOF
exit 1
fi
echo "# Formatting checks succeeded." >> "$GITHUB_STEP_SUMMARY"
exit 0
31 changes: 25 additions & 6 deletions ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ set -ex -o pipefail
export PYRIGHT_PYTHON_IGNORE_WARNINGS=1

# Log some general info about the environment
echo "::group::Environment"
uname -a
env | sort
echo "::endgroup::"

# Curl's built-in retry system is not very robust; it gives up on lots of
# network errors that we want to retry on. Wget might work better, but it's
Expand All @@ -30,8 +32,11 @@ function curl-harder() {
# We have a Python environment!
################################################################

python -c "import sys, struct, ssl; print('#' * 70); print('python:', sys.version); print('version_info:', sys.version_info); print('bits:', struct.calcsize('P') * 8); print('openssl:', ssl.OPENSSL_VERSION, ssl.OPENSSL_VERSION_INFO); print('#' * 70)"
echo "::group::Versions"
python -c "import sys, struct, ssl; print('python:', sys.version); print('version_info:', sys.version_info); print('bits:', struct.calcsize('P') * 8); print('openssl:', ssl.OPENSSL_VERSION, ssl.OPENSSL_VERSION_INFO)"
echo "::endgroup::"

echo "::group::Install dependencies"
python -m pip install -U pip setuptools wheel
python -m pip --version

Expand All @@ -40,10 +45,19 @@ python -m pip install dist/*.zip

if [ "$CHECK_FORMATTING" = "1" ]; then
python -m pip install -r test-requirements.txt
echo "::endgroup::"
source check.sh
else
# Actual tests
python -m pip install -r test-requirements.txt
# expands to 0 != 1 if NO_TEST_REQUIREMENTS is not set, if set the `-0` has no effect
# https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02
if [ ${NO_TEST_REQUIREMENTS-0} == 1 ]; then
python -m pip install pytest coverage
flags="--skip-optional-imports"
else
python -m pip install -r test-requirements.txt
flags=""
fi

# So we can run the test for our apport/excepthook interaction working
if [ -e /etc/lsb-release ] && grep -q Ubuntu /etc/lsb-release; then
Expand Down Expand Up @@ -93,6 +107,9 @@ else
done
netsh winsock show catalog
fi
echo "::endgroup::"

echo "::group::Setup for tests"

# We run the tests from inside an empty directory, to make sure Python
# doesn't pick up any .py files from our working dir. Might have been
Expand All @@ -103,20 +120,21 @@ else
INSTALLDIR=$(python -c "import os, trio; print(os.path.dirname(trio.__file__))")
cp ../pyproject.toml $INSTALLDIR

# TODO: remove this once we have a py.typed file
touch "$INSTALLDIR/py.typed"

# get mypy tests a nice cache
MYPYPATH=".." mypy --config-file= --cache-dir=./.mypy_cache -c "import trio" >/dev/null 2>/dev/null || true

# support subprocess spawning with coverage.py
echo "import coverage; coverage.process_startup()" | tee -a "$INSTALLDIR/../sitecustomize.py"

if COVERAGE_PROCESS_START=$(pwd)/../.coveragerc coverage run --rcfile=../.coveragerc -m pytest -r a -p trio._tests.pytest_plugin --junitxml=../test-results.xml --run-slow ${INSTALLDIR} --verbose --durations=10; then
echo "::endgroup::"
echo "::group:: Run Tests"
if COVERAGE_PROCESS_START=$(pwd)/../.coveragerc coverage run --rcfile=../.coveragerc -m pytest -r a -p trio._tests.pytest_plugin --junitxml=../test-results.xml --run-slow ${INSTALLDIR} --verbose --durations=10 $flags; then
PASSED=true
else
PASSED=false
fi
echo "::endgroup::"
echo "::group::Coverage"

coverage combine --rcfile ../.coveragerc
coverage report -m --rcfile ../.coveragerc
Expand All @@ -128,5 +146,6 @@ else
netsh winsock reset
fi

echo "::endgroup::"
$PASSED
fi
Loading

0 comments on commit 928865c

Please sign in to comment.