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

Use pre commit #407

Merged
merged 36 commits into from
Sep 4, 2020
Merged

Use pre commit #407

merged 36 commits into from
Sep 4, 2020

Conversation

s-weigand
Copy link
Member

This PR adds a config for pre-commit, which will be used as more extensive code quality checker.
New code quality features, run before each commit on the staged files:

  • Autoformatting with black
  • Import sorting with isort
  • Removal of unnecessary # noqa comments with yesqa
  • Syntax uprades with pyupgrade
  • Code style checking with flake8
  • Checking of proper format for *.rst files with rstcheck and rst-backticks
  • Basic spellchecking with codespell
  • Some sanity check from pre-commit-hooks (We can't use check-yaml, since it doesn't support custom flags like !tuple)

All those checks will also be run by the CI on the entire code base (pre-commit run --all).

The enforcing of proper docstrings with pydocstyle is deactivated right now.
Because there are 421 isuues to be solved, which else would break the CI.
I think the best approach will be to improve the docstring quality file by file.
To check a single file, run the following command.

pydocstyle.exe <file-folder-path> --ignore-decorators=wrap_func_as_method

The --ignore-decorators=wrap_func_as_method is needed since wrap_func_as_method, generates docstrings using f-strings, which pydocstyle doesn't like

Testing

Passing the tests is mandatory.

Closing issues

closes #388 closes #389

This is a temporary fix until the issue is resolved, see PyCQA/pycodestyle#914
CONTRIBUTING.rst:60: (INFO/1) Hyperlink target "get-started" is not referenced.
docs/source/introduction.rst:9: (WARNING/2) Inline emphasis start-string without end-string.
CONTRIBUTING.rst:63:Ready to contribute? Here's how to set up `pyglotaran` for local development.
CONTRIBUTING.rst:65:1. Fork the `pyglotaran` repo on GitHub.
CONTRIBUTING.rst:118:   Check your Github Actions `https://github.com/<your_name_here>/pyglotaran/actions`
HISTORY.rst:11:* Package was renamed to `pyglotaran` on PyPi
HISTORY.rst:16:* Changed `nan_policiy` to `omit`
docs/source/index.rst:4:   contain the root `toctree` directive.
docs/source/quickstart.rst:23:Like all data in `glotaran`, the dataset is a :class:`xarray:xarray.Dataset`.
docs/source/quickstart.rst:24:You can find more infomation about the `xarray` library the `xarray hompage`_.
docs/source/quickstart.rst:72:To analyze our data, we need to create a model. Create a file called `model.py`
docs/source/quickstart.rst:150:You can check your model for problems with `model.validate`.
docs/source/quickstart.rst:156:Now define some starting parameters. Create a file called `parameter.yml` with
docs/source/quickstart.rst:195:You can `model.validate` also to check for missing parameters.
docs/source/quickstart.rst:222:You can get the resulting data for your dataset with `result.get_dataset`.
glotaran/model/util.py:21: orginal ==> original
glotaran/model/util.py:23: orginal ==> original
glotaran/model/util.py:25: documenation ==> documentation
glotaran/model/util.py:25: orginal ==> original
glotaran/model/util.py:25: documenation ==> documentation
glotaran/builtin/models/kinetic_image/initial_concentration.py:1: intial ==> initial
glotaran/parameter/parameter.py:31: paramter ==> parameter
glotaran/parameter/parameter.py:80: dictonary ==> dictionary
docs/source/installation.rst:79: preffered ==> preferred
glotaran/analysis/simulation.py:35: Conditionaly ==> Conditionally
glotaran/analysis/result.py:36: dictonary ==> dictionary
glotaran/builtin/models/kinetic_spectrum/spectral_constraints.py:80: documention ==> documentation
glotaran/cli/commands/optimize.py:15: infered ==> inferred
glotaran/cli/commands/optimize.py:112: occured ==> occurred
glotaran/cli/commands/optimize.py:120: successfull ==> successful
glotaran/cli/commands/optimize.py:120: follwing ==> following
glotaran/cli/commands/optimize.py:124: occured ==> occurred
glotaran/analysis/nnls.py:1: conditionaly ==> conditionally
glotaran/analysis/nnls.py:13: conditionaly ==> conditionally
glotaran/parameter/parameter_group.py:29: hirachy ==> hierarchy
glotaran/parameter/parameter_group.py:373: seperator ==> separator
glotaran/parameter/parameter_group.py:382: seperator ==> separator
glotaran/parameter/parameter_group.py:383: seperator ==> separator
glotaran/parameter/parameter_group.py:386: seperator ==> separator
glotaran/parameter/parameter_group.py:390: seperator ==> separator
glotaran/parameter/parameter_group.py:390: seperator ==> separator
glotaran/parameter/parameter_group.py:404: seperator ==> separator
glotaran/analysis/variable_projection.py:1: conditionaly ==> conditionally
glotaran/analysis/variable_projection.py:13: conditionaly ==> conditionally
glotaran/model/model.py:152: Conditionaly ==> Conditionally
glotaran/model/model.py:156: standart ==> standard
glotaran/model/model.py:186: dictonary ==> dictionary
glotaran/model/model.py:221: dictonary ==> dictionary
glotaran/cli/commands/explore.py:114: ouput ==> output
docs/source/quickstart.rst:24: infomation ==> information
This was needed since black replaced the single quotes with double quotes
pydocstyle is very strict on how a good docstring should look like and also complains about missing docstrings. Since pre-commit, with all its hooks, is our new code quality checker the 421 issues pydocstyles finds would break the CI. Thus I leave the fixing of the docstrings to our core developers who know exactly what which function does and what the docstring should look like ;)
@s-weigand s-weigand added the Type: Tooling Tools used for the project (CI, CD, docs etc.) label Sep 1, 2020
@s-weigand s-weigand requested a review from jsnel September 1, 2020 15:01
@codecov
Copy link

