DerwenAI / kglab

Graph Data Science: an abstraction layer in Python for building knowledge graphs, integrated with popular graph libraries – atop Pandas, NetworkX, RAPIDS, RDFlib, pySHACL, PyVis, morph-kgc, pslpython, pyarrow, etc.
https://derwen.ai/docs/kgl/
MIT License
574 stars 65 forks source link

Adding pre-commit to Continuous Integration with GitHub Actions #192

Closed tomaarsen closed 3 years ago

tomaarsen commented 3 years ago

Hello!

@ceteri @louisguitton I'm sure this PR will look somewhat familiar to you, feel free to skim it, as I used my PR from pytextrank as a template.

Pull request overview


Now, let's talk about what I've done:

Renamed docker-demo.yml to ci.yml, and updating it

The updated .github/workflows/ci.yml file works the same as before, with the one addition: It now also runs pre-commit. The renaming was a personal choice. It matches the style used for pytextrank, and it feels more professional than a name that includes "demo".

It does so whenever someone pushes, creates a pull request, or uses the button in the GitHub Actions pane.

Note that pre-commit in particular is very strict. I'm sure you know this. But it will cause the CI to fail if there's a typo in a comment, a single pylint warning, a security warning, a failing test, etc. This could prevent pull requests from being merged until these warnings are resolved. However, this might be exactly what you are after.

Note: The first execution of this workflow took me approximately 8.5 minutes. This time includes 3 minutes for caching the docker. All subsequent executions (I presume, I've only tested one extra run) take less than 5 minutes. You can see the timings here.

To see the exact output generated, click here.

Codespell

I've added codespell to the pre-commit config. The outputs before applying the changes in this PR include:

Resolving pre-commit warnings.

After solving the warnings from codespell, some more changes needed to be made to remove all pre-commit warnings. In particular:

What now?

All tests, like before, pass. In addition, the CI passes, meaning that all elements of pre-commit pass. I would recommend looking over my changes, and looking at my last GitHub Actions CI run. I do recognise that some people prefer testing on their own machine, in which case you can roughly follow:

# Clone my repo
git clone https://github.com/tomaarsen/kglab
cd kglab

# Set up a virtualenvironment (Note, this may differ depending on your OS, I don't need to tell you this)
python -m venv venv
.env39/Scripts/Activate.ps1

# Install requirements
pip install -r requirements.txt
pip install -r requirements-dev.txt

# Run pre-commit on all files
pre-commit run -a

# And then delete the new folder when you've verified that everything works.

You'll see that pre-commit runs without any issues, and this is a big part of what the CI will be doing (alongside running pytest). Furthermore, if you choose to merge this PR, feel free to add me as a contributor on your README.


Lastly, you may need to enable GitHub Actions somewhere within the repository settings (Settings -> Actions -> Actions Permissions)

Let me know if you need anything else from me,

ceteri commented 3 years ago

Looks great, many @tomaarsen !