Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preferred way to develop source #62

Closed
jessebett opened this issue Jun 27, 2019 · 11 comments
Closed

Preferred way to develop source #62

jessebett opened this issue Jun 27, 2019 · 11 comments

Comments

@jessebett
Copy link
Contributor

@Datseris could you give an example for how you set up your src for a project.

I had some trouble following the REPL-Based Workflow. In which I created a module file in src which includes other source files. Then in a script I would include(srcdir()*"module.jl") and using .ModuleName which worked fine. However, developing wasn't great because changes to the source files or module would not be updated by Revise, and reloading them got conflict warnings.

Instead I'm currently pushing the src directory to my LOAD_PATH and using the module in a usual way. This works well with Revise, but isn't really nice.

You mentioned that a better solution would be to ]dev? Is this in the src directory or the entire project directory? I probably misunderstand what ]dev does, but I thought it needed to be a package (though I'm not sure what that entails).

@asinghvi17
Copy link
Member

You can dev any project with a Project.toml that has a name, UUID, and src/ProjectName.jl. That will play well with Revise AFAIK - it just informs Julia that the package will change.

@jessebett
Copy link
Contributor Author

Okay, but following the default setup from the DrWatson docs my Project.toml has no UUID. So I cannot ]dev .. Any idea there?

@jessebett
Copy link
Contributor Author

Further, if I get a uuid from Pkg.generate and put it in there, I cannot ]dev . because, understandably, ERROR: Cannot develop package with same name or uuid as the project.

@asinghvi17
Copy link
Member

Switch to the global env and then dev it? Should work then.

@jessebett
Copy link
Contributor Author

Switch to the global env, dev it, then switch back? Or are you proposing I work inside the global env which would defeat the whole purpose of working in a project, no?

@jessebett
Copy link
Contributor Author

And that doesn't address that Project.toml has no UUID by default, so this is likely not the intended method to develop the project.

I already have a patch (which is to push the srcdir to the LOAD_PATH but I'm trying to learn the correct/intended way to do this, instead of workarounds. It seems to me that if I have to manually generate a UUID, add it to the Project.toml and ]dev from outside my project env, then something isn't right.

The main consideration is that this should be easily reproducible. That I should be able to just hand this repo to someone else and have it work. That definitely won't be easy if there needs to be messing with LOAD_PATH or environments to get the scripts to work with using MyModule...

@Datseris
Copy link
Member

Hi @jessebett , thanks for opening this. I will now address your questions, and I hope I can resolve your confusions. Before that though, I need to stress the following point:

  • DrWatson is not a package to help you develop a Julia package. It is a package to help you manage your scientific project, which is represented by a Julia project. Notice that a Julia project does not have to be a Julia package. (But by definition, a Julia package is always a Julia project).

As you have already mentioned:

And that doesn't address that Project.toml has no UUID by default, so this is likely not the intended method to develop the project.

That is correct and is on purpose. The Project.toml file represents your scientific project, not a Julia package. What I assume you want to do is include a Julia package you are developing inside your own project.

This is how I do it, and how I suggest you do it:

image

Above, kwant_graphene, is my scientific project, which is also a Julia project, and is initialized by DrWatson. I use DrWatson throughout this project. In my src folder you will first see that I have some casual script files that define core functions, e.g. HusimiPlotting.jl. These files I normally include in all my script.

What you will see is that inside my project's src folder I also have two Julia packages, Chebyshev, HusimiFunctions. These are proper Julia packages in every sense of the way. I develop them normally and include them in my project normally using using HusimiFunctions and update them in real time with e.g. Revise. To create this setup you need the following steps:

  1. Active your project that uses DrWatson.
  2. Change directory to the project's src folder.
  3. Go into package mode and initialize a package with the name that you want (in my case HusimiFunctions)
  4. dev the local path to HusimiFunctions using the package manager , e.g. dev /path/to/project/src/HusimiFunctions. It is strongly recommended to dev this using local paths instead, see this PR that will be merged soon: Highlight a bit more the posibility of relative paths JuliaLang/Pkg.jl#1215

That is it.

If this solves your concerns please let me know and I will put it into DrWatson's documentation as is.

@Datseris
Copy link
Member

Datseris commented Jul 2, 2019

@jessebett can you please tell me if this was okay for you?

@jessebett
Copy link
Contributor Author

Hi @Datseris. Yes, you are correct that my issue was conflating packages and projects. I've compartmentalized the package into its own sub-directory as you've suggested and it works for me. I agree that this could be worth highlighting in the docs.

@Datseris
Copy link
Member

Datseris commented Jul 2, 2019

Thanks, will do so soon! :)

@asinghvi17
Copy link
Member

Might also be worth using git submodules? Could be too much hassle though...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants