Package Development

Hi everyone,

I am trying to start using Julia for developing my own package (just for fun), but I am having trouble using my module in, what I call them, “local test files”.

Lets assume I have the following project structure given by the julia package manager generate MyModule:

  • src
    • MyModule.jl
    • test.jl
  • Manifest.toml
  • Project.toml
  • test.jl

I tried creating my test.jl file in the project scope as well as in the src directory, and I also tried all different kind of combinations with include, import, and using, but nothing seemed to be working just fine.
I found a previous, similar question in this thread: Importing package into Main conflicts with an existing identifier - Usage / First steps - JuliaLang, but it did not seem to work out fine for me.

I use julia Version 1.6.2 on Windows 10 Home OS, my IDE is VS Code.
I really don’t know what I am doing wrong.
Any help I get is highly appreciated! Thank you in advance.

Best,
J

There are tests and there are files you just play around with. I think it’s the latter you want.

Try this, just

using MyModule

Try to make sure your environment is activated at the path of your MyModule folder.

Like now if you have done everything correctly, when you add a package. Your Project.toml will change

3 Likes

You should give a try to GitHub - invenia/PkgTemplates.jl: Create new Julia packages, the easy way, it makes creation of packages so much easier and it do everything right from the start.

6 Likes

Thank you, when working with my test.jl file within the src directory, this seems to be working perfectly fine.
Since I am coming from python, I am a great fan of having my namespaces separated, i.e., using import MyModule as MM (or something like that).

Is there a possibility that I can use this formulation within my src/test.jl file?

Thank you, this solved my initial problem!

Thank you for your answer, I had a quick look at it and I will definitely consider using this in some future packages I am planning to make! :slight_smile: