Skip to content

Commit

Permalink
Move to src-layout.
Browse files Browse the repository at this point in the history
The intention of this is better isolation. `trio` is no longer
accidentally on the (python) path and as such requires an explicit
installation for usage, this helps uncover issues in packaging data etc
early on (see
https://packaging.python.org/en/latest/discussions/src-layout-vs-flat-layout/).

This serves as the basis for switching to another build system as well; refs python-trio#2790.
  • Loading branch information
apollo13 committed Sep 13, 2023
1 parent c16003f commit b813917
Show file tree
Hide file tree
Showing 140 changed files with 72 additions and 65 deletions.
5 changes: 5 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ omit=
# this doesn't corrupt the coverage files
parallel=True

[paths]
source =
src/trio
**/site-packages/trio

[report]
precision = 1
skip_covered = True
Expand Down
30 changes: 15 additions & 15 deletions check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fi

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

Expand All @@ -21,21 +21,21 @@ echo "::endgroup::"
# autoflake --recursive --in-place .
# pyupgrade --py3-plus $(find . -name "*.py")
echo "::group::Black"
if ! black --check setup.py trio; then
if ! black --check setup.py src/trio; then
echo "* Black found issues" >> $GITHUB_STEP_SUMMARY
EXIT_STATUS=1
black --diff setup.py trio
black --diff setup.py src/trio
echo "::endgroup::"
echo "::error:: Black found issues"
else
echo "::endgroup::"
fi

echo "::group::ISort"
if ! isort --check setup.py trio; then
if ! isort --check setup.py src/trio; then
echo "* isort found issues." >> $GITHUB_STEP_SUMMARY
EXIT_STATUS=1
isort --diff setup.py trio
isort --diff setup.py src/trio
echo "::endgroup::"
echo "::error:: isort found issues"
else
Expand All @@ -44,7 +44,7 @@ fi

# Run flake8, configured in pyproject.toml
echo "::group::Flake8"
flake8 trio/ || EXIT_STATUS=$?
flake8 src/trio/ || EXIT_STATUS=$?
echo "::endgroup::"

# Run mypy on all supported platforms
Expand All @@ -55,16 +55,16 @@ echo "::group::Mypy"
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 \
mypy src/trio --show-error-end --platform linux | python ./src/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 \
mypy src/trio --show-error-end --platform darwin | python ./src/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 \
mypy src/trio --show-error-end --platform win32 | python ./src/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
python ./src/trio/_tools/mypy_annotate.py --dumpfile mypy_annotate.dat
# Then discard.
rm -f mypy_annotate.dat
echo "::endgroup::"
Expand Down Expand Up @@ -94,11 +94,11 @@ fi

codespell || EXIT_STATUS=$?

python trio/_tests/check_type_completeness.py --overwrite-file || EXIT_STATUS=$?
if git status --porcelain trio/_tests/verify_types*.json | grep -q "M"; then
python src/trio/_tests/check_type_completeness.py --overwrite-file || EXIT_STATUS=$?
if git status --porcelain src/trio/_tests/verify_types*.json | grep -q "M"; then
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
git --no-pager diff --color src/trio/_tests/verify_types*.json
EXIT_STATUS=1
fi

Expand All @@ -112,8 +112,8 @@ Problems were found by static analysis (listed above).
To fix formatting and see remaining errors, run
pip install -r test-requirements.txt
black setup.py trio
isort setup.py trio
black setup.py src/trio
isort setup.py src/trio
./check.sh
in your local checkout.
Expand Down
2 changes: 1 addition & 1 deletion ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ else
# when installing, and then running 'certmgr.msc' and exporting the
# certificate. See:
# http://www.migee.com/2010/09/24/solution-for-unattendedsilent-installs-and-would-you-like-to-install-this-device-software/
certutil -addstore "TrustedPublisher" trio/_tests/astrill-codesigning-cert.cer
certutil -addstore "TrustedPublisher" src/trio/_tests/astrill-codesigning-cert.cer
# Double-slashes are how you tell windows-bash that you want a single
# slash, and don't treat this as a unix-style filename that needs to
# be replaced by a windows-style filename.
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# For our local_customization module
sys.path.insert(0, os.path.abspath("."))
# For trio itself
sys.path.insert(0, os.path.abspath("../.."))
sys.path.insert(0, os.path.abspath("../../src"))

# https://docs.readthedocs.io/en/stable/builds.html#build-environment
if "READTHEDOCS" in os.environ:
Expand Down
91 changes: 46 additions & 45 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ ignore-words-list = 'astroid,crasher,asend'
[tool.flake8]
extend-ignore = ['D', 'E', 'W', 'F403', 'F405', 'F821', 'F822']
per-file-ignores = [
'trio/__init__.py: F401',
'trio/_core/__init__.py: F401',
'trio/_core/_tests/test_multierror_scripts/*: F401',
'trio/abc.py: F401',
'trio/lowlevel.py: F401',
'trio/socket.py: F401',
'trio/testing/__init__.py: F401'
'src/trio/__init__.py: F401',
'src/trio/_core/__init__.py: F401',
'src/trio/_core/_tests/test_multierror_scripts/*: F401',
'src/trio/abc.py: F401',
'src/trio/lowlevel.py: F401',
'src/trio/socket.py: F401',
'src/trio/testing/__init__.py: F401'
]

[tool.isort]
Expand Down Expand Up @@ -61,48 +61,48 @@ disallow_untyped_calls = false
[[tool.mypy.overrides]]
module = [
# 2761
"trio/_core/_generated_io_windows",
"trio/_core/_io_windows",
"src/trio/_core/_generated_io_windows",
"src/trio/_core/_io_windows",

# internal
"trio/_windows_pipes",
"src/trio/_windows_pipes",

# tests
"trio/testing/_fake_net",
"trio/_core/_tests/test_guest_mode",
"trio/_core/_tests/test_instrumentation",
"trio/_core/_tests/test_ki",
"trio/_core/_tests/test_local",
"trio/_core/_tests/test_mock_clock",
"trio/_core/_tests/test_multierror",
"trio/_core/_tests/test_multierror_scripts/ipython_custom_exc",
"trio/_core/_tests/test_multierror_scripts/simple_excepthook",
"trio/_core/_tests/test_parking_lot",
"trio/_core/_tests/test_thread_cache",
"trio/_core/_tests/test_unbounded_queue",
"trio/_tests/test_exports",
"trio/_tests/test_file_io",
"trio/_tests/test_highlevel_generic",
"trio/_tests/test_highlevel_open_tcp_listeners",
"trio/_tests/test_highlevel_open_tcp_stream",
"trio/_tests/test_highlevel_open_unix_stream",
"trio/_tests/test_highlevel_serve_listeners",
"trio/_tests/test_highlevel_socket",
"trio/_tests/test_highlevel_ssl_helpers",
"trio/_tests/test_path",
"trio/_tests/test_scheduler_determinism",
"trio/_tests/test_socket",
"trio/_tests/test_ssl",
"trio/_tests/test_subprocess",
"trio/_tests/test_sync",
"trio/_tests/test_testing",
"trio/_tests/test_threads",
"trio/_tests/test_timeouts",
"trio/_tests/test_tracing",
"trio/_tests/test_util",
"trio/_tests/test_wait_for_object",
"trio/_tests/test_windows_pipes",
"trio/_tests/tools/test_gen_exports",
"src/trio/testing/_fake_net",
"src/trio/_core/_tests/test_guest_mode",
"src/trio/_core/_tests/test_instrumentation",
"src/trio/_core/_tests/test_ki",
"src/trio/_core/_tests/test_local",
"src/trio/_core/_tests/test_mock_clock",
"src/trio/_core/_tests/test_multierror",
"src/trio/_core/_tests/test_multierror_scripts/ipython_custom_exc",
"src/trio/_core/_tests/test_multierror_scripts/simple_excepthook",
"src/trio/_core/_tests/test_parking_lot",
"src/trio/_core/_tests/test_thread_cache",
"src/trio/_core/_tests/test_unbounded_queue",
"src/trio/_tests/test_exports",
"src/trio/_tests/test_file_io",
"src/trio/_tests/test_highlevel_generic",
"src/trio/_tests/test_highlevel_open_tcp_listeners",
"src/trio/_tests/test_highlevel_open_tcp_stream",
"src/trio/_tests/test_highlevel_open_unix_stream",
"src/trio/_tests/test_highlevel_serve_listeners",
"src/trio/_tests/test_highlevel_socket",
"src/trio/_tests/test_highlevel_ssl_helpers",
"src/trio/_tests/test_path",
"src/trio/_tests/test_scheduler_determinism",
"src/trio/_tests/test_socket",
"src/trio/_tests/test_ssl",
"src/trio/_tests/test_subprocess",
"src/trio/_tests/test_sync",
"src/trio/_tests/test_testing",
"src/trio/_tests/test_threads",
"src/trio/_tests/test_timeouts",
"src/trio/_tests/test_tracing",
"src/trio/_tests/test_util",
"src/trio/_tests/test_wait_for_object",
"src/trio/_tests/test_windows_pipes",
"src/trio/_tests/tools/test_gen_exports",
]
check_untyped_defs = false
disallow_any_decorated = false
Expand Down Expand Up @@ -142,6 +142,7 @@ issue_format = "`#{issue} <https://github.com/python-trio/trio/issues/{issue}>`_
# - At release time after bumping version number, run: towncrier
# (or towncrier --draft)
package = "trio"
package_dir = "src"
underlines = ["-", "~", "^"]

[[tool.towncrier.type]]
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import find_packages, setup

exec(open("trio/_version.py", encoding="utf-8").read())
exec(open("src/trio/_version.py", encoding="utf-8").read())

LONG_DESC = """\
.. image:: https://raw.githubusercontent.com/python-trio/trio/9b0bec646a31e0d0f67b8b6ecc6939726faf3e17/logo/logo-with-background.svg
Expand Down Expand Up @@ -80,7 +80,8 @@
author_email="njs@pobox.com",
url="https://github.com/python-trio/trio",
license="MIT OR Apache-2.0",
packages=find_packages(),
packages=find_packages(where="src"),
package_dir={"": "src"},
install_requires=[
# attrs 19.2.0 adds `eq` option to decorators
# attrs 20.1.0 adds @frozen
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def main() -> None: # pragma: no cover
source_root = Path.cwd()
# Double-check we found the right directory
assert (source_root / "LICENSE").exists()
core = source_root / "trio/_core"
core = source_root / "src/trio/_core"
to_wrap = [
File(core / "_run.py", "runner", imports=IMPORTS_RUN),
File(
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit b813917

Please sign in to comment.