Skip to content

Commit

Permalink
Front matter for new tutorial pages. (pantsbuild#18074)
Browse files Browse the repository at this point in the history
To link them to newly-created blank pages.
  • Loading branch information
benjyw authored Jan 23, 2023
1 parent 21ac257 commit f9cc36a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
---
title: "Advanced plugin concepts"
slug: "advanced plugin concepts"
excerpt: "Advanced concepts"
hidden: true
createdAt: "2022-02-07T05:44:28.620Z"
updatedAt: "2022-02-07T05:44:28.620Z"
---
# Introduction

In this tutorial, we continue from where we've left in the [previous tutorial](doc:create-a-new-goal). Having now a complete goal with a custom target, we are ready to make certain improvements and learn more advanced concepts that you would likely find useful when working on your own plugins.

## Adding a custom `source` field

In the first tutorial, to keep things simple, we've used the default `SingleSourceField` class for our `source` field where we provided path to the `VERSION` file. We could have added [a custom field](https://www.pantsbuild.org/docs/target-api-new-fields) to provide a file path, however, when using the `source` field, you get a few features for free such as setting the `default` value and `expected_file_extensions`. Furthermore, with the `source` field, thanks to the [`unmatched_build_file_globs`](https://www.pantsbuild.org/docs/reference-global#unmatched_build_file_globs) option, you won't need to provide custom logic to handle errors when path globs do not expand to any files in your repository.
In the first tutorial, to keep things simple, we used the default `SingleSourceField` class for our `source` field where we provided the path to the `VERSION` file. We could have added [a custom field](https://www.pantsbuild.org/docs/target-api-new-fields) to provide a file path, however, when using the `source` field, you get a few features for free such as setting the `default` value and `expected_file_extensions`. Furthermore, with the `source` field, thanks to the [`unmatched_build_file_globs`](https://www.pantsbuild.org/docs/reference-global#unmatched_build_file_globs) option, you won't need to provide custom logic to handle errors when path globs do not expand to any files in your repository.

Let's modify our `myapp/BUILD` file:

Expand Down Expand Up @@ -387,7 +395,7 @@ $ ./pants project-version --as-json myapp:
ProjectVersionGitTagMismatch: Project version string '0.0.3' from 'myapp/VERSION' doesn't match latest Git tag '0.0.1'
```

This happens because of how Pants cache works. Modifying our repository tags doesn't qualify for the changes that should invalidate the cache. It is not safe to [cache the `Process` runs](https://www.pantsbuild.org/docs/rules-api-process) since we know that Git will access the repository (that is outside the sandbox), we should change its cacheability using the `ProcessCacheScope` parameter so that our Git call would run once per run of Pants.
This happens because of how the Pants cache works. Modifying our repository tags doesn't qualify for the changes that should invalidate the cache. It is not safe to [cache the `Process` runs](https://www.pantsbuild.org/docs/rules-api-process) since we know that Git will access the repository (that is outside the sandbox), we should change its cacheability using the `ProcessCacheScope` parameter so that our Git call would run once per run of Pants.

```python
git_describe = await Get(
Expand Down Expand Up @@ -662,4 +670,4 @@ class ProjectVersionTarget(Target):
help = "A project version target representing the VERSION file."
```

There are a few more things left to do, for example, we haven't written any tests yet. This is what we'll do in the next tutorials!
There are a few more things left to do, for example, we haven't written any tests yet. This is what we'll do in the next tutorial!
8 changes: 8 additions & 0 deletions docs/markdown/Tutorials/test-custom-plugin-goal.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
---
title: "Testing plugins"
slug: "test-custom-plugin-goal"
excerpt: "How to write tests for your custom plugin code"
hidden: true
createdAt: "2022-02-07T05:44:28.620Z"
updatedAt: "2022-02-07T05:44:28.620Z"
---
# Introduction

In this tutorial, we'll learn how to test the custom plugin we wrote earlier. Pants documentation provides comprehensive coverage of the [plugin testing](doc:rules-api-testing) and this tutorial should help you get started writing own tests.
Expand Down

0 comments on commit f9cc36a

Please sign in to comment.