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

Add primer CI tool 🏴 #1402

Merged
merged 6 commits into from May 17, 2020
Merged

Add primer CI tool 🏴 #1402

merged 6 commits into from May 17, 2020

Conversation

cooperlees
Copy link
Collaborator

@cooperlees cooperlees commented May 10, 2020

  • 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:
(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

Addresses #1390

@cooperlees cooperlees added the T: enhancement New feature or request label May 10, 2020
@cooperlees cooperlees changed the title Add primer CI tool πŸ’© Add primer CI tool 🏴 May 10, 2020
Copy link
Contributor

@SanketDG SanketDG left a 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):
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

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"]]
Copy link
Contributor

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup - great call.



DEFAULT_CONFIG = Path(__file__).parent / "primer.json"
DEFAULT_WORKDIR = Path(gettempdir()) / f"primer.{getpid()}"
Copy link
Contributor

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?

Copy link
Collaborator Author

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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: --update or --pull

Copy link
Collaborator Author

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.

Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Collaborator Author

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

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.

Copy link
Collaborator Author

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:

https://pastebin.com/fve4q60S

I could simplify the typing I guess if we prefer.

_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})")
Copy link
Contributor

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,
Copy link
Contributor

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?

Copy link
Collaborator Author

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!

Copy link
Collaborator Author

@cooperlees cooperlees left a 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.



DEFAULT_CONFIG = Path(__file__).parent / "primer.json"
DEFAULT_WORKDIR = Path(gettempdir()) / f"primer.{getpid()}"
Copy link
Collaborator Author

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",
Copy link
Collaborator Author

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):
Copy link
Collaborator Author

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

Copy link
Collaborator Author

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

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"]]
Copy link
Collaborator Author

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,
Copy link
Collaborator Author

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants