Skip to content

Commit

Permalink
Merge pull request #103 from eoyilmaz/83-remove-the-usage-of-repoid-i…
Browse files Browse the repository at this point in the history
…n-stalkerdbsetupcreate_repo_vars

[#83] Removed the usage of old style Repo environment variable genera…
  • Loading branch information
eoyilmaz authored Nov 8, 2024
2 parents c9d1245 + 2537e16 commit b15f246
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 123 deletions.
1 change: 0 additions & 1 deletion src/stalker/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ class Config(ConfigBase):
# Storage for uploaded files
server_side_storage_path=os.path.expanduser("~/Stalker_Storage"),
repo_env_var_template="REPO{code}",
repo_env_var_template_old="REPO{id}",
#
# Tells Stalker to create an admin by default
#
Expand Down
4 changes: 0 additions & 4 deletions src/stalker/db/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,6 @@ def create_repo_vars():
for repo in all_repos:
os.environ[repo.env_var] = repo.path

# TODO: Remove this in upcoming versions.
# This is added for backwards compatibility
os.environ[defaults.repo_env_var_template_old.format(id=repo.id)] = repo.path


def get_alembic_version():
"""Return the alembic version of the database.
Expand Down
17 changes: 0 additions & 17 deletions src/stalker/models/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,6 @@ def _validate_linux_path(self, key, linux_path):
linux_path
)

if self.id is not None and platform.system() == "Linux":
# update the environment variable
os.environ[defaults.repo_env_var_template_old.format(id=self.id)] = (
linux_path
)

return linux_path

@validates("macos_path")
Expand Down Expand Up @@ -165,10 +159,6 @@ def _validate_macos_path(self, key, macos_path):
rendered_env_var = defaults.repo_env_var_template.format(code=self.code)
os.environ[rendered_env_var] = macos_path

if self.id is not None and platform.system() == "Darwin":
rendered_env_var = defaults.repo_env_var_template_old.format(id=self.id)
os.environ[rendered_env_var] = macos_path

return macos_path

@validates("windows_path")
Expand Down Expand Up @@ -203,12 +193,6 @@ def _validate_windows_path(self, key, windows_path):
windows_path
)

if self.id is not None and platform.system() == "Windows":
# update the environment variable
os.environ[defaults.repo_env_var_template_old.format(id=self.id)] = (
windows_path
)

return windows_path

@property
Expand Down Expand Up @@ -464,4 +448,3 @@ def receive_after_insert(mapper, connection, repo):
"""
logger.debug("auto creating env var for Repository: {}".format(repo.name))
os.environ[defaults.repo_env_var_template.format(code=repo.code)] = repo.path
os.environ[defaults.repo_env_var_template_old.format(id=repo.id)] = repo.path
5 changes: 5 additions & 0 deletions tests/config/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,8 @@ def test_update_with_studio_is_working_as_expected(setup_postgresql_db):

# now check it again
assert defaults.timing_resolution == studio.timing_resolution


def test_old_style_repo_env_does_not_exist_anymore():
"""repo_env_var_template_old doesn't exist anymore."""
assert "repo_env_var_template_old" not in defaults.config_values
110 changes: 9 additions & 101 deletions tests/models/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,9 @@ def test_to_linux_path_returns_the_linux_version_of_the_given_path_with_env_vars
data = setup_repository_db_tests
data["test_repo"].id = 1
data["test_repo"].linux_path = "/mnt/T/Stalker_Projects"
os.environ["REPO1"] = "/mnt/T/Stalker_Projects"
os.environ["REPOR1"] = "/mnt/T/Stalker_Projects"
test_linux_path = "/mnt/T/Stalker_Projects/Sero/Task1/Task2/" "Some_file.ma"
test_path_with_env_var = "$REPO1/Sero/Task1/Task2/Some_file.ma"
test_path_with_env_var = "$REPOR1/Sero/Task1/Task2/Some_file.ma"
assert data["test_repo"].to_linux_path(test_path_with_env_var) == test_linux_path


Expand Down Expand Up @@ -557,9 +557,9 @@ def test_to_windows_path_returns_the_windows_version_of_the_given_path_with_env_
data["test_repo"].id = 1
data["test_repo"].windows_path = "T:/Stalker_Projects"
data["test_repo"].linux_path = "/mnt/T/Stalker_Projects"
os.environ["REPO1"] = data["test_repo"].linux_path
os.environ["REPOR1"] = data["test_repo"].linux_path
test_windows_path = "T:/Stalker_Projects/Sero/Task1/Task2/" "Some_file.ma"
test_path_with_env_var = "$REPO1/Sero/Task1/Task2/Some_file.ma"
test_path_with_env_var = "$REPOR1/Sero/Task1/Task2/Some_file.ma"
assert (
data["test_repo"].to_windows_path(test_path_with_env_var) == test_windows_path
)
Expand Down Expand Up @@ -702,9 +702,9 @@ def test_to_macos_path_returns_the_macos_version_of_the_given_path_with_env_vars
data["test_repo"].windows_path = "T:/Stalker_Projects"
data["test_repo"].macos_path = "/Volumes/T/Stalker_Projects"
data["test_repo"].linux_path = "/mnt/T/Stalker_Projects"
os.environ["REPO1"] = data["test_repo"].windows_path
os.environ["REPOR1"] = data["test_repo"].windows_path
test_windows_path = "/Volumes/T/Stalker_Projects/Sero/Task1/Task2/" "Some_file.ma"
test_path_with_env_var = "$REPO1/Sero/Task1/Task2/Some_file.ma"
test_path_with_env_var = "$REPOR1/Sero/Task1/Task2/Some_file.ma"
assert data["test_repo"].to_macos_path(test_path_with_env_var) == test_windows_path


Expand Down Expand Up @@ -1000,18 +1000,6 @@ def test_make_relative_converts_the_given_path_with_env_variable_to_native_path(
assert result == "Sero/Task1/Task2/Some_file.ma"


def test_make_relative_converts_the_given_path_with_old_env_variable_to_native_path(
setup_repository_db_tests,
):
"""make_relative() converts path with old env var to repo root relative path."""
data = setup_repository_db_tests
# so we should have the env var to be configured
# now create a path with env var
path = "$REPO{}/Sero/Task1/Task2/Some_file.ma".format(data["test_repo"].id)
result = data["test_repo"].make_relative(path)
assert result == "Sero/Task1/Task2/Some_file.ma"


def test_to_os_independent_path_is_working_as_expected(setup_repository_db_tests):
"""to_os_independent_path() is working as expected."""
data = setup_repository_db_tests
Expand All @@ -1025,19 +1013,6 @@ def test_to_os_independent_path_is_working_as_expected(setup_repository_db_tests
)


def test_to_os_independent_path_for_old_environment_vars(setup_repository_db_tests):
"""to_os_independent_path with paths that contain old env vars."""
data = setup_repository_db_tests
DBSession.add(data["test_repo"])
DBSession.commit()
relative_part = "some/path/to/a/file.ma"
test_path = "$REPO{}/{}".format(data["test_repo"].id, relative_part)
assert Repository.to_os_independent_path(test_path) == "$REPO{}/{}".format(
data["test_repo"].code,
relative_part,
)


def test_to_os_independent_path_converts_the_given_linux_path_to_universal(
setup_repository_db_tests,
):
Expand Down Expand Up @@ -1096,16 +1071,16 @@ def test_to_os_independent_path_not_change_the_path_with_env_variable(
)


def test_to_os_independent_path_converts_the_given_path_with_old_env_variable_new_env_variable(
def test_to_os_independent_path_cannot_convert_the_given_path_with_old_env_variable_new_env_variable(
setup_repository_db_tests,
):
"""to_os_independent_path converts path with old env var to new env var."""
"""to_os_independent_path cannot convert path with old env var to new env var."""
data = setup_repository_db_tests
# so we should have the env var to be configured
# now create a path with env var
path = "$REPO{}/Sero/Task1/Task2/Some_file.ma".format(data["test_repo"].id)
result = data["test_repo"].to_os_independent_path(path)
assert result == "$REPO{}/Sero/Task1/Task2/Some_file.ma".format(
assert result != "$REPO{}/Sero/Task1/Task2/Some_file.ma".format(
data["test_repo"].code
)

Expand Down Expand Up @@ -1219,13 +1194,6 @@ def test_find_repo_is_working_as_expected_with_env_vars(setup_repository_db_test
test_path = f"$REPO{new_repo1.code}/some/path/to/a/file.ma"
assert Repository.find_repo(test_path) == new_repo1

# Test with old env var
test_path = "$REPO{}/some/path/to/a/file.ma".format(data["test_repo"].id)
assert Repository.find_repo(test_path) == data["test_repo"]

test_path = "$REPO{}/some/path/to/a/file.ma".format(new_repo1.id)
assert Repository.find_repo(test_path) == new_repo1


def test_find_repo_returns_none_if_a_repo_cannot_be_found(setup_repository_db_tests):
"""find_repo() returns None if a repo cannot be found."""
Expand Down Expand Up @@ -1256,11 +1224,6 @@ def test_creating_and_committing_a_new_repository_instance_will_create_env_var(

assert defaults.repo_env_var_template.format(code=repo.code) in os.environ

# check the old ID based env var
assert (
os.environ[defaults.repo_env_var_template_old.format(id=repo.id)] == repo.path
)


def test_updating_a_repository_will_update_repo_path(setup_repository_db_tests):
"""environment variable is updated if the repository path is updated."""
Expand All @@ -1275,7 +1238,6 @@ def test_updating_a_repository_will_update_repo_path(setup_repository_db_tests):
DBSession.commit()

assert defaults.repo_env_var_template.format(code=repo.code) in os.environ
assert defaults.repo_env_var_template_old.format(id=repo.id) in os.environ

# now update the repository
test_value = "/mnt/S/"
Expand All @@ -1285,9 +1247,6 @@ def test_updating_a_repository_will_update_repo_path(setup_repository_db_tests):
assert (
os.environ[defaults.repo_env_var_template.format(code=repo.code)] == test_value
)
assert (
os.environ[defaults.repo_env_var_template_old.format(id=repo.id)] == test_value
)


def test_updating_windows_path_only_update_repo_path_if_on_windows(
Expand All @@ -1307,7 +1266,6 @@ def test_updating_windows_path_only_update_repo_path_if_on_windows(
DBSession.commit()

assert defaults.repo_env_var_template.format(code=repo.code) in os.environ
assert defaults.repo_env_var_template_old.format(id=repo.id) in os.environ

# now update the repository
test_value = "S:/"
Expand All @@ -1322,14 +1280,6 @@ def test_updating_windows_path_only_update_repo_path_if_on_windows(
== repo.linux_path
)

assert (
os.environ[defaults.repo_env_var_template_old.format(id=repo.id)] != test_value
)
assert (
os.environ[defaults.repo_env_var_template_old.format(id=repo.id)]
== repo.linux_path
)

# make it windows
data["patcher"].patch("Windows")

Expand All @@ -1345,13 +1295,6 @@ def test_updating_windows_path_only_update_repo_path_if_on_windows(
os.environ[defaults.repo_env_var_template.format(code=repo.code)]
== repo.windows_path
)
assert (
os.environ[defaults.repo_env_var_template_old.format(id=repo.id)] == test_value
)
assert (
os.environ[defaults.repo_env_var_template_old.format(id=repo.id)]
== repo.windows_path
)


def test_updating_macos_path_only_update_repo_path_if_on_macos(
Expand All @@ -1372,7 +1315,6 @@ def test_updating_macos_path_only_update_repo_path_if_on_macos(
DBSession.commit()

assert defaults.repo_env_var_template.format(code=repo.code) in os.environ
assert defaults.repo_env_var_template_old.format(id=repo.id) in os.environ

# now update the repository
test_value = "/Volumes/S/"
Expand All @@ -1387,14 +1329,6 @@ def test_updating_macos_path_only_update_repo_path_if_on_macos(
== repo.windows_path
)

assert (
os.environ[defaults.repo_env_var_template_old.format(id=repo.id)] != test_value
)
assert (
os.environ[defaults.repo_env_var_template_old.format(id=repo.id)]
== repo.windows_path
)

# make it macos
data["patcher"].patch("Darwin")

Expand All @@ -1411,14 +1345,6 @@ def test_updating_macos_path_only_update_repo_path_if_on_macos(
== repo.macos_path
)

assert (
os.environ[defaults.repo_env_var_template_old.format(id=repo.id)] == test_value
)
assert (
os.environ[defaults.repo_env_var_template_old.format(id=repo.id)]
== repo.macos_path
)


def test_updating_linux_path_only_update_repo_path_if_on_linux(
setup_repository_db_tests,
Expand All @@ -1438,7 +1364,6 @@ def test_updating_linux_path_only_update_repo_path_if_on_linux(
DBSession.commit()

assert defaults.repo_env_var_template.format(code=repo.code) in os.environ
assert defaults.repo_env_var_template_old.format(id=repo.id) in os.environ

# now update the repository
test_value = "/mnt/S/"
Expand All @@ -1453,14 +1378,6 @@ def test_updating_linux_path_only_update_repo_path_if_on_linux(
== repo.macos_path
)

assert (
os.environ[defaults.repo_env_var_template_old.format(id=repo.id)] != test_value
)
assert (
os.environ[defaults.repo_env_var_template_old.format(id=repo.id)]
== repo.macos_path
)

# make it linux
data["patcher"].patch("Linux")

Expand All @@ -1477,15 +1394,6 @@ def test_updating_linux_path_only_update_repo_path_if_on_linux(
== repo.linux_path
)

# expect the environment variable not updated
assert (
os.environ[defaults.repo_env_var_template_old.format(id=repo.id)] == test_value
)
assert (
os.environ[defaults.repo_env_var_template_old.format(id=repo.id)]
== repo.linux_path
)


def test_to_path_path_is_none(setup_repository_db_tests):
"""_to_path() path is None raises TypeError."""
Expand Down

0 comments on commit b15f246

Please sign in to comment.