Files
2012-02-21 01:15:00 -05:00

1 line
4.6 KiB
JSON

[{"user_id": 960, "stars": [], "topic_id": 36252, "date_created": 1306017189.0328281, "message": "Created a small package who's sole purpose is to handle declaring namespaces. It's in the \"it works for me with all the tests passing\" mode right now, but I'm almost positive there's all manner of edge cases I've missed.", "group_id": 292, "id": 1138252}, {"user_id": 960, "stars": [], "topic_id": 36252, "date_created": 1306017202.7568231, "message": "I'd love some feedback on it: https://github.com/tswicegood/ns.py", "group_id": 292, "id": 1138254}, {"user_id": 960, "stars": [], "topic_id": 36252, "date_created": 1306017222.446785, "message": "Bonus points if the feedback is in the form of broken test cases :-)", "group_id": 292, "id": 1138260}, {"user_id": 18665, "stars": [], "topic_id": 36252, "date_created": 1306028048.194751, "message": "Can you provide some fully working examples? As a beginner level Python programmer, it's not immediately obvious to me why this is needed, the benefits it provides and most importantly, how I can start using it.", "group_id": 292, "id": 1139188}, {"user_id": 1736, "stars": [{"date_created": 1306032158.9844279, "user_id": 4156}, {"date_created": 1306080167.4539969, "user_id": 960}, {"date_created": 1306082325.726248, "user_id": 1243}, {"date_created": 1306150081.596951, "user_id": 5778}], "topic_id": 36252, "date_created": 1306028608.411613, "message": "As an example, Foo-A contains the files foo/__init__.py and foo/a.py, Foo-B contains foo/__init__.py and foo/b.py. Normally whichever of these was found first by the importer would become the canonical entry in sys.modules for \"foo\", but if both __init__.py files use this namespace package system, you can import both foo.a and foo.b without either overriding the other.", "group_id": 292, "id": 1139223}, {"user_id": 18665, "stars": [], "topic_id": 36252, "date_created": 1306028110.2758651, "message": "And by \"fully working examples\", try to stay away from foo bar etc. Provide a real life example of where namespacing is essential so I have a production quality pattern to copy from.", "group_id": 292, "id": 1139190}, {"user_id": 1736, "stars": [], "topic_id": 36252, "date_created": 1306028484.913928, "message": "Yeah, when you say \"namespaces\" I'm sure people will think of module and class-level namespaces, which this has nothing to do with. \"Namespace packages\" is the term I hear used, though that is about as clear as mud too. For people finding this, namespace packages are a mechanism whereby two (or more) distributions (which are the things you think of as packages, listed on PyPI, installed via pip, etc) share part of their package path. A common example is the the flaskext namespace. All Flask extensions use \"flaskext.\" as the back of the package path, and use the \"namespace packages\" feature to prevent overriding each other.", "group_id": 292, "id": 1139207}, {"user_id": 18665, "stars": [], "topic_id": 36252, "date_created": 1306053287.7977669, "message": "Thanks @coderanger, that is exactly what I was after!", "group_id": 292, "id": 1140481}, {"user_id": 213, "stars": [{"date_created": 1306085360.411238, "user_id": 1736}], "topic_id": 36252, "date_created": 1306064980.024281, "message": "@tswicegood So what's the difference between ns.declare and pkgutil.extend_path? http://docs.python.org/library/pkgutil.html#pkgutil.extend_path", "group_id": 292, "id": 1141112}, {"user_id": 960, "stars": [], "topic_id": 36252, "date_created": 1306080433.996031, "message": "@jezdez It actually isn't all that different, just a different way to do the same thing.", "group_id": 292, "id": 1142576}, {"user_id": 960, "stars": [], "topic_id": 36252, "date_created": 1306080466.2802041, "message": "Mine is modeled after pkg_resources (obviously, not the best role-model) so it mucks with sys.path rather than modifying a module's __path__.", "group_id": 292, "id": 1142578}, {"user_id": 960, "stars": [], "topic_id": 36252, "date_created": 1306080549.5021651, "message": "That said, it looks like pkgutil.extend_path does what I want without requiring an entirely separate package installed (a la pkg_resources or ns.py)", "group_id": 292, "id": 1142582}, {"user_id": 960, "stars": [], "topic_id": 36252, "date_created": 1306080705.2886319, "message": "@ryan_blunden If you'd like to see a full example using pkg_resources, you can look at the code on GitHub under the user armstrongcms.", "group_id": 292, "id": 1142611}, {"user_id": 213, "stars": [], "topic_id": 36252, "date_created": 1306138895.1956179, "message": "@tswicegood Gotcha, FWIW, I believe pkg_resources forked pkgutil at the time and Tarek moved a few things back again in one of the newer Python versions.", "group_id": 292, "id": 1150208}]