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 an __init__.py in repo root to prevent import confusion #949

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ jobs:
if [[ $FAST_COMPILE == "1" ]]; then export PYTENSOR_FLAGS=$PYTENSOR_FLAGS,mode=FAST_COMPILE; fi
if [[ $FLOAT32 == "1" ]]; then export PYTENSOR_FLAGS=$PYTENSOR_FLAGS,floatX=float32; fi
export PYTENSOR_FLAGS=$PYTENSOR_FLAGS,warn__ignore_bug_before=all,on_opt_error=raise,on_shape_error=raise,gcc__cxxflags=-pipe
python -m pytest -r A --verbose --runslow --durations=50 --cov=pytensor/ --cov-report=xml:coverage/coverage-${MATRIX_ID}.xml --no-cov-on-fail $PART --benchmark-skip
pytest --import-mode=importlib -r A --verbose --runslow --durations=50 --cov=pytensor/ --cov-report=xml:coverage/coverage-${MATRIX_ID}.xml --no-cov-on-fail $PART --benchmark-skip
env:
MATRIX_ID: ${{ steps.matrix-id.outputs.id }}
MKL_THREADING_LAYER: GNU
Expand Down Expand Up @@ -231,7 +231,7 @@ jobs:
shell: micromamba-shell {0}
run: |
export PYTENSOR_FLAGS=mode=FAST_COMPILE,warn__ignore_bug_before=all,on_opt_error=raise,on_shape_error=raise,gcc__cxxflags=-pipe
python -m pytest --runslow --benchmark-only --benchmark-json output.json
pytest --import-mode=importlib --runslow --benchmark-only --benchmark-json output.json
- name: Store benchmark result
uses: benchmark-action/github-action-benchmark@v1
with:
Expand Down
11 changes: 11 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from pathlib import Path


repo_root = Path(__file__).parent

raise RuntimeError(
f"Python is looking for PyTensor in {repo_root}, but it's "
f"actually located in {repo_root / 'pytensor'}. Probably "
f"you need to change your working directory from {Path.cwd()} "
f"to {repo_root}."
)
6 changes: 6 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import os
import sys
from pathlib import Path

import pytest


repo_root = Path(__file__).parent
sys.path.insert(0, str(repo_root))


def pytest_sessionstart(session):
os.environ["PYTENSOR_FLAGS"] = ",".join(
[
Expand Down
8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ versionfile_build = "pytensor/_version.py"
tag_prefix = "rel-"

[tool.pytest]
addopts = "--durations=50 --doctest-modules pytensor --ignore=pytensor/misc/check_duplicate_key.py --ignore=pytensor/link"
addopts = [
"--durations=50",
"--doctest-modules=pytensor",
"--ignore=pytensor/misc/check_duplicate_key.py",
"--ignore=pytensor/link"
]
testpaths = "tests/"

[tool.ruff]
Expand Down Expand Up @@ -163,6 +168,7 @@ warn_return_any = true
warn_unreachable = true
files = ["pytensor", "tests"]
plugins = ["numpy.typing.mypy_plugin"]
explicit_package_bases = true

[tool.cibuildwheel]
build = "*"
Expand Down
Loading