Some more unload/load suggestions/changes

Discuss API design here.
Omega_K2
Senior Member
Posts: 227
Joined: Sat Jul 07, 2012 3:05 am
Location: Europe
Contact:

Some more unload/load suggestions/changes

Postby Omega_K2 » Fri Jul 20, 2012 11:06 pm

Loading (and unloading) subscripts does not seem to work at the moment.

Expected way to load subscripts:

sp_load main/sub

This is trying to load:

main/sub/main/sub.py

Should be:

main/sub/sub.py

Syntax: Select all

# item = cmd argument
path = item + '/' + item.rsplit('/',1)[-1] + '.py'
importstr = item.replace('/','.') + '.' + item.rsplit('/',1)[-1]


EDIT:

Also if your addon happens to have the same name like an internal/python module you won't be able to load it. I think this should be somehow prevented or so, because it may cause confusion on the user side because you'll just get an import error :P
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sat Jul 21, 2012 12:13 am

Correct, I have designed the load/unload section so that if a script wants to load its own subscript, it will need its own API to do so. This is the correct way to handle this, imo.

I have noticed that import error issue, as well, since I can no longer use test as an addon. I'm not sure if we even plan at any point to change that, but I doubt we do as it would likely get too complicated.

Satoon
Omega_K2
Senior Member
Posts: 227
Joined: Sat Jul 07, 2012 3:05 am
Location: Europe
Contact:

Postby Omega_K2 » Sat Jul 21, 2012 12:45 am

satoon101 wrote:Correct, I have designed the load/unload section so that if a script wants to load its own subscript, it will need its own API to do so. This is the correct way to handle this, imo.


I partially argee, but those subfolders can also used to structure scripts further.

For example, when working on the auth stuff I had the idea to put all auth providers in their own subfolder. Obviously each auth provider is independent from each other, but still I think this:
auth_providers/simple
auth_providers/group
auth_providers/mysql
is better compared to:
simpleauth
groupauth
mysqlauth

Another example would be the now obsolete corelib. I still see some use in having this.

satoon101 wrote:I have noticed that import error issue, as well, since I can no longer use test as an addon. I'm not sure if we even plan at any point to change that, but I doubt we do as it would likely get too complicated.


Possibly the output could be changed sightly, so it's the error + "[SP] Note: Check whether your addon has the name of an existing module". I think that might help with confusion
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sat Jul 21, 2012 1:01 am

That is a good idea for the error, I'll look to adding that when I get the chance.

Thank you,
Satoon
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sun Jul 22, 2012 2:43 am

I'm still thinking of how best to let the server know which Auth provider is being used, but that will partly depend on the final build of the Auth API. I don't think, at this point, that I want them to be "scripts". They should be within the Auth API, somewhere. I just am not sure how to load the one the server is supposed to be running. One idea is that we can use an .ini file for some things of this nature that should never be changed while the server is running. That way, when the server loads, it reads the .ini to know (in this instance) which Auth provider to use, and loads it.

Satoon
Omega_K2
Senior Member
Posts: 227
Joined: Sat Jul 07, 2012 3:05 am
Location: Europe
Contact:

Postby Omega_K2 » Mon Aug 05, 2013 2:30 am

Sorry for the necro, but I still think you should be able to load scripts in a sub folder.

Simply because of script collections and organizing your folder structure.
For example, I think this:
k2tools/examples/myexample/myexample.py
k2tools/examples/myexample2/myexample2.py
k2tools/examples/myexample3/myexample3.py
k2tools/anotherthing/anotherthing.py

is much better directory structure then:
k2tools_myexample1/k2tools_myexample1.py
k2tools_myexample2/k2tools_myexample2.py
k2tools_myexample3/k2tools_myexample3.py
k2tools_anotherthing/k2tools_anotherthing.py

You pretty much avoid spamming the main folder also, if you write a bunch of stuff.

Especailly if these scripts have not that much do with another, a custom loader, which also has to be maintained speratly, seems pretty bad to me. After all, you can still use a custom loader if you need one.
Libraries: k2tools
Plugins (any): GSRPG (soon) | Pretty Status List | MySQLAds (soon)
Plugins (game-specific): None atm

If you happen to find a bug or need help, either post in the release threads or contact me in IRC gamesurge.net:6667 / #sourcepython
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Tue Aug 06, 2013 2:25 am

Nope, not gonna happen. It is the job of the script itself to load/unload its own sub-modules. This will not change. If the scripts don't have much to do with one another, then they should be separate scripts.

Satoon

Return to “API Design”

Who is online

Users browsing this forum: No registered users and 21 guests