Skip to content

Commit

Permalink
Integrating ruff precommit (#1473)
Browse files Browse the repository at this point in the history
* added new categories (#1478)

* added new categories

* added try-except

* bugfix list to dictionary

* added output consistency field and blackened code

* Update columns_information.py

* Generalize Standard Run  (#1411)

* Modify header calculation to choose from predefined example output file or standard example output file

* Remove the readiness function from SCRA because it is redundant, since those checks are also performed by the amenable function

* Remove unused method

* Make csv serialization work for any kind of model api response

* Remove the standard flag from the CLI since it is now the default run

* Update tests

* Add Ruff as Linter and Formatter

* Unnecessary files removed

* Unnecessary files removed

* Merge sample command with the example command (#1422)

* Merge sample command with the example command

* Fix example command usage

* Unnecessary files removed

* Unnecessary files removed

* Unnecessary files removed

* Generalize Standard Run  (#1411)

* Modify header calculation to choose from predefined example output file or standard example output file

* Remove the readiness function from SCRA because it is redundant, since those checks are also performed by the amenable function

* Remove unused method

* Make csv serialization work for any kind of model api response

* Remove the standard flag from the CLI since it is now the default run

* Update tests

* Unnecessary files removed

* Unnecessary files removed

* Unnecessary files removed

* Unnecessary files removed

* Unnecessary files removed

* Generalize Standard Run  (#1411)

* Modify header calculation to choose from predefined example output file or standard example output file

* Remove the readiness function from SCRA because it is redundant, since those checks are also performed by the amenable function

* Remove unused method

* Make csv serialization work for any kind of model api response

* Remove the standard flag from the CLI since it is now the default run

* Update tests

* Unnecessary files removed

* Unnecessary files removed

* Unnecessary files removed

* Unnecessary files removed

* Unnecessary files removed

* Reconfiguring ruff to make it simple

* Generalize Standard Run  (#1411)

* Modify header calculation to choose from predefined example output file or standard example output file

* Remove the readiness function from SCRA because it is redundant, since those checks are also performed by the amenable function

* Remove unused method

* Make csv serialization work for any kind of model api response

* Remove the standard flag from the CLI since it is now the default run

* Update tests

* Unnecessary files removed

* Unnecessary files removed

* Unnecessary files removed

* Unnecessary files removed

* Unnecessary files removed

* Upstream merge

* Ruff importing sorting

* updating readme for linting guidline

* circular import fix

* example command fix

* few code fix

* few code fix

* few code fix

* few code fix

* few code fix

* few code fix

* few code fix

* few code fix

* few code fix

* few code fix

* few code fix

* Code fix

* Code fix

* Code fix

* Code fix

* Code fix

* Update close.py

* Update test.py

* Update information.py

* Update test.py

---------

Co-authored-by: Miquel Duran-Frigola <[email protected]>
Co-authored-by: Dhanshree Arora <[email protected]>
  • Loading branch information
3 people authored Jan 3, 2025
1 parent bc98caf commit c41fb34
Show file tree
Hide file tree
Showing 213 changed files with 3,093 additions and 1,127 deletions.
7 changes: 3 additions & 4 deletions .github/scripts/airtableops.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import os

import requests
import pyairtable
import requests
import yaml

from ersilia.hub.content.card import BaseInformation
from ersilia.hub.content.card import RepoMetadataFile
from ersilia.utils.terminal import run_command
from ersilia.hub.content.card import BaseInformation, RepoMetadataFile
from ersilia.utils.logging import make_temp_dir
from ersilia.utils.terminal import run_command

GITHUB_ORG = "ersilia-os"
AIRTABLE_MODEL_HUB_BASE_ID = "appgxpCzCDNyGjWc8"
Expand Down
5 changes: 3 additions & 2 deletions .github/scripts/convert_airtable_to_json.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import os
import json
import logging
import os

import boto3
from botocore.exceptions import ClientError, NoCredentialsError
import requests
from botocore.exceptions import ClientError, NoCredentialsError

AIRTABLE_MODEL_HUB_BASE_ID = "appgxpCzCDNyGjWc8"
AIRTABLE_TABLE_ID = "tblZGe2a2XeBxrEHP"
Expand Down
4 changes: 2 additions & 2 deletions .github/scripts/generate_eos_identifier.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import json
import os
import random
import string
import json
import subprocess
import os


def run_command_check_output(cmd):
Expand Down
3 changes: 2 additions & 1 deletion .github/scripts/place_a_dockerfile_in_current_eos_repo.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os
import shutil
import sys

import requests
import shutil

BUILD_VERSIONS = ["ersiliapack", "legacy-bentoml", "multistage-condapack"]
ENV_TYPES = ["conda", "pip"]
Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/static_version_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def wrapper(package_path):
with open(toml_path, "r") as f:
toml_content = f.read()
toml_content = re.sub(
'version\s=\s"[0-9\.]+"', f'version = "{version}"', toml_content
r'version\s=\s"[0-9\.]+"', f'version = "{version}"', toml_content
)
with open(toml_path, "w") as f:
f.write(toml_content)
Expand Down
4 changes: 2 additions & 2 deletions .github/scripts/update_metadata.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import json
import yaml
import logging
import os
import time

import yaml
from github import Github, GithubException


Expand Down Expand Up @@ -43,7 +43,7 @@ def load_json_input(self):
This is the JSON data parsed from the new model submission request (GitHub issue)
:return: dict
"""
self.log.info(f"loading JSON input from env vars")
self.log.info("loading JSON input from env vars")

# Load the JSON input from the env vars and convert it to a dict
return json.loads(os.environ.get("JSON"))
Expand Down
2 changes: 0 additions & 2 deletions .github/scripts/update_model_request_template.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import os

# Paths to the tag files and the model_request template
tag_file = "ersilia/hub/content/metadata/tag.txt"
model_request_file = ".github/ISSUE_TEMPLATE/model_request.yml"
Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/update_model_workflows_from_template.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
import os
import shutil
import subprocess
import sys

model_repo = sys.argv[1]

Expand Down
1 change: 1 addition & 0 deletions .github/scripts/upload_model_to_s3.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys

from ersilia.publish.s3 import S3BucketRepoUploader

model_id = sys.argv[1]
Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/write_secrets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import collections
import json
import os
import collections

OUTPUT = "secrets.json"

Expand Down
28 changes: 11 additions & 17 deletions .github/workflows/pr_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on:
branches: [ master ]
push:
branches: [ master ]

workflow_dispatch:

permissions:
Expand All @@ -14,42 +13,39 @@ permissions:
jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
shell: bash -el {0}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # [email protected]

- name: Add conda to system path
run: echo $CONDA/bin >> $GITHUB_PATH

- name: Set Python to 3.10.10
run:
conda install -y python=3.10.10

- name: Source conda
run: source $CONDA/etc/profile.d/conda.sh
- uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
python-version: "3.10.10"

- name: Install dependencies
run: |
source activate
conda init
conda install git-lfs -c conda-forge
git-lfs install
conda install gh -c conda-forge
- name: Install Ersilia
run: |
source activate
python --version
echo "After conda init"
conda init
python -m pip install -e .[test]
- name: Run Ruff
run: ruff check --output-format=github .

- name: Hub catalog
run: |
ersilia catalog --hub
- name: Fetch model from GitHub
run: |
source activate
ersilia -v fetch molecular-weight --from_github
echo "Serving molecular-weight model."
ersilia serve molecular-weight --track
Expand All @@ -59,7 +55,6 @@ jobs:
- name: Fetch model from S3
run: |
source activate
ersilia -v fetch molecular-weight --from_s3
echo "Serving molecular-weight model."
ersilia serve molecular-weight --track
Expand All @@ -69,7 +64,6 @@ jobs:
- name: Fetch model from DockerHub
run: |
source activate
ersilia -v fetch molecular-weight --from_dockerhub
echo "Serving molecular-weight model." --track
ersilia serve molecular-weight
Expand All @@ -79,4 +73,4 @@ jobs:
- name: Local catalog
run: |
ersilia catalog --local
ersilia catalog --local
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.4
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,40 @@ The Ersilia Model Hub is a Free, Open Source Software and we highly value new co

The Ersilia Open Source Initiative adheres to the [Contributor Covenant](https://ersilia.gitbook.io/ersilia-wiki/code-of-conduct) code of conduct.

### Development Guidelines

To maintain consistency and code quality, we follow certain coding and linting standards. Please adhere to these guidelines when contributing:

#### Pre-commit Hooks

We use `pre-commit` and `ruff` to automate code quality checks. Ensure you install and set up `pre-commit` and `ruff` before committing any changes:

1. Install pre-commit: `pip install pre-commit`
2. Set up pre-commit hooks in your local repository by running:
```bash
pre-commit install
```
3. When you commit it automatically fix the issues but will fail for critical error such as missing docstring on a public class and public methods.

#### Manual with Ruff

1. Run `ruff` to check for linting errors:
```bash
ruff check .
```
2. Automatically fix linting issues (where possible):
```bash
ruff check . --fix
```

#### Docstring Style

We adhere to the [NumPy-style docstring format](https://numpydoc.readthedocs.io/en/latest/format.html). Please document all public methods and functions using this style.

Consistent documentation ensures the code is easy to understand and maintain.

Thank you for your contributions and for helping make the Ersilia Model Hub a better project!

### Submit a New Model

If you want to incorporate a new model in the platform, open a new issue using the [model request template](https://github.com/ersilia-os/ersilia/issues/new?assignees=&labels=new-model&template=model_request.yml&title=%F0%9F%A6%A0+Model+Request%3A+%3Cname%3E) or contact us using the following [form](https://www.ersilia.io/request-model).
Expand Down
9 changes: 5 additions & 4 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from test.playground.shared import results
from rich.table import Table
from rich.console import Console
from rich.text import Text
from rich import box
from rich.console import Console
from rich.panel import Panel
from rich.table import Table
from rich.text import Text

from test.playground.shared import results


def pytest_terminal_summary(terminalreporter, exitstatus, config):
Expand Down
27 changes: 25 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
#
# This file does only contain a selection of the most common options. For a
# full list see the documentation:
# http://www.sphinx-doc.org/en/master/config

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))


# -- Project information -----------------------------------------------------
import datetime

project = "Ersilia"
copyright = f"{datetime.datetime.now().year}, Ersilia Open Source Initiative"
author = "Miquel Duran-Frigola and Abel Legese"

now = datetime.datetime.now()
copyright = "{0}, Ersilia Open Source Initiative".format(now.year)
author = "Miquel Duran-Frigola"

# The short X.Y version
version = ""
release = ""

Expand Down
1 change: 1 addition & 0 deletions ersilia/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# External imports
# ruff: noqa
import os
from ._version import __version__
import warnings
Expand Down
2 changes: 1 addition & 1 deletion ersilia/_version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from urllib.request import urlopen
import json
import os
from urllib.request import urlopen

STATIC_VERSION_FILE = "_static_version.py"
PACKAGE_NAME = "ersilia"
Expand Down
16 changes: 8 additions & 8 deletions ersilia/auth/auth.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
"""
Deal with privileges in Ersilia.
Base on GitHub login.
"""

from pathlib import Path
import os
from pathlib import Path

import yaml

try:
from github import Github
from github.GithubException import UnknownObjectException
except ModuleNotFoundError as err:
except ModuleNotFoundError:
Github = None
UnknownObjectException = None

Expand All @@ -19,7 +15,11 @@
SECRET_REPO = "ersilia-os/ersilia-secrets"


class Auth(object):
class Auth:
"""
This class handles authentication.
"""

def __init__(self):
self.hosts_yml = os.path.join(str(Path.home()), ".config", "gh", "hosts.yml")
if os.path.exists(self.hosts_yml):
Expand Down
4 changes: 3 additions & 1 deletion ersilia/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from ..utils.session import create_session_dir
from .create_cli import create_ersilia_cli
from .echo import echo
from ..utils.session import create_session_dir

cli = create_ersilia_cli()
create_session_dir()
if __name__ == "__main__":
cli()

__all__ = ["echo"]
Loading

0 comments on commit c41fb34

Please sign in to comment.