-
Notifications
You must be signed in to change notification settings - Fork 194
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
misc: use default env if task available in it. #772
misc: use default env if task available in it. #772
Conversation
Mm im not sure about this implementation. Pavels usecase makes sense but this impl will also select the default env if two tasks with the same name are defined which I think is not correct. |
So your saying that [tasks]
test = "cargo test"
[feature.test.tasks]
test = "cargo test --all-features"
[environments]
test = ["test"] |
Exactly! |
This should change it, @pavelzw could you check if this still fits your idea? |
src/task/task_environment.rs
Outdated
.parsed | ||
.features | ||
.iter() | ||
.filter(|(name, _feature)| name.as_str() != "default") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be good to add a function to check if a feature is the default instead of comparing strings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops I think I got distracted
unfortunately not, running the code with this pr still prompts me for the environment even though the task [project]
name = "test-project"
channels = ["conda-forge"]
platforms = ["linux-64", "osx-arm64", "osx-64", "win-64"]
[dependencies]
python = ">=3.11"
[tasks]
postinstall = "echo running postinstall"
[feature.py311.dependencies]
python = "3.11.*"
[feature.py312.dependencies]
python = "3.12.*"
[feature.test.dependencies]
pytest = "*"
[feature.test.tasks]
test = "echo testing now"
[environments]
default = ["py312", "test"]
py311 = ["py311", "test"]
py312 = ["py312", "test"] This is a minimal example of what i'm trying to achieve. |
My initial commit did exactly that but @baszalmstra`s comment told me I needed to do it differently, I can see 2 use cases.
In your example @pavelzw you could move the test task into the default feature. But that could indeed give weird results as a "lint" env (if that was separately defined) could then also include that task. |
I think prompting only if the |
So @pavelzw you are saying:
But execute in default env when:
|
Yes, that would at least solve my use case 😄 |
yeah that sounds perfect! 👌 |
As I'm trying to re-implement this I'm trying to write down what the rules are and they are so confusing even to me while developing the feature that I think it will never be intuitive to the user. I would like to keep it to these rules:
I think we should discuss an extra rule set that excepts some logic, like I described in #750. |
I think amending with
should solve our issue. |
I assume that now work, check the tests. |
src/task/task_environment.rs
Outdated
let is_unique_task = self.project.environments().iter().all(|env| { | ||
match env.task(name, self.platform) { | ||
Ok(task) => task == default_env_task, | ||
Err(_) => true, | ||
} | ||
}); | ||
|
||
if is_unique_task { | ||
return Ok((default_env, default_env_task)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes more sense to turn this expression around: NOT any other task. Instead of all environments all refer to this task. (faster to find the negative)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Im not entirely happy that we have to compare Task
s now because this now still fails:
[tasks]
bla = "echo foo"
[feature.other.tasks]
bla = "echo foo"
[environments]
other = ["other"]
Which is arguably indeed still ambiguous. I think you should look at the unique features of an environment and see if it contains a task with the same name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I'm lost, I though that is what you described. Could you give an toml/shell example of If the task is in de default environment and there is not other task with the same name (in any environment), run the task in the default environment.
I think I'm parsing it wrong
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[feature.other.tasks]
bla = "echo foo"
[environments]
default = ["other"]
other = ["other"]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming you want that to spawn the selector, that would go against pavels example right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No I think its the same? Let me explain over video!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it now does what we all expect 😅
This addresses @pavelzw issue in #767
Which means that if a task is in the default environment we always automatically run it from that environment.