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

feat: search current working directory for config file #1464

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

IndexSeek
Copy link

Resolves #1333

Adds the current working directory to the search path for the .pyiceberg.yaml file.

As it is now, the file is searched in the following order:

  1. the PYICEBERG_HOME environment variable
  2. ~/
  3. ./

I'm unsure if people would like to have 2 and 3 swapped. In either case, users can still override this with the environment variable.

Copy link
Contributor

@kevinjqliu kevinjqliu left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Added a few nit comments

# Look into the home directory
if pyiceberg_home_config := _load_yaml(os.path.expanduser("~")):
return pyiceberg_home_config
# Directories to search for the configuration file
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: i like the comment on search order "PYICEBERG_HOME, home directory, then current directory"

Copy link
Author

@IndexSeek IndexSeek Dec 22, 2024

Choose a reason for hiding this comment

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

I added a new line to show this in 2bd6913, is this what you are looking for? I just added back this comment underneath.

Copy link
Contributor

Choose a reason for hiding this comment

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

there are a couple other places where pyiceberg.yaml is referenced in the docs
https://grep.app/search?q=pyiceberg.yaml&filter[repo][0]=apache/iceberg-python&filter[path][0]=mkdocs/docs/

Copy link
Author

Choose a reason for hiding this comment

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

Nice finds! That grep tool is pretty neat. I just made some corrections to these in 3ebbb8c.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

I tried adding a test here, but I wonder if there are opportunities to clean it up.

Copy link
Contributor

@kevinjqliu kevinjqliu left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! I added some nit comments on testing



@pytest.mark.parametrize(
"config_location, config_content, expected_result",
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: config_content and expected_result are always the same, we can use one of them, write to the file and verify that it reads back the same

("none", None, None),
],
)
def test_from_multiple_configuration_files(
Copy link
Contributor

Choose a reason for hiding this comment

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

nit can we also test the order of lookup here?

Copy link
Contributor

Choose a reason for hiding this comment

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

we want to test both home directory and current directory here

) -> None:
def create_config_file(directory: str, content: Optional[Dict[str, Any]]) -> None:
config_file_path = os.path.join(directory, ".pyiceberg.yaml")
with open(config_file_path, "w", encoding="utf-8") as file:
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
with open(config_file_path, "w", encoding="utf-8") as file:
with open(config_file_path, "w", encoding=UTF8) as file:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

.pyiceberg.yaml config files should be loaded from current dir instead of home folder
2 participants