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

rewrite the parsed info is not efficient #24

Open
alingse opened this issue Oct 25, 2020 · 3 comments
Open

rewrite the parsed info is not efficient #24

alingse opened this issue Oct 25, 2020 · 3 comments

Comments

@alingse
Copy link

alingse commented Oct 25, 2020

I want to use this package to do auto-migration git repo

eg: import repo from github.com to gitlab.com

I need some code like this :

u = 'https://github.com/nephila/giturlparse'
repo = parse(u)
repo.domain = 'gitlab.com'
new_url = repo.format('https')
# Expect new_url is  --> https://gitlab.com/nephila/giturlparse.git
# but it real not changed --> https://github.com/nephila/giturlparse.git

I find the way to rewrite the repo info

u = 'https://github.com/nephila/giturlparse'
repo = parse(u)
repo._parsed['domain'] = 'gitlab.com'
new_url = repo.format('https') 
# Expect new_url is  --> https://gitlab.com/nephila/giturlparse.git
# Yes, it work, but not so efficient,
#  and need user to know there is a `_parsed` field, a little not pythonic
@alingse alingse changed the title rewrite the parsed_info is not efficient rewrite the parsed info is not efficient Oct 25, 2020
@yakky
Copy link
Member

yakky commented Oct 31, 2020

@alingse could you elaborate please?

@alingse
Copy link
Author

alingse commented Nov 2, 2020

@yakky I update the code in the begin comment.

I want repo instance (GitUrlParsed ) have some method to rewrite the subpart.

@yakky
Copy link
Member

yakky commented Nov 15, 2020

@alingse having a comprehensive way to mutate a URL from one provider to another is not really in scope
It's subject to too many pitfalls (just an example: gitlab supports subgroups - URL like /organization/something/repo.git- while github doesn't) to be reliable the best we can do is to add a public method which does nothing but replacing a single value in _parsed attribute, something like

@data.setter
def data(self, key, value):
    self._parsed[key] = value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants