Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move from doit to just #160

Merged
merged 9 commits into from
Nov 4, 2021
Merged
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ jobs:
- name: Install distro packages
run: sudo apt-get install -qq pandoc graphviz

- name: Install doit
run: python -m pip install --upgrade pip doit
- name: Install `just`
uses: extractions/setup-just@v1

- name: Run `doit`
run: doit
- name: Run `just`
run: just

coverage:
runs-on: ubuntu-latest
Expand Down
11 changes: 6 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
The Python Launcher is _mostly_ run as a typical Rust project. The only
potential differences is the automation tool used (for convenience).

## Using doit for automation
## Using `just` for automation

We use [doit](https://pydoit.org/) as an automation tool. It's
[available on PyPI](https://pypi.org/project/doit/) and may be available in your
preferred package manager (e.g. `apt`).
We use [just](https://github.com/casey/just) as an automation tool. It is similar to [make](https://www.gnu.org/software/make/)
but with a few nice features and fewer quirks.

It is available from a variety of package managers and other sources, see the [install](https://github.com/casey/just#installation) docs
for how to get it for your system.

## Changelog

Expand All @@ -20,7 +22,6 @@ The tool used to maintain the changelog is
[`changelog.d` directory](https://github.com/brettcannon/python-launcher/tree/main/changelog.d)
for details.


## Releasing

1. Adjust the version number in [`Cargo.toml`](https://github.com/brettcannon/python-launcher/blob/main/Cargo.toml) (previous [releases](https://github.com/brettcannon/python-launcher/releases)).
Expand Down
41 changes: 41 additions & 0 deletions changelog.d/20211026_081619_tomfleet2018_use_just.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!--
A new scriv changelog fragment.

Uncomment the section that is right (remove the HTML comment wrapper).
-->

<!--
### Removed

- A bullet item for the Removed category.

-->
<!--
### Added

- A bullet item for the Added category.

-->

### Changed

- Replace doit with [just](https://github.com/casey/just) as a command runner.

<!--
### Deprecated

- A bullet item for the Deprecated category.

-->
<!--
### Fixed

- A bullet item for the Fixed category.

-->
<!--
### Security

- A bullet item for the Security category.

-->
79 changes: 79 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env just --justfile
# Written for https://github.com/casey/just/tree/0.10.2 .

ROOT := justfile_directory()
DOCS := join(ROOT, "docs")
MAN_DIR := join(DOCS, "man-page")
MAN_MD := join(MAN_DIR, "py.1.md")
MAN_FILE := join(MAN_DIR, "py.1")
CARGO_TOML := join(ROOT, "Cargo.toml")
DOT_DIR := join(DOCS, "control-flow")
DOT_FILE := join(DOT_DIR, "control_flow.dot")
DOT_FILE_NO_STEM := without_extension(DOT_FILE)
DOT_SVG := DOT_FILE_NO_STEM + ".svg"
DOT_PNG := DOT_FILE_NO_STEM + ".png"

# TODO: `just` release after 0.10.2 will make `join` accept variadic parameters;
# would clean up the variables quite a bit.

# Set default recipes
_default: lint test man dot

# Run the unit tests
test:
cargo --quiet test

# Run linting on source files
lint:
cargo fmt --quiet --all -- --check
cargo clippy --quiet --all-targets --all-features -- -D warnings

# Install from source
install:
cargo install --quiet --path .

# Convert the markdown man to man file format (hidden)
FollowTheProcess marked this conversation as resolved.
Show resolved Hide resolved
_man-md:
pandoc {{ MAN_MD }} --standalone -t man -o {{ MAN_FILE }}

# Build the man page
man: _man-md
#!/usr/bin/env python3

import datetime
import pathlib
import re

FollowTheProcess marked this conversation as resolved.
Show resolved Hide resolved
VERSION_REGEX = re.compile(r'version\s*=\s*"(?P<version>[\d.]+)"')

with open("{{ CARGO_TOML }}", "r", encoding="utf-8") as file:
cargo_lines = file.readlines()

for line in cargo_lines:
if version_match := VERSION_REGEX.match(line):
version = version_match.group("version")
break
else:
raise ValueError("'version' not found in {{ CARGO_TOML }}")

with open("{{ MAN_FILE }}", "r", encoding="utf-8") as file:
man_text = file.read()

man_text_with_version = man_text.replace("LAUNCHER_VERSION", version)
new_man_text = man_text_with_version.replace(
"CURRENT_DATE", datetime.date.today().isoformat()
)

with open("{{ MAN_FILE }}", "w", encoding="utf-8") as file:
file.write(new_man_text)

# Build the control flow diagram as an SVG
FollowTheProcess marked this conversation as resolved.
Show resolved Hide resolved
dot_svg:
dot -T "svg" -o {{ DOT_SVG }} {{ DOT_FILE }}

# Build the control flow diagram as a PNG
dot_png:
dot -T "png" -o {{ DOT_PNG }} {{ DOT_FILE }}

# Build the control flow diagram
dot: dot_svg dot_png