Skip to content

Commit dacd0bd

Browse files
authored
Maintenance Updates (#289)
* Remove old FF1 tests Old FastF1 auto-test failures #287 * Add `vcr` to jolpica to limit repeat hits - `vcr` in testing #286 * Reticulate changes #288 * FF1 deprecation change session.laps.pick_lap --> session.laps.pick_laps * Style & Document code * Removed `setup_fastf1` because `reticulate::py_require()` handles python * Updated docs (and vignettes) to reflect removal of `setup_fastf1()` * Update test-hard to handle vcr requirement * Fixing issues raised by test failiures * Fixed malformed GH Actions file * Fix to magic python string in repl_python() * Understanding automated python environment deploytment better. * Trying to ensure ggplot absence is tested ok * Style & Document code
1 parent 03d63a4 commit dacd0bd

51 files changed

Lines changed: 1281 additions & 415 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/check-standard.yaml

Lines changed: 10 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,6 @@ jobs:
5555
extra-packages: any::rcmdcheck
5656
needs: check
5757

58-
- name: setup r-reticulate venv
59-
shell: Rscript {0}
60-
run: |
61-
python_packages <- c("numpy", "fastf1")
62-
63-
library(reticulate)
64-
virtualenv_create("r-reticulate", Sys.which("python"))
65-
virtualenv_install("r-reticulate", python_packages)
66-
67-
path_to_python <- virtualenv_python("r-reticulate")
68-
writeLines(sprintf("RETICULATE_PYTHON=%s", path_to_python),
69-
Sys.getenv("GITHUB_ENV"))
70-
7158
- uses: r-lib/actions/check-r-package@v2
7259
with:
7360
upload-snapshots: true
@@ -107,58 +94,6 @@ jobs:
10794
with:
10895
upload-snapshots: true
10996

110-
R-CMD-check-old-ff1:
111-
runs-on: ${{ matrix.config.os }}
112-
113-
name: ${{ matrix.config.os }} (${{ matrix.config.r }}) old fastf1
114-
115-
strategy:
116-
fail-fast: false
117-
matrix:
118-
config:
119-
- {os: ubuntu-latest, r: 'release'}
120-
121-
env:
122-
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
123-
R_KEEP_PKG_SOURCE: yes
124-
125-
steps:
126-
- uses: actions/checkout@v3
127-
128-
- uses: r-lib/actions/setup-pandoc@v2
129-
130-
- uses: r-lib/actions/setup-r@v2
131-
with:
132-
r-version: ${{ matrix.config.r }}
133-
http-user-agent: ${{ matrix.config.http-user-agent }}
134-
use-public-rspm: true
135-
136-
- uses: actions/setup-python@v4
137-
with:
138-
python-version: "3.x"
139-
140-
- uses: r-lib/actions/setup-r-dependencies@v2
141-
with:
142-
extra-packages: any::rcmdcheck
143-
needs: check
144-
145-
- name: setup r-reticulate venv
146-
shell: Rscript {0}
147-
run: |
148-
python_packages <- c("urllib3", "fastf1==3.3.9")
149-
150-
library(reticulate)
151-
virtualenv_create("r-reticulate", Sys.which("python"))
152-
virtualenv_install("r-reticulate", python_packages)
153-
154-
path_to_python <- virtualenv_python("r-reticulate")
155-
writeLines(sprintf("RETICULATE_PYTHON=%s", path_to_python),
156-
Sys.getenv("GITHUB_ENV"))
157-
158-
- uses: r-lib/actions/check-r-package@v2
159-
with:
160-
upload-snapshots: true
161-
16297
R-CMD-check-hard:
16398
# NOTE: This workflow only directly installs "hard" dependencies, i.e. Depends,
16499
# Imports, and LinkingTo dependencies. Notably, Suggests dependencies are never
@@ -201,6 +136,7 @@ jobs:
201136
any::knitr
202137
any::rmarkdown
203138
any::markdown
139+
any::vcr
204140
needs: check
205141

206142
- uses: r-lib/actions/check-r-package@v2
@@ -245,19 +181,15 @@ jobs:
245181
- name: setup r-reticulate venv
246182
shell: Rscript {0}
247183
run: |
248-
python_packages <- c("numpy")
249-
250-
library(reticulate)
251-
virtualenv_create("r-reticulate", Sys.which("python"))
252-
virtualenv_install("r-reticulate", python_packages)
253-
#force dev version install with repl python from reticulate
254-
repl_python(quiet = TRUE)
255-
%pip install git+https://github.com/theOehrly/Fast-F1.git
256-
exit
257-
258-
path_to_python <- virtualenv_python("r-reticulate")
259-
writeLines(sprintf("RETICULATE_PYTHON=%s", path_to_python),
260-
Sys.getenv("GITHUB_ENV"))
184+
path_to_python <- reticulate::virtualenv_create(
185+
envname = "r-reticulate",
186+
python = Sys.which("python"),
187+
packages = c("numpy")
188+
)
189+
writeLines(sprintf("RETICULATE_PYTHON=%s", path_to_python),
190+
Sys.getenv("GITHUB_ENV"))
191+
reticulate::py_require('fastf1@git+https://github.com/theOehrly/Fast-F1.git')
192+
reticulate::py_available(TRUE)
261193
262194
- uses: r-lib/actions/check-r-package@v2
263195
with:

.github/workflows/test-coverage.yaml

Lines changed: 1 addition & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,6 @@ jobs:
3535
any::xml2
3636
needs: coverage
3737

38-
- name: setup r-reticulate venv
39-
shell: Rscript {0}
40-
run: |
41-
python_packages <- c("numpy", "fastf1")
42-
43-
library(reticulate)
44-
virtualenv_create("r-reticulate", Sys.which("python"))
45-
virtualenv_install("r-reticulate", python_packages)
46-
47-
path_to_python <- virtualenv_python("r-reticulate")
48-
writeLines(sprintf("RETICULATE_PYTHON=%s", path_to_python),
49-
Sys.getenv("GITHUB_ENV"))
50-
5138
- name: Test coverage
5239
run: |
5340
cov <- covr::package_coverage(
@@ -81,79 +68,6 @@ jobs:
8168
name: coverage-test-failures
8269
path: ${{ runner.temp }}/package
8370

84-
test-coverage-oldff1:
85-
name: Test coverage - old fastf1
86-
87-
runs-on: ubuntu-latest
88-
89-
env:
90-
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
91-
92-
steps:
93-
- uses: actions/checkout@v4
94-
95-
- uses: r-lib/actions/setup-r@v2
96-
with:
97-
use-public-rspm: true
98-
99-
- uses: actions/setup-python@v4
100-
with:
101-
python-version: "3.x"
102-
103-
- uses: r-lib/actions/setup-r-dependencies@v2
104-
with:
105-
extra-packages: |
106-
any::covr
107-
any::devtools
108-
any::xml2
109-
needs: coverage
110-
111-
- name: setup r-reticulate venv
112-
shell: Rscript {0}
113-
run: |
114-
python_packages <- c("urllib3", "fastf1==3.3.9")
115-
116-
library(reticulate)
117-
virtualenv_create("r-reticulate", Sys.which("python"))
118-
virtualenv_install("r-reticulate", python_packages)
119-
120-
path_to_python <- virtualenv_python("r-reticulate")
121-
writeLines(sprintf("RETICULATE_PYTHON=%s", path_to_python),
122-
Sys.getenv("GITHUB_ENV"))
123-
124-
- name: Test coverage
125-
run: |
126-
cov <- covr::package_coverage(
127-
quiet = FALSE,
128-
clean = FALSE,
129-
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
130-
)
131-
covr::to_cobertura(cov)
132-
shell: Rscript {0}
133-
134-
- uses: codecov/codecov-action@v4
135-
with:
136-
# Fail if error if not on PR, or if on PR and token is given
137-
fail_ci_if_error: ${{ github.event_name != 'pull_request' || secrets.CODECOV_TOKEN }}
138-
file: ./cobertura.xml
139-
plugin: noop
140-
disable_search: true
141-
token: ${{ secrets.CODECOV_TOKEN }}
142-
143-
- name: Show testthat output
144-
if: always()
145-
run: |
146-
## --------------------------------------------------------------------
147-
find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true
148-
shell: bash
149-
150-
- name: Upload test results
151-
if: failure()
152-
uses: actions/upload-artifact@v4
153-
with:
154-
name: coverage-oldff1-test-failures
155-
path: ${{ runner.temp }}/package
156-
15771
test-coverage-hard:
15872
# NOTE: This workflow only directly installs "hard" dependencies, i.e. Depends,
15973
# Imports, and LinkingTo dependencies. Notably, Suggests dependencies are never
@@ -194,6 +108,7 @@ jobs:
194108
any::covr
195109
any::devtools
196110
any::xml2
111+
any::vcr
197112
needs: coverage
198113

199114
- name: Test coverage

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Roxygen: list(markdown = TRUE)
1919
RoxygenNote: 7.3.2
2020
Depends:
2121
R (>= 3.5.0),
22-
reticulate (>= 1.14),
22+
reticulate (>= 1.41)
2323
Imports:
2424
glue,
2525
magrittr,
@@ -42,6 +42,7 @@ Suggests:
4242
knitr,
4343
rmarkdown,
4444
testthat (>= 3.0.0),
45+
vcr
4546
VignetteBuilder: knitr
4647
URL: https://scasanova.github.io/f1dataR/, https://github.com/SCasanova/f1dataR
4748
BugReports: https://github.com/SCasanova/f1dataR/issues

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export(load_session_laps)
3636
export(load_sprint)
3737
export(load_standings)
3838
export(plot_fastest)
39-
export(setup_fastf1)
4039
export(theme_dark_f1)
4140
import(reticulate)
4241
importFrom(magrittr,"%>%")

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# f1dataR (development version)
22

3+
* Updated code to match new `reticulate` interface for package and environment management.
4+
* Updated tests to use `vcr` package to reduce hits on the Jolpica API
5+
* Removed support for FastF1 v < 3.0 (now causes errors instead of warnings).
6+
* Test suite and automated testing changes to reflect the above changes.
37
* Fixed a data conversion issue in `time_to_sec()` (#290)
48

59
# f1dataR 2.0.1

R/load_circuits.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ load_circuits <- function(season = get_current_season()) {
1111
cli::cli_abort('{.var season} must be between 1950 and {get_current_season()} (or use "current")')
1212
}
1313

14-
url <- glue::glue("{season}/circuits.json?limit=40",
14+
url <- glue::glue("{season}/circuits.json",
1515
season = season
1616
)
1717

R/load_constructors.R

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
#' @return A tibble with one row per constructor
99
load_constructors <- function() {
1010
lim <- 100
11-
url <- glue::glue("constructors.json?limit={lim}", lim = lim)
12-
data <- get_jolpica_content(url)
11+
url <- "constructors.json"
12+
parameters <- list(limit = lim)
13+
data <- get_jolpica_content(url, parameters)
1314

1415
if (is.null(data)) {
1516
return(NULL)
@@ -24,10 +25,8 @@ load_constructors <- function() {
2425
while (offset + lim <= total) {
2526
offset <- offset + lim
2627

27-
url <- glue::glue("constructors.json?limit={lim}&offset={offset}",
28-
lim = lim, offset = offset
29-
)
30-
data <- get_jolpica_content(url)
28+
parameters <- list(limit = lim, offset = offset)
29+
data <- get_jolpica_content(url, parameters)
3130

3231
if (is.null(data)) {
3332
return(NULL)

R/load_driver_telemetry.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ load_driver_telemetry <- function(season = get_current_season(), round = 1, sess
7272
driver = driver
7373
))
7474
} else if (laps != "all") {
75-
reticulate::py_run_string(glue::glue("tel = session.laps.pick_drivers('{driver}').pick_lap({laps}).get_telemetry().add_distance().add_driver_ahead()",
75+
reticulate::py_run_string(glue::glue("tel = session.laps.pick_drivers('{driver}').pick_laps({laps}).get_telemetry().add_distance().add_driver_ahead()",
7676
driver = driver, laps = laps
7777
))
7878
} else {

R/load_drivers.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ load_drivers <- function(season = get_current_season()) {
1414
cli::cli_abort('{.var season} must be between 1950 and {get_current_season()} (or use "current")')
1515
}
1616

17-
url <- glue::glue("{season}/drivers.json?limit=50",
17+
url <- glue::glue("{season}/drivers.json",
1818
season = season
1919
)
2020
data <- get_jolpica_content(url)

R/load_laps.R

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ load_laps <- function(season = get_current_season(), round = "last", race = life
2525
lim <- 100
2626

2727
# Function Code
28-
url <- glue::glue("{season}/{round}/laps.json?limit={lim}",
29-
season = season, round = round, lim = lim
28+
url <- glue::glue("{season}/{round}/laps.json",
29+
season = season, round = round
3030
)
31-
data <- get_jolpica_content(url)
31+
data <- get_jolpica_content(url, parameters = list("limit" = lim))
3232

3333
if (is.null(data)) {
3434
return(NULL)
@@ -43,10 +43,7 @@ load_laps <- function(season = get_current_season(), round = "last", race = life
4343
while (offset + lim <= total) {
4444
offset <- offset + lim
4545

46-
url <- glue::glue("{season}/{round}/laps.json?limit={lim}&offset={offset}",
47-
lim = lim, season = season, round = round, offset = offset
48-
)
49-
data <- get_jolpica_content(url)
46+
data <- get_jolpica_content(url, parameters = list(limit = lim, offset = offset))
5047

5148
if (is.null(data)) {
5249
return(NULL)

0 commit comments

Comments
 (0)