-
Notifications
You must be signed in to change notification settings - Fork 5
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
Convert most of the commands from autocommand to typer. #21
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
import autocommand | ||
import typer | ||
from typing_extensions import Annotated | ||
from jaraco.ui.main import main | ||
|
||
from . import github | ||
|
||
|
||
@autocommand.autocommand(__name__) | ||
def run(name, value, project: github.Repo = github.Repo.detect()): | ||
@main | ||
def run( | ||
name: str, | ||
value: str, | ||
project: Annotated[ | ||
github.Repo, typer.Option(parser=github.Repo) | ||
] = github.Repo.detect(), | ||
): | ||
project.add_secret(name, value) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import functools | ||
|
||
import autocommand | ||
import path | ||
from jaraco.ui.main import main | ||
from more_itertools import consume | ||
|
||
from . import git | ||
|
||
|
||
@autocommand.autocommand(__name__) | ||
def main(target: path.Path = path.Path()): | ||
@main | ||
def run(target: path.Path = path.Path()): | ||
checkout = functools.partial(git.checkout_missing, root=target) | ||
consume(map(checkout, git.projects())) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import autocommand | ||
from jaraco.ui.main import main | ||
|
||
from . import github, repo | ||
|
||
|
||
@autocommand.autocommand(__name__) | ||
@main | ||
def run(project: github.Repo = github.Repo.detect()): | ||
md = repo.get_project_metadata() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
project.create_release(tag=f'v{md.version}') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
import autocommand | ||
|
||
from build.util import project_wheel_metadata | ||
from jaraco.ui.main import main | ||
|
||
|
||
@autocommand.autocommand(__name__) | ||
def main(path='.', field='Requires-Dist'): | ||
@main | ||
def run(path='.', field='Requires-Dist'): | ||
for spec in project_wheel_metadata(path).get_all(field): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's annotate these? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good. I'd do that here as a suggestion, but I don't know the syntax (where to put the spaces to satisfy the linter), so I'm going to do it outside of this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On second thought, does it make sense to annotate a variable that's assigned a static string? That feels like over-specifying to me. It's so much easier to read without the annotations and even mypy knows it's a string, right? Let's go without it for now. If there's a benefit to adding the type annotations, I'm open to hear it, but I'm more inclined to keep it simple if the typing system supports that. I wonder how typer would handle There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did end up adding the type annotation, which also gave mypy permission to start nitpicking about the |
||
print(spec) |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,40 +2,37 @@ | |||||||||||||||||||||||||||
Routine to run a command across all projects. | ||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
import argparse | ||||||||||||||||||||||||||||
import functools | ||||||||||||||||||||||||||||
import subprocess | ||||||||||||||||||||||||||||
from typing import List, cast | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
import autocommand | ||||||||||||||||||||||||||||
import typer | ||||||||||||||||||||||||||||
from jaraco.ui.main import main | ||||||||||||||||||||||||||||
from typing_extensions import Annotated | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
from . import filters, git | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
parser = argparse.ArgumentParser() | ||||||||||||||||||||||||||||
parser.add_argument( | ||||||||||||||||||||||||||||
'--keyword', | ||||||||||||||||||||||||||||
'-k', | ||||||||||||||||||||||||||||
dest='selectors', | ||||||||||||||||||||||||||||
type=filters.Keyword, | ||||||||||||||||||||||||||||
default=filters.Selectors(), | ||||||||||||||||||||||||||||
action='append', | ||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||
parser.add_argument( | ||||||||||||||||||||||||||||
'--tag', | ||||||||||||||||||||||||||||
'-t', | ||||||||||||||||||||||||||||
dest='selectors', | ||||||||||||||||||||||||||||
type=filters.Tag, | ||||||||||||||||||||||||||||
default=filters.Selectors(), | ||||||||||||||||||||||||||||
action='append', | ||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||
parser.add_argument('args', nargs='*') | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
@autocommand.autocommand(__name__, parser=parser) | ||||||||||||||||||||||||||||
def main( | ||||||||||||||||||||||||||||
selectors: filters.Selectors, | ||||||||||||||||||||||||||||
args=None, | ||||||||||||||||||||||||||||
@functools.partial( | ||||||||||||||||||||||||||||
main, | ||||||||||||||||||||||||||||
app=typer.Typer( | ||||||||||||||||||||||||||||
context_settings=dict(allow_extra_args=True, ignore_unknown_options=True) | ||||||||||||||||||||||||||||
), | ||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||
def run( | ||||||||||||||||||||||||||||
tag: Annotated[ | ||||||||||||||||||||||||||||
List[filters.Tag], typer.Option('--tag', '-t', parser=filters.Tag) | ||||||||||||||||||||||||||||
jaraco marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||
] = [], | ||||||||||||||||||||||||||||
keyword: Annotated[ | ||||||||||||||||||||||||||||
List[filters.Keyword], | ||||||||||||||||||||||||||||
typer.Option('--keyword', '-k', parser=filters.Keyword), | ||||||||||||||||||||||||||||
] = [], | ||||||||||||||||||||||||||||
args: typer.Context = typer.Option(None), | ||||||||||||||||||||||||||||
): | ||||||||||||||||||||||||||||
cmd = cast(List[str], args.args) | ||||||||||||||||||||||||||||
Comment on lines
+30
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That doesn't look correct.
Suggested change
Additionally, I'd name the context parameter There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call. Not sure how I missed this in the review. I went through the whole thing in the files dialog and didn't see it. I'll get it after the fact. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried removing
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that works; done in 3a80b14. |
||||||||||||||||||||||||||||
selectors = filters.Selectors(tag + keyword) | ||||||||||||||||||||||||||||
for project in filter(selectors, git.projects()): | ||||||||||||||||||||||||||||
print(project, flush=True) | ||||||||||||||||||||||||||||
with git.temp_checkout(project, quiet=True): | ||||||||||||||||||||||||||||
subprocess.Popen(args).wait() | ||||||||||||||||||||||||||||
subprocess.Popen(cmd).wait() | ||||||||||||||||||||||||||||
print(flush=True) |
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.
Interesting. I've used
'.'
as a default withgithub.Repo.detect
being the parser for that thus far (as here), which as I see now is completely wrong, becausegithub.Repo.detect()
doesn't take a path as a non-default parameter (shouldn't that change? :P). Ideally IMO, thegithub.Repo
class should be constructible from path (maybe not on the constructor-level, because that would introduce a side effect to instantiating the class, which often feels clunky and unpredictable), from which the project name would be inferred the same way as ingithub.Repo.detect()
.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.
Because
github.Repo
is a subclass ofstr
, it can be constructed from a simple string, but that string needs to be the name of the project in GitHub. I should probably document that.I think what you're suggesting is that
github.Repo.detect(...)
should accept apath
parameter that defaults to.
instead of assuming the repo is in thecwd
. I'd be okay with that, I think.Regardless, this change is about something different - migrating from autocommand to typer, so I'm aiming for feature parity. We can address other concerns in another issue/PR.