Skip to content

Commit

Permalink
Merge pull request #4 from Samk13/update-pakcage-setup
Browse files Browse the repository at this point in the history
Include CSV and YAML files to manifest
  • Loading branch information
Samk13 authored Feb 7, 2024
2 parents 30d6b7d + ed2bb13 commit 099158f
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 160,487 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2022-2024 KTH Royal Institute of Technology.
#
# invenio-subjects-nasa is free software, you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file details.

name: CI

on:
workflow_dispatch:
inputs:
reason:
description: 'Reason'
required: false
default: 'Manual trigger'

jobs:
Tests:
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: [3.9]
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Generate dependencies
run: |
pip install -e ".[tests]"
pip freeze
- name: Run tests
run: |
./run-tests.sh
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ include .pylintrc
include .vscode/settings.json
include Makefile
recursive-include tests
recursive-include tests *.csv
recursive-include tests *.yaml
recursive-include invenio_subjects_nasa *.csv
recursive-include invenio_subjects_nasa *.py
recursive-include invenio_subjects_nasa *.yaml
14 changes: 14 additions & 0 deletions invenio_subjects_nasa/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2022-2024 KTH Royal Institute of Technology.
#
# invenio-subjects-nasa is free software, you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file details.
from pathlib import Path

nasa_subjects_csv_input_path = (
Path.cwd() / "invenio_subjects_nasa" / "downloads" / "thesaurus-CSV-2024-02-05.csv"
)
nasa_subjects_yaml_output_path = (
Path.cwd() / "invenio_subjects_nasa" / "vocabularies" / "nasa_thesaurus.yaml"
)
12 changes: 3 additions & 9 deletions invenio_subjects_nasa/convert_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,9 @@ def write_to_yaml(data: list, filepath: str):
yaml.dump(data, file)


def main(csv_filepath: str, yaml_filepath: str):
def main(csv_filepath_input: str, yaml_filepath_output: str):
"""Main function to process CSV data and write it to a YAML file."""
data = load_csv_data(csv_filepath)
data = load_csv_data(csv_filepath_input)
transformed_data = [transform_row_to_schema(row) for row in data]
unique_data = remove_duplicates(transformed_data)
write_to_yaml(unique_data, yaml_filepath)


if __name__ == "__main__":
csv_file_path = "invenio_subjects_nasa/downloads/thesaurus-CSV-2024-02-05.csv"
yaml_file_path = "invenio_subjects_nasa/vocabularies/nasa_thesaurus.yaml"
main(csv_file_path, yaml_file_path)
write_to_yaml(unique_data, yaml_filepath_output)
44 changes: 0 additions & 44 deletions invenio_subjects_nasa/converter.py

This file was deleted.

160,371 changes: 0 additions & 160,371 deletions invenio_subjects_nasa/downloads/thesaurus-CSV.csv

This file was deleted.

23 changes: 0 additions & 23 deletions invenio_subjects_nasa/load_data.py

This file was deleted.

23 changes: 0 additions & 23 deletions invenio_subjects_nasa/write_data.py

This file was deleted.

26 changes: 9 additions & 17 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,15 @@
# modify it under the terms of the MIT License; see LICENSE file details.
"""Nasa subject terms for InvenioRDM"""

from invenio_subjects_nasa.converter import csv_to_yaml, write_to_disk
from invenio_subjects_nasa.load_data import load_data
from invenio_subjects_nasa.config import (
nasa_subjects_csv_input_path,
nasa_subjects_yaml_output_path,
)
from invenio_subjects_nasa.convert_data import main
from invenio_subjects_nasa.utils import logger

row_data = "invenio_subjects_nasa/downloads/thesaurus-CSV.csv"
output_yaml = "invenio_subjects_nasa/vocabularies/nasa_thesaurus.yaml"


def main():
"""initiate the app"""
logger("Converting ...")
res = []
for row in load_data(row_data):
res.append(csv_to_yaml(row))
write_to_disk(res, output_yaml)
logger("Subjects is been converted successfully!")


if __name__ == "__main__":
main()

logger.debug("Converting ...")
main(nasa_subjects_csv_input_path, nasa_subjects_yaml_output_path)
logger.debug("Subjects is been converted successfully!")
20 changes: 20 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from pathlib import Path

from invenio_subjects_nasa import config


def test_nasa_subjects_csv_input_path():
"""Test the default value of the NASA subjects CSV input path."""
assert config.nasa_subjects_csv_input_path == (
Path.cwd()
/ "invenio_subjects_nasa"
/ "downloads"
/ "thesaurus-CSV-2024-02-05.csv"
)


def test_nasa_subjects_yaml_output_path():
"""Test the default value of the NASA subjects YAML output path."""
assert config.nasa_subjects_yaml_output_path == (
Path.cwd() / "invenio_subjects_nasa" / "vocabularies" / "nasa_thesaurus.yaml"
)

0 comments on commit 099158f

Please sign in to comment.