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

Cannot run conda 4.4 in a batch script #6553

Closed
isuruf opened this issue Dec 23, 2017 · 27 comments
Closed

Cannot run conda 4.4 in a batch script #6553

isuruf opened this issue Dec 23, 2017 · 27 comments
Labels
¡breaking! used to indicate that the code change will likely require a minor or major version bump cli pertains to the CLI interface locked [bot] locked due to inactivity pending::discussion contains some ongoing discussion that needs to be resolved prior to proceeding source::community catch-all for issues filed by community members

Comments

@isuruf
Copy link
Contributor

isuruf commented Dec 23, 2017

For example if I run a .bat file with

conda --version
echo asd

then only the first line is executed.

cc @kalefranz, this is the reason for the error @jdblischak mentioned in #6527

@kalefranz
Copy link
Contributor

kalefranz commented Dec 23, 2017

Ok, this is all then related to something we've done in https://github.com/conda/conda/blob/1a3353accd4b782835b9736627f890337ff488c1/conda/shell/Library/bin/conda.bat

On Windows for conda 4.4, what you get when you type the command conda is actually that conda.bat file, and not conda.exe. It's a level of shell indirection for the cmd.exe shell. For other shells, bash for example, we've implemented conda as a shell function. Using this conda.bat file is what we were stuck with for cmd.exe though.

@kalefranz
Copy link
Contributor

We probably need to add a lot of

@IF errorlevel 1 exit /b 1

checks to that file.

@isuruf
Copy link
Contributor Author

isuruf commented Dec 23, 2017

Windows shell cmd.exe works differently than bash. When you run a batch script from one batch script control is given to the child script and the parent is simply stopped. To avoid this and have the child return control to the parent you need to use the command call.

Instead of

conda --version
echo asd

you now need to use

call conda --version
echo asd

otherwise the 2nd line will not be run anymore.

@kalefranz
Copy link
Contributor

kalefranz commented Dec 23, 2017

What if, instead, your bat script was

conda.exe --version
echo asd

Is that a possible fix? I realize, if it is a fix, it does require a change to existing code that was relying on old behavior. I'm afraid we might be stuck here with a solution like that though.

@isuruf
Copy link
Contributor Author

isuruf commented Dec 23, 2017

Yes, that works, but the rest of conda.bat is not run. Isn't that a problem?

@isuruf
Copy link
Contributor Author

isuruf commented Dec 23, 2017

Would conda be supporting using the activate.bat script in the future? If so, calling the activate script and then running conda.exe is okay

@kalefranz
Copy link
Contributor

Would conda be supporting using the activate.bat script in the future?

We want to get rid of the activate "executable", because it has name collisions with something like virtualenv's activate. But I agree that we have an unsolved issue here before we can fully end up deprecating it.

but the rest of conda.bat is not run. Isn't that a problem?

The answer is, it depends. For now, using conda.exe instead of conda is no different than what we had in 4.3. Besides adding real conda activate and conda deactivate commands, the only other thing conda.bat does is call "reactivate" for install, update, and remove. But conda 4.3 never did "reactivate", so at least you're no worse off using conda.exe.

@mbargull
Copy link
Member

Maybe we could add something like

@call :run
@goto :eof
:run

at the top of conda.bat to always run the rest inside a call? That just came to mind but I haven't tried it out yet.

@mbargull
Copy link
Member

I'm not sure about the exit status propagation for this, though...

@kalefranz
Copy link
Contributor

I was hoping you might have some ideas here @mbargull :)

@mbargull
Copy link
Member

nvm, thinking about it, it is exactly as @isuruf said

When you run a batch script from one batch script control is given to the child script and the parent is simply stopped. To avoid this and have the child return control to the parent you need to use the command call.

So I'm not sure we can use a batch file-only solution if we want to make conda ... work without call in batch files :/ .. Am thinking about it some more time...

@kalefranz
Copy link
Contributor

We're probably just stuck with the constraints of batch scripting and cmd.exe. Eventually when we have the conda.bat pattern more broadly established, maybe we can just switch everybody writing batch scripts to use call conda. In the interim, while people are flipping back and forth between 4.3 and 4.4, conda.exe seems like the best solution.

