Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tools, dependencies #41

Merged
merged 19 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 43 additions & 37 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ on:
- main
- dev

env:
CLOUD_FUNCTION_MEMORY: 512
CLOUD_FUNCTION_RUN_TIMEOUT: 9m
SCHEDULE_NAME: first-of-the-month
SCHEDULE_CRON: 0 9 1 * *
SCHEDULE_DESCRIPTION: Trigger the wmrc-skid bot at the beginning of the month

concurrency:
group: "${{ github.head_ref || github.ref }}"
cancel-in-progress: true
Expand All @@ -20,22 +27,21 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
show-progress: false

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
# cache: pip
# cache-dependency-path: setup.py
python-version: 3.11
cache: pip
cache-dependency-path: setup.py

- name: Install libkrb5 for Kerberos on Linux
run: |
sudo apt install -y libkrb5-dev
pip install requests-kerberos

- name: Checkout code
uses: actions/checkout@v4
with:
show-progress: false

- name: Install module
run: pip install .[tests]
Expand Down Expand Up @@ -79,38 +85,38 @@ jobs:
source_dir: src/wmrc
service_account_email: cloud-function-sa@${{ secrets.PROJECT_ID }}.iam.gserviceaccount.com
event_trigger_type: providers/cloud.pubsub/eventTypes/topic.publish
event_trigger_resource: projects/${{ secrets.PROJECT_ID }}/topics/monday-morning-topic
event_trigger_resource: projects/${{ secrets.PROJECT_ID }}/topics/${{ env.SCHEDULE_NAME }}-topic
deploy_timeout: 600
memory_mb: 512
timeout: "9m"
memory_mb: ${{ env.CLOUD_FUNCTION_MEMORY }}
timeout: ${{ env.CLOUD_FUNCTION_RUN_TIMEOUT }}
env_vars: STORAGE_BUCKET=${{secrets.STORAGE_BUCKET}}
secret_volumes: |
/secrets/app/secrets.json=${{secrets.PROJECT_ID}}/skid-secrets

- name: 📥 Create PubSub topic
run: |
if [ ! "$(gcloud pubsub topics list | grep monday-morning-topic)" ]; then
gcloud pubsub topics create monday-morning-topic --quiet
if [ ! "$(gcloud pubsub topics list | grep $SCHEDULE_NAME-topic)" ]; then
gcloud pubsub topics create $SCHEDULE_NAME-topic --quiet
fi

- name: 🕰️ Create Cloud Scheduler
run: |
if [ ! "$(gcloud scheduler jobs list --location=us-central1 | grep monday-morning)" ]; then
gcloud scheduler jobs create pubsub monday-morning \
--description="Trigger the wmrc-skid bot once a week on monday morning" \
--schedule="0 9 * * 1" \
if [ ! "$(gcloud scheduler jobs list --location=us-central1 | grep $SCHEDULE_NAME)" ]; then
gcloud scheduler jobs create pubsub $SCHEDULE_NAME \
--description="$SCHEDULE_DESCRIPTION" \
--schedule="$SCHEDULE_CRON" \
--time-zone=America/Denver \
--location=us-central1 \
--topic=monday-morning-topic \
--topic=$SCHEDULE_NAME-topic \
--message-body='{"run": "now"}' \
--quiet
else
gcloud scheduler jobs update pubsub monday-morning \
--description="Trigger the wmrc-skid bot once a week on monday morning" \
--schedule="0 9 * * 1" \
gcloud scheduler jobs update pubsub $SCHEDULE_NAME \
--description="$SCHEDULE_DESCRIPTION" \
--schedule="$SCHEDULE_CRON" \
--time-zone=America/Denver \
--location=us-central1 \
--topic=monday-morning-topic \
--topic=$SCHEDULE_NAME-topic \
--message-body='{"run": "now"}' \
--quiet
fi
Expand Down Expand Up @@ -151,38 +157,38 @@ jobs:
source_dir: src/wmrc
service_account_email: cloud-function-sa@${{ secrets.PROJECT_ID }}.iam.gserviceaccount.com
event_trigger_type: providers/cloud.pubsub/eventTypes/topic.publish
event_trigger_resource: projects/${{ secrets.PROJECT_ID }}/topics/first-of-the-month-topic
event_trigger_resource: projects/${{ secrets.PROJECT_ID }}/topics/${{ env.SCHEDULE_NAME }}-topic
deploy_timeout: 600
memory_mb: 512
timeout: "9m"
memory_mb: ${{ env.CLOUD_FUNCTION_MEMORY }}
timeout: ${{ env.CLOUD_FUNCTION_RUN_TIMEOUT }}
env_vars: STORAGE_BUCKET=${{secrets.STORAGE_BUCKET}}
secret_volumes: |
/secrets/app/secrets.json=${{secrets.PROJECT_ID}}/skid-secrets