codecov bot commented Sep 1, 2020

Codecov Report

Merging #407 into master will increase coverage by 0.4%.
The diff coverage is 65.5%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master    #407     +/-   ##
========================================
+ Coverage    66.6%   67.0%   +0.4%     
========================================
  Files          65      65             
  Lines        3019    3044     +25     
  Branches      603     597      -6     
========================================
+ Hits         2011    2040     +29     
+ Misses        884     880      -4     
  Partials      124     124             
Impacted Files Coverage Δ
glotaran/builtin/models/doas/oscillation.py 100.0% <ø> (ø)
glotaran/cli/commands/explore.py 0.0% <0.0%> (ø)
glotaran/cli/commands/optimize.py 0.0% <0.0%> (ø)
glotaran/cli/commands/util.py 0.0% <0.0%> (ø)
glotaran/cli/commands/validate.py 0.0% <0.0%> (ø)
glotaran/cli/main.py 0.0% <0.0%> (ø)
glotaran/examples/__init__.py 0.0% <0.0%> (ø)
glotaran/examples/sequential.py 0.0% <0.0%> (ø)
...ile_formats/ascii/wavelength_time_explicit_file.py 22.8% <22.5%> (+0.4%) ⬆️
glotaran/analysis/scheme.py 56.5% <37.5%> (+0.4%) ⬆️
... and 51 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c70981d...92462b5. Read the comment docs.

@s-weigand
Copy link
Member Author

Should I fix the issues with SonarCloud Code Analysis and Codacy or @jsnel do you want to do it for the whole code base at a later point?
Btw not my errors, but it got picked up because the reformatting touched a lot of files, which weren't checked before 😉

@jsnel
Copy link
Member

jsnel commented Sep 1, 2020

@s-weigand feel free to make some corrections, not everything is fixable now but do what you can.

Copy link
Member

@jsnel jsnel left a comment

Choose a reason for hiding this comment

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

Reviewed ok!

I went through the individual commits and ignored (most) of the commits tagged IGNORE which were just reformatting.

docs/source/conf.py Outdated Show resolved Hide resolved
docs/source/conf.py Outdated Show resolved Hide resolved
@@ -6,7 +6,7 @@ It is designed to provide a state of the art modeling toolbox to researchers, in

