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

Cleanup .bat scripts and ensure dev/start.bat uses source code's conda_hook.bat #13837

Open
wants to merge 31 commits into
base: 24.5.x
Choose a base branch
from

Conversation

kenodegard
Copy link
Contributor

@kenodegard kenodegard commented Apr 23, 2024

Description

Many small improvements:

  • Replace rem/REM/@rem/@REM with the tidier ::
  • Format all commands as uppercase
  • Standardize %ERRORLEVEL% checking
  • Standardize @IF clauses to use DEFINED when possible and to otherwise use [%VAR%]==[value]
  • Check for DOSKEY conda= instead of DEFINED CONDA_SHLVL
  • Update dev\start.bat to use source code's condabin & conda_hook.bat (so we can test bat script edits via our devenv)

Checklist - did you ...

  • Add a file to the news directory (using the template) for the next release's release notes?
  • Add / update necessary tests?
  • Add / update outdated documentation?

@conda-bot conda-bot added the cla-signed [bot] added once the contributor has signed the CLA label Apr 23, 2024
Copy link

codspeed-hq bot commented Apr 23, 2024

CodSpeed Performance Report

Merging #13837 will not alter performance

Comparing cleanup.bat (e4a388e) with 24.5.x (04308fe)

Summary

✅ 21 untouched benchmarks

@kenodegard kenodegard marked this pull request as ready for review April 24, 2024 02:09
@kenodegard kenodegard requested a review from a team as a code owner April 24, 2024 02:09
@kenodegard kenodegard added the build::review trigger a build for this PR label Apr 24, 2024
@conda-bot conda-bot removed the build::review trigger a build for this PR label Apr 24, 2024
@conda-bot
Copy link
Contributor

conda-bot commented Apr 24, 2024

Review build status

The workflow for building and uploading a canary release for conda with the label conda-conda-pr-13837 in channel conda-canary was started by @kenodegard!

Once it's done, use this command to try it out in a new conda environment:

conda install -c conda-canary/label/conda-conda-pr-13837 conda

@REM SPDX-License-Identifier: BSD-3-Clause
@CALL "%~dp0..\..\condabin\conda.bat" %*
:: Copyright (C) 2012 Anaconda, Inc
:: SPDX-License-Identifier: BSD-3-Clause
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes much tidier ❤️

travishathaway
travishathaway previously approved these changes Apr 25, 2024
Copy link
Contributor

@travishathaway travishathaway left a comment

Choose a reason for hiding this comment

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

Looks good.

One thing I can't help but wonder is if there are any linting tools for batch scripts? Maybe this would be something to add to pre-commit? Not necessary for this PR but just a thought.

@dbast
Copy link
Member

dbast commented Apr 25, 2024

Nice. This can be maybe made even tidier (and better to read) via the pattern cmd || goto :error instead of the many duplicated lines with @IF NOT [%ERRORLEVEL%]==[0] @EXIT /B %ERRORLEVEL% ... see e.g. where this is applied https://github.com/conda-forge/ripgrep-feedstock/blob/main/recipe/bld.bat

@ifitchet
Copy link
Contributor

Nice. This can be maybe made even tidier (and better to read) via the pattern cmd || goto :error instead of the many duplicated lines with @IF NOT [%ERRORLEVEL%]==[0] @EXIT /B %ERRORLEVEL% ... see e.g. where this is applied https://github.com/conda-forge/ripgrep-feedstock/blob/main/recipe/bld.bat

If you're going to do this then Line 13, or an equivalent, is critical, https://github.com/conda-forge/ripgrep-feedstock/blob/main/recipe/bld.bat#L13. exit 0 is an equivalent, of course.

Without it, all your code paths will dutifully run through the :error code.

Copy link
Member

@jezdez jezdez left a comment

Choose a reason for hiding this comment

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

This does look better, but OTOH I wish we'd have something like black for batch files.

conda/shell/Scripts/activate.bat Outdated Show resolved Hide resolved
Comment on lines 8 to 13
IF DEFINED CONDA_PS1_BACKUP (
:: Handle transition from shell activated with conda 4.3 to a subsequent activation
:: after conda updated to 4.4. See issue #6173.
SET "PROMPT=%CONDA_PS1_BACKUP%"
SET CONDA_PS1_BACKUP=
)
Copy link
Member

Choose a reason for hiding this comment

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

Should we... remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would love to, if someone updates from an older conda that breaks their prompt they can just restart their shell and should be good to go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's leave this as is for now and work to remove it in the future

conda/shell/condabin/activate.bat Outdated Show resolved Hide resolved
dev/start.bat Outdated Show resolved Hide resolved
jezdez
jezdez previously approved these changes Apr 30, 2024
@kenodegard kenodegard added the build::review trigger a build for this PR label Apr 30, 2024
@conda-bot conda-bot removed the build::review trigger a build for this PR label Apr 30, 2024
@kenodegard kenodegard added this to the 24.5.x milestone Apr 30, 2024
@kenodegard kenodegard marked this pull request as draft May 1, 2024 14:09
@kenodegard
Copy link
Contributor Author

While testing canary builds I discovered issues with some of these changes, still debugging

@kenodegard kenodegard changed the base branch from main to 24.5.x May 1, 2024 14:59
@kenodegard kenodegard dismissed jezdez’s stale review May 1, 2024 14:59

The base branch was changed.

@kenodegard kenodegard added the build::review trigger a build for this PR label May 7, 2024
@conda-bot conda-bot removed the build::review trigger a build for this PR label May 7, 2024
@kenodegard kenodegard added the build::review trigger a build for this PR label May 7, 2024
@conda-bot conda-bot removed the build::review trigger a build for this PR label May 7, 2024
Comment on lines +7 to +38
:: skip checking for quotes if there are no arguments
IF [%1]==[] GOTO :SKIP_CHECK

:: enter localized variable scope
SETLOCAL

:: Test first character and last character of %1 to see if first character is a "
:: but the last character isn't.
:: This was a bug as described in https://github.com/ContinuumIO/menuinst/issues/60
:: When Anaconda Prompt has the form
:: %windir%\system32\cmd.exe "/K" "C:\Users\builder\Miniconda3\Scripts\activate.bat" "C:\Users\builder\Miniconda3"
:: Rather than the correct
:: %windir%\system32\cmd.exe /K ""C:\Users\builder\Miniconda3\Scripts\activate.bat" "C:\Users\builder\Miniconda3""
:: this solution taken from https://stackoverflow.com/a/31359867

SET "_ARG=%1"
SET _ARG_FIRST=%_ARG:~0,1%
SET _ARG_LAST=%_ARG:~-1%
SET _ARG_FIRST=%_ARG_FIRST:"=+%
SET _ARG_LAST=%_ARG_LAST:"=+%

:: if the first character is not a quote we can skip further quote checking
IF NOT [%_ARG_FIRST%]==[+] ENDLOCAL & GOTO :SKIP_CHECK

:: the first and last characters appear to be matching quotes so we can activate normally
IF [%_ARG_LAST%]==[+] ENDLOCAL & GOTO :SKIP_CHECK

:: found a quote mismatch, we assume this is a bug in the downstream code
ENDLOCAL & CALL "%~dp0\..\condabin\conda.bat" activate
GOTO :EOF

:SKIP_CHECK
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would prefer to remove this special bug handling for Anaconda Prompt/Menuinst

Thoughts @jaimergp @marcoesters

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I missed the tag. Right now, the target of the shortcut looks like this

%windir%\System32\cmd.exe "/K" C:\Users\<user>\miniconda3\Scripts\activate.bat C:\Users\<user>\miniconda3

So, maybe install console_shortcut_miniconda or console_shortcut with the dev version of conda and see if the workaround is still necessary?

if it is, removing it is tricky because that would render that shortcut unusable when a user updates conda.

@kenodegard kenodegard marked this pull request as ready for review May 7, 2024 14:26
@kenodegard kenodegard modified the milestones: 24.5.x, 24.7.x May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed [bot] added once the contributor has signed the CLA
Projects
Status: Approved
Development

Successfully merging this pull request may close these issues.

None yet

7 participants