Skip to content

Conversation

@klamike
Copy link
Contributor

@klamike klamike commented Aug 16, 2025

This PR adds a CLI to JuliaPkg, letting users manage their dependencies from the command line. It also adds the run pass-through mode which can launch a REPL or run scripts using the same julia executable/project as what pyjuliapkg sees.

Closes #63

@klamike klamike marked this pull request as draft August 16, 2025 16:50
@klamike
Copy link
Contributor Author

klamike commented Aug 16, 2025

For some reason the test I removed in 262a9aa doesn't work on CI, though it works fine for me locally...

Specifically I expect the resolve to fail, but it exits with exit code 0.

@klamike klamike marked this pull request as ready for review August 16, 2025 22:08
Comment on lines 12 to 35
class JuliaPkgGroup(click.Group):
"""Custom group to avoid long stacktraces when Julia exits with an error."""

@property
def always_show_python_error(self) -> bool:
return os.environ.get("JULIAPKG_ALWAYS_SHOW_PYTHON_ERROR_CLI", "0") == "1"

@staticmethod
def _is_graceful_exit(e: subprocess.CalledProcessError) -> bool:
"""Try to guess if a CalledProcessError was Julia gracefully exiting."""
return e.returncode == 1

def invoke(self, ctx):
try:
return super().invoke(ctx)
except subprocess.CalledProcessError as e:
# Julia already printed an error message
if (
JuliaPkgGroup._is_graceful_exit(e)
and not self.always_show_python_error
):
click.get_current_context().exit(1)
else:
raise
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The thinking here is that the user does not care to see the subprocess.CalledProcessError stacktrace most of the time. So, for the CLI only, why not hide it?

It may be nice to put something like Hint: Detected a Julia error; the Python stacktrace is hidden. Set JULIAPKG_ALWAYS_SHOW_PYTHON_ERROR_CLI=1 to see the full stacktrace.

@xgdgsc
Copy link

xgdgsc commented Aug 28, 2025

Would this be confused with JuliaLang/juliaup#1230 ?

@klamike
Copy link
Contributor Author

klamike commented Aug 28, 2025

Thanks for the reference @xgdgsc, I wasn't aware of that work. Seems super cool! It might be useful to simplify some of the pyjuliapkg internals once it lands (though AFAICT juliaup is not used if it is not already installed).

For the CLI , I think the python -m py/py prefix should be enough to limit confusion/signal that it is for using the julia install that python is using. In particular resolving stuff like conda environment, PYTHON_JULIAPKG_PROJECT, -X juliapkg-project, etc. is the main motivation for this.

@cjdoris cjdoris self-assigned this Sep 11, 2025
@cjdoris cjdoris merged commit 784f7fa into JuliaPy:main Sep 17, 2025
6 checks passed
@cjdoris
Copy link
Collaborator

cjdoris commented Sep 17, 2025

I made a few small tweaks before merging:

  • I removed the command aliases mainly because it makes the --help page messy. If there's a nicer way to have aliases without it showing as multiple commands, feel free to make another PR.
  • I removed the pyjuliapkg script. Mainly because juliapkg is largely a transitive dependency (i.e. many users have it without knowing about it) so I don't like cluttering up peoples' PATH with scripts they don't need. You can always make an alias yourself.
  • Docs.

Really nice PR, thank you.

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

Successfully merging this pull request may close these issues.

Add a CLI

3 participants