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

g.extension: get branch from version #1700

Merged
merged 21 commits into from
Jul 21, 2021
Merged

Conversation

ninsbl
Copy link
Member

@ninsbl ninsbl commented Jul 1, 2021

Replaces #1678
Once we have a grass8 branch in grass-addons, the hardcoded version 7 should be removed from g.extension...

@ninsbl ninsbl added the enhancement New feature or request label Jul 1, 2021
@ninsbl ninsbl added this to the 7.8.6 milestone Jul 1, 2021
@ninsbl ninsbl marked this pull request as draft July 1, 2021 22:18
@neteler neteler added backport_needed blocker Blocking a release labels Jul 2, 2021
@ninsbl
Copy link
Member Author

ninsbl commented Jul 2, 2021

It would be nice if we could remove the hardcoded version here:

# TODO: update temporary workaround of using grass7 subdir of addon-repo, see
# https://github.com/OSGeo/grass-addons/issues/528
version[0] = 7
version[1] = 9

Then we do not have to change that in master later on and it probably causes less trouble with addons on windows where we have pre-compiled addons going back to version 7.4...

But that requires a branch "grass8" in the addon repo for g.extension to work with GRASS 8 (or current master)...

Comment on lines 2322 to 2325
if branch in ["master", "main"]:
svn_reference = "trunk"
if branch is None or branch in ["master", "main"]:
svn_reference = "branches/grass{}".format(version)
Copy link
Member

Choose a reason for hiding this comment

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

This is confusing. None (default) may be expected to resolve to the default branch which is represented by trunk in Subversion interface, although perhaps default resulting in the version branch makes sense in this context. However, explicit master or main should resolve to branch/master and branch/main unless there is a clear reason to do it otherwise.

I though -o is somewhat "behave as with the official repository" which is broader than its defintion "url refers to a fork of the official extension repository". Also depends on what people think fork is. Overall, this might be limiting when you let's say create an institutional repo which should work as the official repository, but you support only one version.

scripts/g.extension/g.extension.py Outdated Show resolved Hide resolved
@wenzeslaus
Copy link
Member

But that requires a branch "grass8" in the addon repo for g.extension to work with GRASS 8 (or current master)...

To maximize freshness of addons for v7 and minimize the backporting needs, it would be best to have a fix in code for v8 and create grass8 branch only close to the release (perhaps we are already?). The v8 specific fix can be later removed or rewritten for v9 because the idea now is that we just do the same grassX to grassY branch switch for v8->v9 as we will do for v7->v8.

@ninsbl
Copy link
Member Author

ninsbl commented Jul 5, 2021

But that requires a branch "grass8" in the addon repo for g.extension to work with GRASS 8 (or current master)...

To maximize freshness of addons for v7 and minimize the backporting needs, it would be best to have a fix in code for v8 and create grass8 branch only close to the release (perhaps we are already?). The v8 specific fix can be later removed or rewritten for v9 because the idea now is that we just do the same grassX to grassY branch switch for v8->v9 as we will do for v7->v8.

In 1b39a61 I tried to solve this by listing branches via github API (should be OK, if addons are supposed to be fetched from online repo).
The logic is to pick the branch of the current version if present in the repo (and if no branch is specified explicitly), otherwise take the latest branch. That should work for grass8 and 9 and hardcoded versions are not necessary, unless you would want to fetch addons for e.g. GRASS 7.8. from grass8 branch by default...

@ninsbl ninsbl requested a review from wenzeslaus July 5, 2021 10:16
@neteler
Copy link
Member

neteler commented Jul 5, 2021

(for an easier backporting, g.extensionin the G78 branch needs to receive a black update first)

scripts/g.extension/g.extension.py Outdated Show resolved Hide resolved
scripts/g.extension/g.extension.py Outdated Show resolved Hide resolved
scripts/g.extension/g.extension.py Outdated Show resolved Hide resolved
scripts/g.extension/g.extension.py Outdated Show resolved Hide resolved
scripts/g.extension/g.extension.py Outdated Show resolved Hide resolved
scripts/g.extension/g.extension.py Outdated Show resolved Hide resolved
@ninsbl ninsbl requested a review from wenzeslaus July 5, 2021 22:31
@ninsbl
Copy link
Member Author

ninsbl commented Jul 5, 2021

Thanks for your feedback!

scripts/g.extension/g.extension.py Outdated Show resolved Hide resolved
scripts/g.extension/g.extension.py Outdated Show resolved Hide resolved
scripts/g.extension/g.extension.py Outdated Show resolved Hide resolved
scripts/g.extension/g.extension.py Outdated Show resolved Hide resolved
scripts/g.extension/g.extension.py Show resolved Hide resolved
scripts/g.extension/g.extension.py Outdated Show resolved Hide resolved
scripts/g.extension/g.extension.py Outdated Show resolved Hide resolved
scripts/g.extension/g.extension.py Outdated Show resolved Hide resolved
scripts/g.extension/g.extension.py Outdated Show resolved Hide resolved
scripts/g.extension/g.extension.py Outdated Show resolved Hide resolved
scripts/g.extension/g.extension.py Outdated Show resolved Hide resolved
@ninsbl ninsbl requested a review from wenzeslaus July 19, 2021 22:36
@ninsbl ninsbl marked this pull request as ready for review July 19, 2021 22:37
@ninsbl
Copy link
Member Author

ninsbl commented Jul 19, 2021

Should be ready to merge.
I fixed the issues from review (and some additional) and the download tests pass locally.
Given the blocker status, maybe best to merge now, and then backport all required changes of g.extension to the release branch. We should probably check if it would work with 7.6 as well...

Copy link
Member

@wenzeslaus wenzeslaus left a comment

Choose a reason for hiding this comment

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

We can merge this as is. I have some additional comments which don't need to be addressed in this PR. I marked most of the conversations as resolved.

Comment on lines 274 to 282
# Parse URL
url_parts = urlparse(full_url)
# Get organization and repository component
try:
organization, repository = url_parts.path.split("/")[
1:3
]
except URLError:
gscript.fatal(_("Cannot retrieve organization and repository from URL: <{}>.".format(full_url)))
Copy link
Member

Choose a reason for hiding this comment

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

Having this part here (and not e.g. in a separate, possibly nested function and called only when needed), prohibits general URLs to be used here (just to get main). I'm not sure how relevant that is, though.

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 function is only meant for known hosting services (currently: github, gitlab, bitbucket), so, this should not be an issue...

Copy link
Member

Choose a reason for hiding this comment

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

I was thinking the main would be used as a the default for any other service, but in that case, use likely needs to (and can) specify branch explicitly anyway.

Comment on lines 2357 to 2361
repo_branches = get_github_branches()
# Define branch to fetch from (latest or current version)
version_branch = "grass{}".format(version[0])
if version_branch not in repo_branches:
version_branch = repo_branches[-1]
Copy link
Member

Choose a reason for hiding this comment

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

Agreed that documentaion is needed for that, but maybe in another PR. The whole "fork" think here is suboptimal. Typical (soft) fork on GitHub will have the branches. Do we mean hard project fork? I think the aim is institutional repositories (private or public), right? That was the case in the past, I think. I'm not sure how to call "a repo with the same structure as the official repo", plus there is the issues with the generated metadata file which is separate if I recall correctly. ...next PR. Perhaps open an issue?

Comment on lines 2292 to 2294
get_default_branch(actual_start)
if urlparse(actual_start).netloc == "gitlab.com"
else "main"
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this what get_default_branch is doing?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. I moved it into the function in the latest commit.

Copy link
Member Author

Choose a reason for hiding this comment

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

As for the "fork" issue, I agree that it should be more clear.
The case I had in mind was an addon-dev contributing a new addon, for example. Until the fork-flag got implemented, it was not possible to test contributions to the official addon repo without cloning the repo of the addon-dev and installing from local URL. So, the main intention has been to allow to install directly from e.g. a feature branch of a (soft) fork of the official repo...
Should be probably added to the manual....

Copy link
Member

Choose a reason for hiding this comment

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

As for the "fork" issue...The case I had in mind was an addon-dev contributing a new addon...

Just for the record, I think in the past (Subversion times) it was possible to install from repositories which behaved like the official repo (I think @neteler or @landam created some). Today, the "test from contributor's fork" use case you mentioned is definitively more important, esp. since individual modules can be installed from small repos (without a need for mirroring the official repo infrastructure).

@wenzeslaus
Copy link
Member

This can be tested without compiling or download using Binder: Binder

@wenzeslaus
Copy link
Member

@ninsbl Leaving the fork-related conversations open (I marked the rest as resolved). Please, resolve them as you see fit. Thank you.

@ninsbl ninsbl merged commit 4705cc5 into OSGeo:master Jul 21, 2021
@ninsbl ninsbl deleted the g_extension_version branch July 21, 2021 14:33
@ninsbl
Copy link
Member Author

ninsbl commented Jul 21, 2021

Thanks, @wenzeslaus for bearing with me here. I mentioned this PR in the ticket about general git related improvements of g.extension. Refactoring g.extension may be a good task for the next community sprint...

But an open question to me is how we backport best? Not all earlier changes in g.extension were backported, see:
https://github.com/OSGeo/grass/commits/master/scripts/g.extension/g.extension.py
vs.
https://github.com/OSGeo/grass/commits/releasebranch_7_8/scripts/g.extension/g.extension.py
Should the version from master be copied into the releasebranch? And should we try to support the new addon-repo also for GRASS 7.6 (and Python 2), as that is still the most recent version on some systems?

@neteler
Copy link
Member

neteler commented Jul 21, 2021

Thanks for your hard work!

Let me suggest to backport it completely to 7.8 and create a new 7.8.6 RC2 to get it tested.

Concerning 7.6, I don't really expect a new release. They may upgrade to at least 7.8 - see also https://repology.org/project/grass/versions.

@neteler
Copy link
Member

neteler commented Dec 5, 2021

Update: the grass8 branch has recently been created in grass-addons (new default branch).

Shall this PR be backported now to G7.8.7? Would any changes be needed for that (i.e., in new PR), @ninsbl?

@neteler
Copy link
Member

neteler commented Jan 8, 2022

Gentle ping, @ninsbl :)

@neteler
Copy link
Member

neteler commented Jan 8, 2022

Ah, if I understand correctly, it has already been backported in #1762 (?)

@wenzeslaus
Copy link
Member

This is in 8.0 and 8.2 branches and seems to be in 7.8 as 42f015e (#1700), so removing the backport label.

ninsbl added a commit to ninsbl/grass that referenced this pull request Oct 26, 2022
* branch from version

* black

* address review, flake8

* get branch from github API

* handle branch=None

* handle branch=None better

* black/flake8

* cleanup after code review

* update from code review

* try orgs and users

* use repo API

* pass propper API URL

* defaults for get_github_branches, fix l-flag, updates from code review

* abandon github API due to rate limits

* version over default

* use URLError

* use urlparse

* use urlparse

* use get_default_branch for gitlab

* fix keyword issue with urlopen

* global GIT_URL, get_default update
ninsbl added a commit to ninsbl/grass that referenced this pull request Feb 17, 2023
* branch from version

* black

* address review, flake8

* get branch from github API

* handle branch=None

* handle branch=None better

* black/flake8

* cleanup after code review

* update from code review

* try orgs and users

* use repo API

* pass propper API URL

* defaults for get_github_branches, fix l-flag, updates from code review

* abandon github API due to rate limits

* version over default

* use URLError

* use urlparse

* use urlparse

* use get_default_branch for gitlab

* fix keyword issue with urlopen

* global GIT_URL, get_default update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocker Blocking a release enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants