Skip to content

Commit

Permalink
add new github actions workflow using microconda, add suggested pylin…
Browse files Browse the repository at this point in the history
…t edits, fix environment.yml
  • Loading branch information
mccroweyclinton-EPA committed Nov 27, 2024
1 parent 06ddfa6 commit e28d2cd
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 104 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/buildandtestpyaqsapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ jobs:
conda env update --file=environment.yml -vv
#echo "source activate base" >> ~/.bashrc
#source ~/.bashrc
sphinx-build --version # Verify sphinx installation
- name: Display Python and sphinx version and system info
run: |
Expand Down
58 changes: 0 additions & 58 deletions .github/workflows/new.yml

This file was deleted.

67 changes: 67 additions & 0 deletions .github/workflows/newbuildandtestpyaqsapi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: new_build_and_test_pyaqsapi
run-name: A push event from ${{ github.actor }} caused a rebuilding and retesting of the pyaqsapi package via GitHub actions

on:
push:
branches:
- main
- github_workflow
pull_request:
branches:
- main
- github_workflow

jobs:
setup_environment:
runs-on: ubuntu-latest
env:
AQSkey: ${{ secrets.AQSKEY }}
AQSuser: ${{ secrets.AQSUSER }}
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]

steps:
- name: checkout
uses: actions/checkout@v3

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

- name: setup environment
uses: mamba-org/setup-micromamba@v2
with:
environment-file: environment.yml
init-shell: >-
bash
powershell
cache-environment: true
environment-name: pyaqsapi
post-cleanup: 'all'
shell: powershell