- name: 📥 Create PubSub topic
run: |
if [ ! "$(gcloud pubsub topics list | grep first-of-the-month-topic)" ]; then
gcloud pubsub topics create first-of-the-month-topic --quiet
if [ ! "$(gcloud pubsub topics list | grep $SCHEDULE_NAME-topic)" ]; then
gcloud pubsub topics create $SCHEDULE_NAME-topic --quiet
fi

- name: 🕰️ Create Cloud Scheduler
run: |
if [ ! "$(gcloud scheduler jobs list --location=us-central1 | grep first-of-the-month)" ]; then
gcloud scheduler jobs create pubsub first-of-the-month \
--description="Trigger the wmrc-skid bot on the first day of the month" \
--schedule="0 9 1 * *" \
if [ ! "$(gcloud scheduler jobs list --location=us-central1 | grep $SCHEDULE_NAME)" ]; then
gcloud scheduler jobs create pubsub $SCHEDULE_NAME \
--description="$SCHEDULE_DESCRIPTION" \
--schedule="$SCHEDULE_CRON" \
--time-zone=America/Denver \
--location=us-central1 \
--topic=first-of-the-month-topic \
--topic=$SCHEDULE_NAME-topic \
--message-body='{"run": "now"}' \
--quiet
else
gcloud scheduler jobs update pubsub first-of-the-month \
--description="Trigger the wmrc-skid bot on the first day of the month" \
--schedule="0 9 1 * *" \
gcloud scheduler jobs update pubsub $SCHEDULE_NAME \
--description="$SCHEDULE_DESCRIPTION" \
--schedule="$SCHEDULE_CRON" \
--time-zone=America/Denver \
--location=us-central1 \
--topic=first-of-the-month-topic \
--topic=$SCHEDULE_NAME-topic \
--message-body='{"run": "now"}' \
--quiet
fi
Expand Down
17 changes: 17 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"editorconfig.editorconfig",
"njpwerner.autodocstring",
"ms-python.black-formatter",
"ms-python.vscode-pylance",
"ms-python.python",
"donjayamanne.python-environment-manager",
"charliermarsh.ruff",
"tamasfe.even-better-toml"
],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": []
}
26 changes: 24 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,27 @@
"ugrc",
"wkid",
"wmrc"
]
}
],
"editor.formatOnSave": true,
"editor.rulers": [
120
],
"coverage-gutters.showGutterCoverage": false,
"coverage-gutters.showLineCoverage": true,
"coverage-gutters.showRulerCoverage": false,
"coverage-gutters.highlightdark": "rgb(61, 153, 112, .05)",
"coverage-gutters.noHighlightDark": "rgb(255, 65, 54, .05)",
"coverage-gutters.partialHighlightDark": "rgb(255, 133, 27, .05)",
"python.languageServer": "Pylance",
"python.testing.pytestEnabled": true,
"python.testing.pytestArgs": [
"--no-cov"
],
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
},
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true
}
}
6 changes: 0 additions & 6 deletions pylintrc

This file was deleted.

11 changes: 11 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[tool.ruff]
line-length = 120
ignore = ["E501"]
[tool.black]
line-length = 120
[tool.pytest.ini_options]
minversion = "6.0"
testpaths = ["tests", "src"]
norecursedirs = [".env", "data", "maps", ".github", ".vscode"]
console_output_style = "count"
addopts = "--ruff --cov-branch --cov=wmrc --cov-report term --cov-report xml:cov.xml --instafail"
19 changes: 0 additions & 19 deletions setup.cfg

This file was deleted.

74 changes: 37 additions & 37 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,62 @@
setup.py
A module that installs the wmrc skid as a module
"""
from glob import glob
from os.path import basename, splitext
from pathlib import Path

from setuptools import find_packages, setup

#: Load version from source file
version = {}
with open('src/wmrc/version.py') as fp:
exec(fp.read(), version)
version_file = Path(__file__).parent / "src" / "wmrc" / "version.py"
exec(version_file.read_text(), version)


setup(
name='wmrc-skid',
version=version['__version__'],
license='MIT',
description='Update the wmrc data from Google Sheets via GCF',
author='Jacob Adams',
author_email='jdadms@utah.gov',
url='https://github.com/agrc/wmrc-skid',
packages=find_packages('src'),
package_dir={'': 'src'},
py_modules=[splitext(basename(path))[0] for path in glob('src/*.py')],
name="wmrc-skid",
version=version["__version__"],
license="MIT",
long_description=(Path(__file__).parent / "README.md").read_text(),
long_description_content_type="text/markdown",
author="Jacob Adams",
author_email="jdadms@utah.gov",
url="https://github.com/agrc/wmrc-skid",
packages=find_packages("src"),
package_dir={"": "src"},
include_package_data=True,
zip_safe=True,
classifiers=[
# complete classifier list: http://pypi.python.org/pypi?%3Aaction=list_classifiers
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'Topic :: Utilities',
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Topic :: Utilities",
],
project_urls={
'Issue Tracker': 'https://github.com/agrc/wmrc-skid/issues',
"Issue Tracker": "https://github.com/agrc/wmrc-skid/issues",
},
keywords=['gis'],
keywords=["gis"],
install_requires=[
'ugrc-palletjack>=4.1,<4.4',
'agrc-supervisor==3.0.*',
"ugrc-palletjack>=4.1,<4.5",
"agrc-supervisor==3.0.*",
],
extras_require={
'tests': [
'pylint-quotes~=0.2',
'pylint>=2.15,<4.0',
'pytest-cov>=4,<6',
'pytest-instafail~=0.4',
'pytest-isort>=3.1,<5.0',
'pytest-pylint~=0.19',
'pytest-watch~=4.2',
'pytest>=7.2,<9.0',
'yapf~=0.32',
'pytest-mock>=3.10,<3.15',
'functions-framework~=3.3',
"tests": [
"pytest-cov>=3,<5",
"pytest-instafail==0.5.*",
"pytest-mock==3.*",
"pytest-ruff==0.*",
"pytest-watch==4.*",
"pytest>=6,<8",
"black>=23.3,<23.12",
"ruff==0.0.*",
"functions-framework==3.4.*",
]
},
setup_requires=[
'pytest-runner',
"pytest-runner",
],
entry_points={'console_scripts': [
'wmrc = wmrc.main:process',
]},
entry_points={
"console_scripts": [
"wmrc = wmrc.main:process",
]
},
)
24 changes: 12 additions & 12 deletions src/wmrc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@
import socket
import urllib.request

SKID_NAME = 'wmrc'
SKID_NAME = "wmrc"
#: Try to get project id from GCP metadata server for hostname. If it's empty or errors out, revert to local hostname
try:
url = 'http://metadata.google.internal/computeMetadata/v1/project/project-id'
url = "http://metadata.google.internal/computeMetadata/v1/project/project-id"
req = urllib.request.Request(url)
req.add_header('Metadata-Flavor', 'Google')
req.add_header("Metadata-Flavor", "Google")
project_id = urllib.request.urlopen(req).read().decode()
if not project_id:
raise ValueError
HOST_NAME = project_id
except Exception:
HOST_NAME = socket.gethostname()

AGOL_ORG = 'https://utahdeq.maps.arcgis.com'
AGOL_ORG = "https://utahdeq.maps.arcgis.com"
SENDGRID_SETTINGS = { #: Settings for SendGridHandler
'from_address': 'noreply@utah.gov',
'to_addresses': ['jdadams@utah.gov', 'stevienorcross@utah.gov', 'gerardorodriguez@utah.gov'],
'prefix': f'{SKID_NAME} on {HOST_NAME}: ',
"from_address": "noreply@utah.gov",
"to_addresses": ["jdadams@utah.gov", "stevienorcross@utah.gov", "gerardorodriguez@utah.gov"],
"prefix": f"{SKID_NAME} on {HOST_NAME}: ",
}
LOG_LEVEL = logging.DEBUG
LOG_FILE_NAME = 'log'
LOG_FILE_NAME = "log"

COUNTIES_ITEMID = '90431cac2f9f49f4bcf1505419583753'
COUNTIES_ITEMID = "90431cac2f9f49f4bcf1505419583753"

# FEATURE_LAYER_ITEMID = '4df06137fb0a45459e49107a5f47a326' #: Beta version
FEATURE_LAYER_ITEMID = '056bbc52ff3240f6b69666750a61aeff' #: Live version
JOIN_COLUMN = 'id_'
# FEATURE_LAYER_ITEMID = "4df06137fb0a45459e49107a5f47a326" #: Beta version
FEATURE_LAYER_ITEMID = "056bbc52ff3240f6b69666750a61aeff" #: Live version
JOIN_COLUMN = "id_"
Loading
Loading