diff --git a/.github/workflows/test-mars.yml b/.github/workflows/test-mars.yml index 90159af..0f16d39 100644 --- a/.github/workflows/test-mars.yml +++ b/.github/workflows/test-mars.yml @@ -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 }} diff --git a/mars-cli/.coveragerc b/mars-cli/.coveragerc new file mode 100644 index 0000000..2c3ba72 --- /dev/null +++ b/mars-cli/.coveragerc @@ -0,0 +1,2 @@ +[run] +omit = mars_lib/__init__.py, mars_lib/submit.py, mars_lib/credential.py diff --git a/mars-cli/README.md b/mars-cli/README.md index b602705..6a816c0 100644 --- a/mars-cli/README.md +++ b/mars-cli/README.md @@ -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. @@ -127,4 +142,4 @@ public class BiosamplesIntegration { // Handle other operations similarly } } -```` \ No newline at end of file +```` diff --git a/mars-cli/mars_lib/credential.py b/mars-cli/mars_lib/credential.py index a62306a..333c4c1 100644 --- a/mars-cli/mars_lib/credential.py +++ b/mars-cli/mars_lib/credential.py @@ -1,6 +1,7 @@ import keyring import os import getpass +import keyring.util.platform_ as keyring_platform """ Credential Manager Module @@ -42,7 +43,6 @@ # 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 @@ -50,6 +50,7 @@ print(keyring.get_keyring()) # keyring.backends.SecretService.Keyring (priority: 5) + class CredentialManager: def __init__(self, service_name): self.service_name = service_name @@ -57,7 +58,7 @@ def __init__(self, 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. """ @@ -66,7 +67,7 @@ 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: ") @@ -74,7 +75,7 @@ def prompt_for_password(self): 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. """ @@ -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. """ @@ -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) - diff --git a/mars-cli/pytest.ini b/mars-cli/pytest.ini new file mode 100644 index 0000000..987643d --- /dev/null +++ b/mars-cli/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +addopts = --doctest-modules --cov=mars_lib tests/ --cov-fail-under=80 diff --git a/mars-cli/requirements.txt b/mars-cli/requirements.txt index 7aaac6a..bd4c238 100644 --- a/mars-cli/requirements.txt +++ b/mars-cli/requirements.txt @@ -1,3 +1,3 @@ requests jsonschema -pytest \ No newline at end of file +keyring \ No newline at end of file diff --git a/mars-cli/setup.py b/mars-cli/setup.py index 8f20e8b..69c1ffd 100644 --- a/mars-cli/setup.py +++ b/mars-cli/setup.py @@ -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", diff --git a/repository-services/docker-compose.yml b/repository-services/docker-compose.yml index 073f68f..3102ecd 100644 --- a/repository-services/docker-compose.yml +++ b/repository-services/docker-compose.yml @@ -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