-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Add primer CI tool 🏴 #1402
Add primer CI tool 🏴 #1402
Conversation
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.
This looks great!
I am assuming this has been already discussed, but can we also rope in some of the top projects here that are mentioned in the README as using Black?
LOG = logging.getLogger(__name__) | ||
|
||
|
||
class Results(NamedTuple): |
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.
suggestion: implement as a dataclass
because we have more reads than writes?
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.
Yeah, not going to do this as benefits are low.
src/black_primer/lib.py
Outdated
path_parts = repo_url_parts.path[1:].split("/", maxsplit=1) | ||
|
||
repo_path: Path = work_path / path_parts[1].replace(".git", "") | ||
cmd = [git_bin, "clone", project_config["git_clone_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.
Would doing a shallow
clone be performant here? Especially with the long_checkouts
option?
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.
Yup - great call.
src/black_primer/cli.py
Outdated
|
||
|
||
DEFAULT_CONFIG = Path(__file__).parent / "primer.json" | ||
DEFAULT_WORKDIR = Path(gettempdir()) / f"primer.{getpid()}" |
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.
suggestion: Would a timestamp: primer.timestamp
be better here?
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.
Agree. Will change to this.
) | ||
@click.option( | ||
"-R", | ||
"--rebase", |
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.
suggestion: --update
or --pull
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.
Is this more common in the Open Source world? I'm stuck thinking in Facebook terms.
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 am going to say --rebase
is pretty intuitive too, so it's fine either way.
@@ -0,0 +1,246 @@ | |||
#!/usr/bin/env python3 | |||
|
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.
this needs a from __future__ import annotations
if used > 3.7
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 really need to sit down and understand this more - I'll ping you to understand on IRC
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.
relevant: https://www.python.org/dev/peps/pep-0563
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.
Sorry, why is this needed at all? It's nice to turn the future import on but I'm not sure why it's necessary here.
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.
Without it we get a runtime TypeError:
I could simplify the typing I guess if we prefer.
src/black_primer/lib.py
Outdated
_stdout, _stderr = await _gen_check_output(cmd, cwd=repo_path) | ||
except asyncio.TimeoutError: | ||
results.stats["failed"] += 1 | ||
LOG.error(f"Running black for {repo_path} timedout ({cmd})") |
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.
nit: timed out
config_file: str, | ||
work_path: Path, | ||
workers: int, | ||
keep: bool = False, |
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.
question: this is unimplemented for now?
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.
Ahhh good find. This should delete the prokects as we finish with them rather than a large delete at the end. Will add!
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.
Absolutely fantastic review @SanketDG ! Appreciate it. Many good little fixes coming in my next commit due to you.
src/black_primer/cli.py
Outdated
|
||
|
||
DEFAULT_CONFIG = Path(__file__).parent / "primer.json" | ||
DEFAULT_WORKDIR = Path(gettempdir()) / f"primer.{getpid()}" |
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.
Agree. Will change to this.
) | ||
@click.option( | ||
"-R", | ||
"--rebase", |
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.
Is this more common in the Open Source world? I'm stuck thinking in Facebook terms.
LOG = logging.getLogger(__name__) | ||
|
||
|
||
class Results(NamedTuple): |
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.
Yeah, not going to do this as benefits are low.
@@ -0,0 +1,246 @@ | |||
#!/usr/bin/env python3 | |||
|
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 really need to sit down and understand this more - I'll ping you to understand on IRC
src/black_primer/lib.py
Outdated
path_parts = repo_url_parts.path[1:].split("/", maxsplit=1) | ||
|
||
repo_path: Path = work_path / path_parts[1].replace(".git", "") | ||
cmd = [git_bin, "clone", project_config["git_clone_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.
Yup - great call.
config_file: str, | ||
work_path: Path, | ||
workers: int, | ||
keep: bool = False, |
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.
Ahhh good find. This should delete the prokects as we finish with them rather than a large delete at the end. Will add!
- Run in PATH `black` binary on configured projects - Can set wether we expect changes or not per project - Can set what python versions are supported for a project - if `long_checkout` True project will not be ran on CI Will add to CI after I finish unit tests to avoid silly bugs I'm sure I have 🤪 Tests: - Manual Run - Will add unit tests if people think it will be useful - Output: ```shell (b) cooper-mbp1:black cooper$ time /tmp/b/bin/black-primer -k -w /tmp/cooper_primer_1 [2020-05-10 08:48:25,696] INFO: 4 projects to run black over (lib.py:212) [2020-05-10 08:48:25,697] INFO: Skipping aioexabgp as it's disabled via config (lib.py:166) [2020-05-10 08:48:25,699] INFO: Skipping bandersnatch as it's disabled via config (lib.py:166) [2020-05-10 08:48:28,676] INFO: Analyzing results (lib.py:225) -- primer results 📊 -- 2 / 4 succeeded (50.0%) ✅ 0 / 4 FAILED (0.0%) 💩 - 2 projects Disabled by config - 0 projects skipped due to Python Version - 0 skipped due to long checkout real 0m3.304s user 0m9.529s sys 0m1.019s ``` - ls of /tmp/cooper_primer_1 ``` (b) cooper-mbp1:black cooper$ ls -lh /tmp/cooper_primer_1 total 0 drwxr-xr-x 21 cooper wheel 672B May 10 08:48 attrs drwxr-xr-x 14 cooper wheel 448B May 10 08:48 flake8-bugbear ```
- Don't use asyncio.run() ... go back to the past :P - Refactor results into a named tuple of two dicts to avoid typing nightmare - Fix some variable names - Fix bug with rebase logic in git_checkout_or_rebase
black
binary on configured projectslong_checkout
True project will not be ran on CIWill add to CI after I finish unit tests to avoid silly bugs I'm sure I have 🤪
Tests:
Addresses #1390