Skip to content

Commit

Permalink
Move to src-layout. (#2798)
Browse files Browse the repository at this point in the history
* Move to src-layout.

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 #2790.

---------

Co-authored-by: CoolCat467 <52022020+CoolCat467@users.noreply.github.com>
Co-authored-by: jakkdl <h6+github@pm.me>
  • Loading branch information
3 people committed Nov 11, 2023
1 parent b7d2054 commit 315a0e8
Show file tree
Hide file tree
Showing 142 changed files with 27 additions and 30 deletions.
4 changes: 2 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ include README.rst
include LONG_DESCRIPTION.rst
include CODE_OF_CONDUCT.md CONTRIBUTING.md
include test-requirements.txt
include trio/py.typed
recursive-include trio/_tests/test_ssl_certs *.pem
include src/trio/py.typed
recursive-include src/trio/_tests/test_ssl_certs *.pem
recursive-include docs *
prune docs/build
24 changes: 12 additions & 12 deletions check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,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 @@ -23,10 +23,10 @@ echo "::endgroup::"
# autoflake --recursive --in-place .
# pyupgrade --py3-plus $(find . -name "*.py")
echo "::group::Black"
if ! black --check trio; then
if ! black --check src/trio; then
echo "* Black found issues" >> "$GITHUB_STEP_SUMMARY"
EXIT_STATUS=1
black --diff trio
black --diff src/trio
echo "::endgroup::"
echo "::error:: Black found issues"
else
Expand Down Expand Up @@ -57,16 +57,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 @@ -97,11 +97,11 @@ 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
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 @@ -118,8 +118,8 @@ Problems were found by static analysis (listed above).
To fix formatting and see remaining errors, run
pip install -r test-requirements.txt
black trio
isort trio
black src/trio
ruff check 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 @@ -95,7 +95,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"))

# Enable reloading with `typing.TYPE_CHECKING` being True
os.environ["SPHINX_AUTODOC_RELOAD_MODULES"] = "1"
Expand Down
23 changes: 10 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ Changelog = "https://trio.readthedocs.io/en/latest/history.html"
# doesn't look like a source file, so long as it appears in MANIFEST.in:
include-package-data = true

[tool.setuptools.packages]
find = {namespaces = false}

[tool.setuptools.dynamic]
version = {attr = "trio._version.__version__"}

Expand All @@ -84,15 +81,14 @@ force-exclude = '''
ignore-words-list = 'astroid,crasher,asend'

[tool.ruff]
target-version = "py38"
respect-gitignore = true
fix = true

allowed-confusables = [""]

# The directories to consider when resolving first vs. third-party imports.
# Does not control what files to include/exclude!
src = ["trio", "notes-to-self"]
src = ["src/trio", "notes-to-self"]

select = [
"RUF", # Ruff-specific rules
Expand Down Expand Up @@ -124,13 +120,13 @@ extend-exclude = [
]

[tool.ruff.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.ruff.isort]
combine-as-imports = true
Expand Down Expand Up @@ -184,6 +180,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 Expand Up @@ -228,7 +225,7 @@ showcontent = true

[tool.coverage.run]
branch = true
source = ["trio"]
source_pkgs = ["trio"]
omit = [
# These are run in subprocesses, but still don't work. We follow
# coverage's documentation to no avail.
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.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,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 315a0e8

Please sign in to comment.