-
Notifications
You must be signed in to change notification settings - Fork 74
Fixup and refactor root_env_config resolution #985
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
Open
bpkroth
wants to merge
98
commits into
microsoft:main
Choose a base branch
from
bpkroth:fixup-refactor/allow-git-repo-root-env-resolution-from-different-dirs-and-restores
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
98 commits
Select commit
Hold shift + click to select a range
8a07c58
start using datetimes with fractional seconds with mysql
bpkroth d6fc9e2
adjust tests to also check for fractional time
bpkroth 65e7f08
Revert "start using datetimes with fractional seconds with mysql"
bpkroth b7dad42
Reapply "start using datetimes with fractional seconds with mysql"
bpkroth 4bf0c5f
apply black on alembic commit
bpkroth 8088734
preparing to support testing multiple backend engines for schema changes
bpkroth a2c3256
refactoring storage tests to check other db engines
bpkroth 5d3f0d3
change column lengths for mysql
bpkroth 01b9df4
more refactor of storage tests
bpkroth d578176
preparing to support testing multiple backend engines for schema changes
bpkroth 3b3bf6c
refactoring storage tests to check other db engines
bpkroth 1c9633c
change column lengths for mysql
bpkroth f5b7bf3
fixups
bpkroth 7fdf06d
fixup
bpkroth 1bf3c30
fixup
bpkroth bd5862f
cleanup
bpkroth a5e9c05
Merge branch 'refactor/storage-tests' into feature/mysql-schema-chang…
bpkroth 67f84ea
fixup
bpkroth 41199fc
format
bpkroth ef33825
Merge branch 'refactor/storage-tests' into feature/mysql-schema-chang…
bpkroth ee4a900
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 82220ec
fixup
bpkroth aa2621b
fixup
bpkroth a84d30b
switch to interprocesslock - already using that
bpkroth 2341a10
address a lint issue
bpkroth 45ad11f
restore the original alembic comments - moving to separate PR
bpkroth cfa07ea
Merge branch 'refactor/storage-tests' into feature/mysql-schema-chang…
bpkroth bbcf689
Revert "restore the original alembic comments - moving to separate PR"
bpkroth 53ee6e2
more comments
bpkroth 994a32a
mypy
bpkroth 2faf643
pylint
bpkroth a6b8941
allow retrieving storage url from the environment
bpkroth 9c5ac14
more alembic tweaks
bpkroth 988bc90
remove env
bpkroth f720d0d
temporarily revert back to something like the original schema
bpkroth f250e61
Revert "temporarily revert back to something like the original schema"
bpkroth 793c2e5
Reapply "temporarily revert back to something like the original schema"
bpkroth 952fba0
include timezone
bpkroth d6617ba
make mysql datetimes support fractional seconds
bpkroth 2f28d79
log the alembic target engine url
bpkroth 1b0fb2c
engine no longer optional
bpkroth 928f491
Revert "make mysql datetimes support fractional seconds"
bpkroth 4863a5b
Enable alembic to detect datetime precision issues with MySQL
bpkroth 6a697a0
Enable floating point seconds with mysql
bpkroth f7ccf26
Alembic script to add floating point seconds precision
bpkroth 40374c2
fixup
bpkroth fe4171a
rework to only apply to mysql
bpkroth 5a42a14
be sure to mark that version as required
bpkroth f273ea3
add that refactor too
bpkroth b1b3733
Fixups and refactors to allow two things
bpkroth f632f90
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 565ac4d
Merge branch 'main' into fixup-refactor/allow-git-repo-root-env-resol…
bpkroth bf13366
copilot fixups
bpkroth 9df032c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 07140b6
Merge branch 'main' into fixup-refactor/allow-git-repo-root-env-resol…
bpkroth e001d9a
merge cleanup
bpkroth c46f16a
unused-imnport
bpkroth 8560416
bad merge
bpkroth f451e2b
add a test for non-git dirs, refactor to reduce duplicate code
bpkroth 32a18fe
docs
bpkroth 19fefde
test
bpkroth 4041723
improvements on git info handling
bpkroth 1757b7e
cleanup
bpkroth 38ed63e
style
bpkroth 7903c41
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 6838d45
mypy
bpkroth e9bf5f2
test tweak
bpkroth 8263484
fixup
bpkroth 3c10846
refactor
bpkroth 0cb5948
fixup
bpkroth 59050ce
start to disable the lookup logic for abs config path
bpkroth 062fad7
error handling
bpkroth 4bf6b88
remove resolution logic
bpkroth e5374e0
docs
bpkroth 81dcea0
imports
bpkroth 948c3d5
mypy
bpkroth 7179301
cleanup
bpkroth 43c5887
notes
bpkroth 82c6b8b
rename
bpkroth a1eb6de
Fixups and improvements to git info retrieval
bpkroth d0f8e74
comments
bpkroth f7d91a7
tweaks
bpkroth 739c3ce
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] a0dd7b7
tweak
bpkroth 942d57b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 6d563a8
refactor
bpkroth 4e33efb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] a93b93e
Merge branch 'fixup/git-info' into fixup-refactor/allow-git-repo-root…
bpkroth 5f13ff9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 8f8f0bb
comment
bpkroth d009fe8
Merge branch 'fixup/git-info' into fixup-refactor/allow-git-repo-root…
bpkroth 2257e17
format
bpkroth 718f66e
Merge branch 'fixup/git-info' into fixup-refactor/allow-git-repo-root…
bpkroth 01e844a
comments
bpkroth 0357849
fixup
bpkroth 8119ef4
Merge branch 'fixup/git-info' into fixup-refactor/allow-git-repo-root…
bpkroth c7245a2
fix docs
bpkroth 1874b0e
Merge branch 'fixup/git-info' into fixup-refactor/allow-git-repo-root…
bpkroth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,14 +3,95 @@ | |
# Licensed under the MIT License. | ||
# | ||
"""Unit tests for get_git_info utility function.""" | ||
import os | ||
import re | ||
import tempfile | ||
from pathlib import Path | ||
from subprocess import CalledProcessError | ||
from subprocess import check_call as run | ||
|
||
from mlos_bench.util import get_git_info | ||
import pytest | ||
|
||
from mlos_bench.util import get_git_info, get_git_root, path_join | ||
|
||
|
||
def test_get_git_info() -> None: | ||
"""Check that we can retrieve git info about the current repository correctly.""" | ||
(git_repo, git_commit, rel_path) = get_git_info(__file__) | ||
"""Check that we can retrieve git info about the current repository correctly from a | ||
file. | ||
""" | ||
(git_repo, git_commit, rel_path, abs_path) = get_git_info(__file__) | ||
assert "mlos" in git_repo.lower() | ||
assert re.match(r"[0-9a-f]{40}", git_commit) is not None | ||
assert rel_path == "mlos_bench/mlos_bench/tests/util_git_test.py" | ||
assert abs_path == path_join(__file__, abs_path=True) | ||
|
||
|
||
def test_get_git_info_dir() -> None: | ||
"""Check that we can retrieve git info about the current repository correctly from a | ||
directory. | ||
""" | ||
dirname = os.path.dirname(__file__) | ||
(git_repo, git_commit, rel_path, abs_path) = get_git_info(dirname) | ||
assert "mlos" in git_repo.lower() | ||
assert re.match(r"[0-9a-f]{40}", git_commit) is not None | ||
assert rel_path == "mlos_bench/mlos_bench/tests" | ||
assert abs_path == path_join(dirname, abs_path=True) | ||
|
||
|
||
def test_non_git_dir() -> None: | ||
"""Check that we can handle a non-git directory.""" | ||
with tempfile.TemporaryDirectory() as non_git_dir: | ||
with pytest.raises(CalledProcessError): | ||
# This should raise an error because the directory is not a git repository. | ||
get_git_root(non_git_dir) | ||
|
||
|
||
def test_non_upstream_git() -> None: | ||
"""Check that we can handle a git directory without an upstream.""" | ||
with tempfile.TemporaryDirectory() as local_git_dir: | ||
local_git_dir = path_join(local_git_dir, abs_path=True) | ||
# Initialize a new git repository. | ||
run(["git", "init", local_git_dir, "-b", "main"]) | ||
run(["git", "-C", local_git_dir, "config", "--local", "user.email", "[email protected]"]) | ||
run(["git", "-C", local_git_dir, "config", "--local", "user.name", "PyTest User"]) | ||
Path(local_git_dir).joinpath("README.md").touch() | ||
run(["git", "-C", local_git_dir, "add", "README.md"]) | ||
run(["git", "-C", local_git_dir, "commit", "-m", "Initial commit"]) | ||
# This should have slightly different behavior when there is no upstream. | ||
(git_repo, _git_commit, rel_path, abs_path) = get_git_info(local_git_dir) | ||
assert git_repo == f"file://{local_git_dir}" | ||
assert abs_path == local_git_dir | ||
assert rel_path == "." | ||
|
||
|
||
@pytest.mark.skipif( | ||
os.environ.get("GITHUB_ACTIONS") != "true", | ||
reason="Not running in GitHub Actions CI.", | ||
) | ||
def test_github_actions_git_info() -> None: | ||
""" | ||
Test that get_git_info matches GitHub Actions environment variables if running in | ||
CI. | ||
|
||
Examples | ||
-------- | ||
Test locally with the following command: | ||
|
||
.. code-block:: shell | ||
|
||
export GITHUB_ACTIONS=true | ||
export GITHUB_SHA=$(git rev-parse HEAD) | ||
# GITHUB_REPOSITORY should be in "owner/repo" format. | ||
# e.g., GITHUB_REPOSITORY="bpkroth/MLOS" or "microsoft/MLOS" | ||
export GITHUB_REPOSITORY=$(git rev-parse --abbrev-ref --symbolic-full-name HEAD@{u} | cut -d/ -f1 | xargs git remote get-url | grep https://github.com | cut -d/ -f4-) | ||
pytest -n0 mlos_bench/mlos_bench/tests/util_git_test.py | ||
""" # pylint: disable=line-too-long # noqa: E501 | ||
repo_env = os.environ.get("GITHUB_REPOSITORY") # "owner/repo" format | ||
sha_env = os.environ.get("GITHUB_SHA") | ||
assert repo_env, "GITHUB_REPOSITORY not set in environment." | ||
assert sha_env, "GITHUB_SHA not set in environment." | ||
git_repo, git_commit, _rel_path, _abs_path = get_git_info(__file__) | ||
assert git_repo.endswith(repo_env), f"git_repo '{git_repo}' does not end with '{repo_env}'" | ||
assert ( | ||
git_commit == sha_env | ||
), f"git_commit '{git_commit}' does not match GITHUB_SHA '{sha_env}'" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.