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

Refactored requirement operation and added multi-target/multi-language compatibility #3487

Merged
merged 50 commits into from
Sep 23, 2024

Conversation

Naatan
Copy link
Member

@Naatan Naatan commented Sep 10, 2024

TaskDX-1897 Refactor ExecuteRequirementOperation

A lot went into this one. More than I had anticipated, but less than I would've liked.

Overall this focusses on trying to simplify and streamline the logic for installing and uninstalling packages. Similar to Mitchell's original PR this separates the install and uninstall actions. It also separates platform installs/uninstalls from requirement operations altogether, since platforms are not requirements. Finally, I turned this into a top level runner rather than a runbit, because there is no need for command centric runners as all the behaviour is already covered.

Summary of side-effects:

  • Multiple install targets:
    • We no longer print the actual package names we're searching for, instead we just say a generic "searching for packages"
      • Reasoning: Depending on how input is passed not all packages are actually searched for. 
    • The --revision flag has been dropped.
      • Reasoning: this flag is targeting a single package operation, but state install now supports multiple operations. The only way to specify a revision would be to use buildscripts.
  • Multiple languages:
    • We can no longer normalize names, as this requires a namespace and we cannot determine the namespace without exact matching.
      • Means users have to give the exact ingredient name, casing and all.
  • Misc:
    • Added an --expand flag to state manifest which will show requirements by their full namespace.
      • This is to give a user a tool to review namespaces in case they need to disambiguate their input for state uninstall (eg. multiple packages with the same name, but different namespace).
    • Commit messages and install/uninstall success messages have been updated. Eg. instead of "Package added: pkgName" it will now say: "Added: namespace/to/pkgName".
      • Adding the namespace is intentional as the user will need to reason about them when working with multi-language projects or projects with private ingredients.

@github-actions github-actions bot changed the base branch from master to version/0-47-0-RC1 September 10, 2024 20:43
Copy link
Contributor

@mitchell-as mitchell-as left a comment

Choose a reason for hiding this comment

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

At a high level this looks fine to me. Good job! Some small things to address before merging, though.

@@ -48,6 +48,7 @@ constants:
scripts:
- name: install-deps-dev
language: bash
standalone: true
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious why this was added, and if this is needed for other activestate.yaml files with custom scripts.

Copy link
Member Author

Choose a reason for hiding this comment

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

Because I find often while testing that it re-sources my runtime because I invoked it with another state tool version (ie. the one I'm working on vs my installed state tool). And end of the day none of our scripts actually require the runtime, they were always standalone, just never marked as such.

@@ -1145,23 +1083,25 @@ err_exec_recursion:
To allow recursion, set [ACTIONABLE]{{.V1}}=true[/RESET]
package_ingredient_alternatives:
other: |
No results found for search term "[NOTICE]{{.V0}}[/RESET]". Did you mean:
No results found for search term {{.V0}}. Did you mean:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should keep this quoted.

Copy link
Member Author

@Naatan Naatan Sep 13, 2024

Choose a reason for hiding this comment

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

It's still highlighted, but because it now takes multiple values it happens outside of the locale file:

names = append(names, fmt.Sprintf(`[ACTIONABLE]%s[/RESET]`, r.Requested.Name))

I'll mark similar comments as resolved, but if you want to iterate further on this we can do it via this comment (just to keep it simple).

internal/locale/locales/en-us.yaml Show resolved Hide resolved
internal/locale/locales/en-us.yaml Show resolved Hide resolved
}

// Start runtime sourcing UI
if !cfg.GetBool(constants.AsyncRuntimeConfig) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we're handling this conditional inside runtime_runbit.Update(), so you can remove it here.

Copy link
Member Author

Choose a reason for hiding this comment

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

This was not intentional on my part, I think I copied this from the old code. But reading through it now I think it makes sense to retain it here. The comment in Update says that we still want the actual solving logic to run so we can raise errors. But that solving logic has already ran in this case when we created the commit. So solving it again in the async use-case wouldn't really give us any benefit.

I'll add a comment explaining as much.

@@ -169,6 +174,18 @@ func (n Namespace) String() string {
return n.value
}

func ParseNamespace(ns string) Namespace {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, I've been hoping for a function like this for a while now.

@@ -204,21 +221,24 @@ func NewNamespacePlatform() Namespace {
return Namespace{NamespacePlatform, "platform"}
}

const OrgNamespacePrefix = "private/"

func NewOrgNamespace(orgName string) Namespace {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: for consistency we should rename this NewNamespaceOrg() to match the other functions.

cp = ts.Spawn("install", "djang")
cp.Expect("No results found")
cp.Expect("Did you mean")
cp.Expect("language/python/djang")
Copy link
Contributor

Choose a reason for hiding this comment

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

Please double-check you mean to expect "djang" instead of "django".

cp.Expect(fmt.Sprintf("Operating on project %s/python3-pkgtest", user.Username))
cp.ExpectRe("(?:Package added|being built)", termtest.OptExpectTimeout(30*time.Second))
cp.Expect("Operating on project ActiveState-CLI/small-python")
cp.Expect("Added: language/python/requests", e2e.RuntimeSourcingTimeoutOpt)
Copy link
Contributor

Choose a reason for hiding this comment

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

We have async runtimes enabled, so normally we don't need timeouts like this. Could you add a comment (perhaps top-level) explaining why we're using timeouts here? (Including the functions below.)

Based on the diff, it looks like we're expecting a long "resolving dependencies" window due to the Platform needing to build packages, but you wouldn't know that from looking at this code by itself.

Copy link
Member Author

Choose a reason for hiding this comment

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

This was addressing solve times, not sourcing times. You're totally right for flagging this though. I've introduced a new RuntimeSolvingTimeoutOpt.

func (suite *PackageIntegrationTestSuite) TestPackage_UninstallDoesNotExist() {
suite.OnlyRunForTags(tagsuite.Package)

ts := e2e.New(suite.T(), false)
ts := e2e.New(suite.T(), true)
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you mean to leave this change in place?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, great catch!

Copy link
Contributor

@mitchell-as mitchell-as 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, but there are some test failures to address. Then it's good to go!

@Naatan
Copy link
Member Author

Naatan commented Sep 23, 2024

The only test failure appears to be a sporadic one unrelated to this PR. Gonna move on ahead.

@Naatan Naatan merged commit fd95129 into version/0-47-0-RC1 Sep 23, 2024
7 of 8 checks passed
@Naatan Naatan deleted the DX-1897 branch September 23, 2024 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants