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

Should the CurrentEnv path be set at julia startup and not follow with the pwd? #27411

Closed
KristofferC opened this issue Jun 4, 2018 · 15 comments
Labels
packages Package management and loading
Milestone

Comments

@KristofferC
Copy link
Member

KristofferC commented Jun 4, 2018

Opening this issue after some discussion on slack.

Currently, the CurrentEnv in LOAD_PATH (the one that says what project file you should use based on your path) looks at the pwd of the julia session. This means that if you cd somewhere and there happens to be a project file there, you will load packages for that project. Or if you cd somewhere where there is no project, you will start loading from the NamedEnv.

It could be argued that tying code loading to pwd is a bit brittle and that the path should be set at julia startup and require some explicit invokation to update to the current pwd would make it less likely to be consfused about what environment you are currently in.

cc @mortenpi, @quinnj, @davidanthoff, @StefanKarpinski

@KristofferC KristofferC added the packages Package management and loading label Jun 4, 2018
@KristofferC KristofferC changed the title Should the CurrentEnv path be set at julia startup and not follow with the pwd Should the CurrentEnv path be set at julia startup and not follow with the pwd? Jun 4, 2018
@StefanKarpinski
Copy link
Member

The consensus on Slack seems to be that using the initial pwd() would be better and having some explicit function for changing the current working directory. Bikeshed: what to call the function/command to change the current env directory?

@davidanthoff
Copy link
Contributor

I think using pwd() by default is great, but it might also be useful to have either a command line argument to pass an explicit path, or maybe an environmental var?

If there is a way to change the env from within a julia session, would that be allowed at any point? Even if one has loaded a package already?

@StefanKarpinski
Copy link
Member

You can use JULIA_LOAD_PATH to change it to anything you want. Inside of a running Julia session, you can manipulate LOAD_PATH to get the same effect.

@DrKrar
Copy link
Contributor

DrKrar commented Jun 4, 2018

I think it would be nice if the CurrentEnv does not change merely just for the current path. It would be nice if there is an explicit way to do this.

@StefanKarpinski
Copy link
Member

Adding command line options to control this conveniently is definitely in the plans. Some discussion is needed about what they should be called and how they should work, of course.

@KristofferC KristofferC added the triage This should be discussed on a triage call label Jun 13, 2018
@KristofferC KristofferC added this to the 0.7 milestone Jun 13, 2018
@staticfloat
Copy link
Member

what to call the function/command to change the current env directory?

I would vote forPkg.activate(). It's similar to python's virtual environments, and sounds cool.

@StefanKarpinski
Copy link
Member

See also JuliaLang/Pkg.jl#360: I'm not familiar with direnv but I do think we need to have an explicit step to "bless" an environment for automatic loading and/or activation.

@KristofferC
Copy link
Member Author

Triage didn't reach a decision here, punting for next week (when more people are on the call).

StefanKarpinski added a commit that referenced this issue Jun 19, 2018
This makes LOAD_PATH just a vector of strings again. Some
special syntaxes in JULIA_LOAD_PATH are handled specially:

- split on `:` or `;` (on Windows)
- replace the first empty entry with DEFAULT_LOAD_PATH
- ignore the remaining empty entries
- replace `@` with `current_env()`

Other special syntaxes are left alone and expanded during
load path lookup:

- occurrences of `#` in `@...` entries to version digits
- `@name` is looked up in the depot path
- `@` is replaced with `current_env()`

The last functionality is not accessible via JULIA_LOAD_PATH
in this version since `@` in that is expanded early. This does
allow putting a literal `@` in LOAD_PATH to get late expansion
to `current_env()` instead of early expansion.

Fixes #27411
StefanKarpinski added a commit that referenced this issue Jun 19, 2018
This makes LOAD_PATH just a vector of strings again. Some
special syntaxes in JULIA_LOAD_PATH are handled specially:

- split on `:` or `;` (on Windows)
- replace the first empty entry with DEFAULT_LOAD_PATH
- ignore the remaining empty entries
- replace `@` with `current_env()`

Other special syntaxes are left alone and expanded during
load path lookup:

- occurrences of `#` in `@...` entries to version digits
- `@name` is looked up in the depot path
- `@` is replaced with `current_env()`

The last functionality is not accessible via JULIA_LOAD_PATH
in this version since `@` in that is expanded early. This does
allow putting a literal `@` in LOAD_PATH to get late expansion
to `current_env()` instead of early expansion.

Fixes #27411
@StefanKarpinski
Copy link
Member

#27633 changes this to be resolved early: @ in JULIA_LOAD_PATH is expanded at startup time to Base.current_env(). However, it also removes it from the default LOAD_PATH, which after that PR is just ["@v#.#", "@stdlib"], i.e. a named environment for the current Julia version and the standard libraries. With that PR someone can do the following in their shell to prepend the current environment to their load path:

export JULIA_LOAD_PATH="@:$JULIA_LOAD_PATH"

This works whether JULIA_LOAD_PATH is defined beforehand or not since an empty entry in JULIA_LOAD_PATH is expanded to the default contents of LOAD_PATH.

@KristofferC
Copy link
Member Author

I don't think this is resolved yet since some new things got merged.

@KristofferC KristofferC reopened this Jun 25, 2018
@StefanKarpinski
Copy link
Member

It got deresolved. The current situation is that @@ is in the default load path and acts like the old CurrentEnv. I still think that it should not be in the default load path. One of the action items to fix that was to implement pkg> activate which we did; the other was to fix the travis/other CI scripts that relied on the current behavior; I asked for some feedback on that on Slack but didn't get any so I didn't want to break everything in the beta. Unfortunately, that means that we either leave things as in 0.7/1.0 final and have a potential security trap in Julia OR we have to change this before RC1 which will be fairly breaking. I still don't really understand what needs to be done on the travis/CI script side.

@StefanKarpinski StefanKarpinski removed the triage This should be discussed on a triage call label Jun 28, 2018
@JeffBezanson
Copy link
Member

Does this still block 0.7?

@StefanKarpinski
Copy link
Member

It does but it's fixed.

@ufechner7
Copy link

ufechner7 commented Jul 17, 2018

StefanKarpinski wrote:

The current situation is that @@ is in the default load path and acts like the old CurrentEnv.

Is that still the case?

@StefanKarpinski
Copy link
Member

StefanKarpinski commented Jul 17, 2018

No, the current situation is that by default LOAD_PATH = ["@", "@v#.#", "@stdlib"] which gets expanded to:

  1. Your current active project (if any)
  2. ~/.julia/environments/v0.7/Project.toml
  3. the location of the standard library.

The initial active project can be set by the JULIA_PROJECT environment variable and the new --project command-line flag. If you just pass --project then the project containing the current working directory when you start up julia is the initial active project.

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

No branches or pull requests

7 participants