diff --git a/.github/workflows/buildandtestpyaqsapi.yml b/.github/workflows/buildandtestpyaqsapi.yml index 44b9aaa..61a372a 100644 --- a/.github/workflows/buildandtestpyaqsapi.yml +++ b/.github/workflows/buildandtestpyaqsapi.yml @@ -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: | diff --git a/.github/workflows/new.yml b/.github/workflows/new.yml deleted file mode 100644 index ce45f1e..0000000 --- a/.github/workflows/new.yml +++ /dev/null @@ -1,58 +0,0 @@ -name: 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, pull_request, branch] - branches: - - main - - github_workflow - - -jobs: - setup_environment: - runs-on: ubuntu-latest - env: - AQSkey: ${{ secrets.AQSKEY }} - AQSuser: ${{ secrets.AQSUSER }} - strategy: - max-parallel: 3 - fail-fast: false - steps: - - uses: actions/checkout@v4 - - name: Set up Python >=3.8 - uses: actions/setup-python@v3 - with: - python-version: ["3.8", "3.9", "3.10", "3.11"] - - name: Add conda to system path - run: | - # $CONDA is an environment variable pointing to the root of the miniconda directory - echo $CONDA/bin >> $GITHUB_PATH - - name: Install dependencies - run: | - conda config --add channels conda-forge - conda update --yes conda - conda install --yes conda-libmamba-solver - conda config --set solver libmamba - conda env update --file environment.yml --name setuppyaqsapi - - name: Display Python and sphinx version and system info - run: | - python -c "import platform; print(platform.uname())" - sphinx-build --version - - name: build documentation - run: | - cd docs - make clean - sphinx-apidoc --ext-autodoc -o . ../pyaqsapi/ - make html - #build twice to resolve bibtex references - make html - - - name: build and install pyaqsapi in a test environment - run: | - python -m build . - pip install . - - name: Test with pytest - env: - AQSkey: ${{ secrets.AQSKEY }} - AQSuser: ${{ secrets.AQSUSER }} - run: | - pytest diff --git a/.github/workflows/newbuildandtestpyaqsapi.yml b/.github/workflows/newbuildandtestpyaqsapi.yml new file mode 100644 index 0000000..2ad2c6f --- /dev/null +++ b/.github/workflows/newbuildandtestpyaqsapi.yml @@ -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 \ No newline at end of file diff --git a/bld.bat b/bld.bat index 3c37d5b..6021130 100644 --- a/bld.bat +++ b/bld.bat @@ -1,2 +1,2 @@ -"%PYTHON%" python -m build . -if errorlevel 1 exit 1 +"%PYTHON%" setup.py install +if errorlevel 1 exit 1 \ No newline at end of file diff --git a/docs/_build/doctrees/environment.pickle b/docs/_build/doctrees/environment.pickle index aee8285..6a0006e 100644 Binary files a/docs/_build/doctrees/environment.pickle and b/docs/_build/doctrees/environment.pickle differ diff --git a/environment.yml b/environment.yml index 5cf724c..4c66f2e 100644 --- a/environment.yml +++ b/environment.yml @@ -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 @@ -21,3 +21,4 @@ dependencies: - certifi - cryptography - pytest + - python-build diff --git a/pyaqsapi/bybox/bybox.py b/pyaqsapi/bybox/bybox.py index 040a7cb..5da0a57 100644 --- a/pyaqsapi/bybox/bybox.py +++ b/pyaqsapi/bybox/bybox.py @@ -101,8 +101,7 @@ def monitors( if return_header: return aqsresultlist - else: - return helperfunctions.aqs_removeheader(aqsresultlist) + return helperfunctions.aqs_removeheader(aqsresultlist) def sampledata( @@ -202,8 +201,7 @@ def sampledata( if return_header: return aqsresultlist - else: - return helperfunctions.aqs_removeheader(aqsresultlist) + return helperfunctions.aqs_removeheader(aqsresultlist) def annualsummary( @@ -293,8 +291,7 @@ def annualsummary( if return_header: return aqsresultlist - else: - return helperfunctions.aqs_removeheader(aqsresultlist) + return helperfunctions.aqs_removeheader(aqsresultlist) def dailysummary( @@ -384,8 +381,7 @@ def dailysummary( if return_header: return aqsresultlist - else: - return helperfunctions.aqs_removeheader(aqsresultlist) + return helperfunctions.aqs_removeheader(aqsresultlist) def quarterlysummary( @@ -494,5 +490,4 @@ def quarterlysummary( if return_header: return aqsresultlist - else: - return helperfunctions.aqs_removeheader(aqsresultlist) + return helperfunctions.aqs_removeheader(aqsresultlist) diff --git a/pyaqsapi/helperfunctions.py b/pyaqsapi/helperfunctions.py index e30a70b..3bbb9a1 100644 --- a/pyaqsapi/helperfunctions.py +++ b/pyaqsapi/helperfunctions.py @@ -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: """ @@ -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"])) @@ -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" @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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" @@ -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} @@ -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 @@ -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