- name: Display Python and sphinx version and system info
run: |
python -c "import platform; print(platform.uname())"
sphinx-build --version
- name: build and install pyaqsapi in a test environment using python-build and pip
run: |
python -m build .
pip install .
- name: build apidocs
run: |
cd docs
make clean
sphinx-apidoc --ext-autodoc -o . ../pyaqsapi/
make html
- name: test_package
env:
AQSkey: ${{ secrets.AQSKEY }}
AQSuser: ${{ secrets.AQSUSER }}
run: pytest
4 changes: 2 additions & 2 deletions bld.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"%PYTHON%" python -m build .
if errorlevel 1 exit 1
"%PYTHON%" setup.py install
if errorlevel 1 exit 1
Binary file modified docs/_build/doctrees/environment.pickle
Binary file not shown.
7 changes: 4 additions & 3 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# environment.yml
name: pyaqsapi
channels:
- conda-forge
- defaults
environment:
- setuppyaqsapi
dependencies:
# - python>=3.8
# - conda-build
- python>=3.8
- conda-build
- tox-conda
- pandas
- pep517
Expand All @@ -21,3 +21,4 @@ dependencies:
- certifi
- cryptography
- pytest
- python-build
15 changes: 5 additions & 10 deletions pyaqsapi/bybox/bybox.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ def monitors(

if return_header:
return aqsresultlist
else:
return helperfunctions.aqs_removeheader(aqsresultlist)
return helperfunctions.aqs_removeheader(aqsresultlist)


def sampledata(
Expand Down Expand Up @@ -202,8 +201,7 @@ def sampledata(

if return_header:
return aqsresultlist
else:
return helperfunctions.aqs_removeheader(aqsresultlist)
return helperfunctions.aqs_removeheader(aqsresultlist)


def annualsummary(
Expand Down Expand Up @@ -293,8 +291,7 @@ def annualsummary(

if return_header:
return aqsresultlist
else:
return helperfunctions.aqs_removeheader(aqsresultlist)
return helperfunctions.aqs_removeheader(aqsresultlist)


def dailysummary(
Expand Down Expand Up @@ -384,8 +381,7 @@ def dailysummary(

if return_header:
return aqsresultlist
else:
return helperfunctions.aqs_removeheader(aqsresultlist)
return helperfunctions.aqs_removeheader(aqsresultlist)


def quarterlysummary(
Expand Down Expand Up @@ -494,5 +490,4 @@ def quarterlysummary(

if return_header:
return aqsresultlist
else:
return helperfunctions.aqs_removeheader(aqsresultlist)
return helperfunctions.aqs_removeheader(aqsresultlist)
61 changes: 33 additions & 28 deletions pyaqsapi/helperfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def __init__(self) -> None:
self._request_time: str | None = None
self._rows: str | None = None
self._url: str | None = None
self._status_code: str = None

def set_header(self, Header: DataFrame) -> None:
"""
Expand Down Expand Up @@ -297,7 +298,9 @@ def __aqs(
# AQS_domain = "https://aqs.epa.gov/data/api/" + service + "/" + aqsfilter
header = {"User-Agent": user_agent, "From": AQS_user}

query = get(url=url, params=variables, headers=header, verify=where())
query = get(
url=url, params=variables, headers=header, verify=where(), timeout=15
)
query.raise_for_status()
self.set_header(DataFrame(query.headers))
self.set_data(DataFrame.from_dict(query.json()["Data"]))
Expand Down Expand Up @@ -376,8 +379,8 @@ def _aqs_services_by_site(
(pandas DataFrame or an AQSAPI_V2 object): The information requested.
"""
global AQS_user
global AQS_key
# global AQS_user
# global AQS_key
user = AQS_user
key = AQS_key
aqsfilter = "bySite"
Expand Down Expand Up @@ -468,8 +471,8 @@ def _aqs_services_by_county(
(pandas DataFrame or an AQSAPI_V2 object): The information requested.
"""
global AQS_user
global AQS_key
# global AQS_user
# global AQS_key
aqsfilter = "byCounty"
user = AQS_user
key = AQS_key
Expand Down Expand Up @@ -554,8 +557,8 @@ def _aqs_services_by_state(
(pandas DataFrame or an AQSAPI_V2 object): The information requested.
"""
global AQS_user
global AQS_key
# global AQS_user
# global AQS_key
aqsfilter = "byState"
user = AQS_user
key = AQS_key
Expand Down Expand Up @@ -653,8 +656,8 @@ def _aqs_services_by_box(
-------
(pandas DataFrame or an AQSAPI_V2 object): The information requested.
"""
global AQS_user
global AQS_key
# global AQS_user
# global AQS_key
aqsfilter = "byBox"
user = AQS_user
key = AQS_key
Expand Down Expand Up @@ -739,8 +742,8 @@ def _aqs_services_by_cbsa(
-------
(pandas DataFrame or an AQSAPI_V2 object): The information requested.
"""
global AQS_user
global AQS_key
# global AQS_user
# global AQS_key
aqsfilter = "byCBSA"
user = AQS_user
key = AQS_key
Expand Down Expand Up @@ -820,8 +823,8 @@ def _aqs_services_by_pqao(
-------
(pandas DataFrame or an AQSAPI_V2 object): The information requested.
"""
global AQS_user
global AQS_key
# global AQS_user
# global AQS_key
aqsfilter = "byPQAO"
user = AQS_user
key = AQS_key
Expand Down Expand Up @@ -891,8 +894,8 @@ def _aqs_services_by_MA(
-------
(pandas DataFrame or an AQSAPI_V2 object): The information requested.
"""
global AQS_user
global AQS_key
# global AQS_user
# global AQS_key
aqsfilter = "byMA"
user = AQS_user
key = AQS_key
Expand Down Expand Up @@ -963,8 +966,8 @@ def _aqs_list_services(
-------
(pandas DataFrame or an AQSAPI_V2 object): The information requested.
"""
global AQS_user
global AQS_key
# global AQS_user
# global AQS_key
user = AQS_user
key = AQS_key
service = "list"
Expand Down Expand Up @@ -1009,8 +1012,8 @@ def _aqs_metadata_services(
-------
(pandas DataFrame or an AQSAPI_V2 object): The information requested.
"""
global AQS_user
global AQS_key
# global AQS_user
# global AQS_key
user = AQS_user
key = AQS_key
variables = {"email": user, "key": key, "service": service}
Expand Down Expand Up @@ -1110,7 +1113,7 @@ def aqs_removeheader(
"""
aqsresult = DataFrame()
for x in range(len(aqsobject)):
for x in enumerate(aqsobject):
aqsresult = concat([aqsresult, aqsobject[x].get_data()], axis=0)

return aqsresult
Expand Down Expand Up @@ -1267,18 +1270,20 @@ def _aqsmultiyearcall(
# case _:
# RuntimeError("invalid function sent to _aqsmultiyearcall")
if fun == "_aqs_services_by_site":
return list(starmap(aqsresult._aqs_services_by_site, params)) # type: ignore
returnvalue = list(starmap(aqsresult._aqs_services_by_site, params)) # type: ignore
elif fun == "_aqs_services_by_county":
return list(starmap(aqsresult._aqs_services_by_county, params)) # type: ignore
returnvalue = list(starmap(aqsresult._aqs_services_by_county, params)) # type: ignore
elif fun == "_aqs_services_by_state":
return list(starmap(aqsresult._aqs_services_by_state, params)) # type: ignore
returnvalue = list(starmap(aqsresult._aqs_services_by_state, params)) # type: ignore
elif fun == "_aqs_services_by_MA":
return list(starmap(aqsresult._aqs_services_by_MA, params)) # type: ignore
returnvalue = list(starmap(aqsresult._aqs_services_by_MA, params)) # type: ignore
elif fun == "_aqs_services_by_pqao":
return list(starmap(aqsresult._aqs_services_by_pqao, params)) # type: ignore
returnvalue = list(starmap(aqsresult._aqs_services_by_pqao, params)) # type: ignore
elif fun == "_aqs_services_by_cbsa":
return list(starmap(aqsresult._aqs_services_by_cbsa, params)) # type: ignore
returnvalue = list(starmap(aqsresult._aqs_services_by_cbsa, params)) # type: ignore
elif fun == "_aqs_services_by_box":
return list(starmap(aqsresult._aqs_services_by_box, params)) # type: ignore
returnvalue = list(starmap(aqsresult._aqs_services_by_box, params)) # type: ignore
else:
return None
returnvalue = None

return returnvalue

0 comments on commit e28d2cd

Please sign in to comment.