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

Expand write_to_template to permit commit hash and date #818

Closed
effigies opened this issue Mar 16, 2023 · 8 comments
Closed

Expand write_to_template to permit commit hash and date #818

effigies opened this issue Mar 16, 2023 · 8 comments

Comments

@effigies
Copy link

While shifting a project to setuptools_scm, I saw someone ask if they could generate a copyright field dynamically based on the current year. Something like:

from datetime import datetime
__copyright__ = f"Copyright {datetime.today():%Y}, The Project X developers"

Obviously this would be bad, as the copyright would apply to the most recent change to the source code, not time of import. This information is available to setuptools_scm, and it could be useful to permit something like the following:

from datetime import datetime
from ._version import commit_date

__copyright__ = f"Copyright {datetime.fromisoformat(commit_date):%Y}, The Project X developers"

Is there any appetite to permit additional SCM-derived data in the generated file? I would imagine anything available in the ScmVersion data class would be potentially useful. Beyond saving a chore, generating more detailed bug report templates are the main other use case I can think of.

Anyway, any appetite for this? It could be done in a separate build tool plugin, but it would be nice to consolidate interaction with the SCM to a single utility.

@RonnyPfannschmidt
Copy link
Contributor

There is a wish to add the scm version

Generating copyright based on recent dates is fundamentally broken

In particular it is absolutely useless for a autogenerated file

I recommend spdx aware pre commit hooks

@RonnyPfannschmidt
Copy link
Contributor

@effigies also important warning - copyright does not start at the commit date - it can t best be used as the end of a range, else its wrong data

@effigies
Copy link
Author

Fair points. Thanks for the feedback on the idea and apologies for leaving this open so long.

@effigies effigies closed this as not planned Won't fix, can't repro, duplicate, stale Mar 25, 2023
@RonnyPfannschmidt
Copy link
Contributor

This is still planned as feature

@ZhiyuanChen
Copy link
Contributor

It semms #854 can only help in terms of node.
I tried to add date, but it's impossible to strftime a date object inside a format call.

Maybe we need a new function like format_template to resolve this issue.

@RonnyPfannschmidt
Copy link
Contributor

Date objects can uses strftime Style Formats in Format specifiers

@ZhiyuanChen
Copy link
Contributor

Date objects can uses strftime Style Formats in Format specifiers

Ahhhh right! I've never noticed this behaviour before.
__date__ = {scm_version.node_date:%Y-%m-%d} would work

@RonnyPfannschmidt
Copy link
Contributor

closing this as solves as the scm version is passed now

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

No branches or pull requests

3 participants