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

RE: Add black and mdformat to CI #10

Merged
merged 5 commits into from
Mar 27, 2023
Merged

RE: Add black and mdformat to CI #10

merged 5 commits into from
Mar 27, 2023

Conversation

PraxTube
Copy link
Collaborator

Closes #7

Failed previous attempt #9

This PR adds a python linter and a markdown linter to the CI. I added black and mdformat. If you want to add something else feel free to suggest something. The CI is also testing if the project can be build, so if there are some problems with the build process the CI will fail.

In order for you to format your files on you local branch run

black .
mdformat .

Note that this will format in-place. If you want to check see if something would be formatted before actually doing anything use the --check flag (works for both).

Reviewer Notes

Given that all files need to be formatted in order for the CI to pass, I had to run both black and mdformat, which is why there are so many changes. So here are the things that are actually new (that have not changed because of a formatter):

  • .github/workflow/python-app.yml this contains the github actions instructions
  • requirements.txt added black and mdformat
  • added .mdformat.toml which contains settings for mdformat

The CI will automatically check the formatting of python files with
black and the format of markdown files with mdformat. The CI will fail
if there are any format issues.

In order to format files on you local branch, run

```
black .
mdformat .
```

Note that this will happen **in-place**. You can use the `--check` flag
to see if any files need to be formatted.
@PraxTube PraxTube changed the title RE: Add black and mdformat to CI **RE:** Add black and mdformat to CI Mar 26, 2023
@PraxTube PraxTube changed the title **RE:** Add black and mdformat to CI *RE:* Add black and mdformat to CI Mar 26, 2023
@PraxTube PraxTube changed the title *RE:* Add black and mdformat to CI **RE:** Add black and mdformat to CI Mar 26, 2023
@PraxTube PraxTube changed the title **RE:** Add black and mdformat to CI RE: Add black and mdformat to CI Mar 26, 2023
@PraxTube
Copy link
Collaborator Author

Note that the README.md should be updated too. Though I would honestly rework that altogether (given that there were quite a lot of changes both in the back-end and the front-end). Therefore I would do that in a separate PR.

@efJerryYang
Copy link
Owner

holy..., you can just let me know that you cannot create a branch (I forgot that, my fault), and I can then force push the updated cleaned history to your remote.

@efJerryYang
Copy link
Owner

Wait, you can absolutely create a new branch on your local machine. I just tested the command git checkout -b tmp on a forked repository and no problem occurred.

@efJerryYang
Copy link
Owner

efJerryYang commented Mar 26, 2023

Now, can I just force-push to your remote using the commits I have shown to you in #9 ? This can simplify the procedure, but it will replace your remote commits history, I think you do have it on your local machine currently.

Or I can just merge this PR with your only one commit (I guess it is a merge of the others)?

@efJerryYang
Copy link
Owner

efJerryYang commented Mar 26, 2023

Fine, I will merge it tomorrow morning if no other changes are applied.

@PraxTube
Copy link
Collaborator Author

PraxTube commented Mar 26, 2023

