Skip to content

Commit

Permalink
Merge pull request #11 from BONSAMURAIS/issue-9
Browse files Browse the repository at this point in the history
Issue 9
  • Loading branch information
tngTUDOR committed Jul 1, 2020
2 parents 1705ac8 + f886545 commit f76e49a
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 89 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/python-publish.yml
@@ -0,0 +1,31 @@
# This workflows will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

name: Upload Python Package

on:
release:
types: [created]

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.5.0] - 2020-07-01
### Added
- package is published to pypi repository
### Changed
- new command line syntax:
```
Expand Down
111 changes: 63 additions & 48 deletions README.md
@@ -1,6 +1,7 @@
# YSTAFDB

YSTAFDB creates turtle files of the istances of data based on an ontology. The turtle files are needed for the BONSAI knowledge graph.
YSTAFDB creates turtle files of the istances of data based on an ontology.
The turtle files are needed for the BONSAI knowledge graph.

The turtle files generated are stored in the BONSAI [rdf repository](https://github.com/BONSAMURAIS/rdf).

Expand All @@ -10,9 +11,14 @@ Currently generates the following:

## Installation

### with package managers [pip or conda]
### with package manager pip from pypi

Installable via `pip`:

```
pip install ystafdb
```

Installable via `pip`
### manual

Clone git repo
Expand All @@ -24,11 +30,24 @@ Enter cloned repo
```
$ cd ystafdb
```
##### Download Base Data
Before progressing the installation, the base ystafdb data must be downloaded, and placed in a folder of your choosing, inside the repo.

Now install package

```
$ python setup.py install
```

## Usage

You must first download the Base Data, and then use `ystafdb-cli` to produce the ttl/nt/xml files.

### Download Base Data

The data can be downloaded [here](https://www.sciencebase.gov/catalog/file/get/5b9a7c28e4b0d966b485d915?f=__disk__0f%2F58%2Fa7%2F0f58a74db669ee5418f36a698bc85781e867e0ab) as a zip file.
Extract the zip file and move relevant files to a folder. As an example, the data can be placed under `/ystafdb/data/`.
The following ystafdb files are mandatory to have in the folder:

Extract the contents of the zip file. As an example, the data can be placed under `ystafdb-input`.
The following files from the Base Data are _mandatory_ to have in the folder (`ystafdb-input` in our example):

- `material_names.csv`
- `subsystems.csv`
- `flows.csv`
Expand All @@ -37,63 +56,59 @@ The following ystafdb files are mandatory to have in the folder:
- `reference_materials.csv`
- `reference_timeframes.csv`

##### Create env and install dependencies
Either 1) create new virtualenv and enter shell or 2) enter already existing virtualenv and install dependencies
##### Option 1)
```
$ pipenv install
$ pipenv shell
```

##### Option 2)
Under a Linux terminal, you can acomplish the previous two operations with:

```
$ source path/to/environment/bin/activate
$ pip install -r requirements.txt
curl -L "https://www.sciencebase.gov/catalog/file/get/5b9a7c28e4b0d966b485d915?f=__disk__0f%2F58%2Fa7%2F0f58a74db669ee5418f36a698bc85781e867e0ab" -o YSTAFDB_CSV_files.zip
unzip -d ystafdb-input YSTAFDB_CSV_files.zip
```

Now install package
### Generate the ttl or nt or xml files

If the package is correctly installed, you can use the command line tool `ystafdb-cli` to produce the rdfs as follows:

```
$ python setup.py install
$ ystafdb-cli -i <inputdir> -o <outputdir>
```


## Usage

### As a command line tool
Where:
+ `<inputdir>` is the location of the ystafdb csv files, and
+ `<outputdir>` is the directory where the output triples graphs will be placed. This is optional,
if not supplied, the output directory will be `output`

If the package is correctly installed, you can use the command line tool `ystafdb-cli` to produce the rdfs as follows:
In the Linux terminal example from above, this would be done with:

```
$ ystafdb-cli -i <input/dir> -o <output/dir>
ystafdb-cli -i ystafdb-input
```

Where `<input/dir>` is the location of the ystafdb csv files, and `<output/dir>` is the directory where the output triples graphs will be placed.
The `<output/dir>` directory will have the following content:
The `<outputdir>` directory will have the following contents:

```
output
├── activitytype
│   └── ystafdb
│      └── ystafdb.ttl
├── flowobject
│   └── ystafdb
│      └── ystafdb.ttl
├── location
│   └── ystafdb
│   └── ystafdb.ttl
├── foaf
│   └── ystafdb
│      └── ystafdb.ttl
└── prov
|   └── ystafdb
|   └── ystafdb.ttl
└── flow
  └── ystafdb
   └── huse
   └── huse.ttl
