Re: Get module file path from ModuleInfo

2019-06-07 Thread Jacob Carlborg via Digitalmars-d-learn

On 2019-06-06 12:43, Andre Pany wrote:


Also __traits(getUnitTests) does not return the module file name.
The approach above is working fine in the d-unit library
(https://code.dlang.org/packages/d-unit)


Well, to use __traits(getUnitTests) you need to collect all the files 
and generate a new file which imports all the files. Therefore you need 
to know the module name anyway. You can also at the mangled name of a 
unit test (returned by __traits(getUnitTests)), which will start with 
the module name. That's a bit of a hack.


--
/Jacob Carlborg


Re: Why this fails when using unittest?

2019-06-07 Thread Machine Code via Digitalmars-d-learn

On Friday, 7 June 2019 at 16:41:12 UTC, Adam D. Ruppe wrote:

On Friday, 7 June 2019 at 16:33:13 UTC, Machine Code wrote:
All this effort is because I do not want unittest code in a 
release or even debug.


Well, that part is easy:

version(unittest)
struct Foo {}

at any scope is only build when unittests are turned on in this 
build.


Thank you! I was about to read version docs to see if I could 
determine if I was in unittest by versioning. That's exact 
behavior I was trying to acomplish.


I ended up doing this:

version(unittest)
{
  struct Foo { }
  shared static this() {
// test code ...
  }
}

Act like a unittest {} but I can use CTFE stuff nicely.

Thank you all guys.



Re: Why this fails when using unittest?

2019-06-07 Thread Adam D. Ruppe via Digitalmars-d-learn

On Friday, 7 June 2019 at 16:33:13 UTC, Machine Code wrote:
All this effort is because I do not want unittest code in a 
release or even debug.


Well, that part is easy:

version(unittest)
struct Foo {}

at any scope is only build when unittests are turned on in this 
build.





Re: Why this fails when using unittest?

2019-06-07 Thread Machine Code via Digitalmars-d-learn

On Friday, 7 June 2019 at 16:30:34 UTC, Machine Code wrote:
On Thursday, 6 June 2019 at 21:02:37 UTC, Steven Schveighoffer 
wrote:

[...]


Intesting, I also tried to declare it inside a function, that 
did not work either. Is this hidden context pointer a current 
limitation in CTFE? I've tried to declare the struct at module 
level and run the functions on static this() to workaround that 
but to finish, I'd like to eble to run the code in static 
main() only when unnitest is enabled but so I haven't manged to 
do that.


*Imaginary code* would be:

unittest
{
enum enabled = true;
}
else
{
enum enabled = true;
}

but I was on my mind unittest was similar to static if() but as 
it's like a function, there are no else let alone acess to enum 
enabled as true, outside the block but the idea is run (or even 
only declare) a piece of code (which includes that struct) only 
if we are an unittest.


All this effort is because I do not want unittest code in a 
release or even debug. So I want to this be invisible anywhere 
but unittest or at least simulate that wit static if() how I'm 
tring to do


Re: Why this fails when using unittest?

2019-06-07 Thread Machine Code via Digitalmars-d-learn
On Thursday, 6 June 2019 at 21:02:37 UTC, Steven Schveighoffer 
wrote:

On 6/6/19 1:49 PM, Adam D. Ruppe wrote:

On Thursday, 6 June 2019 at 17:40:17 UTC, Machine Code wrote:

outside an unittest, this compiles fine:

struct A


try making it `static struct` instead


cannot implicitly convert expression "hehe" of type string 
to A


Why does inside a unittest it doesn't work? the constructor 
this(string) {} seems to get disabled.


My suspicion is it is trying to access the context of the 
unittest as a hidden paramater to that constructor there... 
and in an enum, it can't, just stupid compiler didn't think to 
mention the hidden arg here.


my guess.


Yes, correct guess. A unittest block is actually a function, so 
it's considered an inner struct with a hidden context pointer.


-Steve


Intesting, I also tried to declare it inside a function, that did 
not work either. Is this hidden context pointer a current 
limitation in CTFE? I've tried to declare the struct at module 
level and run the functions on static this() to workaround that 
but to finish, I'd like to eble to run the code in static main() 
only when unnitest is enabled but so I haven't manged to do that.


*Imaginary code* would be:

unittest
{
enum enabled = true;
}
else
{
enum enabled = true;
}

but I was on my mind unittest was similar to static if() but as 
it's like a function, there are no else let alone acess to enum 
enabled as true, outside the block but the idea is run (or even 
only declare) a piece of code (which includes that struct) only 
if we are an unittest.





Re: Why this fails when using unittest?

2019-06-07 Thread Machine Code via Digitalmars-d-learn

On Thursday, 6 June 2019 at 17:49:58 UTC, Adam D. Ruppe wrote:

On Thursday, 6 June 2019 at 17:40:17 UTC, Machine Code wrote:

outside an unittest, this compiles fine:

struct A


try making it `static struct` instead


didn't work either



cannot implicitly convert expression "hehe" of type string to 
A


Why does inside a unittest it doesn't work? the constructor 
this(string) {} seems to get disabled.


My suspicion is it is trying to access the context of the 
unittest as a hidden paramater to that constructor there... and 
in an enum, it can't, just stupid compiler didn't think to 
mention the hidden arg here.


my guess.


So it's a CTFE limitation in unittest/local functions(I also 
tried to declare that struct inside a function, but did not work 
either). right? assuming it's an error, it's going to be fixed 
anytime soon?


