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

Add C/C++ diff: scope, modules, packages. #37167

Merged
merged 9 commits into from Oct 25, 2022
Merged

Conversation

ma-laforge
Copy link
Contributor

Some of this information would be well suited for a more general (non-c-specific) section.

But from my observations on Discourse:
C/C++ users are particularly confused with the import/using vs include concepts.

Co-authored-by: Stefan Karpinski <stefan@karpinski.org>
@ma-laforge
Copy link
Contributor Author

Thanks.

@ma-laforge
Copy link
Contributor Author

Help: Correction needed?

Sorry. I think I misunderstood something:
-->https://docs.julialang.org/en/v1/base/constants/#Base.LOAD_PATH

Excerpt from docs for context:


LOAD_PATH

An array of paths for using and import statements to consider as project environments or package directories when loading code. It is populated based on the JULIA_LOAD_PATH environment variable if set; otherwise it defaults to ["@", "@v#.#", "@stdlib"]. Entries starting with @ have special meanings:

  • @ refers to the "current active environment", the initial value of which is initially determined by the JULIA_PROJECT environment variable or the --project command-line option.

My issue.

My PR said the following:

  • To develop a "conventional" application/project in Julia, you can initialize its root directory as a "Project Environment", and house application-specific code/packages there. This provides good control over project dependencies, and future reproducibility.

Though I had not tried it before a few days ago, I thought that was the point of having @ in JULIA_LOAD_PATH. That way, all the submodules of your project could be bundled as subdirectory of your "project environment":

  • However, when I tried putting submodules under the @ directory, julia did not find them.
  • I then explicitly tried to add the hardcoded absolute path to the project environment in JULIA_LOAD_PATH, and julia still would not load said modules.

It is almost like julia doesn't want us to place our packages under the environment path.

Question

Am I mistaken here?

@StefanKarpinski
Copy link
Sponsor Member

The @ entry has to be a project, it cannot be a directory with packages in it, it has to be a project with a project file add such. If you want to load packages from a directory, you can put, e.g. . in the load path.

@ma-laforge
Copy link
Contributor Author

Oh. I understand now that I looked into:

Base.load_path_expand("@somelib") #show what an entry in LOAD_PATH means
Base.load_path() #show everything in LOAD_PATH

LOAD_PATH entries either represent environment paths (locations of Project.toml) - or paths where project directories will be loaded by Julia (mutually exclusive).

@ma-laforge
Copy link
Contributor Author

I suppose this is is probably the best way we could create "conventional" applications in Julia, then:

Sample directory tree (root: a "generated" project)

MyApplication
├── startup.jl
├── Project.toml
├── src
|   ├── MyApplication.jl
|   └── additionalcode1.jl
└── lib
    ├── AppSpecificModule1
    |   └── src
    |       ├── AppSpecificModule1.jl
    |       └── additionalcode1.jl
    └── AppSpecificModule2
        └── src
            ├── AppSpecificModule2.jl
            └── additionalcode1.jl

MyApplication/startup.jl:

using Pkg

#Make sure we have a reproducible environment:
Pkg.activate(joinpath(@__DIR__)) #where startup.jl is located

#Setup LOAD_PATH environment
empty!(LOAD_PATH)
push!(LOAD_PATH, "@", "@stdlib", joinpath(@__DIR__, "lib"))
#NOTE:
# - Don't add: "@v#.#". Don't want user config to modify environment.
# - Now has `MyApplication/lib` to store application-specific code

# Start application
#-------------------------------------------------------------------------------
using MyApplication
MyApplication.run() #User-defined

Command to launch your "conventional" application:

julia --load "MyApplication/startup.jl"

@ma-laforge
Copy link
Contributor Author

Check failing:
On my last commit, I re-merged into the master branch because I thought it might have been the cause of the failures.

It now looks like it had nothing to do with me.

Should I do a rebase or revert my commits something?
I know some people don't like these merge commits in their history.

@ViralBShah ViralBShah added the doc This change adds or pertains to documentation label Sep 6, 2022
@StefanKarpinski
Copy link
Sponsor Member

Would be nice if someone with C++ expertise reviewed this and merged it if it seems good.

Copy link
Sponsor Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some minor tweaks

doc/src/manual/noteworthy-differences.md Outdated Show resolved Hide resolved
doc/src/manual/noteworthy-differences.md Outdated Show resolved Hide resolved
doc/src/manual/noteworthy-differences.md Outdated Show resolved Hide resolved
doc/src/manual/noteworthy-differences.md Outdated Show resolved Hide resolved
doc/src/manual/noteworthy-differences.md Outdated Show resolved Hide resolved
doc/src/manual/noteworthy-differences.md Outdated Show resolved Hide resolved
doc/src/manual/noteworthy-differences.md Outdated Show resolved Hide resolved
doc/src/manual/noteworthy-differences.md Outdated Show resolved Hide resolved
doc/src/manual/noteworthy-differences.md Outdated Show resolved Hide resolved
doc/src/manual/noteworthy-differences.md Outdated Show resolved Hide resolved
@ma-laforge
Copy link
Contributor Author

ma-laforge commented Oct 22, 2022

I'm ok with all of your suggestions @vtjnash.
Am I expected to click on "Commit suggestion"? (Never done this before).

@vtjnash
Copy link
Sponsor Member

vtjnash commented Oct 25, 2022

Yeah, you can do "add suggestion to batch" to all of them in the "files changed" view to easily accept all of them as-written, or copy them locally individually and push the result. But I can also just accept all of them for you and then tag for merging once CI finishes.

@vtjnash vtjnash added the merge me PR is reviewed. Merge when all tests are passing label Oct 25, 2022
@giordano giordano merged commit a1ecc80 into JuliaLang:master Oct 25, 2022
@giordano giordano removed the merge me PR is reviewed. Merge when all tests are passing label Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc This change adds or pertains to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants