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

Changed order of the url check. #100

Merged
merged 3 commits into from
Jun 1, 2017

Conversation

allenh1
Copy link

@allenh1 allenh1 commented May 26, 2017

Fixes #99

url = repo.url
release_tag = 'release/{0}/{1}/{2}'.format(rosdistro, self.name, repo.version)
tail = '/{0}/package.xml'.format(release_tag)
url = url.replace('.git', tail)
url = url.replace('git://', 'https://')
Copy link
Contributor

Choose a reason for hiding this comment

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

Has this been removed intentionally ? If yes, why did this become unnecessary ?

Copy link
Author

Choose a reason for hiding this comment

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

It was not intentional. Good catch. Oddly, it works, but... I haven't tried it for indigo yet. One moment.

Copy link
Member

@dirk-thomas dirk-thomas left a comment

Choose a reason for hiding this comment

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

It makes sense to check the url of the new format first. It has been quite a while since this logic has been introduced (838b119) and by now the new format is the standard. So 👍 from me to invert the logic.

Instead of shuffling the logic I would suggest to just swap the lines 203 and 214.

@dirk-thomas
Copy link
Member

My previous comment still applies: why shuffle all this code? Isn't it enough to swap these two lines:

release_tag = 'release/{0}/{1}'.format(self.name, upstream_version)
and
release_tag = 'release/{0}/{1}/{2}'.format(rosdistro, self.name, repo.version)

release_tag = 'release/{0}/{1}'.format(self.name, upstream_version)
url = url.replace('.git', '/{0}/package.xml'.format(release_tag))
url = url.replace('git://', 'https://')
url = url.replace('https://', 'https://raw.')
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like a duplication of the more robust logic which is here:

https://github.com/ros-infrastructure/rosdistro/blob/master/src/rosdistro/manifest_provider/github.py#L65

Can we consolidate?

Copy link
Author

Choose a reason for hiding this comment

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

That would be a much better solution, yes. Let me do that.

Copy link
Member

Choose a reason for hiding this comment

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

Please keep the actual change swapping the order or urls fetched separate from code refactoring (like deduplicating logic). At least in separate commits - maybe even in separate PRs.

@allenh1
Copy link
Author

allenh1 commented May 30, 2017

Upon further inspection, it appears that, in the function you linked, they call get_release_tag which calls
fetch package url.

https://github.com/ros-infrastructure/rosdistro/blob/master/src/rosdistro/rosdistro.py#L238

There seems to be some redundancy here in fetching the package.xml file. In particular, it happens twice. So I think the best consolidation here would be to modify the github_manifest_provider to not fetch the package.xml file, as it is already available.

@mikepurvis
Copy link
Contributor

In that case you'd want to use the CachedManifestProvider, as in:

dist = Distribution(
cache.distribution_file,
[CachedManifestProvider(cache, Distribution.default_manifest_providers if allow_lazy_load else None)],
[CachedSourceManifestProvider(cache, Distribution.default_source_manifest_providers if allow_lazy_load else None)])

However, looks like it might be some crazy legacy-supporting side logic, so let's wait for a verdict from @dirk-thomas about the right path forward before you try to change too much.

@allenh1
Copy link
Author

allenh1 commented May 30, 2017

Will do. I was mistaken by the structure a little -- I will play around with it some, then bother dirk in a few.

@allenh1 allenh1 force-pushed the master branch 2 times, most recently from 6141662 to fc89de1 Compare May 30, 2017 19:03
@allenh1
Copy link
Author

allenh1 commented May 30, 2017

@dirk-thomas Should be the correct format now.

@mikepurvis After digging through things for a good while, I've determined that the amount of refactoring needed to avoid duplication of this logic reaches beyond the bounds of this pull request.

upstream_version = repo.version.split('-')[0]
release_tag = 'release/{0}/{1}'.format(self.name, upstream_version)
url = url.replace('.git', '/{0}/package.xml'.format(release_tag))
# release_tag = get_release_tag(self.name)
Copy link
Member

Choose a reason for hiding this comment

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

This line should be removed.

try:
try:
release_tag = 'release/{0}/{1}/{2}'.format(rosdistro, self.name, repo.version)
url = url.format(release_tag)
Copy link
Member

Choose a reason for hiding this comment

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

Before format was only called on strings defined in the source code. Now format is being called on a user provided string which might contain characters like {} and therefore result in problems. Therefore please only use format on strings defined in the code directly.

Same below in line 218:

url = url.format(release_tag)

package_xml = urlopen(url).read()
except Exception as e:
except Exception as e:
Copy link
Member

Choose a reason for hiding this comment

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

Please remove the trailing whitespace.

try:
try:
release_tag = 'release/{0}/{1}/{2}'.format(rosdistro, self.name, repo.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 line as well as the next one shouldn't be in the try / except block.

@allenh1
Copy link
Author

allenh1 commented May 30, 2017

@dirk-thomas I restructured the logic a little to fix it. Should be good now.

upstream_version = repo.version.split('-')[0]
release_tag = 'release/{0}/{1}'.format(self.name, upstream_version)
url = url.replace('.git', '/{0}/package.xml'.format(release_tag))
tail = 'release/{0}/{1}/{2}/package.xml'.format(rosdistro, self.name, repo.version)
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest to keep the variable name as release_tag since the string is the release tag.

url = url.replace('https://', 'https://raw.')
info("Trying to read from url '{0}' instead".format(url))
upstream_version = repo.version.split('-')[0]
legacy_tail = 'release/{0}/{1}/package.xml'.format(self.name, upstream_version)
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest to rename the variable to legacy_release_tag.

Copy link
Author

Choose a reason for hiding this comment

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

@dirk-thomas you got it

@dirk-thomas
Copy link
Member

The previous state seem to lack the leading slash in the replacement: see 1c6eb29#diff-65e54a8cd0a3220cd2b0b2091bd58708R202

Anyway I added two commits to this PR to minimize the changes and keep the semantic of the variables (release_tag and legacy_release_tag are actualy containing valid tag names of the repo). Please double check that the overall patch still works as expected.

@allenh1
Copy link
Author

allenh1 commented Jun 1, 2017

@dirk-thomas All is working as expected!

@dirk-thomas
Copy link
Member

Thanks!

@dirk-thomas dirk-thomas merged commit c4f076d into ros-infrastructure:master Jun 1, 2017
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.

4 participants