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

Expose workspace names through bazel info #2317

Closed
dinowernli opened this issue Dec 30, 2016 · 13 comments
Closed

Expose workspace names through bazel info #2317

dinowernli opened this issue Dec 30, 2016 · 13 comments
Assignees
Labels
category: misc > misc good first issue P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) type: feature request

Comments

@dinowernli
Copy link
Contributor

It would be really nice to have bazel info expose the name of the workspace in a similar way that bazel info workspace exposes the path to the root of the workspace. Perhaps as additional output to bazel info workspace, or maybe a bazel info workspace-name?

@hlopko hlopko added category: misc > misc P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) type: feature request labels Jan 9, 2017
@roysaurav
Copy link

roysaurav commented Mar 7, 2017

@dinowernli @aehlig @mhlopko @buchgr Can you provide an example of the above situtation?

@kchodorow
Copy link
Contributor

I'm actually working on a change right now that will make the execution root basename be the workspace name (so basename $(bazel info execution_root) would give you the workspace name). Would that be sufficient for your use case?

@dinowernli
Copy link
Contributor Author

Yes, that would be great. Thanks.

@kchodorow
Copy link
Contributor

Marking as a dup of #1681, then. Hopefully should be fixed in a couple of days (won't make it into 0.4.5, though).

@EricCousineau-TRI
Copy link
Contributor

I have made a hacky workaround for people with Bazel <=0.4.5 (myself included):
https://github.com/EricCousineau-TRI/repro/blob/860323d/shell/bazel_workspace_name.py

Slow, but it appears to work.

@dpetrou-continua
Copy link

Hi. I'd like to get the workspace name from a Python script that I bazel run. The script calls bazel info using subprocess. This fails because the script's CWD when it runs is not the source tree, so bazel info execution_root fails:

WARNING: Invoking Bazel in batch mode since it is not invoked from within a workspace (below a directory having a WORKSPACE file).
ERROR: The 'info' command is only supported from within a workspace (below a directory having a WORKSPACE file).

You may wonder why I need to bazel run the script instead of executing it directly: It's because it uses imports that are pulled in via pip_parse().

Would love any guidance.
Thanks,
David

@dpetrou-continua
Copy link

Nevermind; if I run the script from the root, ala ./bazel-bin/package/target it works.

@guw
Copy link
Contributor

guw commented Dec 11, 2023

This seems to be broken with bzlmod.

I tried (without success):

  • MODULE.bazel using module(name="foo")
  • WORKSPACE.bzlmod and defining workspace(name="foo")
  • MODULE.bazel using module(..., repo_name="foo")
  • keeping WORKSPACE using workspace(name="foo")

However, the information in execution root is always _main.

The documentation in the migration guide says:

the default repository name for your workspace is __main__

The documentation for module function says:

By default, the name of the repo is the name of the module.

My goal is detecting the workspace name. I have been following guidance given in the issue here but seems to be no longer applicable.

There are three possibilities:

  • __main__
  • _main
  • name of the module

@fmeum
Copy link
Collaborator

fmeum commented Dec 11, 2023

@guw The term "workspace name" is extremely overloaded at this point. Which name do you really need and what do you need it for?

@guw
Copy link
Contributor

guw commented Dec 11, 2023

The immediate need is to allow a human to identify a workspace in an IDE (this is my "foo").

I am currently also using it to customize classpath resolution within IDEs in case of override_repository. But that needs to be investigated separately as I found additional bits of breaking changes.

So let's define workspace name as per the initial ask, which I assume is workspace( name = "foo" ).

@fmeum
Copy link
Collaborator

fmeum commented Dec 11, 2023

As a human-readable identifier, I would recommend either the name of the containing directory (which Bazel uses to name the bazel-foo convenience symlink, also used by IntelliJ) or the name of the main module (which you can get with native.module_name in the main repository).

@guw
Copy link
Contributor

guw commented Dec 11, 2023

Thanks a lot @fmeum. Would native.module_name return the repo_name or just name of the module metadata?

@fmeum
Copy link
Collaborator

fmeum commented Dec 11, 2023

Thanks a lot @fmeum. Would native.module_name return the repo_name or just name of the module metadata?

It always returns the name, i.e. the one you would also find the module under in a registry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: misc > misc good first issue P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) type: feature request
Projects
None yet
Development

No branches or pull requests

10 participants