Skip to content

Commit 9f9b54d

Browse files
Bump python version and fix workflows (#8)
* Update python version for repo and migrate to pyproject.toml * Fix lint * Update pypi.py to compare dates properly * pass arguments to rsplit * Update append with concat * Fix lint * Make dialy workflow available on dispatch * Use python 3.13 or above * Add tasks.py to lint
1 parent c4416ce commit 9f9b54d

File tree

17 files changed

+241
-430
lines changed

17 files changed

+241
-430
lines changed

.github/workflows/daily.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
name: Daily Collection
22

33
on:
4+
workflow_dispatch:
45
schedule:
56
- cron: '0 0 * * *'
67

78
jobs:
89
collect:
910
runs-on: ubuntu-latest
1011
steps:
11-
- uses: actions/checkout@v1
12+
- uses: actions/checkout@v4
1213
- name: Set up Python ${{ matrix.python-version }}
13-
uses: actions/setup-python@v1
14+
uses: actions/setup-python@v5
1415
with:
15-
python-version: 3.8
16+
python-version: '3.13'
1617
- name: Install dependencies
1718
run: |
1819
python -m pip install --upgrade pip

.github/workflows/dryrun.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ jobs:
99
collect:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v1
12+
- uses: actions/checkout@v4
1313
- name: Set up Python ${{ matrix.python-version }}
14-
uses: actions/setup-python@v1
14+
uses: actions/setup-python@v5
1515
with:
16-
python-version: 3.8
16+
python-version: '3.13'
1717
- name: Install dependencies
1818
run: |
1919
python -m pip install --upgrade pip

.github/workflows/lint.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Style Checks
2+
3+
on:
4+
push:
5+
pull_request:
6+
types: [opened, reopened]
7+
8+
jobs:
9+
lint:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- name: Set up Python 3.13
14+
uses: actions/setup-python@v5
15+
with:
16+
python-version: '3.13'
17+
- name: Install dependencies
18+
run: |
19+
python -m pip install --upgrade pip
20+
python -m pip install invoke .[dev]
21+
- name: Run lint checks
22+
run: invoke lint
23+

.github/workflows/manual.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ jobs:
2424
collect:
2525
runs-on: ubuntu-latest
2626
steps:
27-
- uses: actions/checkout@v1
27+
- uses: actions/checkout@v4
2828
- name: Set up Python ${{ matrix.python-version }}
29-
uses: actions/setup-python@v1
29+
uses: actions/setup-python@v5
3030
with:
31-
python-version: 3.8
31+
python-version: '3.13'
3232
- name: Install dependencies
3333
run: |
3434
python -m pip install --upgrade pip

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,15 @@ install: clean-build clean-pyc ## install the package to the active Python's sit
5959

6060
.PHONY: install-develop
6161
install-develop: clean-build clean-pyc ## install the package in editable mode and dependencies for development
62-
pip install -r dev-requirements.txt -e .
62+
pip install -e .[dev]
6363

6464

6565
# LINT TARGETS
6666

6767
.PHONY: lint
6868
lint: ## check style with flake8 and isort
6969
invoke lint
70+
71+
.PHONY: fix-lint
72+
fix-lint:
73+
invoke fix-lint

dev-requirements.txt

Lines changed: 0 additions & 26 deletions
This file was deleted.

download_analytics/__main__.py

Lines changed: 60 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,21 @@ def _valid_date(arg):
7171
def _get_parser():
7272
# Logging
7373
logging_args = argparse.ArgumentParser(add_help=False)
74-
logging_args.add_argument('-v', '--verbose', action='count', default=0,
75-
help='Be verbose. Use `-vv` for increased verbosity.')
76-
logging_args.add_argument('-l', '--logfile',
77-
help='If given, file where the logs will be written.')
74+
logging_args.add_argument(
75+
'-v',
76+
'--verbose',
77+
action='count',
78+
default=0,
79+
help='Be verbose. Use `-vv` for increased verbosity.',
80+
)
81+
logging_args.add_argument(
82+
'-l', '--logfile', help='If given, file where the logs will be written.'
83+
)
7884

7985
parser = argparse.ArgumentParser(
8086
prog='download-analytics',
8187
description='Download Analytics Command Line Interface',
82-
parents=[logging_args]
88+
parents=[logging_args],
8389
)
8490
parser.set_defaults(action=None)
8591
action = parser.add_subparsers(title='action')
@@ -90,36 +96,67 @@ def _get_parser():
9096
collect.set_defaults(action=_collect)
9197

9298
collect.add_argument(
93-
'-o', '--output-folder', type=str, required=False,
99+
'-o',
100+
'--output-folder',
101+
type=str,
102+
required=False,
94103
help=(
95104
'Path to the folder where data will be stored. It can be a local path or a'
96105
' Google Drive folder path in the format gdrive://<folder-id>'
97-
)
106+
),
98107
)
99108
collect.add_argument(
100-
'-a', '--authentication-credentials', type=str, required=False,
101-
help='Path to the GCP (BigQuery) credentials file to use.')
109+
'-a',
110+
'--authentication-credentials',
111+
type=str,
112+
required=False,
113+
help='Path to the GCP (BigQuery) credentials file to use.',
114+
)
102115
collect.add_argument(
103-
'-c', '--config-file', type=str, default='config.yaml',
104-
help='Path to the configuration file.')
116+
'-c',
117+
'--config-file',
118+
type=str,
119+
default='config.yaml',
120+
help='Path to the configuration file.',
121+
)
105122
collect.add_argument(
106-
'-p', '--projects', nargs='*',
107-
help='List of projects to collect. If not given use the configured ones.')
123+
'-p',
124+
'--projects',
125+
nargs='*',
126+
help='List of projects to collect. If not given use the configured ones.',
127+
)
108128
collect.add_argument(
109-
'-s', '--start-date', type=_valid_date, required=False,
110-
help='Date from which to start pulling data.')
129+
'-s',
130+
'--start-date',
131+
type=_valid_date,
132+
required=False,
133+
help='Date from which to start pulling data.',
134+
)
111135
collect.add_argument(
112-
'-m', '--max-days', type=int, required=False,
113-
help='Max days of data to pull if start-date is not given.')
136+
'-m',
137+
'--max-days',
138+
type=int,
139+
required=False,
140+
help='Max days of data to pull if start-date is not given.',
141+
)
114142
collect.add_argument(
115-
'-d', '--dry-run', action='store_true',
116-
help='Do not run the actual query, only simulate it.')
143+
'-d',
144+
'--dry-run',
145+
action='store_true',
146+
help='Do not run the actual query, only simulate it.',
147+
)
117148
collect.add_argument(
118-
'-f', '--force', action='store_true',
119-
help='Force the download even if the data already exists or there is a gap')
149+
'-f',
150+
'--force',
151+
action='store_true',
152+
help='Force the download even if the data already exists or there is a gap',
153+
)
120154
collect.add_argument(
121-
'-M', '--add-metrics', action='store_true',
122-
help='Compute the aggregation metrics and create the corresponding spreadsheets.')
155+
'-M',
156+
'--add-metrics',
157+
action='store_true',
158+
help='Compute the aggregation metrics and create the corresponding spreadsheets.',
159+
)
123160

