EzRyder
MModular
•Created by Jack Clayton on 5/11/2024 in #community-showcase
mojo-pytest: Mojo test runner and pytest plugin
So what I did was to install
pip
by adding it to the mojoproject.toml
file, then manually installing pytest-mojo
from the command line.
pip install git+https://github.com/guidorice/mojo-pytest.git
pytest
now finds my Mojo tests. Is this workaround the 'proper' way to do it when using magic
?13 replies
MModular
•Created by Jack Clayton on 5/11/2024 in #community-showcase
mojo-pytest: Mojo test runner and pytest plugin
Hi @guidorice! I'm using
magic
to manage my Mojo environment, and it seems like I should be able to add pytest-mojo
as a dependency, but it's not working as expected. In short, magic
cannot find pytest-mojo
in PiPy.
Error message:
Here's an excerpt from my mojoproject.toml
file. What am I missing?
13 replies
MModular
•Created by EzRyder on 3/14/2024 in #questions
Mojo Dict: Store struct instances based on a common trait as CollectionElement.
I was hoping for a different answer...this seemed like an elegant solution. 😀
I'd like to store any type that adheres to the trait, even ones that haven't been written yet. I'll play with the Variant and see how it goes.
Thanks Michael!
9 replies
MModular
•Created by EzRyder on 3/14/2024 in #questions
Mojo Dict: Store struct instances based on a common trait as CollectionElement.
I just removed StringKey and synced the latest to GitHub. Only works for MyPet, not YourPet.
9 replies
MModular
•Created by EzRyder on 3/14/2024 in #questions
Mojo Dict: Store struct instances based on a common trait as CollectionElement.
This only works for MyPet (i.e. cats), but not for YourPet (i.e. dogs). Both MyPet and YourPet structs use the trait TPet defined previously in the file.
So I'm trying to assign the Dict with TPet instead of MyPet:
var d = Dict[StringKey, Pet[TPet]]() # Error here
But get this error:
9 replies
MModular
•Created by EzRyder on 3/14/2024 in #questions
Mojo Dict: Store struct instances based on a common trait as CollectionElement.
I just made one more change in the main function to use 'CollectionElement' instead of 'Pet' to define the dictionary (see below). The VS Code IDE is happy with this change, but the compiler throws this error:
Alternate
var d = DictStringKey, CollectionElement # Compiler crashes
9 replies
MModular
•Created by EzRyder on 3/14/2024 in #questions
Mojo Dict: Store struct instances based on a common trait as CollectionElement.
Thanks for the suggestion Michael!
The code below is the Pet struct from my 'playground' example. As you can see, it already matched your suggestion, but Mojo flags it with the error described in my initial post. I just added the @ value with no discernible effect.
Here's a link to my 'playground' file with all the code.
GitHub: https://github.com/johnsoez4/dict
9 replies
MModular
•Created by EzRyder on 2/1/2024 in #questions
error: use of unknown declaration '_ZeroStartingRange'
Thanks @Michael K! I hoped it was something fairly simple. Still learning! 😀
4 replies
MModular
•Created by EzRyder on 1/21/2024 in #questions
Jupyter - Import Custom Mojo Modules?
So I think I have some VS Code weirdness going on, and maybe an issue with Mojo version
0.6.1
. With the Jupyter notebook open, VS Code highlighted the import statement saying it was unable to locate module 'my_name'
, so I prefixed it with the current folder shared.my_name
which made the type checker happy but gave an error when I tried to run the Mojo code. I removed the extra shared.
and it now runs as expected.
Perhaps also important...I updated to Mojo version 0.6.3
Hope this helps anyone else trying to import custom modules in a Jupyter notebook.
Cheers...EzRyder
Edit: In VS Code, I found that I needed to restart the kernel in order for changes in a Mojo module to propagate into the open Jupyter file.
Module: my_name.mojo
Jupyter
Output:
Hi Bob!
3 replies
MModular
•Created by MPloppy on 9/11/2023 in #questions
Why the crappy system-breaking script for installation?
I use OpenSUSE Tumbleweed on my laptop, and would appreciate an rpm repo compatible with Yast to provide easy installation and updates to Mojo. TIA! 😀
10 replies