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

[loader] Properly walk module directories #990

Closed
wants to merge 2 commits into from

Conversation

maxpowa
Copy link
Contributor

@maxpowa maxpowa commented Jan 8, 2016

Tested fairly thoroughly, works with reloading, fresh starts. Should ignore compiled python (__pycache__) directories, as well as both hidden files and directories. Works with pypi installed third party modules, should work with third party packaged modules put directly in the modules directory. Standalone python files in the modules directory work as before.

Edit: It will currently ignore symlinks, dunno if we should do that or not.

Edit2: It doesn't work if you drop a python package in the modules directory, not really sure what subtlety is messing that up.

Tested fairly thoroughly, works with reloading, fresh starts. Should ignore compiled python (__pycache__) directories, as well as both hidden files and directories. Works with pypi installed third party modules, should work with third party packaged modules put directly in the modules directory. Standalone python files in the modules directory work as before.
@thomastanck
Copy link
Contributor

+1 not sure why this could hurt, and it only allows for better organisation of custom modules

I will test this on Saturday.

@dgw
Copy link
Member

dgw commented Mar 27, 2018

@thomastanck Is it Saturday yet? 😸 (Translation: Are you still able to test this?)

Note to self: Squash out 601936d before merging, assuming the code requires no other changes.

@dgw dgw added this to the 6.6.0 milestone Mar 27, 2018
@thomastanck
Copy link
Contributor

Sorry about that... it's Sunday already :(
(Translation: sorry I completely forgot about this, and now it's so late I no longer have sopel set up for testing)

@dgw dgw modified the milestones: 6.6.0, 7.0.0 Mar 29, 2018
@dgw
Copy link
Member

dgw commented Mar 29, 2018

Punting to next major update: There is currently no one with prior experience to review this, and the known issues (ignoring symlinks, failing on packaged modules) really should be solved before merging.

Copy link
Member

@dgw dgw left a comment

Choose a reason for hiding this comment

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

This is mostly a comment for when this gets seriously looked at in the future, but I might as well also officially mark this as needing changes (because of the reported issues in the main thread: not following symlinks and not loading packaged modules correctly).

result = get_module_description(path)
if result:
modules[result[0]] = result[1:]
for root, dirs, files in os.walk(directory):
Copy link
Member

Choose a reason for hiding this comment

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

Following symlinks is probably as simple as adding followlinks=True to this function call.

Copy link
Contributor

@Exirel Exirel left a comment

Choose a reason for hiding this comment

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

My main request here is the dirs manipulation. I'm not convince by the dirs[:] syntax, and I'm not sure we need to keep it between iterations of the for-in loop.

for root, dirs, files in os.walk(directory):
# Ignore hidden folders/files and __ prefixed (__pycache__)
files = [f for f in files if not f[0] == '.']
dirs[:] = [d for d in dirs if not d[0] == '.']
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this syntax works, but here it is equivalent to this less confusing one:

dirs = [d for d in dirs if not d[0] == '.']

# Ignore hidden folders/files and __ prefixed (__pycache__)
files = [f for f in files if not f[0] == '.']
dirs[:] = [d for d in dirs if not d[0] == '.']
dirs[:] = [d for d in dirs if not d.startswith('__')]
Copy link
Contributor

Choose a reason for hiding this comment

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

It is possible to merge both filter in a single iteration:

dirs = [
    d for d in dirs
    if not d.startswith('.') and not d.startswith('__')
]

modules[result[0]] = result[1:]
else:
non_pkg_dirs.append(folder)
dirs[:] = non_pkg_dirs
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure we need to store non_pkg_dirs and why it replaces dirs either.

@dgw
Copy link
Member

dgw commented Jan 31, 2019

@Exirel Do you want to take this over in a new PR? You could just git rebase -i master and "fixup" 601936d into the initial commit (which I would do, but I can't push a revised history to Max's branch), then add your own stuff onto there. That way we can un-stall this PR and keep the original authorship info!

@Exirel
Copy link
Contributor

Exirel commented Jan 31, 2019

@dgw let's do this then!

@dgw dgw added Tweak Stale Mostly used for PRs that no longer work and need updating before re-review/merge. and removed Needs Review labels Feb 28, 2019
@dgw dgw mentioned this pull request Apr 3, 2019
@dgw
Copy link
Member

dgw commented Apr 4, 2019

Closing in favor of #1479

@dgw dgw closed this Apr 4, 2019
@dgw dgw added Replaced Superseded by a newer PR and removed Stale Mostly used for PRs that no longer work and need updating before re-review/merge. labels Apr 4, 2019
@Exirel Exirel removed this from the 7.0.0 milestone May 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Replaced Superseded by a newer PR Tweak
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants