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

Fix crawl test #36

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jlpm build
jupyter labextension link .
jupyter serverextension enable --sys-prefix jupyterlab_thredds
```

(`jlpm` command is JupyterLab's pinned version of [yarn](https://yarnpkg.com/) that is installed with JupyterLab.)

To rebuild the package and the JupyterLab app:
Expand All @@ -56,6 +57,7 @@ jupyter lab build
```

Watch mode

```bash
# shell 1
jlpm watch
Expand All @@ -66,11 +68,12 @@ jupyter lab --ip=0.0.0.0 --no-browser --watch
## Release

To make a new release perform the following steps:

1. Update version in `package.json` and `jupyterlab_thredds/version.py`
2. Record changes in `CHANGELOG.md`
3. Make sure tests pass by running `jlpm test` and `pytest`
5. Commit and push all changes
6. Publish lab extension to npmjs with `jlpm build` and `jlpm publish --access=public`
7. Publish server extension to pypi with `python setup.py sdist bdist_wheel` and `twine upload dist/*`
8. Create GitHub release
9. Update DOI in `CITATION.cff`
4. Commit and push all changes
5. Publish lab extension to npmjs with `jlpm build` and `jlpm publish --access=public`
6. Publish server extension to pypi with `python setup.py sdist bdist_wheel` and `twine upload dist/*`
7. Create GitHub release
8. Update DOI in `CITATION.cff`
19 changes: 8 additions & 11 deletions jupyterlab_thredds/crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,24 +107,22 @@ def __init__(self, url: str) -> None:


class TDSCrawler:
def __init__(self, rooturl: str, loop, maxtasks=10):
def __init__(self, rooturl: str, maxtasks=10):
"""Asynchronous THREDDS catalog crawler

Crawler based on https://github.com/aio-libs/aiohttp/blob/master/examples/legacy/crawl.py

Args:
rooturl: URL with THREDDS catalog xml file
loop: Event loop, eg. asyncio.get_event_loop()
maxtasks: Number of download tasks to run concurrently
"""
self.rooturl = rooturl
self.loop = loop
self.todo = set()
self.busy = set()
self.done = {}
self.tasks = set()
self.sem = asyncio.Semaphore(maxtasks, loop=loop)
self.session = aiohttp.ClientSession(loop=loop)
self.sem = asyncio.Semaphore(maxtasks)
self.session = aiohttp.ClientSession()
self.datasets = []

async def run(self):
Expand All @@ -134,11 +132,10 @@ async def run(self):
List of datasets
"""
delay = 0.2
t = asyncio.ensure_future(self.addurls([self.rooturl]),
loop=self.loop)
await asyncio.sleep(delay, loop=self.loop)
t = asyncio.ensure_future(self.addurls([self.rooturl]))
await asyncio.sleep(delay)
while self.busy:
await asyncio.sleep(delay, loop=self.loop)
await asyncio.sleep(delay)

await t
await self.session.close()
Expand All @@ -151,11 +148,11 @@ async def addurls(self, urls):
url not in self.todo):
self.todo.add(url)
await self.sem.acquire()
task = asyncio.ensure_future(self.process(url), loop=self.loop)
task = asyncio.ensure_future(self.process(url))
task.add_done_callback(lambda t: self.sem.release())
task.add_done_callback(self.tasks.remove)
self.tasks.add(task)
await task # TODO waiting for task here will not make multiple tasks run concurrently, but if not exception are not captured
# await task # TODO waiting for task here will not make multiple tasks run concurrently, but if not exception are not captured

async def process(self, url):
logger.info('processing: %s', url)
Expand Down
3 changes: 1 addition & 2 deletions jupyterlab_thredds/fetchers/thredds.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ async def get(self):
catalog_url = self.get_argument('catalog_url')
self.set_header('Content-Type', 'application/json')
c = ThreddsConfig(config=self.config)
loop = asyncio.get_event_loop()
crawler = TDSCrawler(catalog_url, loop, maxtasks=c.maxtasks)
crawler = TDSCrawler(catalog_url, maxtasks=c.maxtasks)
try:
datasets = await asyncio.wait_for(crawler.run(), c.timeout)

Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[tool:pytest]
addopts = --cov=jupyterlab_thredds --cov-report xml --cov-report term --cov-branch --junit-xml xunit-reports/xunit-result-jupyterlab_thredds.xml
junit_family=xunit2
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
'ipyleaflet',
'OWSLib',
'traitlets',
'aiohttp',
'aiohttp>=3.5,<4',
],
version=get_version('jupyterlab_thredds/version.py'),
long_description=readme,
Expand Down
114 changes: 57 additions & 57 deletions tests/fixtures/crawler.expected.json
Original file line number Diff line number Diff line change
@@ -1,86 +1,86 @@
[
{
"id": "ewc/dischargeEns.nc",
"name": "ewc/dischargeEns.nc",
"name": "ewc/data/dischargeEns.nc",
"id": "ewc/data/dischargeEns.nc",
"services": {
"DAP4": "http://localhost:8080/thredds/dap4/ewc/dischargeEns.nc",
"HTTPSERVER": "http://localhost:8080/thredds/fileServer/ewc/dischargeEns.nc",
"NETCDFSUBSET": "http://localhost:8080/thredds/ncss/ewc/dischargeEns.nc",
"OPENDAP": "http://localhost:8080/thredds/dodsC/ewc/dischargeEns.nc",
"WCS": "http://localhost:8080/thredds/wcs/ewc/dischargeEns.nc",
"WMS": "http://localhost:8080/thredds/wms/ewc/dischargeEns.nc"
"OPENDAP": "http://localhost:8080/thredds/dodsC/ewc/data/dischargeEns.nc",
"DAP4": "http://localhost:8080/thredds/dap4/ewc/data/dischargeEns.nc",
"HTTPSERVER": "http://localhost:8080/thredds/fileServer/ewc/data/dischargeEns.nc",
"WCS": "http://localhost:8080/thredds/wcs/ewc/data/dischargeEns.nc",
"WMS": "http://localhost:8080/thredds/wms/ewc/data/dischargeEns.nc",
"NETCDFSUBSET": "http://localhost:8080/thredds/ncss/ewc/data/dischargeEns.nc"
}
},
{
"id": "ewc/dischargeEnsStdOut.nc",
"name": "ewc/dischargeEnsStdOut.nc",
"name": "ewc/data/dischargeEnsStdOut.nc",
"id": "ewc/data/dischargeEnsStdOut.nc",
"services": {
"DAP4": "http://localhost:8080/thredds/dap4/ewc/dischargeEnsStdOut.nc",
"HTTPSERVER": "http://localhost:8080/thredds/fileServer/ewc/dischargeEnsStdOut.nc",
"NETCDFSUBSET": "http://localhost:8080/thredds/ncss/ewc/dischargeEnsStdOut.nc",
"OPENDAP": "http://localhost:8080/thredds/dodsC/ewc/dischargeEnsStdOut.nc",
"WCS": "http://localhost:8080/thredds/wcs/ewc/dischargeEnsStdOut.nc",
"WMS": "http://localhost:8080/thredds/wms/ewc/dischargeEnsStdOut.nc"
"OPENDAP": "http://localhost:8080/thredds/dodsC/ewc/data/dischargeEnsStdOut.nc",
"DAP4": "http://localhost:8080/thredds/dap4/ewc/data/dischargeEnsStdOut.nc",
"HTTPSERVER": "http://localhost:8080/thredds/fileServer/ewc/data/dischargeEnsStdOut.nc",
"WCS": "http://localhost:8080/thredds/wcs/ewc/data/dischargeEnsStdOut.nc",
"WMS": "http://localhost:8080/thredds/wms/ewc/data/dischargeEnsStdOut.nc",
"NETCDFSUBSET": "http://localhost:8080/thredds/ncss/ewc/data/dischargeEnsStdOut.nc"
}
},
{
"id": "ewc/forcingEnsemble/precipEnsMem01.nc",
"name": "ewc/forcingEnsemble/precipEnsMem01.nc",
"name": "ewc/data/forcingEnsemble/precipEnsMem01.nc",
"id": "ewc/data/forcingEnsemble/precipEnsMem01.nc",
"services": {
"DAP4": "http://localhost:8080/thredds/dap4/ewc/forcingEnsemble/precipEnsMem01.nc",
"HTTPSERVER": "http://localhost:8080/thredds/fileServer/ewc/forcingEnsemble/precipEnsMem01.nc",
"NETCDFSUBSET": "http://localhost:8080/thredds/ncss/ewc/forcingEnsemble/precipEnsMem01.nc",
"OPENDAP": "http://localhost:8080/thredds/dodsC/ewc/forcingEnsemble/precipEnsMem01.nc",
"WCS": "http://localhost:8080/thredds/wcs/ewc/forcingEnsemble/precipEnsMem01.nc",
"WMS": "http://localhost:8080/thredds/wms/ewc/forcingEnsemble/precipEnsMem01.nc"
"OPENDAP": "http://localhost:8080/thredds/dodsC/ewc/data/forcingEnsemble/precipEnsMem01.nc",
"DAP4": "http://localhost:8080/thredds/dap4/ewc/data/forcingEnsemble/precipEnsMem01.nc",
"HTTPSERVER": "http://localhost:8080/thredds/fileServer/ewc/data/forcingEnsemble/precipEnsMem01.nc",
"WCS": "http://localhost:8080/thredds/wcs/ewc/data/forcingEnsemble/precipEnsMem01.nc",
"WMS": "http://localhost:8080/thredds/wms/ewc/data/forcingEnsemble/precipEnsMem01.nc",
"NETCDFSUBSET": "http://localhost:8080/thredds/ncss/ewc/data/forcingEnsemble/precipEnsMem01.nc"
}
},
{
"id": "ewc/forcingEnsemble/tempEnsMem01.nc",
"name": "ewc/forcingEnsemble/tempEnsMem01.nc",
"name": "ewc/data/forcingEnsemble/tempEnsMem01.nc",
"id": "ewc/data/forcingEnsemble/tempEnsMem01.nc",
"services": {
"DAP4": "http://localhost:8080/thredds/dap4/ewc/forcingEnsemble/tempEnsMem01.nc",
"HTTPSERVER": "http://localhost:8080/thredds/fileServer/ewc/forcingEnsemble/tempEnsMem01.nc",
"NETCDFSUBSET": "http://localhost:8080/thredds/ncss/ewc/forcingEnsemble/tempEnsMem01.nc",
"OPENDAP": "http://localhost:8080/thredds/dodsC/ewc/forcingEnsemble/tempEnsMem01.nc",
"WCS": "http://localhost:8080/thredds/wcs/ewc/forcingEnsemble/tempEnsMem01.nc",
"WMS": "http://localhost:8080/thredds/wms/ewc/forcingEnsemble/tempEnsMem01.nc"
"OPENDAP": "http://localhost:8080/thredds/dodsC/ewc/data/forcingEnsemble/tempEnsMem01.nc",
"DAP4": "http://localhost:8080/thredds/dap4/ewc/data/forcingEnsemble/tempEnsMem01.nc",
"HTTPSERVER": "http://localhost:8080/thredds/fileServer/ewc/data/forcingEnsemble/tempEnsMem01.nc",
"WCS": "http://localhost:8080/thredds/wcs/ewc/data/forcingEnsemble/tempEnsMem01.nc",
"WMS": "http://localhost:8080/thredds/wms/ewc/data/forcingEnsemble/tempEnsMem01.nc",
"NETCDFSUBSET": "http://localhost:8080/thredds/ncss/ewc/data/forcingEnsemble/tempEnsMem01.nc"
}
},
{
"id": "ewc/work01/output/netcdf/discharge_dailyTot_output.nc",
"name": "ewc/work01/output/netcdf/discharge_dailyTot_output.nc",
"name": "ewc/data/work01/output/netcdf/discharge_dailyTot_output.nc",
"id": "ewc/data/work01/output/netcdf/discharge_dailyTot_output.nc",
"services": {
"DAP4": "http://localhost:8080/thredds/dap4/ewc/work01/output/netcdf/discharge_dailyTot_output.nc",
"HTTPSERVER": "http://localhost:8080/thredds/fileServer/ewc/work01/output/netcdf/discharge_dailyTot_output.nc",
"NETCDFSUBSET": "http://localhost:8080/thredds/ncss/ewc/work01/output/netcdf/discharge_dailyTot_output.nc",
"OPENDAP": "http://localhost:8080/thredds/dodsC/ewc/work01/output/netcdf/discharge_dailyTot_output.nc",
"WCS": "http://localhost:8080/thredds/wcs/ewc/work01/output/netcdf/discharge_dailyTot_output.nc",
"WMS": "http://localhost:8080/thredds/wms/ewc/work01/output/netcdf/discharge_dailyTot_output.nc"
"OPENDAP": "http://localhost:8080/thredds/dodsC/ewc/data/work01/output/netcdf/discharge_dailyTot_output.nc",
"DAP4": "http://localhost:8080/thredds/dap4/ewc/data/work01/output/netcdf/discharge_dailyTot_output.nc",
"HTTPSERVER": "http://localhost:8080/thredds/fileServer/ewc/data/work01/output/netcdf/discharge_dailyTot_output.nc",
"WCS": "http://localhost:8080/thredds/wcs/ewc/data/work01/output/netcdf/discharge_dailyTot_output.nc",
"WMS": "http://localhost:8080/thredds/wms/ewc/data/work01/output/netcdf/discharge_dailyTot_output.nc",
"NETCDFSUBSET": "http://localhost:8080/thredds/ncss/ewc/data/work01/output/netcdf/discharge_dailyTot_output.nc"
}
},
{
"id": "ewc/work01/output/netcdf/satDegUppSurface_dailyTot_output.nc",
"name": "ewc/work01/output/netcdf/satDegUppSurface_dailyTot_output.nc",
"name": "ewc/data/work01/output/netcdf/satDegUppSurface_dailyTot_output.nc",
"id": "ewc/data/work01/output/netcdf/satDegUppSurface_dailyTot_output.nc",
"services": {
"DAP4": "http://localhost:8080/thredds/dap4/ewc/work01/output/netcdf/satDegUppSurface_dailyTot_output.nc",
"HTTPSERVER": "http://localhost:8080/thredds/fileServer/ewc/work01/output/netcdf/satDegUppSurface_dailyTot_output.nc",
"NETCDFSUBSET": "http://localhost:8080/thredds/ncss/ewc/work01/output/netcdf/satDegUppSurface_dailyTot_output.nc",
"OPENDAP": "http://localhost:8080/thredds/dodsC/ewc/work01/output/netcdf/satDegUppSurface_dailyTot_output.nc",
"WCS": "http://localhost:8080/thredds/wcs/ewc/work01/output/netcdf/satDegUppSurface_dailyTot_output.nc",
"WMS": "http://localhost:8080/thredds/wms/ewc/work01/output/netcdf/satDegUppSurface_dailyTot_output.nc"
"OPENDAP": "http://localhost:8080/thredds/dodsC/ewc/data/work01/output/netcdf/satDegUppSurface_dailyTot_output.nc",
"DAP4": "http://localhost:8080/thredds/dap4/ewc/data/work01/output/netcdf/satDegUppSurface_dailyTot_output.nc",
"HTTPSERVER": "http://localhost:8080/thredds/fileServer/ewc/data/work01/output/netcdf/satDegUppSurface_dailyTot_output.nc",
"WCS": "http://localhost:8080/thredds/wcs/ewc/data/work01/output/netcdf/satDegUppSurface_dailyTot_output.nc",
"WMS": "http://localhost:8080/thredds/wms/ewc/data/work01/output/netcdf/satDegUppSurface_dailyTot_output.nc",
"NETCDFSUBSET": "http://localhost:8080/thredds/ncss/ewc/data/work01/output/netcdf/satDegUppSurface_dailyTot_output.nc"
}
},
{
"id": "ewc/work01/output/netcdf/totalEvaporation_dailyTot_output.nc",
"name": "ewc/work01/output/netcdf/totalEvaporation_dailyTot_output.nc",
"name": "ewc/data/work01/output/netcdf/totalEvaporation_dailyTot_output.nc",
"id": "ewc/data/work01/output/netcdf/totalEvaporation_dailyTot_output.nc",
"services": {
"DAP4": "http://localhost:8080/thredds/dap4/ewc/work01/output/netcdf/totalEvaporation_dailyTot_output.nc",
"HTTPSERVER": "http://localhost:8080/thredds/fileServer/ewc/work01/output/netcdf/totalEvaporation_dailyTot_output.nc",
"NETCDFSUBSET": "http://localhost:8080/thredds/ncss/ewc/work01/output/netcdf/totalEvaporation_dailyTot_output.nc",
"OPENDAP": "http://localhost:8080/thredds/dodsC/ewc/work01/output/netcdf/totalEvaporation_dailyTot_output.nc",
"WCS": "http://localhost:8080/thredds/wcs/ewc/work01/output/netcdf/totalEvaporation_dailyTot_output.nc",
"WMS": "http://localhost:8080/thredds/wms/ewc/work01/output/netcdf/totalEvaporation_dailyTot_output.nc"
"OPENDAP": "http://localhost:8080/thredds/dodsC/ewc/data/work01/output/netcdf/totalEvaporation_dailyTot_output.nc",
"DAP4": "http://localhost:8080/thredds/dap4/ewc/data/work01/output/netcdf/totalEvaporation_dailyTot_output.nc",
"HTTPSERVER": "http://localhost:8080/thredds/fileServer/ewc/data/work01/output/netcdf/totalEvaporation_dailyTot_output.nc",
"WCS": "http://localhost:8080/thredds/wcs/ewc/data/work01/output/netcdf/totalEvaporation_dailyTot_output.nc",
"WMS": "http://localhost:8080/thredds/wms/ewc/data/work01/output/netcdf/totalEvaporation_dailyTot_output.nc",
"NETCDFSUBSET": "http://localhost:8080/thredds/ncss/ewc/data/work01/output/netcdf/totalEvaporation_dailyTot_output.nc"
}
}
]
]
Loading