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

Fix docker compose and GitHub actions #7

Merged
merged 13 commits into from
Apr 11, 2024
66 changes: 37 additions & 29 deletions .github/workflows/test-mars.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,44 @@
name: Test MARS
on:
pull_request:
paths:
-'mars-cli/**'
push:
paths:
- "mars-cli/**"
pull_request:
paths:
- "mars-cli/**"
branches:
- main
workflow_dispatch:

jobs:
test-mars:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
test-mars:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11", "3.12"]
runs-on: ${{ matrix.os }}
env:
working-directory: ./mars-cli

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'

- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
pip install -r requirements.txt
pip install black
pip install ruff

- name: Test python code
run: pytest --doctest-modules --cov=mars_lib tests/ --cov-fail-under=80
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: '**/setup.py'
- run: pip install -e '.[test]'
working-directory: ${{ env.working-directory }}

- name: Test python code
run: pytest
working-directory: ${{ env.working-directory }}

- name: Formatting
run: black --check mars_lib/
- name: Formatting
run: black --check mars_lib/
working-directory: ${{ env.working-directory }}

- name: Linting
run: ruff check mars_lib/
- name: Linting
run: ruff check mars_lib/
working-directory: ${{ env.working-directory }}
2 changes: 2 additions & 0 deletions mars-cli/.coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[run]
omit = mars_lib/__init__.py, mars_lib/submit.py, mars_lib/credential.py
17 changes: 16 additions & 1 deletion mars-cli/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# Installing the mars-cli

Installing the mars-cli from source:

```sh
cd mars-cli # Assuming you are in the root folder
pip install .
```

If you want to install the optional testing dependencies as well, useful when contributing to the project:

```sh
pip install .[test]
```

# Extending BioSamples' records
The Python script ``biosamples-externalReferences.py`` defines a class BiosamplesRecord for managing biosample records. This class is designed to interact with the BioSamples database, allowing operations like fetching, updating, and extending biosample records.
The script takes in a dictionary of BioSamples' accessions and their associated external references, and expands the former with the latter.
Expand Down Expand Up @@ -127,4 +142,4 @@ public class BiosamplesIntegration {
// Handle other operations similarly
}
}
````
````
14 changes: 7 additions & 7 deletions mars-cli/mars_lib/credential.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import keyring
import os
import getpass
import keyring.util.platform_ as keyring_platform

"""
Credential Manager Module
Expand Down Expand Up @@ -42,22 +43,22 @@

# Don't forget to handle exceptions and secure your credentials properly.
"""
import keyring.util.platform_ as keyring_platform

print(keyring_platform.config_root())
# /home/username/.config/python_keyring # Might be different for you

print(keyring.get_keyring())
# keyring.backends.SecretService.Keyring (priority: 5)


class CredentialManager:
def __init__(self, service_name):
self.service_name = service_name

def get_credential_env(self, username):
"""
Retrieves a credential from environment variables.

:param username: The environment variable username.
:return: The value of the environment variable or None if not found.
"""
Expand All @@ -66,15 +67,15 @@ def get_credential_env(self, username):
def prompt_for_password(self):
"""
Securely prompts the user to enter a password in the console.

:return: The password entered by the user.
"""
return getpass.getpass(prompt="Enter your password: ")

def set_password_keyring(self, username, password):
"""
Stores a password in the keyring under the given username.

:param username: The username associated with the password.
:param password: The password to store.
"""
Expand All @@ -83,7 +84,7 @@ def set_password_keyring(self, username, password):
def get_password_keyring(self, username):
"""
Retrieves a password from the keyring for the given username.

:param username: The username whose password to retrieve.
:return: The password or None if not found.
"""
Expand All @@ -92,8 +93,7 @@ def get_password_keyring(self, username):
def delete_password_keyring(self, username):
"""
Deletes a password from the keyring for the given username.

:param username: The username whose password to delete.
"""
keyring.delete_password(self.service_name, username)

2 changes: 2 additions & 0 deletions mars-cli/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
addopts = --doctest-modules --cov=mars_lib tests/ --cov-fail-under=80
2 changes: 1 addition & 1 deletion mars-cli/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
requests
jsonschema
pytest
keyring
9 changes: 9 additions & 0 deletions mars-cli/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
version=__version__,
license="MIT",
install_requires=[required_deps],
extras_require={
"test": [
# Dependencies for testing only
"black",
"ruff",
"pytest",
"pytest-cov",
]
},
project_urls={
"Source": "https://github.com/elixir-europe/MARS",
"Bug Reports": "https://github.com/elixir-europe/MARS/issues",
Expand Down
8 changes: 4 additions & 4 deletions repository-services/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
version: '3'

services:
isa_biosamples:
build: ./repository-testservers/isajson-biosamples
build: isajson-biosamples
ports:
- "8032:8032"
restart: unless-stopped

isa_sra:
build: ./repository-testservers/isajson-ena
build: isajson-ena
ports:
- "8042:8042"
restart: unless-stopped