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

Lint #1093

Merged
merged 15 commits into from
Oct 13, 2023
Merged

Lint #1093

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[run]
omit = *HardwareRepository/*
omit = *HardwareRepository/*
12 changes: 12 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[flake8]
ignore = E203, E266, E501, W503, F403, F401
max-line-length = 88
max-complexity = 18
select = B,C,E,F,W,T4,B9
exclude =
.git,
__pycache__,
docs/conf.py,
build,
dist,
test,
43 changes: 20 additions & 23 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build and test
name: Lint and test

on: [push, pull_request]

Expand All @@ -8,7 +8,7 @@ jobs:
strategy:
max-parallel: 5
matrix:
python-version: ["3.10"] #, "3.9", "3.10"]
python-version: ["3.10"] #, "3.9", "3.10"]

# Skip `pull_request` runs on local PRs for which `push` runs are already triggered
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
Expand All @@ -35,26 +35,23 @@ jobs:
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Add conda to system path
run: |
# $CONDA is an environment variable pointing to the root of the miniconda directory
echo $CONDA/bin >> $GITHUB_PATH
- name: Install ldap dependencies

- name: Install LDAP dependencies
run: sudo apt-get -y install libsasl2-dev libldap2-dev libssl-dev
- name: Install dependencies
run: |
conda install -c conda-forge mamba
mamba env update --file conda-environment.yml --name base
pip install -e .
- name: Lint with flake8
run: |
#conda install flake8
# 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. The GitHub editor is 127 chars wide
#flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics

- name: Set up Conda environment
uses: mamba-org/setup-micromamba@v1
with:
micromamba-version: "latest"
environment-file: conda-environment.yml
cache-environment: true
post-cleanup: "all"

- name: Install MXCuBE
run: "${MAMBA_EXE} run --name mxcubeweb poetry install"

- name: Linting & Code Quality
run: "${MAMBA_EXE} run --name mxcubeweb poetry run pre-commit run --all-files"

- name: Test with pytest
run: |
conda install pytest
conda install pytest-cov
pytest
run: "${MAMBA_EXE} run --name mxcubeweb poetry run pytest"
57 changes: 57 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
default_language_version:
python: python3.10
repos:
- repo: https://github.com/python-poetry/poetry
rev: 1.5.0
hooks:
- id: poetry-check
language_version: python3.10
# - id: poetry-lock
# language_version: python3.10
- repo: https://github.com/myint/autoflake
rev: v1.6.0
hooks:
- id: autoflake
name: Autoflake
args:
- --expand-star-imports
- --ignore-init-module-imports
- --in-place
- --remove-duplicate-keys
- --ignore-pass-after-docstring
- repo: https://github.com/psf/black
rev: 22.8.0
hooks:
- id: black
name: Black
language_version: python3.10
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-case-conflict
- id: check-merge-conflict
# exclude files where underlines are not distinguishable from merge conflicts
exclude: /README\.rst$|^docs/.*\.rst$
- id: check-symlinks
- id: check-xml
- id: check-yaml
exclude: ^.drone\.yml|meta.yaml
- id: mixed-line-ending
args: ["--fix=lf"]
# - repo: https://github.com/PyCQA/isort
# rev: 5.10.1
# hooks:
# - id: isort
# name: Import Sort
# args:
# - --settings=.
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: flake8
name: Flake8
# Not using bugbear for now
# additional_dependencies: ["flake8-bugbear==22.9.11"]
exclude: (ui/|test/)
34 changes: 17 additions & 17 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Pull requests (PR's) are used to submitt new code to the repository, it helps de
```bash
git remote add upstream [email protected]:mxcube/mxcubecore.git
```

A branching model based on the popular [gitlfow model](https://nvie.com/posts/a-successful-git-branching-model/) is used inorder to be able to provide versioned releases and at the same time continue seperate development. The stable releases are kept on the [**master**](https://github.com/mxcube/mxcube3/tree/master) branch and the development takes place on [**develop**](https://github.com/mxcube/mxcube3/tree/develop).

This means that all pull requests should be made against the [**develop**](https://github.com/mxcube/mxcube3/tree/develop) branch. The work on the **develop** branch is performed by simply creating a branch for the work to be done and then making a PR according to the description below.
Expand All @@ -34,7 +34,7 @@ This means that all pull requests should be made against the [**develop**](https
git checkout develop
git rebase upstream/develop
```

* If you already are working on the **develop** branch and tracking the official repository, simply:
```bash
git pull --rebase develop
Expand All @@ -47,19 +47,19 @@ We **recommend to always rebase your local changes instead of merging them**, gi

#### Preparing a new commit
* First, make sure that you are working with the latest changes from develop
```bash
```bash
git checkout develop`
git pull --rebase develop
```
* Create a new branch, its recommended to use a meaningfull name. for instance [initials]-[fix/feature]-[some name] i.e mo-feature-gizmo1
`git checkout -b mo-feature-gizmo1`
* If the pull request is associated with an issue then reference the issue in the name. For example:
`git checkout -b issue_100`
`git checkout -b issue_100`
* Edit necessary files, delete existing or add a new file.
* Add files to the staging area:
`git add ChangedFile1 ChangedFile2`
* Save your new commit to the local repository:
`git commit`
`git commit`
* Commit command will open a text editor:
* In the first line write a short commit summary (max 50 characters. It will appear as a title of PR.
* Add an empty line.
Expand All @@ -81,25 +81,25 @@ git pull --rebase develop
* The changes made in the PR are assumed to be tested by the author
* All the assigned reviewers of a PR have to review the PR before it can be merged.
* A PR that has no reviewer assigned can be reviewed by anyone.
* The author of the PR is free to merge the PR once its been reviewed and all pending comments/discussions are solved
* The author of the PR is free to merge the PR once its been reviewed and all pending comments/discussions are solved

### Versioning
### Versioning
Versioning is partly automated by GitHub actions and [Poetry](https://python-poetry.org/)) and based on the gitflow braching model:

- Each new feature is implemented in a `feature branch`, branching from the `develop branch`.

- The minor version is bumped automatically by the CI workflow when a PR is merged on develop
- The minor version is bumped automatically by the CI workflow when a PR is merged on develop

- The merge of a `feature branch` is made via PR to the `develop branch`. The author of
- The merge of a `feature branch` is made via PR to the `develop branch`. The author of
the PR must solve any conflicts with the latest development version before the merge.

- When decided, a release branch is created from the development branch and becomes
a release candidate version.

- Once the code can be released, the release branch is merged to the `master branch` and
also to the `develop branch`.
- If a bug is found in a released version, a `hotfix branch` is created with the

- If a bug is found in a released version, a `hotfix branch` is created with the
necessary changes and applied to the `main branch` and the corresponding commits are
also cherry-picked to the development branch.

Expand All @@ -108,8 +108,8 @@ The exact routine is described more preceisly in [MEP01](https://github.com/mxcu
### Coding convention and style guidelines

#### Units
Functions returning a value representing a physical quantity should in general be assoicated with
a unit. It has been agreed that the following units should, where applicable, be used across the
Functions returning a value representing a physical quantity should in general be assoicated with
a unit. It has been agreed that the following units should, where applicable, be used across the
code base

* mm (millimeter) for translative motors and sizes
Expand All @@ -122,7 +122,7 @@ code base
* Datetime YYYY-MM-DD HH:MM:SS(.ff) ,possibly with hundreds of seconds (ff), and with 24 hour clock.

#### Type hints
We strongly encourage the usage of type hints
We strongly encourage the usage of type hints

#### Naming convention

Expand All @@ -138,13 +138,13 @@ We strongly encourage the usage of type hints
* names of maps are plural or contain 'map', 'dict', 'data', or an internel '2', like 'name2state'
* variables should distinguish between objects (e.g. 'motor') and their names or string representations (e.g. 'motor_name'))
* Booleans can be indcated by participles (e.g. 'enabled', 'tunable') or an 'is_' prefix. We should use positive rather than negative expressions (e.g. 'enabled' rather than 'disabled')

#### Properties v. functions
* You should prefer functions ('get_', 'set_', 'update_') when attributes are mutable and changing the value requires moving hardware or is slow or has side effects, or where you (might) need additional parameters like swithces or timeout values.
* For Boolean states prefer e.g. set_enabled (True/False) rather than separate enable()/disable() functions.
* You should prefer properties for simple properties or states of objects (e.g. 'name', 'user_name', 'tolerance'). Contained HardwareObjects also use properties


#### Style guidlines

It is very important to write a clean and readable code. Therefore we follow the [PEP8 guidlines](https://www.python.org/dev/peps/pep-0008/). Minimal required guidlines are:
Expand Down
3 changes: 1 addition & 2 deletions conda-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ dependencies:
- python >=3.8,<3.11
- openldap
- python-ldap=3.4.0
- pip
- poetry
- nodejs
- redis-server
- pnpm
- pnpm
4 changes: 2 additions & 2 deletions conda-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ mxcube_download() {
echo >&2 'You need git, curl, or wget to install MXCuBE'
exit 1
fi

command git clone "$(mxcube_web_source)" "$(mxcube_install_dir)" || {
echo >&2 'Failed to clone mxcube-3 repo. Please report this !'
exit 2
Expand All @@ -41,7 +41,7 @@ mxcube_download() {
command cd "$(mxcubecore_install_dir)"
command pip install -e .
command cd ..

command cd "$(mxcube_install_dir)"
}

Expand Down
4 changes: 2 additions & 2 deletions debian-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ mxcube_download() {
echo >&2 'You need git, curl, or wget to install MXCuBE'
exit 1
fi

command git clone "$(mxcube_source)" "$(mxcube_install_dir)" || {
echo >&2 'Failed to clone mxcube-3 repo. Please report this !'
exit 2
Expand All @@ -44,7 +44,7 @@ install_debian_deps() {
command sudo apt-get install v4l2loopback-dkms v4l2loopback-utils

#ffmpeg
command sudo apt-get install ffmpeg
command sudo apt-get install ffmpeg
}

install_python_deps() {
Expand Down
2 changes: 1 addition & 1 deletion docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ Point the browser to localhost:8090 to start using MXCuBE3

The test credentials are:
username: idtest0
password: 000
password: 000
30 changes: 17 additions & 13 deletions mxcube3/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import argparse
import mock
import os
import redis
import sys
import traceback


from gevent import monkey

monkey.patch_all(thread=False)

from mxcube3.server import Server as server
from mxcube3.app import MXCUBEApplication as mxcube
from mxcube3.config import Config
# Disabling E402 (module level import not at top of file)
# for the lines below as we are monkey patching
import argparse # noqa: E402
import mock # noqa: E402
import os # noqa: E402
import redis # noqa: E402
import sys # noqa: E402
import traceback # noqa: E402

from mxcubecore import HardwareRepository as HWR
from mxcube3.server import Server as server # noqa: E402
from mxcube3.app import MXCUBEApplication as mxcube # noqa: E402
from mxcube3.config import Config # noqa: E402
from mxcubecore import HardwareRepository as HWR # noqa: E402

sys.modules["Qub"] = mock.Mock()
sys.modules["Qub.CTools"] = mock.Mock()
Expand Down Expand Up @@ -66,7 +66,11 @@ def parse_args(argv):
"-el",
"--enabled-loggers",
dest="enabled_logger_list",
help="Which loggers to use, default is to use all loggers ([exception_logger, hwr_logger, mx3_hwr_logger, user_logger, queue_logger])",
help=(
"Which loggers to use, default is to use all loggers"
" ([exception_logger, hwr_logger, mx3_hwr_logger,"
" user_logger, queue_logger])"
),
default=[
"exception_logger",
"hwr_logger",
Expand Down
Loading
Loading