Its features are:

* user-friendly modeling with a custom YAML (*.yml) based modeling language
* user-friendly modeling with a custom YAML (``*.yml``) based modeling language
Copy link
Member

Choose a reason for hiding this comment

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

I have seen a mix of .yml and .yaml, I know both are possible, and that the creator(s) of YAML prefer .yaml whereas the rest of the world prefers .yml but better check if we don't mix and match ourselves, that may be confusing for first time users.

Copy link
Member Author

Choose a reason for hiding this comment

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

IMHO that is up to a different PR + issue, just for checking the text in the docs.

docs/source/quickstart.rst Outdated Show resolved Hide resolved
glotaran/analysis/nnls.py Show resolved Hide resolved
glotaran/__init__.py Outdated Show resolved Hide resolved

__version__ = '0.1.0'
__version__ = "0.1.0"
Copy link
Member

Choose a reason for hiding this comment

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

reminder to maintainers: to be increased to 0.2.0 in the near future

glotaran/analysis/result.py Outdated Show resolved Hide resolved
glotaran/analysis/result.py Outdated Show resolved Hide resolved
forcing import to be each on its own line
* Removed unneeded path setup

* Replaced hardcoded author and title with variables

* Replaced unsave http links with https

* Fixed sonarcloud issues in wavelength_time_explicit_file

* Made errors raised in simulate less generic

* Made errors raised in IrfMultiGaussian less generic

* Made errors raised in _calculate_for_k_matrix less generic

* Made errors raised in Scheme less generic and combined nested if statements

* Renamed set to model_set, not to overwrite builtin set

* Made errors raised in Model less generic

* Made errors raised in Parameter less generic

* Made errors raised in ParameterGroup less generic

* Made errors raised in model_attribute less generic

* Made errors raised in model.decorator less generic and combined nested if

* Improved some docstrings

* Commented out unused variable and added TODO comment
@s-weigand
Copy link
Member Author

s-weigand commented Sep 2, 2020

Got the sonarcloud code smells down from 53 to 25 (some were caused by reformatting i.e. func("foo " "bar")).
The one Security Hotspot, is because of http://glotaran.org, but since the certificate isn't validated (i.e. by letsencrypt), I left it to be http instead of https, so users won't be prompted the "Continue on your own risk" dialog.
IMHO the other issues need to be addressed in a different PR and I feel pretty much done here, so feel free to merge it whenever you feel like it. 😄

@@ -49,7 +49,7 @@ def __init__(self,
self._optimized_parameter = parameter
self._nfev = nfev
self._nvars = nvars
self._ndata = ndata,
self._ndata = (ndata,)
Copy link
Member

Choose a reason for hiding this comment

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

@s-weigand Why that?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is just a more obious to declare a single value tuple, since a comma can be easily overlooked.

except Exception as e:
raise Exception(f"Error opening scheme: {e}")
raise OSError(f"Error opening scheme: {e}")
Copy link
Member

Choose a reason for hiding this comment

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

@s-weigand Are all this changes in the exceptions done by you or py black?

Copy link
Member Author

Choose a reason for hiding this comment

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

The Exception changes are all done by me (only in this case pyupgrade changed my IOError to an OSError), so sonar cloud complains about less code smells see s-weigand#14 and #409 .

Copy link
Member Author

Choose a reason for hiding this comment

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

For the OSError see the changes in python 3.3 https://docs.python.org/3/library/exceptions.html#OSError.filename2

@sonarcloud
Copy link

sonarcloud bot commented Sep 4, 2020

SonarCloud Quality Gate failed.

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 1 Security Hotspot to review)
Code Smell A 25 Code Smells

No Coverage information No Coverage information
11.8% 11.8% Duplication

@joernweissenborn joernweissenborn merged commit 328357b into glotaran:master Sep 4, 2020
@s-weigand s-weigand deleted the use-pre-commit branch September 8, 2020 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Tooling Tools used for the project (CI, CD, docs etc.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Format code with black Use pre-commit-hooks
3 participants