Skip to content

Commit

Permalink
Merge pull request #23 from GSA/feature/prepare-for-pypi
Browse files Browse the repository at this point in the history
init pypi github actions config
  • Loading branch information
rshewitt authored Dec 19, 2023
2 parents 96596e7 + 25f2f93 commit d15f61f
Show file tree
Hide file tree
Showing 21 changed files with 638 additions and 332 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Publish to PyPI
on:
# TODO: configure repo to and uncomment below
# pull_request:
# branches: [main]
# types: [closed]
workflow_dispatch:
inputs:
version_no:
description: 'Release Version:'
required: true

jobs:
deploy:
name: Publish to PyPI
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch'
steps:
- name: checkout
uses: actions/checkout@v3
- name: Update setup.py if manual release
if: github.event_name == 'workflow_dispatch'
run: |
# TODO update for pyproject.toml
sed -i "s/version='[0-9]\{1,2\}.[0-9]\{1,4\}.[0-9]\{1,4\}',/version='${{github.event.inputs.version_no}}',/g" setup.py
- name: Create packages
run: |
python setup.py sdist
python setup.py bdist_wheel
- name: pypi-publish
uses: pypa/gh-action-pypi-publish@v1.8.11
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
name: Tests on Commit
on: [push, pull_request]
on: [push]

env:
PY_VERSION: "3.9"
POETRY_VERSION: "1.4.2"
PY_VERSION: "3.10"
POETRY_VERSION: "1.7.1"

jobs:
lint:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pytest-coverage.txt
__pycache__/
venv/
credentials.py
dist/

# any previous versions of schemas
**/dataset_**.json
Expand All @@ -16,4 +17,4 @@ credentials.py
tmp/

# vscode debugger
.vscode/
.vscode/
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## Public Domain

This project constitutes a work of the United States Government and is not subject to domestic copyright protection under 17 USC § 105. Additionally, we waive copyright and related rights in the work worldwide through the [CC0 1.0 Universal public domain dedication](https://creativecommons.org/publicdomain/zero/1.0/).

All contributions to this project will be released under the CC0 dedication. By submitting a pull request, you are agreeing to comply with this waiver of copyright interest. See [CONTRIBUTING](CONTRIBUTING.md) for more information.

## GNU General Public License

This project utilizes code [licensed under the terms of the GNU General Public License](https://wordpress.org/about/gpl/) and therefore is licensed under GPL v2 or later.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Visit http://www.gnu.org/licenses/ to learn more about the GNU General Public License.

## Other Information

In no way are the patent or trademark rights of any person affected by CC0, nor are the rights that other persons may have in the work or in how the work is used, such as publicity or privacy rights.

Unless expressly stated otherwise, the person who associated a work with this deed makes no warranties about the work, and disclaims liability for all uses of the work, to the fullest extent permitted by applicable law. When using or citing the work, you should not imply endorsement by the author or the affirmer.
26 changes: 26 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
pypi-upload: build-dist ## Uploads new package to PyPi after clean, build
poetry publish

# pypi-upload-test: build-dist ## Uploads new package to TEST PyPi after clean, build
# twine upload -r testpypi dist/*

build-dist: clean-dist ## Builds new package dist
poetry build --verbose

clean-dist: ## Cleans dist dir
rm -rf dist/*

test: up ## Runs poetry tests, ignores ckan load
poetry run pytest --ignore=./tests/load/ckan

up: ## Sets up local docker environment
docker compose up -d

lint: ## Lints wtih ruff
ruff .

# Output documentation for top-level targets
# Thanks to https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
.PHONY: help
help: ## This help
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-10s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
13 changes: 13 additions & 0 deletions harvester/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# TODO: maybe turn off this ruff ignore?
# ruff: noqa: F405, F403

__all__ = ["compare", "extract", "load", "transform", "validate", "utils"]

# TODO these imports will need to be updated to ensure a consistent api
from .compare import compare
from .extract import extract
from .load import load
from .transform import transform
from .utils import *
from .validate import *

# configuration settings
bucket_name = "test-bucket"
content_types = {
Expand Down
11 changes: 11 additions & 0 deletions harvester/compare.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import logging

logger = logging.getLogger("harvester")


# stub, TODO complete
def compare(compare_obj):
"""Compares records"""
logger.info("Hello from harvester.compare()")

return compare_obj
17 changes: 16 additions & 1 deletion harvester/extract/dcatus.py → harvester/extract.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import logging

import requests
from requests.exceptions import RequestException, JSONDecodeError
from requests.exceptions import JSONDecodeError, RequestException

logger = logging.getLogger("harvester")


def download_dcatus_catalog(url):
Expand All @@ -20,3 +24,14 @@ def download_dcatus_catalog(url):
return resp.json()
except JSONDecodeError as e:
return Exception(e)


def extract(harvest_source) -> list:
"""Extracts all records from a harvest_source"""
logger.info("Hello from harvester.extract()")

datasets = []

# stub

return datasets
1 change: 0 additions & 1 deletion harvester/extract/__init__.py

This file was deleted.

15 changes: 14 additions & 1 deletion harvester/load/ckan.py → harvester/load.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import ckanapi
import logging
import re

import ckanapi

logger = logging.getLogger("harvester")


def load():
""" """
logger.info("Hello from harvester.load()")

# stub

pass


def create_ckan_extra_base(*args):
keys = ["publisher_hierarchy", "resource-type", "publisher"]
Expand Down
Empty file removed harvester/load/__init__.py
Empty file.
11 changes: 11 additions & 0 deletions harvester/transform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import logging

logger = logging.getLogger("harvester")


# stub, TODO complete
def transform(transform_obj):
"""Transforms records"""
logger.info("Hello from harvester.transform()")

return transform_obj
3 changes: 3 additions & 0 deletions harvester/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import json

__all__ = ["json"]
3 changes: 3 additions & 0 deletions harvester/validate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import dcat_us

__all__ = ["dcat_us"]
Loading

1 comment on commit d15f61f

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
harvester
   __init__.py100100% 
   compare.py50100% 
   extract.py2177 67%
   load.py8522 98%
   transform.py50100% 
harvester/utils
   __init__.py20100% 
   json.py40100% 
harvester/validate
   __init__.py20100% 
   dcat_us.py2433 88%
TOTAL1581292% 

Tests Skipped Failures Errors Time
23 0 💤 0 ❌ 0 🔥 27.745s ⏱️

Please sign in to comment.