Skip to content

Commit

Permalink
Merge pull request #16 from TechnologyBrewery/6-create-behave-plugin
Browse files Browse the repository at this point in the history
6 - Create behave plugin goal
  • Loading branch information
meliz19 authored Jan 23, 2025
2 parents f43d7cb + b51ab5f commit 9f8ecc5
Show file tree
Hide file tree
Showing 23 changed files with 233 additions and 1,788 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,18 @@ jobs:
- name: Lint and typecheck
run: |
pants lint ::
- name: Test
- name: PyTests (for uv-sync and uv-build plugins)
run: |
pants test ::
- name: uv sync
run: |
pants uv-sync ::
- name: Package
- name: Build
run: |
pants uv-build ::
- name: Behave Tests
run: |
pants uv-run-behave
- name: Publish
if: github.ref == 'refs/heads/dev'
run: |
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Pants workspace files
/.pants.d
/dist/
**/dist/
__pycache__/
.venv/
.DS_Store
Expand Down
12 changes: 10 additions & 2 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
python_sources()

python_requirements(source="pyproject.toml")
pants_requirements(name="pants", resolve="pants-uv-lifecycle-plugin")

# Generates File target for each file in the sources field - useful if you want to treat all targets uniformly
Expand All @@ -9,3 +8,12 @@ files(
description="Files target representing all pyproject.toml files",
tags=["pyproject-toml-files"],
)

# Generates File target for each file in the sources field - useful if you want to treat all targets uniformly
files(
name="feature_files",
sources=["**/*.feature"],
description="Files target representing all behave *.feature files",
tags=["feature-files"],
)

13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This repository contains plugins to integrate the following `uv` commands into P
To run a plugin, run `pants <name-of-goal>`.

## Run Tests
To run the tests within this repo, from the project root, run `pants test ::`.
To run the tests within this repo, from the project root, run `pants uv-run-behave`.

## Publish Plugin
Currently this is done by running `pants uv-build` and `uv publish --publish-url https://test.pypi.org/legacy/` within the CI build.
Expand All @@ -24,5 +24,12 @@ backend_packages = ["pants_uv_lifecycle_plugin"]
plugins = ["pants-uv-lifecycle-plugin==<version>"]
```
## Current Available Plugins
- `uv-sync`: Runs `uv sync` across all modules containing a `pyproject.toml` file within a pants project.
- `uv-build`: Runs `uv build` across all modules containing a `pyproject.toml` file within a pants project.
- `uv-sync`: Runs `uv sync` across all modules containing a `pyproject.toml` file within a Pants project.
- `uv-build`: Runs `uv build` across all modules containing a `pyproject.toml` file within a Pants project.
- `uv-run-behave`: Runs `uv run behave` across all modules containing `"**/*.feature"` files within a `**/tests/features"` directory within a Pants project. (Note: anytime you run `uv run`, it will create the virtual environment if it doesn't already exist and update the module's `uv.lock` file.)

## Tests
To test the plugins within a sample project, run the following commands from the root project directory.
```
pants uv-run-behave # the example-project contains a set of simple unit tests
```
1 change: 1 addition & 0 deletions example-project/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
40 changes: 40 additions & 0 deletions example-project/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# example-project
This is an example project used to test out the pants plugins.

## Set up
This project was generated by running `uv init example-project --lib` within the root project directory.

## Adding dependencies
The dependencies were added to the `pyproject.toml` file by running the following.
```
cd example-project
uv add behave numpy
```

## Run Sample Code
To run the sample code,
```
cd example-project
uv run python src/example_project/generate_array.py
```

## Run Tests

## Behave Test
To run the behave unit tests,
```
cd example-project
uv run behave tests/features
```

## PyTest Test
To run the PyTest tests,
```
cd example-project
uv run pytest pytests
```

## Monorepo Level Build Lifecyle
Often times, when we are working in a monorepo, we want to be able to run commands within a module, but also at the root project level. In this README, we treat `example-project` as a module within the `pants-uv-lifecycle-plugin` monorepo. In the above sections, we give the `uv` commands to run within this module. We can run these same commands* across the entire monorepo at the root project level. To do so, checkout the [Current Available Plugins](../README.md#current-available-plugins) the root [README](../README.md).

* Note: We cannot run the `uv run pytest` command currently from the root project level.
18 changes: 18 additions & 0 deletions example-project/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[project]
name = "example-project"
version = "0.1.0"
description = "A simple project to illustrate the `pants-uv-lifecycle-plugin` plugins"
readme = "README.md"
authors = [
{ name = "Margaret Black", email = "black_margaret@bah.com" }
]
requires-python = ">=3.9"
dependencies = [
"behave>=1.2.6",
"numpy>=2.0.2",
"pytest>=8.3.4",
]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
File renamed without changes.
7 changes: 7 additions & 0 deletions example-project/pytests/test_generate_array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import numpy as np
from src.example_project.generate_array import generate_array

def test_generate_array():
numpy_array = generate_array()
numpy_array_type = type(numpy_array)
assert isinstance(numpy_array, np.ndarray), f'The numpy_array is of type {numpy_array_type}, but it was expected to be of type numpy.ndarray.'
Empty file.
7 changes: 7 additions & 0 deletions example-project/src/example_project/generate_array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import numpy as np

def generate_array():
return np.arange(10)

if __name__ == '__main__':
print('numpy array: ', generate_array())
5 changes: 5 additions & 0 deletions example-project/tests/features/generate_array.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Feature: Simple test to verify we can generate a numpy array

Scenario: Generate a numpy array
When the generate numpy array functionality is executed
Then a numpy array is generated
12 changes: 12 additions & 0 deletions example-project/tests/features/steps/generate_array_step.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from behave import when, then
import numpy as np
from src.example_project.generate_array import generate_array

@when("the generate numpy array functionality is executed")
def step_impl(context):
context.numpy_array = generate_array()

@then("a numpy array is generated")
def step_impl(context):
numpy_array_type = type(context.numpy_array)
assert isinstance(context.numpy_array, np.ndarray), f'The context.numpy_array is of type {numpy_array_type}, but it was expected to be of type numpy.ndarray.'
Loading

0 comments on commit 9f8ecc5

Please sign in to comment.