@mbargull
Copy link
Member

mbargull commented Dec 23, 2017

Yeah, I can't come up with a solution which supports the non-call usage but uses conda.bat..
A question might be whether you would might just want to deprecate the old usage but support it until some 4.5 version [EDIT]gets released[/EDIT] to allow a transition phase. That would mean to not add shell/Library/bin to path on default for Windows, i.e., withheld the 4.4 shell function/conda activate feature on Windows for some time.

@kalefranz
Copy link
Contributor

kalefranz commented Dec 23, 2017

Lots of packages require that $PREFIX/Library/bin is added to PATH, on activate. So it would mean I think keeping conda.bat out of that directory.

I guess we could consider moving conda.bat to the $PREFIX/bin directory, but I'm not keen on that solution either.

    def _get_path_dirs(self, prefix):
        if on_win:  # pragma: unix no cover
            yield prefix.rstrip("\\")
            yield join(prefix, 'Library', 'mingw-w64', 'bin')
            yield join(prefix, 'Library', 'usr', 'bin')
            yield join(prefix, 'Library', 'bin')
            yield join(prefix, 'Scripts')
            yield join(prefix, 'bin')
        else:
            yield join(prefix, 'bin')

That set of paths for activate now is pretty set in stone. Those assumptions are baked into a bunch of existing conda packages.

@mbargull
Copy link
Member

