3 ms·
Love this. I created (half-jokingly, but only half) the concept of a monofile (inspired by our monorepo) in our team. I have not managed to convince my colleagu
by c-fe 2y ago
Love this. I created (half-jokingly, but only half) the concept of a monofile (inspired by our monorepo) in our team. I have not managed to convince my colleagues to switch yet, but maybe this package can help. Unironically, I find that in larger python projects, combining various related sub 100 loc files into one big sub 1000 loc file can do magic to circular import errors and remove 100s of lines of import statements.
- sureglymop 2y agoI usually do this with docker/podman compose files for dev environments. I see people creating all kinds of mounts and volumes but I just embed files inline under the configs top level key. I even embed shell scripts that way to do one shot/initialization tasks. The goal is to just have one compose.yml file that the developer can spin up for a local development reproduction of what they need. It's quite nice.
- phito 2y agoI like splitting large compose file in smaller units and including them in the main compose file
- SuchAnonMuchWow 2y agoTo help with circular import, we switched a few years ago to lazily importing submodules on demand, and never switched back. Just add to your __init__.py files: import importlib def __getattr__(submodule_name): return importlib.import_module('.' + submodule_name, __package__) And then just import the root module and use it without ever needing to import individual submodules: import foo def bar(): return foo.subfoo.bar() # foo.subfoo is imported when the function is first executed instead of when it is parsed, so no circular import happen
- hobs 2y agoDoesn't that mean your editor support is crap though?
- aunderscored 2y agoIt does, which is why this is more easily done by importing exact bits or using a single file
- SuchAnonMuchWow 2y agoNot at all. Sublime is perfectly fine with it. I suspect that from the usage in the code, it knows that there is a module foo and a submodule subfoo with a function bar() in it, and it can look directly in the file for the definition of bar(). It would be another story if we used this opportunity to mangle the submodules names for example, but that the kind of hidden control flow that nobody want in his codebase. Also, it is not some dark arts of import or something: it is pretty standard at this point since its one of the most sane way of breaking circular dependencies between your modules, and the feature of overloading a module __getattr__ was introduced specifically for this usecase. (I couldn't find the specific PEP that introduced it, sorry)
- Muromec 2y agoI once had a 4k line javascript file (a vuex module), which I navigated using / in vim, which came with another 20k likes of tests (also in the single file). I would say 5k lines is the real celling.