-
Notifications
You must be signed in to change notification settings - Fork 1
Add workflows and adjust configuration #8
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # This workflow will install Python dependencies, run tests and lint with a single version of Python | ||
| # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python | ||
|
|
||
| name: Python Workflow | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main, develop] | ||
| pull_request: | ||
| branches: [main, develop] | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
| fetch-tags: true | ||
| - name: Set up Python 3.11 | ||
| uses: actions/setup-python@v3 | ||
| with: | ||
| python-version: "3.11" | ||
| - name: Install dependencies | ||
| run: | | ||
| pip install --upgrade pip setuptools && pip install .[dev] | ||
| - name: Run flake8 lint checks | ||
| run: | | ||
| # stop the build if there are Python syntax errors or undefined names | ||
| flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | ||
| # exit-zero treats all errors as warnings | ||
| flake8 . --count --exit-zero --max-complexity=10 --max-line-length=120 --statistics | ||
| - name: Run black format checks | ||
| run: black --check --diff ogc example || true # For now pass even if files need formatting | ||
| - name: Run pytest with coverage | ||
| run: | | ||
| pytest -v --cov=ogc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| repos: | ||
| - repo: https://github.com/ambv/black | ||
| rev: stable | ||
| hooks: | ||
| - id: black | ||
| language_version: python3 | ||
| files: (^ogc|^example) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,6 +57,7 @@ dev = [ | |
| # FORMATTING | ||
| "pre_commit", | ||
| "black", | ||
| "flake8", | ||
| ] | ||
|
|
||
| [tool.setuptools.packages.find] | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
For my own curiosity more than anything else - what does this file affect? Does it create a pre-commit hook for commits that are done through the GitHub site, or is it something that's meant to take effect on developer machines?
Uh oh!
There was an error while loading. Please reload this page.
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.
It's supposed to take effect on the developer's machine. This prevents you from committing code that hasn't been formatted using Black. Unfortunately, there have been cases where developers do not properly install this precommit hook, and so unformatted text does show up in the repo.
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 - how does one install that hook? I don't see any directions in the readme, and git commands usually don't take yaml files, is there a tool we're supposed to use?
We could also flip a switch now, to make Black formatting mandatory for pull requests to be accepted: line 35
I'm personally not a fan of pre-commit hooks for a couple reasons:
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.
The hook "used" to get automatically installed with setup.py. See here: https://github.com/creare-com/ogc/blob/main/setup.py#L66C7-L66C25 and here: https://github.com/creare-com/ogc/blob/main/setup.py#L102
With Python's move to a pyproject.toml file, I'm not sure how this works anymore.
The main advantages of this approach is that the automatic formatting makes the total codebase smaller, and you don't have to look at all the changes to to formatting when you're reviewing a merge request. In theory it's also automatic with no effort on the developer's part... in practice the hook seems to misbehave. Personally, I'm a fan of doing both the CI check and the hook.
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 can totally get behind that! Seems like one of those situations where the redundancy is helpful.
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.
Setup.py still gets called with pyproject.toml present. However our
PostDevelopCommanddoes not. In order to get the pre commit install you now need to runpython setup.py developdirectly. I can add a note on this or come up with a workaround.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 think we provide a
setup.shfile in our python project template to install precommit hooks now... that was the best workaround we came up with.