Closed drayde closed 4 months ago
I think what I've done in some of my other hardware repos is to do import sys
and sys.path.append()
to manipulate the Python path so that I only ever need one form of the import statement. I think you can put it in an __init__.py
so that boiler plate is not required in each model. I don't know if that ends up being better or not though.
I think the path modifications need to be done in the server code in our case, so that it will find non-relative imports. What I am wondering: should there be some cq-cli modification (or option?) to handle this? I guess it's a use case not only for us
So maybe cq-cli would have an --addpaths
option to add to the Python path? It could be formatted similar to how the PTHONPATH variable is done.
cq-cli --infile /path/to/file.py --codec step --addpaths /path/to:/path/to/subdir
Does that seem reasonable?
Turns out cq-cli already does that: https://github.com/CadQuery/cq-cli/blob/9502fafe12069e938eb5b25f8547193e2c2656f1/src/cq_cli/main.py#L91
And modifying the path still does not allow relative imports as this would mean that the script must be treated as a module rather than the main script. Probably not the way we should go, as it will change the cqgi conventions.
So instead, we probably have to change the server code. What do you think about using cqgi there as well instead of loading the code as module?
Check out the new version of exsource. It should run cq-cli in a subprocess (without python -m) so it should always be directly run from cq-cli.
@drayde Does the suggestion by @julianstirling solve the issue?
I'm afraid it doesn't make a difference how you run cq-cli
Can you give a short code example so I understand what you mean. The issue is that cq-cli and the web-server must run the same script but they have different conventions for relative imports?
I think it is worth thinking of a non-hacky solution. Even if we have to change how one of them processes files. We want the project to be an example for a customisable methodology. So clean and simple scripts are important.
I agree on finding a non-hacky solution.
To clear up the problem: The cadquery scripts are accessed in 2 ways:
We could solve this by:
My preferred solution is 1, as to me it looks like the cleanest solution. @jmwright and @julianstirling do you agree?
I'm ok with doing option 1. @julianstirling ?
Option 1 I think is best. It allows us to simply say
"Our CadQuery Scripts are processed with cq-cil"
Simplicity is good when possible
Perfect. I would suggest to merge my changes and open a new issue for this. @jmwright is this something you would like to implement?
@drayde When you open the issue, please post an example of how the orchestration script should be called now. I'll get the server updated for the latest changes after that.
Thanks for merge @jmwright ! The discussed new issue is here: https://github.com/Wakoma/nimble/issues/15
To clarify: The orchestration script is already called from the web server code. This works fine, nothing to change there. The issue is only about the rack_leg code in nimble_server.py. I guess I don't need to give you example code for using cqgi, you probably know that better than me.
I had to do this if statement for the module import to allow both exsource/cq-cli and the web server run the code https://github.com/Wakoma/nimble/blob/791da1e2ba7c7905b309d9f430f046b28147e335/doc_generator/mechanical/components/cadquery/rack_leg.py#L4-L7 Do you have a better idea, @jmwright ?