├── [ 4.0K] activitytype
│   └── [ 4.0K] ystafdb
│   └── [ 249K] ystafdb.ttl
├── [ 4.0K] flow
│   └── [ 4.0K] ystafdb
│   └── [ 4.0K] huse
│   └── [ 41M] huse.ttl
├── [ 4.0K] flowobject
│   └── [ 4.0K] ystafdb
│   └── [ 63K] ystafdb.ttl
├── [ 4.0K] foaf
│   └── [ 4.0K] ystafdb
│   └── [ 1.4K] ystafdb.ttl
├── [ 4.0K] location
│   └── [ 4.0K] ystafdb
│   └── [ 158K] ystafdb.ttl
└── [ 4.0K] prov
└── [ 4.0K] ystafdb
└── [ 1.0M] ystafdb.ttl
```


## Contributing
All contributions should be via pull request, do not edit this package directly! We actually use it for stuff.
All contributions should be via pull request, do not edit this package directly! We actually use it for stuff.

72 changes: 31 additions & 41 deletions setup.py
Expand Up @@ -16,64 +16,54 @@


# Probably should be changed, __init__.py is no longer required for Python 3
for dirpath, dirnames, filenames in os.walk('ystafdb'):
# Ignore dirnames that start with '.'
if '__init__.py' in filenames:
pkg = dirpath.replace(os.path.sep, '.')
for dirpath, dirnames, filenames in os.walk("ystafdb"):
# Ignore dirnames that start with "."
if "__init__.py" in filenames:
pkg = dirpath.replace(os.path.sep, ".")
if os.path.altsep:
pkg = pkg.replace(os.path.altsep, '.')
pkg = pkg.replace(os.path.altsep, ".")
packages.append(pkg)


def package_files(directory):
paths = []
for (path, directories, filenames) in os.walk(directory):
for filename in filenames:
paths.append(os.path.join('..', path, filename))
paths.append(os.path.join("..", path, filename))
return paths


setup(
name='ystafdb',
version="0.5",
name="ystafdb",
version="0.5.0",
packages=packages,
description="CLI tool to parse YSTAFDB and produce ttl/nt/xml.",
long_description=open("README.md").read(),
long_description_content_type="text/markdown",
author="Emil Riis Hansen",
author_email="emilrh@cs.aau.dk",
license=open('LICENSE').read(),
package_data={'ystafdb': package_files(os.path.join('ystafdb', 'data'))},
package_data={"ystafdb": package_files(os.path.join("ystafdb", "data"))},
# Only if you have non-python data (CSV, etc.). Might need to change the directory name as well.
# package_data={'your_name_here': package_files(os.path.join('your_library_name', 'data'))},
entry_points = {
'console_scripts': [
'ystafdb-cli = ystafdb.bin.ystafdb:main',
]
},
install_requires=[
'appdirs',
'docopt',
'rdflib',
'pandas'
],
# package_data={"your_name_here": package_files(os.path.join("your_library_name", "data"))},
entry_points={"console_scripts": ["ystafdb-cli = ystafdb.bin.ystafdb:main",]},
install_requires=["appdirs", "docopt", "rdflib", "pandas"],
url="https://github.com/BONSAMURAIS/ystafdb/",
long_description_content_type='text/markdown',
long_description=open('README.md').read(),
description='',
classifiers=[
'Intended Audience :: End Users/Desktop',
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: BSD License',
'Operating System :: MacOS :: MacOS X',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Topic :: Scientific/Engineering :: Information Analysis',
'Topic :: Scientific/Engineering :: Mathematics',
'Topic :: Scientific/Engineering :: Visualization',
"Intended Audience :: End Users/Desktop",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: BSD License",
"Operating System :: MacOS :: MacOS X",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Topic :: Scientific/Engineering :: Information Analysis",
"Topic :: Scientific/Engineering :: Mathematics",
"Topic :: Scientific/Engineering :: Visualization",
],
)

0 comments on commit f76e49a

Please sign in to comment.