-
-
Notifications
You must be signed in to change notification settings - Fork 186
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
feat(settings): add user settings support with defaults
values and trusts
#1940
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1940 +/- ##
==========================================
+ Coverage 97.90% 98.05% +0.14%
==========================================
Files 51 53 +2
Lines 5404 5511 +107
==========================================
+ Hits 5291 5404 +113
+ Misses 113 107 -6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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.
Very nice! I like the prefix matching approach for trusted repositories, it's simple and it makes sense.
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.
Fantastic work, @noirbizarre! 🎉 Thanks for working on and contributing these valuable features! 🙏
I have a few minor remarks. And would you mind fixing the formatting errors in the corresponding commit and drop the auto-fix commit? We'll likely want to rebase-merge this PR to keep the two feature commits, so the auto-fix commit would only add some noise to the Git history.
You're welcome ! 🙏🏼 |
ac3b856
to
f8a881c
Compare
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.
Just a few more comments after another review iteration. 🙂
return any( | ||
repository.startswith(self.normalize(trusted)) | ||
if trusted.endswith("/") | ||
else repository == self.normalize(trusted) | ||
for trusted in self.trust | ||
) | ||
|
||
def normalize(self, url: str) -> str: | ||
"""Normalize an URL using user settings.""" | ||
if url.startswith("~"): # Only expand on str to avoid messing with URLs | ||
url = expanduser(url) | ||
return url |
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 wonder whether we should use copier.vcs.get_repo()
to normalize trusted repository URLs to be more robust against non-canonical URLs. From the tests below, a (normalized) repository https://github.com/user/repo.git
wouldn't be considered trusted despite the trust list entry https://github.com/user/repo
. Won't this lead to confusion?
I realize that copier.vcs.get_repo()
currently doesn't handle URLs with a trailing slash properly:
>>> get_repo("https://github.com/user/repo/")
'https://github.com/user/repo/.git'
But this could be fixed. WDYT?
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.
Yes, I noticed that when I started #1941. That's one of the reasons I separated the shortcuts into their own PR.
If this is OK for you, I would prefer handling get_repo
and URL normalization in #1941 as it is its main point. It would allow having the full picture and craft a solution that handles more cases.
I think we have the opportunity to properly review/complete/fix normalization rules in #1941. (I'll properly rebase it when this one is merged so we can have a clear view)
f8a881c
to
211835d
Compare
Hello 👋🏼
This PR adds support for user settings with initial support for:
Settings are stored in
<CONFIG_ROOT>/settings.yml
where<CONFIG_ROOT>
is thestandard configuration directory for your platform:
$XDG_CONFIG_HOME/copier
(~/.config/copier
in most cases) on Linux as defined byXDG Base Directory Specifications
~/Library/Application Support/copier
on macOS as defined byApple File System Basics
%USERPROFILE%\AppData\Local\copier
on Windows as defined inKnown folders
This location can be overridden by setting the
COPIER_SETTINGS
environment variable.The settings look like: