Skip to content

Commit

Permalink
Merge pull request #4 from DigitalGeographyLab/3-gh-actions
Browse files Browse the repository at this point in the history
GH action workflows
  • Loading branch information
christophfink authored Jan 8, 2024
2 parents c6d4790 + 69c9e23 commit a3500d4
Show file tree
Hide file tree
Showing 16 changed files with 289 additions and 242 deletions.
29 changes: 29 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1.

**Expected behavior**
A clear and concise description of what you expected to happen.

**Environment:**
- OS:
- Python package source (PyPi, conda, ...)
- Versions of Python, Java Development Kit, Python modules

**Additional context**
Add any other context about the problem here.

**Test data and/or script/notebook**
If you have a reproducible example case, including test data or a snippet of code, please attach them to this issue.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
33 changes: 33 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# vim: set tabstop=2 softtabstop=2 shiftwidth=2 expandtab:

name: Build main branch

on:
pull_request:
branches: [main]
types: [closed]
push:
branches: [main]
workflow_call:

jobs:
build:
name: Build wheel(s) and packages
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
cache: "pip"
- name: Install build tools
run: python -m pip install build
- name: Build wheel(s) and packages
run: python -m build .
- name: Upload built packages
uses: actions/upload-artifact@v3
with:
name: package
path: dist/*.*
19 changes: 19 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# vim: set tabstop=2 softtabstop=2 shiftwidth=2 expandtab:

name: Lint code of pull requests
on:
pull_request:

jobs:
lint:
name: Linting code
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.11"
cache: "pip"
- run: pip install black flake8
- run: python -m black --check .
- run: python -m flake8 .
86 changes: 86 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# vim: set tabstop=2 softtabstop=2 shiftwidth=2 expandtab:

name: Create a release and deploy to PyPi whenever a protected tag (v0.0.0) is created

on:
push:
tags:
- v*.*.*

jobs:
build:
name: Build package
uses: ./.github/workflows/build.yml
secrets: inherit

merge-into-stable:
name: Update stable branch to point to this release
runs-on: ubuntu-latest
needs: [build]
if: "!contains(github.ref, 'dev')"
permissions: write-all
steps:
- name: Clone repository, check-out stable
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: stable
- name: Merge tag into stable
run: |
TAG="${{github.ref}}" # /ref/tags/v0.0.0
git merge "${TAG:10}"
git push
deploy:
name: Upload built package to PyPi
runs-on: ubuntu-latest
needs: [build]
steps:
- name: Download built artifacts
uses: actions/download-artifact@v3
with:
name: package
path: dist/
- name: Upload package to PyPi
uses: pypa/gh-action-pypi-publish@release/v1.5
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
skip_existing: true

release:
name: Create a new release
runs-on: ubuntu-latest
needs: [deploy]
if: "!contains(github.ref, 'dev')"
permissions:
contents: write
steps:
- name: Download built artifacts
uses: actions/download-artifact@v3
with:
name: package
path: dist/
- name: Create release and upload package
uses: softprops/action-gh-release@v1
with:
files: dist/*

prerelease:
name: Create a new pre-release
runs-on: ubuntu-latest
needs: [deploy]
if: contains(github.ref, 'dev')
permissions:
contents: write
steps:
- name: Download built artifacts
uses: actions/download-artifact@v3
with:
name: package
path: dist/
- name: Create release and upload package
uses: softprops/action-gh-release@v1
with:
files: dist/*
prerelease: true
72 changes: 30 additions & 42 deletions flickrhistory/basicflickrhistorydownloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,15 @@ def download(self):
# start downloaders
for _ in range(self.NUM_WORKERS):
worker = PhotoDownloaderThread(
self._api_key_manager,
self._todo_deque,
self._done_queue
self._api_key_manager, self._todo_deque, self._done_queue
)
worker.start()
self._worker_threads.append(worker)

# start user profile updaters
for i in range(self.NUM_WORKERS):
worker = UserProfileUpdaterThread(
self._api_key_manager,
(i + 1, self.NUM_WORKERS)
self._api_key_manager, (i + 1, self.NUM_WORKERS)
)
worker.start()
self._worker_threads.append(worker)
Expand All @@ -100,10 +97,7 @@ def download(self):
self.report_progress()
time.sleep(self.STATUS_UPDATE_SEC)

except (
KeyboardInterrupt,
SigTermReceivedException
):
except (KeyboardInterrupt, SigTermReceivedException):
self.announce_shutdown()
for worker in self._worker_threads:
worker.shutdown.set()
Expand All @@ -128,11 +122,11 @@ def report_progress(self):
photos=photo_count,
profiles=profile_count,
workers=(threading.active_count() - self.NUM_MANAGERS),
todo=len(self._todo_deque)
todo=len(self._todo_deque),
),
file=sys.stderr,
end=self.STATUS_UPDATE_LINE_END,
flush=True
flush=True,
)

def announce_shutdown(self):
Expand All @@ -141,7 +135,7 @@ def announce_shutdown(self):
"Cleaning up" + (" " * 69), # 80 - len("Cleaning up")
file=sys.stderr,
end=self.STATUS_UPDATE_LINE_END,
flush=True
flush=True,
)

def summarise_overall_progress(self):
Expand All @@ -152,14 +146,10 @@ def summarise_overall_progress(self):
"""
photo_count, _, profile_count, _ = self._statistics
print(
(
"Downloaded {photos:d} photos "
+ "and {profiles:d} user profiles"
).format(
photos=photo_count,
profiles=profile_count
("Downloaded {photos:d} photos " + "and {profiles:d} user profiles").format(
photos=photo_count, profiles=profile_count
),
file=sys.stderr
file=sys.stderr,
)

@property
Expand All @@ -169,10 +159,7 @@ def gaps_in_download_history(self):
one_day = datetime.timedelta(days=1) # for comparison

for i in range(len(already_downloaded) - 1):
gap = TimeSpan(
already_downloaded[i].end,
already_downloaded[i + 1].start
)
gap = TimeSpan(already_downloaded[i].end, already_downloaded[i + 1].start)
if gap.duration > one_day:
divider = math.ceil(gap.duration / one_day)
for part_of_gap in gap / divider:
Expand All @@ -191,7 +178,8 @@ def already_downloaded_timespans(self):

# delete existing 0-length time spans
timespans = [
timespan for timespan in timespans
timespan
for timespan in timespans
if timespan.duration > datetime.timedelta(0)
]

Expand All @@ -206,34 +194,34 @@ def already_downloaded_timespans(self):
# on top of that, some small timestamps seems to be simply 0 +- timezone offset
# which invalidates pretty much the entire first day after epoch 0
# this is why we use epoch 0 + 1 day
zero = (
datetime.datetime.fromtimestamp(0, tz=datetime.timezone.utc)
+ datetime.timedelta(days=1)
)
zero = datetime.datetime.fromtimestamp(
0, tz=datetime.timezone.utc
) + datetime.timedelta(days=1)
now = datetime.datetime.now(datetime.timezone.utc)
timespans += [
TimeSpan(zero, zero),
TimeSpan(now, now)
]
timespans += [TimeSpan(zero, zero), TimeSpan(now, now)]

return sum(timespans) # sum resolves overlaps

@property
def _statistics(self):
runtime = float((datetime.datetime.now() - self.started).total_seconds())

photo_count = sum([
worker.count
for worker in self._worker_threads
if isinstance(worker, PhotoDownloaderThread)
])
photo_count = sum(
[
worker.count
for worker in self._worker_threads
if isinstance(worker, PhotoDownloaderThread)
]
)
photo_rate = photo_count / runtime

profile_count = sum([
worker.count
for worker in self._worker_threads
if isinstance(worker, UserProfileUpdaterThread)
])
profile_count = sum(
[
worker.count
for worker in self._worker_threads
if isinstance(worker, UserProfileUpdaterThread)
]
)
profile_rate = profile_count / runtime

return (photo_count, photo_rate, profile_count, profile_rate)
Loading

0 comments on commit a3500d4

Please sign in to comment.