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

Rename __root_path__ to __development_base_path__ #9136

Merged
merged 2 commits into from
Apr 7, 2023
Merged
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
13 changes: 10 additions & 3 deletions scripts/run-integration-flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@
from pathlib import Path
from typing import Union

from prefect import __root_path__, __version__

DEFAULT_PATH = __root_path__ / "flows"
import prefect
from prefect import __version__

# See https://github.com/PrefectHQ/prefect/pull/9136
DEFAULT_PATH = (
getattr(
prefect, "__development_base_path__", getattr(prefect, "__root_path__", None)
)
/ "flows"
)


def run_flows(search_path: Union[str, Path]):
Expand Down
2 changes: 1 addition & 1 deletion src/prefect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# The absolute path to this module
__module_path__ = pathlib.Path(__file__).parent
# The absolute path to the root of the repository, only valid for use during development.
__root_path__ = __module_path__.parents[1]
__development_base_path__ = __module_path__.parents[1]
# The absolute path to the built UI within the Python module
__ui_static_path__ = __module_path__ / "server" / "ui"

Expand Down
20 changes: 10 additions & 10 deletions src/prefect/cli/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
def exit_with_error_if_not_editable_install():
if (
prefect.__module_path__.parent == "site-packages"
or not (prefect.__root_path__ / "setup.py").exists()
or not (prefect.__development_base_path__ / "setup.py").exists()
):
exit_with_error(
"Development commands require an editable Prefect installation. "
Expand Down Expand Up @@ -124,7 +124,7 @@ def build_docs(

if not schema_path:
schema_path = (
prefect.__root_path__ / "docs" / "api-ref" / "schema.json"
prefect.__development_base_path__ / "docs" / "api-ref" / "schema.json"
).absolute()
# overwrite info for display purposes
schema["info"] = {}
Expand All @@ -136,7 +136,7 @@ def build_docs(
BUILD_UI_HELP = f"""
Installs dependencies and builds UI locally.

The built UI will be located at {prefect.__root_path__ / "ui"}
The built UI will be located at {prefect.__development_base_path__ / "ui"}

Requires npm.
"""
Expand All @@ -145,8 +145,8 @@ def build_docs(
@dev_app.command(help=BUILD_UI_HELP)
def build_ui():
exit_with_error_if_not_editable_install()
with tmpchdir(prefect.__root_path__):
with tmpchdir(prefect.__root_path__ / "ui"):
with tmpchdir(prefect.__development_base_path__):
with tmpchdir(prefect.__development_base_path__ / "ui"):
app.console.print("Installing npm packages...")
try:
subprocess.check_output(["npm", "ci"], shell=sys.platform == "win32")
Expand Down Expand Up @@ -179,8 +179,8 @@ async def ui():
Starts a hot-reloading development UI.
"""
exit_with_error_if_not_editable_install()
with tmpchdir(prefect.__root_path__):
with tmpchdir(prefect.__root_path__ / "ui"):
with tmpchdir(prefect.__development_base_path__):
with tmpchdir(prefect.__development_base_path__ / "ui"):
app.console.print("Installing npm packages...")
await run_process(["npm", "install"], stream_output=True)

Expand Down Expand Up @@ -365,7 +365,7 @@ def build_image(
command = [
"docker",
"build",
str(prefect.__root_path__),
str(prefect.__development_base_path__),
"--tag",
tag,
"--platform",
Expand Down Expand Up @@ -426,7 +426,7 @@ def container(bg: bool = False, name="prefect-dev", api: bool = True, tag: str =
name=name,
auto_remove=True,
working_dir="/opt/prefect/repo",
volumes=[f"{prefect.__root_path__}:/opt/prefect/repo"],
volumes=[f"{prefect.__development_base_path__}:/opt/prefect/repo"],
shm_size="4G",
)

Expand Down Expand Up @@ -497,7 +497,7 @@ def kubernetes_manifest():
)
manifest = template.substitute(
{
"prefect_root_directory": prefect.__root_path__,
"prefect_root_directory": prefect.__development_base_path__,
"image_name": get_prefect_image_name(),
}
)
Expand Down
3 changes: 2 additions & 1 deletion src/prefect/cli/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import yaml
from rich.table import Table

import prefect
from prefect.cli._types import PrefectTyper
from prefect.cli._utilities import exit_with_error
from prefect.cli.root import app
Expand All @@ -33,7 +34,7 @@ async def ls():
List available recipes.
"""

recipe_paths = Path(__file__).parent / ".." / "projects" / "recipes"
recipe_paths = prefect.__module_path__ / "projects" / "recipes"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have strong feelings about this change but it's consistent with the purpose of having the module path in the init.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me!

recipes = {}

for recipe in recipe_paths.iterdir():
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from prefect.testing.cli import invoke_and_assert
from prefect.utilities.asyncutils import run_sync_in_worker_thread

TEST_PROJECTS_DIR = prefect.__root_path__ / "tests" / "test-projects"
TEST_PROJECTS_DIR = prefect.__development_base_path__ / "tests" / "test-projects"


@pytest.fixture
Expand Down
14 changes: 11 additions & 3 deletions tests/projects/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
register_flow,
)

TEST_PROJECTS_DIR = prefect.__root_path__ / "tests" / "test-projects"
TEST_PROJECTS_DIR = prefect.__development_base_path__ / "tests" / "test-projects"


@pytest.fixture(autouse=True)
Expand Down Expand Up @@ -60,7 +60,11 @@ async def test_configure_project_by_recipe_raises(self):
[
d.absolute().name
for d in Path(
prefect.__root_path__ / "src" / "prefect" / "projects" / "recipes"
prefect.__development_base_path__
/ "src"
/ "prefect"
/ "projects"
/ "recipes"
).iterdir()
if d.is_dir()
],
Expand All @@ -75,7 +79,11 @@ async def test_configure_project_by_recipe_doesnt_raise(self, recipe):
[
d.absolute().name
for d in Path(
prefect.__root_path__ / "src" / "prefect" / "projects" / "recipes"
prefect.__development_base_path__
/ "src"
/ "prefect"
/ "projects"
/ "recipes"
).iterdir()
if d.is_dir() and "git" in d.absolute().name
],
Expand Down
2 changes: 1 addition & 1 deletion tests/test_filesystems.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from prefect.testing.utilities import AsyncMock, MagicMock
from prefect.utilities.filesystem import tmpchdir

TEST_PROJECTS_DIR = prefect.__root_path__ / "tests" / "test-projects"
TEST_PROJECTS_DIR = prefect.__development_base_path__ / "tests" / "test-projects"


def setup_test_directory(tmp_src: str, sub_dir: str = "puppy") -> Tuple[str, str]:
Expand Down
24 changes: 18 additions & 6 deletions tests/utilities/test_importtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pytest

import prefect
from prefect import __root_path__
from prefect import __development_base_path__
from prefect.docker import docker_client
from prefect.exceptions import ScriptError
from prefect.utilities.filesystem import tmpchdir
Expand All @@ -19,7 +19,7 @@
to_qualified_name,
)

TEST_PROJECTS_DIR = __root_path__ / "tests" / "test-projects"
TEST_PROJECTS_DIR = __development_base_path__ / "tests" / "test-projects"


def my_fn():
Expand Down Expand Up @@ -146,10 +146,22 @@ def test_lazy_import_includes_help_message_in_deferred_failure():
"working_directory,script_path",
[
# Working directory is not necessary for these imports to work
(__root_path__, TEST_PROJECTS_DIR / "flat-project" / "implicit_relative.py"),
(__root_path__, TEST_PROJECTS_DIR / "flat-project" / "explicit_relative.py"),
(__root_path__, TEST_PROJECTS_DIR / "nested-project" / "implicit_relative.py"),
(__root_path__, TEST_PROJECTS_DIR / "nested-project" / "explicit_relative.py"),
(
__development_base_path__,
TEST_PROJECTS_DIR / "flat-project" / "implicit_relative.py",
),
(
__development_base_path__,
TEST_PROJECTS_DIR / "flat-project" / "explicit_relative.py",
),
(
__development_base_path__,
TEST_PROJECTS_DIR / "nested-project" / "implicit_relative.py",
),
(
__development_base_path__,
TEST_PROJECTS_DIR / "nested-project" / "explicit_relative.py",
),
# They also work with the working directory set to the project
(TEST_PROJECTS_DIR / "flat-project", "implicit_relative.py"),
(TEST_PROJECTS_DIR / "flat-project", "explicit_relative.py"),
Expand Down