Re: if (X !is null && X.Y !is null) access crash

2019-06-07 Thread Adam D. Ruppe via Digitalmars-d-learn

It happens when I close down my app.


is this inside a destructor?


Re: if (X !is null && X.Y !is null) access crash

2019-06-07 Thread Amex via Digitalmars-d-learn

On Friday, 7 June 2019 at 14:07:34 UTC, KnightMare wrote:

On Friday, 7 June 2019 at 09:26:52 UTC, Amex wrote:

if (X !is null && X.Y !is null) access crash
is crashing.


imo this code is valid. u can write shorter
if (X && X.Y)
probably crashed in some another place (X is not objRef but 
something else.. some code later at same line.. dunno)


The debugger is telling me it is at that line.

X is an object.

In the debugger X is shown with an address yet when expanded all 
the members are invalid. It happens rarely so it makes it even 
harder to diagnose. Only thing I can think of is that it has to 
do with the GC. I suppose I could turn off the GC for shutting 
down and that might prevent such as crash.




Re: if (X !is null && X.Y !is null) access crash

2019-06-07 Thread KnightMare via Digitalmars-d-learn

On Friday, 7 June 2019 at 09:26:52 UTC, Amex wrote:

if (X !is null && X.Y !is null) access crash
is crashing.


imo this code is valid. u can write shorter
if (X && X.Y)
probably crashed in some another place (X is not objRef but 
something else.. some code later at same line.. dunno)


Re: Using python in D

2019-06-07 Thread rnd via Digitalmars-d-learn

On Friday, 7 June 2019 at 10:55:22 UTC, JN wrote:

On Friday, 7 June 2019 at 05:04:30 UTC, rnd wrote:

On Friday, 7 June 2019 at 04:39:14 UTC, rikki cattermole wrote:

On 07/06/2019 3:54 PM, rnd wrote:


How should I 'initialize python' ?


The example is probably a good place to begin.

https://github.com/ariovistus/pyd/blob/master/examples/simple_embedded/hello.d


Thanks for the link. After putting in missing statements, it 
started running but reported:


 exceptions.ImportError: No module named pandas

I believe pyd is working on Python2 while I have pandas 
installed in Python3.


How can I specify Python version 3 in pyd?


https://github.com/ariovistus/pyd

"To use with dub, either specify the relevant subConfiguration 
for your python version, or run source pyd_set_env_vars.sh 
 on linux or pyd_set_env_vars.bat  on 
windows to set the relevant environment variables and use the 
env subConfiguration."


I tried following in dub.selections.json file:

{
"fileVersion": 1,
"versions": {
"pyd": "0.10.5"
},
"subConfigurations": {
"pyd": "python35"
}
}

I also tried python3.5 and python3 in place of python35, but 
everytime python27 is being used (where pandas is not installed). 
The error is:


$ dub run
Performing "debug" build using /usr/bin/dmd for x86_64.
pyd 0.10.5: target for configuration "python27" is up to date.   
<<< NOTE VERSON HERE;

rntestpy ~master: building configuration "application"...
Linking...
To force a rebuild of up-to-date targets, run again with --force.
Running ./rntestpy
pyd.exception.PythonException@/home/cardio/.dub/packages/pyd-0.10.5/pyd/infrastructure/pyd/pydobject.d(59):
exceptions.ImportError: No module named pandas

/home/cardio/.dub/packages/pyd-0.10.5/pyd/infrastructure/pyd/exception.d:46 
void pyd.exception.handle_exception(immutable(char)[], ulong) [0x56438721e9e8]
/home/cardio/.dub/packages/pyd-0.10.5/pyd/infrastructure/pyd/pydobject.d:59 
pyd.pydobject.PydObject 
pyd.pydobject.PydObject.__ctor(deimos.python.object.PyObject*) [0x56438721f2e8]
/home/cardio/.dub/packages/pyd-0.10.5/pyd/infrastructure/pyd/embedded.d:54 
pyd.pydobject.PydObject pyd.embedded.py_import(immutable(char)[]) 
[0x56438721e501]
source/main.d:6 _Dmain [0x56438721ded0]
Program exited with code 1

I also tried command "dub run --force" but still the error 
persists.


I also tried to give command "source pyd_set_env_vars.sh 
/usr/bin/python3" but still it is not working.


Another command which I tried produced following output but still 
the problem persisted:


$ python3 pyd_get_env_set_text.py
export PYD_D_VERSION_1=Python_2_4_Or_Later
export PYD_D_VERSION_2=Python_2_5_Or_Later
export PYD_D_VERSION_3=Python_2_6_Or_Later
export PYD_D_VERSION_4=Python_2_7_Or_Later
export PYD_D_VERSION_5=Python_3_0_Or_Later
export PYD_D_VERSION_6=Python_3_1_Or_Later
export PYD_D_VERSION_7=Python_3_2_Or_Later
export PYD_D_VERSION_8=Python_3_3_Or_Later
export PYD_D_VERSION_9=Python_3_4_Or_Later
export PYD_D_VERSION_10=Python_3_5_Or_Later
export PYD_D_VERSION_11=__PYD__DUMMY__
export PYD_D_VERSION_12=__PYD__DUMMY__
export PYD_D_VERSION_13=__PYD__DUMMY__
export PYD_LIBPYTHON_DIR=/usr/lib
export PYD_LIBPYTHON=python3.5m

Where could be the problem and how can it be solved?



Re: Using python in D

2019-06-07 Thread Rnd via Digitalmars-d-learn

On Friday, 7 June 2019 at 10:55:22 UTC, JN wrote:

On Friday, 7 June 2019 at 05:04:30 UTC, rnd wrote:

On Friday, 7 June 2019 at 04:39:14 UTC, rikki cattermole wrote:

On 07/06/2019 3:54 PM, rnd wrote:


How can I specify Python version 3 in pyd?


https://github.com/ariovistus/pyd

"To use with dub, either specify the relevant subConfiguration 
for your python version, or run source pyd_set_env_vars.sh 
 on linux or pyd_set_env_vars.bat  on 
windows to set the relevant environment variables and use the 
env subConfiguration."


After executable is created, will it work on systems where Python 
and pandas are not installed?


Blog Post #0042 - File Dialog VIII - Custom Dialogs (1 of 3)

2019-06-07 Thread Ron Tarrant via Digitalmars-d-learn
Today starts a mini-series within a series about rolling yer own 
Dialogs. And because aesthetics is such a big part of doing 
layout, we start with a mini crash course in design. Here's the 
link: http://gtkdcoding.com/2019/06/07/0042-custom-dialog-i.html


Re: Using python in D

2019-06-07 Thread JN via Digitalmars-d-learn

On Friday, 7 June 2019 at 05:04:30 UTC, rnd wrote:

On Friday, 7 June 2019 at 04:39:14 UTC, rikki cattermole wrote:

On 07/06/2019 3:54 PM, rnd wrote:


How should I 'initialize python' ?


The example is probably a good place to begin.

https://github.com/ariovistus/pyd/blob/master/examples/simple_embedded/hello.d


Thanks for the link. After putting in missing statements, it 
started running but reported:


 exceptions.ImportError: No module named pandas

I believe pyd is working on Python2 while I have pandas 
installed in Python3.


How can I specify Python version 3 in pyd?


https://github.com/ariovistus/pyd

"To use with dub, either specify the relevant subConfiguration 
for your python version, or run source pyd_set_env_vars.sh python> on linux or pyd_set_env_vars.bat  on windows 
to set the relevant environment variables and use the env 
subConfiguration."


Re: FieldNameTuple!T and std.traits.Fields!T not empty for interfaces

2019-06-07 Thread Amex via Digitalmars-d-learn
On Thursday, 6 June 2019 at 20:52:42 UTC, Steven Schveighoffer 
wrote:

On 6/6/19 4:49 PM, Steven Schveighoffer wrote:
Oh wait! It's not empty, it has an empty string as a single 
member! That's definitely a bug.




OK, not a bug, but not what I would have expected. From docs:

"If T isn't a struct, class, or union, an expression tuple with 
an empty string is returned."


I wonder why that behavior is there, certainly it's intentional.

-Steve


It is wrong, regardless if it is intentional. Every day people do 
intentional things that are wrong.


The problem is that one returns a non-empty tuple and so loops 
will be executed on the empty string. While one can test for the 
empty string return there is absolutely no reason why one 
shouldn't just return an empty tuple as it plays correctly with 
the use case.





if (X !is null && X.Y !is null) access crash

2019-06-07 Thread Amex via Digitalmars-d-learn

I don't understand why

if (X !is null && X.Y !is null) access crash

is crashing.

It is true that it is being used in a thread. It happens when I 
close down my app.


The whole point of the check is to make sure X is not null but it 
seems to be failing.


The debugger is showing X is not null yet X.Y is null. (Y is a 
delegate)


I believe this is because I'm not using shared(which causes 
problems with orange serdes) and the GC.


I'm not sure though.