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
Expand some userpaths in internals.py #2825 #3128
base: develop
Are you sure you want to change the base?
Expand some userpaths in internals.py #2825 #3128
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than the one comment I made, the changes seem reasonable, but do you know if it would be possible to make tests for them? This may not be feasible (as the goal is to have the tests pass locally and also on the CI), but it may be worthwhile.
For example, having an environment variable that points to "~\test_dir", which is then used by find_file
(or find_file
, find_binary
, find_jar_iter
, etc.):
Line 624 in 5ebdde6
def find_file( |
Perhaps this is possible by creating a temporary file/folder for a test? Maybe there's some permission issues with that, though...
nltk/internals.py
Outdated
@@ -540,6 +540,7 @@ def find_file_iter( | |||
|
|||
# Check environment variables | |||
for env_var in env_vars: | |||
env_var = os.path.expanduser(env_var) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
env_var
is just a string like "HUNPOS_TAGGER"
, e.g.:
Line 94 in cbe715a
path_to_model, env_vars=("HUNPOS_TAGGER",), verbose=verbose |
nltk/nltk/tokenize/stanford_segmenter.py
Line 157 in cbe715a
env_vars=("STANFORD_MODELS",), |
Line 91 in cbe715a
return find_file(model_filename, env_vars=("MALT_MODEL",), verbose=False) |
So, we don't want to expand these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, thanks. Reverted this change in 9797986.
Hey @tomaarsen - apologies for the piecemeal approach. I've made the requested change in 9797986. Feel free to review/mark as resolved. As for the tests - I agree with the sentiment but am conscious of creating files in a users' home directory (e.g., we need to ensure we are creating/deleting an obscure directory/filename (or within nltk-data/ etc.) as to not interfere with user setups). Happy to come back to adding the doctest, after more thought - I can create an issue about this now? |
Hi - I added some of the path expansions to internals.py as described in #2825.
The tox command seems ok (output below).
Note - I tried expanding the remaining paths with a few different approaches. e.g., Adding a utility function that converted tuples to lists and expanded each of their items, like this:
But this wasn't a robust solution (particularly for the
filename
variable), so these paths remain unchanged for now.In any-case, hopefully this PR is a start!