Skip to content

Commit

Permalink
Fix import error and prepare for PyPI (#55)
Browse files Browse the repository at this point in the history
* fix import error

* adjust test

* use pyproject.toml

* remove test debugging

* upload release wheel to pypi
  • Loading branch information
mmacata authored Jun 26, 2024
1 parent b602114 commit a35d486
Show file tree
Hide file tree
Showing 61 changed files with 107 additions and 204 deletions.
43 changes: 10 additions & 33 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,19 @@
# This workflow 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

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Upload Python Package

on:
release:
types: [published]

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python3 -m build --outdir build .
- name: Release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
files: build/*.whl
publish-python-test-pypi:
uses: mundialis/github-workflows/.github/workflows/python-publish.yml@main
with:
test_pypi: true
secrets:
PYPI_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }}

# - name: Publish package
# uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
# with:
# user: __token__
# password: ${{ secrets.PYPI_API_TOKEN }}
publish-python-pypi:
uses: mundialis/github-workflows/.github/workflows/python-publish.yml@main
secrets:
PYPI_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
9 changes: 0 additions & 9 deletions actinia_module_plugin/__init__.py

This file was deleted.

9 changes: 5 additions & 4 deletions docker/actinia-module-plugin-test/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ ENV TEMPLATE_VALUE_ENV_TYPE raster

# install things only for tests
RUN apk add redis
RUN pip3 install iniconfig colorlog pwgen
RUN pip install --upgrade setuptools
RUN pip install pytest pytest-cov pwgen

ENTRYPOINT ["/bin/sh"]
CMD ["/src/start.sh"]

RUN pip3 uninstall actinia-module-plugin.wsgi -y
RUN pip uninstall actinia-module-plugin.wsgi -y
RUN pip uninstall actinia-module-plugin -y

# add data for tests
RUN grass -e -c 'EPSG:3358' /actinia_core/grassdb/nc_spm_08
Expand All @@ -33,10 +35,9 @@ COPY docker/actinia-module-plugin-test/actinia-module-plugin-test.cfg /etc/defau
COPY docker/actinia-module-plugin-test/actinia-module-plugin-test.cfg /etc/default/actinia-module-plugin-test
COPY . /src/actinia-module-plugin/


WORKDIR /src/actinia-module-plugin/

RUN chmod a+x tests_with_redis.sh
RUN python3 setup.py install
RUN pip install .

RUN ./tests_with_redis.sh
67 changes: 66 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,68 @@
[build-system]
requires = ["setuptools>=40.6.0", "wheel"]
requires = ["setuptools>=61.0.0", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "actinia-module-plugin"
version = "2.5.1"
description = "A (RESTFUL) Flask application which adds module self-description and process-chain-template management to actinia-core"
readme = "README.md"
authors = [
{ name = "Carmen Tawalika"},
{ name = "Markus Neteler"},
{ name = "Julia Haas"},
{ name = "Guido Riembauer"},
{ name = "Anika Weinmann"},
{ name = "Jan Suleiman"},
{ name = "Lina Krisztian"},
]
classifiers = [
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3",
]
requires-python = ">=3.8"
keywords = [
"processing",
"earth observation",
"cloud-based processing",
"rest api",
"gis",
"grass gis",
"osgeo",
]
dependencies = [
"colorlog>=4.2.1",
]

[project.optional-dependencies]
test = [
"pytest",
"pytest-cov",
]

[project.scripts]
pc2grass = "actinia_module_plugin.resources.cli:pc2grass"

[project.urls]
Homepage = "https://github.com/mundialis/actinia-module-plugin"
Tutorial = "https://mundialis.github.io/actinia_core"
API_Docs = "https://redocly.github.io/redoc/?url=https://actinia.mundialis.de/latest/swagger.json"

[tool.flake8]
max-line-length = 88

[tool.setuptools.packages.find]
where = ["src"]

[tool.setuptools.package-data]
"*" = ["*.*"]

[tool.pytest.ini_options]
minversion = "6.0"
addopts = "--cov actinia_module_plugin --cov-report term-missing --verbose --tb=line -x -s"
testpaths = [
"tests",
]
markers = [
"dev: test current in development",
]
66 changes: 2 additions & 64 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,73 +1,11 @@
[metadata]
name = actinia_module_plugin.wsgi
description = A (RESTFUL) Flask application which adds module self-description and process-chain-template management and processing
author = Carmen Tawalika
author-email = [email protected]
license = apache-2.0
url = https://github.com/mundialis/actinia-module-plugin
long-description = file: README.md
platforms = any
# Add here all kinds of additional classifiers as defined under
# https://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers =
Development Status :: 4 - Beta
Programming Language :: Python

[options]
zip_safe = False
packages = find:
include_package_data = True
package_dir =
=.
install_requires = colorlog;Flask;Flask-Cors;Flask-RESTful;flask-restful-swagger-2;python-json-logger;xmltodict;
tests_require = pytest; pytest-cov; pwgen
=src

[options.packages.find]
where = .
where = src
exclude =
tests

[options.extras_require]

[test]
# py.test options when running `python setup.py test`
addopts = tests

[tool:pytest]
# Options for py.test:
# Specify command line options as you would do when invoking py.test directly.
# e.g. --cov-report html (or xml) for html/xml output or --junitxml junit.xml
# in order to write a coverage file that can be read by Jenkins.
# for debugging in tests, see https://docs.pytest.org/en/latest/usage.html
addopts =
--cov actinia_module_plugin --cov-report html
--verbose --tb=line
-x --pdb
norecursedirs =
dist
build
.tox

[aliases]
release = sdist bdist_wheel upload

[bdist_wheel]
# Use this option if your package is pure-python
universal = 1

[build_sphinx]
source_dir = docs
build_dir = docs/_build

[flake8]
# Some sane defaults for the code style checker flake8
exclude =
.tox
build
dist
.eggs
docs/conf.py

[pyscaffold]
version = 3.0.3
package = actinia_module_plugin
52 changes: 1 addition & 51 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Copyright (c) 2018-2021 mundialis GmbH & Co. KG
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Setup file for actinia_module_plugin.
This file was generated with PyScaffold 3.0.2.
PyScaffold helps you to put up the scaffold of your new Python project.
Learn more under: http://pyscaffold.org/
"""

__author__ = "Carmen Tawalika"
__copyright__ = "2018-2021 mundialis GmbH & Co. KG"
__license__ = "Apache-2.0"


from setuptools import setup

entry_points = {
"console_scripts": [
"name = actinia_module_plugin.resources.cli:name",
"about = actinia_module_plugin.resources.cli:about",
"pc2grass = actinia_module_plugin.resources.cli:pc2grass",
]
}


def setup_package():
setup(
setup_requires=["pyscaffold>=3.0a0,<3.1a0"],
entry_points=entry_points,
packages=["actinia_module_plugin"],
package_dir={"actinia_module_plugin": "actinia_module_plugin"},
include_package_data=True,
use_pyscaffold=True,
)


if __name__ == "__main__":
setup_package()
setup()
9 changes: 9 additions & 0 deletions src/actinia_module_plugin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-
import importlib.metadata

try:
# Change here if project is renamed and does not equal the package name
dist_name = __name__
__version__ = importlib.metadata.version(dist_name)
except Exception:
__version__ = "unknown"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,6 @@
import sys


def name():
"""Print name to console"""
return "actinia-module-plugin"


def about():
"""Print information about actinia-module-plugin to console"""

text = "actinia-module-plugin"
text = text + "\n This package communicates via HTTP"
text = text + "\n To start application, run "
text = text + "\n 'python -m actinia_module_plugin.main'"
return text


# used in pc2grass
def parseExe(process):
# no api docs model
Expand Down Expand Up @@ -127,8 +112,12 @@ def defineFile(file):
def pc2grass():
"""Parser for actinia-core process chains to GRASS executables"""

input = sys.argv[1]
output = sys.argv[2]
try:
input = sys.argv[1]
output = sys.argv[2]
except IndexError:
print("ERROR: No input or output file given")
return

if os.path.isfile(input):
input = input
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
11 changes: 3 additions & 8 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import pytest
import unittest
from pkg_resources import get_distribution, DistributionNotFound
import importlib
from flask import Response

import actinia_module_plugin
Expand Down Expand Up @@ -55,10 +55,5 @@ def test_app_static(self):
class InitTest(unittest.TestCase):
def test_init(self):
"""Test if version can be detected"""
# TODO: apply to __init__.py
pkg_version = get_distribution("actinia_module_plugin.wsgi").version
assert actinia_module_plugin.__version__ == pkg_version

with pytest.raises(DistributionNotFound):
v = get_distribution("false_distro_name").version
assert v == "unknown"
version = importlib.metadata.version("actinia_module_plugin")
assert actinia_module_plugin.__version__ == version
15 changes: 3 additions & 12 deletions tests/test_resources_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,10 @@

import unittest

from actinia_module_plugin.resources.cli import name, about
from actinia_module_plugin.resources.cli import pc2grass


class CliTest(unittest.TestCase):
def test_cli_name(self):
def test_cli_pc2grass(self):
"""Test basic cli command"""
assert name() == "actinia-module-plugin"

def test_cli_about(self):
"""Test basic cli command"""
text = "actinia-module-plugin"
text = text + "\n This package communicates via HTTP"
text = text + "\n To start application, run "
text = text + "\n 'python -m actinia_module_plugin.main'"

assert about() == text
assert pc2grass() == None
Loading

0 comments on commit a35d486

Please sign in to comment.