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

Change default --app-dir from from "." (dot) to "" (empty string). #1835

Merged
merged 1 commit into from Jan 6, 2023
Merged

Change default --app-dir from from "." (dot) to "" (empty string). #1835

merged 1 commit into from Jan 6, 2023

Conversation

mila
Copy link
Contributor

@mila mila commented Jan 5, 2023

Both the dot and empty string are interpreted as the current working directory but Python, but the dot causes ugly __file__ of imported modules. The empty string is consistent with Python behavior, inserting an empy string to sys.path when running interactively.

Discussion: #1814

Both the dot and empty string are interpreted as the current working directory but Python,
but the dot causes ugly __file__ of imported modules.
The empty string is consistent with Python behavior,
inserting an empy string to sys.path when running interactively.
Copy link
Sponsor Member

@Kludex Kludex left a comment

Choose a reason for hiding this comment

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

Does os.getcwd() instead empty string has the same behavior here?

Also, can we add a test for it? Just to validate exactly what you said in the discussion. Ideally, the test would fail on master right now, and pass here.

@mila
Copy link
Contributor Author

mila commented Jan 5, 2023

Does os.getcwd() instead empty string has the same behavior here?

The behavior would be different if the application changed cwd at runtime. Both "." and "" mean the cwd at the time of import, os.getcwd() would freeze the value.

Also, can we add a test for it? Just to validate exactly what you said in the discussion. Ideally, the test would fail on master right now, and pass here.

I was considering that and but I am not sure what I should test and whether it is worth it.

Today, a test for --app-dir asserts that sys.path is modified. I can copy this test and assert that the empty string is inserted there. But that would just ensure that default value is honored by Click.

It would be safer to test that it is possible to import an app from --app-dir (empty or custom). But all CLI tests now use mocks, so I did not want to introduce a test that would run a real server.

Copy link
Sponsor Member

@Kludex Kludex left a comment

Choose a reason for hiding this comment

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

It's fine. 👍

Thanks! 🙏

Ref.: https://docs.python.org/3/library/sys.html#sys.path

@Kludex Kludex added this to the Version 0.21.0 milestone Jan 6, 2023
@Kludex Kludex changed the title Change default --app-dir from from "." (dot) to "" (empty string). Change default --app-dir from from "." (dot) to "" (empty string). Jan 6, 2023
@Kludex Kludex merged commit 4831d79 into encode:master Jan 6, 2023
@mila mila deleted the app-dir branch January 6, 2023 11:02
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.

None yet

2 participants