124161
return parser
125162

download_analytics/bq.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ def _get_bq_client(credentials_file):
3030
scopes=['https://www.googleapis.com/auth/cloud-platform'],
3131
)
3232

33-
return bigquery.Client(credentials=credentials, project=credentials.project_id,)
33+
return bigquery.Client(
34+
credentials=credentials,
35+
project=credentials.project_id,
36+
)
3437

3538

3639
def run_query(query, dry_run=False, credentials_file=None):
@@ -41,14 +44,14 @@ def run_query(query, dry_run=False, credentials_file=None):
4144

4245
job_config = bigquery.QueryJobConfig(dry_run=True, use_query_cache=False)
4346
dry_run_job = client.query(query, job_config=job_config)
44-
LOGGER.info('Estimated processed GBs: %.2f', dry_run_job.total_bytes_processed / 1024 ** 3)
47+
LOGGER.info('Estimated processed GBs: %.2f', dry_run_job.total_bytes_processed / 1024**3)
4548

4649
if dry_run:
4750
return None
4851

4952
query_job = client.query(query)
5053
data = query_job.to_dataframe()
51-
LOGGER.info('Total processed GBs: %.2f', query_job.total_bytes_processed / 1024 ** 3)
52-
LOGGER.info('Total billed GBs: %.2f', query_job.total_bytes_billed / 1024 ** 3)
54+
LOGGER.info('Total processed GBs: %.2f', query_job.total_bytes_processed / 1024**3)
55+
LOGGER.info('Total billed GBs: %.2f', query_job.total_bytes_billed / 1024**3)
5356

5457
return data

download_analytics/drive.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,7 @@ def upload(content, filename, folder, convert=False):
9191
except FileNotFoundError:
9292
file_config = {
9393
'title': filename,
94-
'parents': [
95-
{
96-
'id': folder
97-
}
98-
],
94+
'parents': [{'id': folder}],
9995
}
10096
drive_file = drive.CreateFile(file_config)
10197

download_analytics/main.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,16 @@
99
LOGGER = logging.getLogger(__name__)
1010

1111

12-
def collect_downloads(projects, output_folder, start_date=None, max_days=1, credentials_file=None,
13-
dry_run=False, force=False, add_metrics=True):
12+
def collect_downloads(
13+
projects,
14+
output_folder,
15+
start_date=None,
16+
max_days=1,
17+
credentials_file=None,
18+
dry_run=False,
19+
force=False,
20+
add_metrics=True,
21+
):
1422
"""Pull data about the downloads of a list of projects.
1523
1624
Args:
@@ -49,7 +57,7 @@ def collect_downloads(projects, output_folder, start_date=None, max_days=1, cred
4957
max_days=max_days,
5058
credentials_file=credentials_file,
5159
dry_run=dry_run,
52-
force=force
60+
force=force,
5361
)
5462

5563
if pypi_downloads.empty:

0 commit comments

Comments
 (0)