Ah sorry I explained it a bit poorly. I meant that I cannot create branches on your repo (I can of course create local branches, but I can't push them). In order for me to create a pull request I need to have a branch to work on. Because I cannot create branches on you repo, I need to create a fork and create branches there which I can then use to create PR.

I am not sure if this is the usual way you do things, I am used to simple have one repo where everyone that contributes can create branches and then you simple use these branches to create PR (I don't know if the Github Standard is to use forks, I haven't collaborated with many people on Github yet). But I now know how to use my fork and keep it up to date so this should not be a problem in the future.

Regardless, this PR contains all the changes, written in one commit. So if you don't want to add anything to this PR, it's ready to be merged.

@efJerryYang
Copy link
Owner

Yes, we commonly will use the fork of a repository to create PR for collaboration on GitHub. This is regarded as a good practice as it ensures the repository's security when collaborating with other developers we are not familiar. Creating branches will generally be the cases for personal use and not recommended for collaboration, as it may cause a great number of branches and other developers are hard to recognize which one should be for them to work on (although there are something that can specify the exact rights to specific branches, it is another topic and a little tiresome to manage). Forking an independent repository of their own would be much clearer, as developers can focus on their forked repositories, branch their repositories for personal maintenance and raise a PR when they want to merge their contributions to the upstream.

I tend to limit the access right to this repository currently, and later if there are more people interested in this repository I would consider adding you or someone else to the "collaborators" to help manage this repository. But now, only you and I are interested in perfecting this CLI tool so I will keep the original access right.

Anyway, thanks for your interest and contributions to this project! You are always welcome to create new PRs and I will review them as soon as possible!

The original Markdown support is provided by CommonMark, and it lacks support
for Todo list so that make the Todos section broken. We add the dependencies
for full GitHub according to the installing section of https://github.com/executablebooks/mdformat
@efJerryYang
Copy link
Owner

efJerryYang commented Mar 27, 2023

First I add dependencies for full GitHub markdown support for the use of Todos, but the READMEs still look ugly (broken lines, icons alignment at the top of the docs), thus I revert the use of mdformat temporarily. I also revert the changes in demo and old README.

This PR will be merged when a solution to automatic markdown formatting is found.

Update: I only remove the option wrap = 90 in .mdformat.toml for this purpose.

Current `mdformat` causes the READMEs format to be changed in a way not
as expected. It causes the layout of long paragraphs to be broken into
multiple lines and the alignment of the links at the first line of READMEs
to be broken. This is the result of the option `wrap = 90` in `.mdformat.toml`.

This commit remove this option and revert the changes
@efJerryYang
Copy link
Owner

One more thing to be finished before merging: the dependencies inconsistency in pyproject.toml and requirements.txt.

I am not very sure about how to achieve this automatically, and I also have concerns about what you mentioned earlier about the packages in the requirements.txt.

You said in your earlier commit message (which had been squashed into the commit you were creating this PR) that:

It's much better to let the CI build the packages it needs rather than to have them in the requirements.txt.

I only find the "pip install -r requirements.txt" in the python-app.yml, which actually uses the requirements.txt, and not fully understand what you really mean by "rather than to have them in the requirements.txt".

@PraxTube
Copy link
Collaborator Author

Thanks for explaining the workflow on Github in such great detail! Wait you said certainly makes a lot of sense and forking seems like a clean practice. I was pretty unfamiliar with the concept, so I made some mistakes, but I am more familiar with the concept now, so it should work much better in the future.

@PraxTube
Copy link
Collaborator Author

PraxTube commented Mar 27, 2023

Regarding the broken lines in the markdown files: Can you give me an example were the lines broke? To me they seem fine (it only create one \n if the line was too long, which is still valid and doesn't change the way it gets rendered). However I just tested a bit and also saw that mdformat seems strange in certain situations. The numbering was reset (which is actually intentional). But we can use number = true in the .mdformat.toml file to keep the consecutive numbering.

@PraxTube
Copy link
Collaborator Author

The added dependencies should not be added to pyproject.toml because they are only needed for the developers. The end-user doesn't need them, and therefore they should not be inside pyproject.toml.

It's much better to let the CI build the packages it needs rather than to have them in the requirements.txt.

I only find the "pip install -r requirements.txt" in the python-app.yml, which actually uses the requirements.txt, and not fully understand what you really mean by "rather than to have them in the requirements.txt".

The CI also tests the build process. For that in needs certain packages, which could be installed directly through requirements.txt but I found that this is not ideal, because this would mean that any need developer would automatically need to download them too (in the least cases they would ever need to build the package though). That's why instead of putting them in requirements.txt, the CI is instead going to create them by running python3 -m pip install --upgrade build. This will install all packages needed to create the build.

@efJerryYang
Copy link
Owner

Yes, you are right about the rendering using mdformat and I was misled by the rendering of vscode markdown support. It truly does not affect the appearance on GitHub (I checked it at the commit branch da30fe6 just now).

@PraxTube
Copy link
Collaborator Author

Ye the only thing that changed was the numbering see here. However we can disable that by setting number = true in the .mdformat.toml file.

@PraxTube
Copy link
Collaborator Author

I pushed some changes. I added the number = true and also added the wrap = 90 again. The changes made to the .md files are purely new lines now, which doesn't change the way things get rendered.

If you want to format the markdowns differently, feel free to change the settings.

@efJerryYang
Copy link
Owner

I agree with your decision, but one problem leaves here. Do you still use the CommonMark rather than the full support for GitHub? Maybe you need to first install the requirements.txt so that the reformatting later will not change the Todo list (CommonMark would escape the square brackets and the full support would not).

The `CommonMark` would escape square brackets in Todo list, which will
lead the rendering of Todo list not correct in some Markdown renderers.
@efJerryYang
Copy link
Owner

efJerryYang commented Mar 27, 2023

I merged it now.

@efJerryYang efJerryYang merged commit 3deeb46 into efJerryYang:main Mar 27, 2023
@PraxTube
Copy link
Collaborator Author

Awesome 👍

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

Successfully merging this pull request may close these issues.

Use python linter/formatter and CI
2 participants