Ah, I just didn't look at the install scripts and thus didn't notice
https://github.com/conda/conda/blob/4.4.3/utils/functions.sh#L192-L196
and thought conda.bat would still be inside shell (with shell being added to also added to $PATH, too). Removing Library/bin from $PATH would of course be no option and moving conda.bat to bin doesn't sound good to me, likewise. Currently, I don't have any further ideas :/ ...
(Stupid CMD! Let's just dream of an utopia with world peace and a decommissioned CMD... dammit!)

@mingwandroid
Copy link
Contributor

Well Powershell is deprecating cmd so I wonder if we shouldn't just do the best we can there (I know nothing about Powershell though) and support only using call for cmd?

@kalefranz
Copy link
Contributor

kalefranz commented Dec 23, 2017

All the other shell wrappers are working out pretty well I think. Even the conda.bat isn't that bad, although this is certainly and issue. So is the question of what we do when we deprecate activate.bat (I have ideas there).

Actually, the only wrapper that's still pending to go into 4.4 is the powershell one. I have NO experience there though, and really don't know the best practices "powershell way" on how to implement that. At least there are plenty of examples now in the conda/shell directory for all the other wrappers. And I did start #6471.

@mbargull
Copy link
Member

and support only using call for cmd? (@mingwandroid)

Of course, I agree you should

just switch everybody writing batch scripts to use call conda (@kalefranz)

as soon as possible since I think the more unified shell handling with the wrappers, including conda.bat, is a really nice step forward! If it's possible to create a transitioning period, that would be nice, I guess, but if it's not easily done, pushing the unified concept should be more important, IMHO.
(As for Powershell, absolutely no experience here either -- scurried away from Windows before that became more widely known.)

@kalefranz
Copy link
Contributor

scurried away from Windows before that became more widely known

I just installed powershell on my mac. 😱

pwsh

Yes, they changed the executable name for unix from what it is on Windows. Microsoft maybe just won't ever learn.

@isuruf
Copy link
Contributor Author

isuruf commented Dec 24, 2017

Maybe this should go in another issue, but note that you'll run into trouble updating conda.bat in the future as the batch script will be changing itself and it'll error out if you change anything above the invocation to conda.exe.

@kalefranz
Copy link
Contributor

9a774a6d-c480-4f7a-81e7-ae605510f965

Roel pushed a commit to Roel/pydov that referenced this issue Jan 10, 2018
Roel added a commit to DOV-Vlaanderen/pydov that referenced this issue Jan 10, 2018
Add tox, travis and appveyor environments for variations with and without lxml.

Since we use either the integrated XML parsing of Python or the one provided by the 'lxml' library, it is best to run our tests in both setups. Especially since lxml supports additional functionality, so we have to make sure not to rely on this in the code.
OWSLib has a similar testing environment.

Also: use conda.exe to avoid issues with the new conda.bat
See conda/conda#6527
and conda/conda#6553
@kalefranz
Copy link
Contributor

Maybe this should go in another issue, but note that you'll run into trouble updating conda.bat in the future as the batch script will be changing itself and it'll error out if you change anything above the invocation to conda.exe.

I actually think we have this problem all the time now. We've tried to deal with it multiple times in multiple ways, and where we are right now with it is #6631. Trying again to address the issue in #6660, but I've sunk a lot of time into that and still haven't been successful yet.

@kalefranz
Copy link
Contributor

I think it's safe to close this issue now. Let me know if anyone disagrees.

@kalefranz kalefranz added source::community catch-all for issues filed by community members important-discussion ¡breaking! used to indicate that the code change will likely require a minor or major version bump pending::discussion contains some ongoing discussion that needs to be resolved prior to proceeding labels Jan 24, 2018
@mbargull mbargull added the cli pertains to the CLI interface label Mar 13, 2018
coldfix added a commit to hibtc/cpymad that referenced this issue Feb 14, 2019
Otherwise, since conda is a .bat script itself, the invoking .bat script
will exit after conda.

See: conda/conda#6553
coldfix added a commit to hibtc/cpymad that referenced this issue Feb 14, 2019
Otherwise, since conda is a .bat script itself, the invoking .bat script
will exit after conda.

See: conda/conda#6553
coldfix added a commit to hibtc/cpymad that referenced this issue Feb 14, 2019
Otherwise, since conda is a .bat script itself, the invoking .bat script
will exit after conda.

See: conda/conda#6553
coldfix added a commit to hibtc/cpymad that referenced this issue Feb 14, 2019
Otherwise, since conda is a .bat script itself, the invoking .bat script
will exit after conda.

See: conda/conda#6553
coldfix added a commit to hibtc/cpymad that referenced this issue Feb 14, 2019
Otherwise, since conda is a .bat script itself, the invoking .bat script
will exit after conda.

See: conda/conda#6553
coldfix added a commit to hibtc/cpymad that referenced this issue Feb 14, 2019
Otherwise, since conda is a .bat script itself, the invoking .bat script
will exit after conda.

See: conda/conda#6553
coldfix added a commit to hibtc/cpymad that referenced this issue Feb 14, 2019
Otherwise, since conda is a .bat script itself, the invoking .bat script
will exit after conda.

See: conda/conda#6553
coldfix added a commit to hibtc/cpymad that referenced this issue Feb 15, 2019
Otherwise, since conda is a .bat script itself, the invoking .bat script
will exit after conda.

See: conda/conda#6553
coldfix added a commit to hibtc/cpymad that referenced this issue Feb 15, 2019
Otherwise, since conda is a .bat script itself, the invoking .bat script
will exit after conda.

See: conda/conda#6553
@certik
Copy link
Contributor

certik commented Mar 29, 2019

This really should be documented somewhere. It took me hours to figure out I have to put "call" in front of conda, otherwise the rest of the file is not executed.

@sytelus
Copy link

sytelus commented Nov 3, 2019

I want to share my scripts between Windows and Linux and this issue is breaking it. I hope conda.bat can be eliminated and conda.exe itself executes all necessary code so this hack is not needed.

@sbourdeauducq
Copy link

Well that's conda for you; you may want to try MSYS2 if you want to get things done.

@github-actions
Copy link

Hi there, thank you for your contribution to Conda!

This issue has been automatically locked since it has not had recent activity after it was closed.

Please open a new issue if needed.

@github-actions github-actions bot added the locked [bot] locked due to inactivity label Aug 21, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
¡breaking! used to indicate that the code change will likely require a minor or major version bump cli pertains to the CLI interface locked [bot] locked due to inactivity pending::discussion contains some ongoing discussion that needs to be resolved prior to proceeding source::community catch-all for issues filed by community members
Projects
None yet
Development

No branches or pull requests

7 participants