Skip to content

Commit

Permalink
setup changes (#146)
Browse files Browse the repository at this point in the history
* use `pooch` instead of `wget`

* use functiosn from `gartersnake`

* update workflow

* remove `dunamai` from documentation requirements

* update build workflow

* fix syntax error
  • Loading branch information
zacharyburnett authored Mar 2, 2022
1 parent eac41c4 commit 728e35f
Show file tree
Hide file tree
Showing 13 changed files with 160 additions and 388 deletions.
44 changes: 23 additions & 21 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,59 +7,61 @@ on:

jobs:
build_wheels:
name: Python ${{ matrix.python-version }} wheel on ${{ matrix.os }}
name: build wheel
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-latest, windows-latest ]
os: [ ubuntu-latest ]
python-version: [ '3.x' ]
steps:
- name: Checkout repository
- name: checkout repository
uses: actions/checkout@v2
- name: Install Python
- name: install Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Restore cached dependencies
- name: load cached `~/.local`
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.py') }}
restore-keys: ${{ runner.os }}-pip-${{ matrix.python-version }}-
- name: Install dependencies
run: pip install --user --upgrade pip setuptools wheel
- name: Build wheel
run: python setup.py bdist_wheel
- name: Save wheel
path: ~/.local
key: ${{ runner.os }}-python${{ matrix.python-version }}-${{ hashFiles('pyproject.toml', 'setup.*') }}
restore-keys: ${{ runner.os }}-python${{ matrix.python-version }}-
- name: build wheel
run: pip wheel . -w dist --no-deps
- name: save wheel
uses: actions/upload-artifact@v2
with:
name: build
path: ./dist/*.whl
build_sdist:
name: package source
runs-on: ubuntu-latest
steps:
- name: Checkout repository
- name: checkout repository
uses: actions/checkout@v2
- name: Install Python
- name: install Python
uses: actions/setup-python@v2
- name: Package source
- name: install dependencies
run: pip install dunamai
- name: package source
run: python setup.py sdist
- name: Save source package
- name: save source package
uses: actions/upload-artifact@v2
with:
name: build
path: ./dist/*.tar.gz
upload_pypi:
name: publish to PyPI
needs: [ build_wheels, build_sdist ]
runs-on: ubuntu-latest
steps:
- name: Retrieve wheel(s) and source
- name: retrieve wheel(s) and source
uses: actions/download-artifact@v2
with:
name: artifact
name: build
path: dist
- name: Upload wheel(s) and source
uses: pypa/gh-action-pypi-publish@master
- name: upload wheel(s) and source
uses: pypa/gh-action-pypi-publish@v1.5.0
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
22 changes: 0 additions & 22 deletions .github/workflows/formatting.yml

This file was deleted.

66 changes: 40 additions & 26 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,58 @@ name: tests
on: [ push ]

jobs:
tests:
name: Python ${{ matrix.python-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
lint:
name: lint
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest ]
python-version: [ '3.6', '3.x' ]
python-version: [ '3.x' ]
steps:
- name: Checkout repository
- name: clone repository
uses: actions/checkout@v2
- name: Install Python
- name: install Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Restore cached dependencies
- name: load cached `~/.local`
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.py') }}
restore-keys: ${{ runner.os }}-pip-${{ matrix.python-version }}-
- name: Install netCDF4 library on Linux
if: contains(matrix.os, 'ubuntu')
run: sudo apt-get update -y && sudo apt-get install -y libnetcdf-dev libnetcdff-dev
- name: Install dependencies
run: pip install ".[testing,development]"
- name: Lint with flake8
path: ~/.local
key: ${{ runner.os }}-python${{ matrix.python-version }}-${{ hashFiles('pyproject.toml', 'setup.*') }}
restore-keys: ${{ runner.os }}-python${{ matrix.python-version }}-
- name: install dependencies
run: pip install ".[development]"
- name: lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Run tests with coverage
run: pytest --numprocesses auto --cov ./ --cov-report xml:coverage.xml
- name: Upload coverage to Codecov
if: matrix.python-version == '3.x'
uses: codecov/[email protected]
test:
needs: lint
name: test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-latest ]
python-version: [ '3.6', '3.x' ]
steps:
- name: clone repository
uses: actions/checkout@v2
- name: install Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: load cached `~/.local`
uses: actions/cache@v2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.xml
fail_ci_if_error: true
path: ~/.local
key: ${{ runner.os }}-python${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('pyproject.toml', 'setup.*') }}
restore-keys: ${{ runner.os }}-python${{ matrix.python-version }}-
- name: install `pipwin` on Windows
if: contains(matrix.os, 'windows')
run: pip install pipwin
- name: install dependencies
run: pip install ".[testing]"
- name: run tests
run: pytest --numprocesses auto
20 changes: 13 additions & 7 deletions adcircpy/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,32 @@
import sys
import tarfile

import wget
import pooch


def download_mesh(url: str, directory: PathLike, overwrite: bool = False):
def download_mesh(
url: str, directory: PathLike, known_hash: str = None, overwrite: bool = False
):
if not isinstance(directory, Path):
directory = Path(directory)
if not directory.exists():
directory.mkdir(parents=True, exist_ok=True)

if not (directory / 'fort.14').exists() or overwrite:
logging.info(f'downloading mesh files to {directory}')
extract_download(url, directory, ['fort.13', 'fort.14'])
extract_download(
url, directory, ['fort.13', 'fort.14'], known_hash=known_hash, overwrite=overwrite
)

return directory


def extract_download(
url: str, directory: PathLike, filenames: [str] = None, overwrite: bool = False
url: str,
directory: PathLike,
filenames: [str] = None,
known_hash: str = None,
overwrite: bool = False,
):
if not isinstance(directory, Path):
directory = Path(directory)
Expand All @@ -35,7 +43,7 @@ def extract_download(

temporary_filename = directory / 'temp.tar.gz'
logging.debug(f'downloading {url} -> {temporary_filename}')
wget.download(url, f'{temporary_filename}')
temporary_filename = pooch.retrieve(url, known_hash=known_hash, fname=temporary_filename)
logging.debug(f'extracting {temporary_filename} -> {directory}')
with tarfile.open(temporary_filename) as local_file:
if len(filenames) > 0:
Expand All @@ -49,8 +57,6 @@ def extract_download(
else:
local_file.extractall(directory)

os.remove(temporary_filename)


def get_logger(
name: str,
Expand Down
5 changes: 3 additions & 2 deletions examples/example_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
INPUT_DIRECTORY = DATA_DIRECTORY / 'input' / 'shinnecock'
OUTPUT_DIRECTORY = DATA_DIRECTORY / 'output' / 'example_1'

MESH_URL = 'https://www.dropbox.com/s/1wk91r67cacf132/NetCDF_shinnecock_inlet.tar.bz2?dl=1'
MESH_DIRECTORY = INPUT_DIRECTORY / 'shinnecock'

download_mesh(
url=MESH_URL, directory=MESH_DIRECTORY,
url='https://www.dropbox.com/s/1wk91r67cacf132/NetCDF_shinnecock_inlet.tar.bz2?dl=1',
directory=MESH_DIRECTORY,
known_hash='99d764541983bfee60d4176af48ed803d427dea61243fa22d3f4003ebcec98f4',
)

# open mesh file
Expand Down
5 changes: 3 additions & 2 deletions examples/example_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
INPUT_DIRECTORY = DATA_DIRECTORY / 'input'
OUTPUT_DIRECTORY = DATA_DIRECTORY / 'output' / 'example_2'

MESH_URL = 'https://www.dropbox.com/s/1wk91r67cacf132/NetCDF_shinnecock_inlet.tar.bz2?dl=1'
MESH_DIRECTORY = INPUT_DIRECTORY / 'shinnecock'

download_mesh(
url=MESH_URL, directory=MESH_DIRECTORY,
url='https://www.dropbox.com/s/1wk91r67cacf132/NetCDF_shinnecock_inlet.tar.bz2?dl=1',
directory=MESH_DIRECTORY,
known_hash='99d764541983bfee60d4176af48ed803d427dea61243fa22d3f4003ebcec98f4',
)

# open mesh file
Expand Down
5 changes: 3 additions & 2 deletions examples/example_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
INPUT_DIRECTORY = DATA_DIRECTORY / 'input'
OUTPUT_DIRECTORY = DATA_DIRECTORY / 'output' / 'example_3'

MESH_URL = 'https://www.dropbox.com/s/1wk91r67cacf132/NetCDF_shinnecock_inlet.tar.bz2?dl=1'
MESH_DIRECTORY = INPUT_DIRECTORY / 'shinnecock'

download_mesh(
url=MESH_URL, directory=MESH_DIRECTORY,
url='https://www.dropbox.com/s/1wk91r67cacf132/NetCDF_shinnecock_inlet.tar.bz2?dl=1',
directory=MESH_DIRECTORY,
known_hash='99d764541983bfee60d4176af48ed803d427dea61243fa22d3f4003ebcec98f4',
)

# open mesh file
Expand Down
5 changes: 3 additions & 2 deletions examples/example_4.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
INPUT_DIRECTORY = DATA_DIRECTORY / 'input'
OUTPUT_DIRECTORY = DATA_DIRECTORY / 'output' / 'example_4'

MESH_URL = 'https://www.dropbox.com/s/1wk91r67cacf132/NetCDF_shinnecock_inlet.tar.bz2?dl=1'
MESH_DIRECTORY = INPUT_DIRECTORY / 'shinnecock'

download_mesh(
url=MESH_URL, directory=MESH_DIRECTORY,
url='https://www.dropbox.com/s/1wk91r67cacf132/NetCDF_shinnecock_inlet.tar.bz2?dl=1',
directory=MESH_DIRECTORY,
known_hash='99d764541983bfee60d4176af48ed803d427dea61243fa22d3f4003ebcec98f4',
)

# open mesh file
Expand Down
54 changes: 0 additions & 54 deletions examples/make_best_track_ensemble.py

This file was deleted.

6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[build-system]
requires = [
"dunamai",
"setuptools",
]
build-backend = "setuptools.build_meta"
Loading

0 comments on commit 728e35f

Please sign in to comment.