PySlither / Slither

A Python module for bridging Scratch and Python
http://pyslither.github.io/
MIT License
14 stars 6 forks source link

Move code from __init__.py to slither.py #69

Closed CosmicWebServices closed 8 years ago

CosmicWebServices commented 8 years ago

See #68

Not tested.

skistaddy commented 8 years ago

+1

CosmicWebServices commented 8 years ago

Thanks!

skistaddy commented 8 years ago

:D

BookOwl commented 8 years ago

I don't like this, it means that instead of just importing slither, users have to do from slither import slither, which just seems weird.

CosmicWebServices commented 8 years ago

or from slither import *

BookOwl commented 8 years ago

But that's considered bad practice. and we really shouldn't be encouraging that. What's wrong with having everything in the init.py

CosmicWebServices commented 8 years ago

I just realised we can put import slither in __init__.py

ghost commented 8 years ago

But why do we need this? And besides It's not like we have optional modules for slither.

skistaddy commented 8 years ago

@CosmicWebServices +1

emmatyping commented 8 years ago

But why do we need this? And besides It's not like we have optional modules for slither.

Python style dictates that as little operational code should go in an__init__.py file as possible. I believe the importing of slither.py, as @Omegabyte suggested is often the practice used.

BookOwl commented 8 years ago

I think that @Tymewalk needs to make this decision.

CosmicWebServices commented 8 years ago

OK

Tymewalk commented 8 years ago

I'm confused here.

So users will have to use from slither import *? Why not have a from slither import * in __init__.py and then use import slither like normal? Or just keeping things the way they are?

@ethanhs Where does it say that? I've never heard that rule, nor seen it used anywhere.

CosmicWebServices commented 8 years ago

no it will be the same as now

Tymewalk commented 8 years ago

@CosmicWebServices Oh, OK. But the code doesn't look that way.

CosmicWebServices commented 8 years ago

Well I made it in the format that __init__.py should be in but I would still test it...

emmatyping commented 8 years ago

I might have mis-spoken. What I really mean when I say "as little operational code as possible" is to say that the __init__.py should contain setup code.

The purpose of the init.py files is to include optional initialization code that runs as different levels of a package are encountered.

and

More often that not, it’s fine to just leave the init.py files empty. However, there are certain situations where they might include code. For example, an init.py file can be used to automatically load submodules

src

Also:

For a simple package, you might be tempted to throw utility methods, factories and exceptions into your init.py. Don’t. A well-formed init.py serves one very important purpose: to import from sub-modules.

src

One more:

init.py can be an empty file but it is often used to perform setup needed for the package(import things, load things into path, etc).

src

Based on these, I would recommend from . import slither or simply import slither and move all the code to slither.py

skistaddy commented 8 years ago

@ethanhs +1

Tymewalk commented 8 years ago

@ethanhs Oh, OK. That makes more sense.

Based on that I think we should restructure init.py so users can still use import slither, but so the code is in a separate file.

CosmicWebServices commented 8 years ago

yeah that makes more sense

Tymewalk commented 8 years ago

I'm going to close this pull request as it doesn't do this which is the eventual goal (unless you'd like to update it so it does do this, @CosmicWebServices).

CosmicWebServices commented 8 years ago

u do it

Tymewalk commented 8 years ago

@CosmicWebServices I can't since I don't have write access to your repo.

If you'd like I can close this and just make a new PR.

CosmicWebServices commented 8 years ago

PR?

skistaddy commented 8 years ago

@CosmicWebServices Pull Request

CosmicWebServices commented 8 years ago

What is in the new pull request???

Tymewalk commented 8 years ago

@CosmicWebServices I'd rewrite the current version of Slither to work so init.py only contains an import and users can still use import slither.

CosmicWebServices commented 8 years ago

OK I will do that tommarow

Tymewalk commented 8 years ago

@CosmicWebServices OK then.

This PR is being left open since @CosmicWebServices is working on updating it.

CosmicWebServices commented 8 years ago

Updated it!

emmatyping commented 8 years ago

I'm going to recommend that you do from . import slither, as that will not cause issues with namespaces getting imported twice etc.

Just an idea.

CosmicWebServices commented 8 years ago

Good Idea Fixing that

CosmicWebServices commented 8 years ago

Done

Tymewalk commented 8 years ago

Tests can still use import slither correctly, right?

BookOwl commented 8 years ago

I think that for this change to be accepted, all the tests must work perfectly without making any changes.

CosmicWebServices commented 8 years ago

@BookOwl I agree

BookOwl commented 8 years ago

@CosmicWebServices, what progress have you made?

CosmicWebServices commented 8 years ago

It is done

BookOwl commented 8 years ago

OK, @Tymewalk can look it over one more time and then we can merge.

Tymewalk commented 8 years ago

@BookOwl @CosmicWebServices I'm cloning that repo now to test.

Tymewalk commented 8 years ago

Used import slither in basicTest.py.

Traceback (most recent call last):
  File "slither/tests/basicTest.py", line 3, in <module>
    snakey = slither.Sprite()
AttributeError: 'module' object has no attribute 'Sprite'
BookOwl commented 8 years ago

@Tymewalk, I think that the __init__.py file needs to be changed to from .slither import *

BookOwl commented 8 years ago

Yep, that fixes it.

BookOwl commented 8 years ago

@CosmicWebServices, can you add that fix? Also, the tests need to be changed back to import slither, not from slither import *

CosmicWebServices commented 8 years ago

Got it...

BookOwl commented 8 years ago

I just tested it and it seems to work, but you need to revert the tests' import back to import slither Other than that, it looks great! Thanks for putting in all this work.

CosmicWebServices commented 8 years ago

I forgot about the tests I will do that soon (tomorrow probably)

BookOwl commented 8 years ago

@CosmicWebServices, when do you think that you will finish this?

CosmicWebServices commented 8 years ago

I forgot doing it now

CosmicWebServices commented 8 years ago

Done sorry it took so long!