MK
Marius Kintel
Fri, Mar 9, 2018 11:10 PM
Of course one cane import module like
require ('./node_modules/some_module’)
With npm, it’s possible to do ‘npm install --prefix <someprefix>’ to install into any location
For global installs, setting the prefix to OpenSCAD’s global library folder would work automatically.
For local installs, we could combine this with setting the OPENSCADPATH environment variable.
For more into, see https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Libraries
-Marius
>
> Of course one cane import module like
> require ('./node_modules/some_module’)
With npm, it’s possible to do ‘npm install --prefix <someprefix>’ to install into any location
For global installs, setting the prefix to OpenSCAD’s global library folder would work automatically.
For local installs, we could combine this with setting the OPENSCADPATH environment variable.
For more into, see https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Libraries
-Marius
M
Mindfab
Mon, Mar 12, 2018 11:08 PM
I have come across this thread after having an idea to use npm to manage
packages for OpenSCAD :) I already use NPM to store some NodeJS modules
and
feel that OpenSCAD is missing such central modules repo. I am going to
give
it a try and publish some modules I use in my projects. Can I somehow
register?
That would be great!
You can register yourself by using npms adduser command against the
openscad-modules registry. More details can be found in the github
repository.
Let me know if there are any problems or suggestions.
--
Sent from: http://forum.openscad.org/
1i7 wrote
> I have come across this thread after having an idea to use npm to manage
> packages for OpenSCAD :) I already use NPM to store some NodeJS modules
> and
> feel that OpenSCAD is missing such central modules repo. I am going to
> give
> it a try and publish some modules I use in my projects. Can I somehow
> register?
That would be great!
You can register yourself by using npms adduser command against the
openscad-modules registry. More details can be found in the github
repository.
Let me know if there are any problems or suggestions.
--
Sent from: http://forum.openscad.org/
M
Mindfab
Mon, Mar 12, 2018 11:26 PM
Also, good module repository support might require better build logic
integration in OpenSCAD itself.
With NodeJS when you have project dir project1 and run
npm install some_module
inside, the module copy comes from central repository to
project1/node_modules/some_module
So whe I import some_module from JavaScript source file by name like:
require ('some_module');
NodeJS runtime would search ./node_modules/some_module to resolve this
dependency (even more, if it doest not find requested module in project
dir
./node_modules, it would go one level up to ../node_modules, then one more
level up to ../../node_modules etc - so with this mecanics some module
deps
can be shared among multiple projects).
This logic should be implemented on the level of build/runtime tool
(NodeJS
or OpenSCAD), not on the level of package manager.
Of course one cane import module like
require ('./node_modules/some_module');
But this would not be so elegant.
Well, one point we should consider when thinking about this optimization is
the problem of name clashing and versioning conflicts. If you install all
modules in a common location the user would need to handle conflicting
module versions and also naming issues. In my opinion, the advantage of
having a modular systems, where I (as a module author and consumer) only
have to take care about my own dependencies (and not the one somebody else
is using in combination with my module) outperforms the advantage of saving
space. So, using "include <node_modules/fractals/fractals.scad>" inside a
module, as its described in the simple example, does this trick. Maybe it's
not a real feature of OpenSCAD, but it works and gives us the isolation for
naming and versioning issues :)
Beside that, I agree, that the look and feel is not as good as it could be.
The 'node_modules' part is just in the path because I didn't want to add
another command line parameter to the npm call. Maybe there is a better
solution that has a better presentation/usability but preserves the above
mentioned property?
--
Sent from: http://forum.openscad.org/
1i7 wrote
> Also, good module repository support might require better build logic
> integration in OpenSCAD itself.
>
> With NodeJS when you have project dir project1 and run
> npm install some_module
>
> inside, the module copy comes from central repository to
> project1/node_modules/some_module
>
> So whe I import some_module from JavaScript source file by name like:
> require ('some_module');
>
> NodeJS runtime would search ./node_modules/some_module to resolve this
> dependency (even more, if it doest not find requested module in project
> dir
> ./node_modules, it would go one level up to ../node_modules, then one more
> level up to ../../node_modules etc - so with this mecanics some module
> deps
> can be shared among multiple projects).
>
> This logic should be implemented on the level of build/runtime tool
> (NodeJS
> or OpenSCAD), not on the level of package manager.
>
> Of course one cane import module like
> require ('./node_modules/some_module');
>
> But this would not be so elegant.
Well, one point we should consider when thinking about this optimization is
the problem of name clashing and versioning conflicts. If you install all
modules in a common location the user would need to handle conflicting
module versions and also naming issues. In my opinion, the advantage of
having a modular systems, where I (as a module author and consumer) only
have to take care about my own dependencies (and not the one somebody else
is using in combination with my module) outperforms the advantage of saving
space. So, using "include <node_modules/fractals/fractals.scad>" inside a
module, as its described in the simple example, does this trick. Maybe it's
not a real feature of OpenSCAD, but it works and gives us the isolation for
naming and versioning issues :)
Beside that, I agree, that the look and feel is not as good as it could be.
The 'node_modules' part is just in the path because I didn't want to add
another command line parameter to the npm call. Maybe there is a better
solution that has a better presentation/usability but preserves the above
mentioned property?
--
Sent from: http://forum.openscad.org/
M
Mindfab
Mon, Mar 12, 2018 11:35 PM
Of course one cane import module like
require ('./node_modules/some_module’)
With npm, it’s possible to do ‘npm install --prefix
<someprefix>
’ to install into any location
For global installs, setting the prefix to OpenSCAD’s global library
folder would work automatically.
For local installs, we could combine this with setting the OPENSCADPATH
environment variable.
For more into, see
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Libraries
-Marius
Hi Marius, thx for your feedback. I just answered 1i7 regarding the
suggestion to install modules globally... Right now, I think there is one
big advantage in installing the modules in the NPMs preferred hierarchy
under a local folder, whićh is, it helps us to avoid naming and versioning
issues. A more detailed explanation can be found in the reply to 1i7
question.
In my opinion having this ability can speed up the development of modules,
as module authors itself doesn't need to be concerned about the context of
their module usage, they just need to be concerned about their module and
their dependencies.
--
Sent from: http://forum.openscad.org/
kintel wrote
>>
>> Of course one cane import module like
>> require ('./node_modules/some_module’)
>
> With npm, it’s possible to do ‘npm install --prefix
> <someprefix>
> ’ to install into any location
> For global installs, setting the prefix to OpenSCAD’s global library
> folder would work automatically.
> For local installs, we could combine this with setting the OPENSCADPATH
> environment variable.
>
> For more into, see
> https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Libraries
>
> -Marius
Hi Marius, thx for your feedback. I just answered 1i7 regarding the
suggestion to install modules globally... Right now, I think there is one
big advantage in installing the modules in the NPMs preferred hierarchy
under a local folder, whićh is, it helps us to avoid naming and versioning
issues. A more detailed explanation can be found in the reply to 1i7
question.
In my opinion having this ability can speed up the development of modules,
as module authors itself doesn't need to be concerned about the context of
their module usage, they just need to be concerned about their module and
their dependencies.
--
Sent from: http://forum.openscad.org/
R
runsun
Mon, Mar 12, 2018 11:59 PM
I believe the existing of a standard package manager will prompt owners to
write libs with specific names.
Gadgetmind wrote
On 04/03/18 01:40, Len Trigg wrote:
I think that a decent package manager would be a good addition to the
openscad community.
While I don't disagree, I've been bitten more than once by clashing
names within libraries. These cause mayhem that's very hard to debug.
Namespaces, or at least a convention on naming within libraries to avoid
these issues, would soon turn out to be pretty important IMO.
OpenSCAD mailing list
$ Runsun Pan, PhD $ libs: scadx , doctest , faces ( git ), offline doc ( git ), runscad.py ( 2 , git ), editor of choice: CudaText ( OpenSCAD lexer ); $ Tips ; $ Snippets
--
Sent from: http://forum.openscad.org/
I believe the existing of a standard package manager will prompt owners to
write libs with specific names.
Gadgetmind wrote
> On 04/03/18 01:40, Len Trigg wrote:
>> I think that a decent package manager would be a good addition to the
>> openscad community.
>
> While I don't disagree, I've been bitten more than once by clashing
> names within libraries. These cause mayhem that's *very* hard to debug.
>
> Namespaces, or at least a convention on naming within libraries to avoid
> these issues, would soon turn out to be pretty important IMO.
>
>
>
> _______________________________________________
> OpenSCAD mailing list
> Discuss@.openscad
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
-----
$ Runsun Pan, PhD $ libs: scadx , doctest , faces ( git ), offline doc ( git ), runscad.py ( 2 , git ), editor of choice: CudaText ( OpenSCAD lexer ); $ Tips ; $ Snippets
--
Sent from: http://forum.openscad.org/
JF
Joe Francis
Tue, Mar 13, 2018 12:08 AM
I worried about this quite a bit while working on scad_bundler (a
different package manager).
This is actually less of an issue than it appears if libraries are built
well. See the Conventions listed on the github page for scad_bundler,
the 3rd bullet and later is meant to address this and it seems to work
pretty well (so far) in practice.
https://github.com/lostapathy/scad_bundler#draft-conventions
On 03/12/2018 06:59 PM, runsun wrote:
I believe the existing of a standard package manager will prompt owners to
write libs with specific names.
Gadgetmind wrote
On 04/03/18 01:40, Len Trigg wrote:
I think that a decent package manager would be a good addition to the
openscad community.
While I don't disagree, I've been bitten more than once by clashing
names within libraries. These cause mayhem that's very hard to debug.
Namespaces, or at least a convention on naming within libraries to avoid
these issues, would soon turn out to be pretty important IMO.
I worried about this quite a bit while working on scad_bundler (a
different package manager).
This is actually less of an issue than it appears if libraries are built
well. See the Conventions listed on the github page for scad_bundler,
the 3rd bullet and later is meant to address this and it seems to work
pretty well (so far) in practice.
https://github.com/lostapathy/scad_bundler#draft-conventions
On 03/12/2018 06:59 PM, runsun wrote:
> I believe the existing of a standard package manager will prompt owners to
> write libs with specific names.
>
>
> Gadgetmind wrote
>> On 04/03/18 01:40, Len Trigg wrote:
>>> I think that a decent package manager would be a good addition to the
>>> openscad community.
>> While I don't disagree, I've been bitten more than once by clashing
>> names within libraries. These cause mayhem that's *very* hard to debug.
>>
>> Namespaces, or at least a convention on naming within libraries to avoid
>> these issues, would soon turn out to be pretty important IMO.
>>
R
runsun
Tue, Mar 13, 2018 1:00 AM
Interesting. I didn't know OpenSCAD has so-called 'public' var and 'private'
var. I really can't figure this out: Suppose I have 3 scads file:
============================
private.scad
abc="private";
public.scad
include <private.scad>
function f()= abc; // <=== use the private var
abc = "public"; // <== define the public var
user.scad
include <public.scad>
echo( private= f());
echo( public= abc);
Following your description on the "#draft-conventions", this will give
ECHO: private = "private"
ECHO: public = "public"
But it's not. Can you show an example ?
lostapathy wrote
$ Runsun Pan, PhD $ libs: scadx , doctest , faces ( git ), offline doc ( git ), runscad.py ( 2 , git ), editor of choice: CudaText ( OpenSCAD lexer ); $ Tips ; $ Snippets
--
Sent from: http://forum.openscad.org/
Interesting. I didn't know OpenSCAD has so-called 'public' var and 'private'
var. I really can't figure this out: Suppose I have 3 scads file:
============================
*private.scad*
abc="private";
--------------------------------------------------
*public.scad*
include <private.scad>
function f()= abc; // <=== use the private var
abc = "public"; // <== define the public var
--------------------------------------------------
*user.scad*
include <public.scad>
echo( private= f());
echo( public= abc);
============================
Following your description on the "#draft-conventions", this will give
ECHO: private = "private"
ECHO: public = "public"
But it's not. Can you show an example ?
lostapathy wrote
> https://github.com/lostapathy/scad_bundler#draft-conventions
-----
$ Runsun Pan, PhD $ libs: scadx , doctest , faces ( git ), offline doc ( git ), runscad.py ( 2 , git ), editor of choice: CudaText ( OpenSCAD lexer ); $ Tips ; $ Snippets
--
Sent from: http://forum.openscad.org/
JF
Joe Francis
Tue, Mar 13, 2018 1:11 AM
In your case - private.scad gets (effectively) inlined into public.scad
- because it uses include instead of use.
So try this example:
###############################
~/scad_example $ cat private.scad
module priv_mod() {
echo("I'm private");
}
###############################
~/scad_example $ cat public.scad
use <private.scad>
module pub_mod() {
priv_mod();
//also do other things
}
###############################
~/scad_example $ cat user.scad
use <public.scad>
echo("calling pub_mod()");
pub_mod();
echo("calling priv_mod()");
priv_mod();
###############################
~/scad_example $ openscad-nightly user.scad -o blank.png
ECHO: "calling pub_mod()"
ECHO: "I'm private"
ECHO: "calling priv_mod()"
WARNING: Ignoring unknown module 'priv_mod'.
Compiling design (CSG Products normalization)...
###############################
I this case - user.scad is use'ing public.scad. So while public.scad is
able to call priv_mod() on it's behalf, user.scad can't call that module
directly.
Joe
On 03/12/2018 08:00 PM, runsun wrote:
Interesting. I didn't know OpenSCAD has so-called 'public' var and 'private'
var. I really can't figure this out: Suppose I have 3 scads file:
============================
private.scad
abc="private";
public.scad
include <private.scad>
function f()= abc; // <=== use the private var
abc = "public"; // <== define the public var
user.scad
include <public.scad>
echo( private= f());
echo( public= abc);
Following your description on the "#draft-conventions", this will give
ECHO: private = "private"
ECHO: public = "public"
But it's not. Can you show an example ?
lostapathy wrote
In your case - private.scad gets (effectively) inlined into public.scad
- because it uses include instead of use.
So try this example:
###############################
~/scad_example $ cat private.scad
module priv_mod() {
echo("I'm private");
}
###############################
~/scad_example $ cat public.scad
use <private.scad>
module pub_mod() {
priv_mod();
//also do other things
}
###############################
~/scad_example $ cat user.scad
use <public.scad>
echo("calling pub_mod()");
pub_mod();
echo("calling priv_mod()");
priv_mod();
###############################
~/scad_example $ openscad-nightly user.scad -o blank.png
ECHO: "calling pub_mod()"
ECHO: "I'm private"
ECHO: "calling priv_mod()"
WARNING: Ignoring unknown module 'priv_mod'.
Compiling design (CSG Products normalization)...
###############################
I this case - user.scad is use'ing public.scad. So while public.scad is
able to call priv_mod() on it's behalf, user.scad can't call that module
directly.
Joe
On 03/12/2018 08:00 PM, runsun wrote:
> Interesting. I didn't know OpenSCAD has so-called 'public' var and 'private'
> var. I really can't figure this out: Suppose I have 3 scads file:
>
> ============================
> *private.scad*
> abc="private";
> --------------------------------------------------
> *public.scad*
> include <private.scad>
>
> function f()= abc; // <=== use the private var
> abc = "public"; // <== define the public var
> --------------------------------------------------
> *user.scad*
> include <public.scad>
>
> echo( private= f());
> echo( public= abc);
> ============================
>
> Following your description on the "#draft-conventions", this will give
>
> ECHO: private = "private"
> ECHO: public = "public"
>
> But it's not. Can you show an example ?
>
>
> lostapathy wrote
>> https://github.com/lostapathy/scad_bundler#draft-conventions
>
>
>
>
> -----
>
> $ Runsun Pan, PhD $ libs: scadx , doctest , faces ( git ), offline doc ( git ), runscad.py ( 2 , git ), editor of choice: CudaText ( OpenSCAD lexer ); $ Tips ; $ Snippets
>
> --
> Sent from: http://forum.openscad.org/
>
> _______________________________________________
> OpenSCAD mailing list
> Discuss@lists.openscad.org
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>
R
runsun
Tue, Mar 13, 2018 2:17 AM
But, your intention is to solve name collisions. In your example, "priv_mod"
and "pub_mod" are DIFFERENT names. By nature there is no conflict exists. So
why bother all this design ?
$ Runsun Pan, PhD $ libs: scadx , doctest , faces ( git ), offline doc ( git ), runscad.py ( 2 , git ), editor of choice: CudaText ( OpenSCAD lexer ); $ Tips ; $ Snippets
--
Sent from: http://forum.openscad.org/
But, your intention is to solve name collisions. In your example, "priv_mod"
and "pub_mod" are DIFFERENT names. By nature there is no conflict exists. So
why bother all this design ?
-----
$ Runsun Pan, PhD $ libs: scadx , doctest , faces ( git ), offline doc ( git ), runscad.py ( 2 , git ), editor of choice: CudaText ( OpenSCAD lexer ); $ Tips ; $ Snippets
--
Sent from: http://forum.openscad.org/
JF
Joe Francis
Tue, Mar 13, 2018 3:23 AM
I was trying to illustrate that user.scad doesn't know about priv_mod()
at all - it's scope ends in prublic.scad, if you will. But what that
means is we can have more than one priv_mod() in different files, so
long as the same file doesn't use/include them both directly.
This is getting hard for email, so I put it on github
https://github.com/lostapathy/openscad-var-scope
I added a public2.scad and private2.scad. Both private.scad and
private2.scad have a module named priv_mod(), but each can only be
called from the file that use'd them. And neither leaks into
user.scad's namespace.
$ openscad user.scad -o blank.png
ECHO: "calling pub_mod()"
ECHO: "I'm private"
ECHO: "calling pub2_mod()"
ECHO: "I'm private 2"
ECHO: "calling priv_mod()"
WARNING: Ignoring unknown module 'priv_mod'.
Hopefully that illustrates it better. I haven't pushed this super hard
in any of my code yet, but it seems to work.
Joe
On 03/12/2018 09:17 PM, runsun wrote:
But, your intention is to solve name collisions. In your example, "priv_mod"
and "pub_mod" are DIFFERENT names. By nature there is no conflict exists. So
why bother all this design ?
I was trying to illustrate that user.scad doesn't know about priv_mod()
at all - it's scope ends in prublic.scad, if you will. But what that
means is we can have more than one priv_mod() in different files, so
long as the same file doesn't use/include them both directly.
This is getting hard for email, so I put it on github
https://github.com/lostapathy/openscad-var-scope
I added a public2.scad and private2.scad. Both private.scad and
private2.scad have a module named priv_mod(), but each can only be
called from the file that use'd them. And neither leaks into
user.scad's namespace.
$ openscad user.scad -o blank.png
ECHO: "calling pub_mod()"
ECHO: "I'm private"
ECHO: "calling pub2_mod()"
ECHO: "I'm private 2"
ECHO: "calling priv_mod()"
WARNING: Ignoring unknown module 'priv_mod'.
Hopefully that illustrates it better. I haven't pushed this super hard
in any of my code yet, but it seems to work.
Joe
On 03/12/2018 09:17 PM, runsun wrote:
> But, your intention is to solve name collisions. In your example, "priv_mod"
> and "pub_mod" are DIFFERENT names. By nature there is no conflict exists. So
> why bother all this design ?
>