Skip to content

Commit

Permalink
Let's try even more impure Python
Browse files Browse the repository at this point in the history
  • Loading branch information
zupo committed Oct 20, 2023
1 parent 30a2101 commit d23cc68
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 88 deletions.
37 changes: 31 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ concurrency:

jobs:

tests:
pure_tests:
name: Pure Tests
# strategy:
# matrix:
# python: ["python3.9", "python3.10", "python3.11"]

name: Tests

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -45,13 +44,39 @@ jobs:
- name: Run linters and unit tests the Nix way
run: nix flake check

- name: Run linters and unit tests the Python way
impure_tests:
name: Impure Tests

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install Poetry
uses: snok/install-poetry@v1


- name: Install Poetry environment
run: poetry install

- name: Install test dependencies
run: sudo apt-get -y install nmap

- name: Run linters and unit tests the Poetry way
run: |
nix develop --command make tests
# make lint -> pre-commit-config.yaml is managed by Nix,
# so path entries won't work in Poetry env
make types
make unit
make tesh
- uses: cachix/install-nix-action@v22

- name: Run 'make examples'
run: poetry run tesh examples/

release:
name: Release
needs: tests
needs: [pure_tests, impure_tests]

# To test publishing to testpypi:
# * comment out "verify git tag matches pyproject.toml version"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ __pycache__

# nix stuff
result
.pre-commit-config.yaml
65 changes: 0 additions & 65 deletions .pre-commit-config.orig.yaml

This file was deleted.

1 change: 0 additions & 1 deletion .pre-commit-config.yaml

This file was deleted.

3 changes: 3 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
rules:
line-length:
max: 88

ignore:
- .pre-commit-config.impure.yaml
17 changes: 10 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ PYTHON ?= python3.11

# Check if this a machine in nix, in which case "poetry run" prefix to commands
# is not necessary
PREFIX :=
$(shell nix store ping >/dev/null 2>&1; if [ $$? -eq 0 ]; then PREFIX="poetry run "; fi;)
PREFIX := $(shell nix store ping 2> /dev/null || echo "poetry run ")


.PHONY: all
Expand All @@ -20,7 +19,7 @@ lint:
# 3. get all untracked files
# 4. run pre-commit checks on them
ifeq ($(all),true)
@$(PREFIX)poetry run pre-commit run --all-files
@pre-commit run --all-files
else
@{ git diff --name-only ./; git diff --name-only --staged ./;git ls-files --other --exclude-standard; } \
| sort -u | uniq | xargs pre-commit run --hook-stage push --files
Expand Down Expand Up @@ -64,18 +63,22 @@ endif
.PHONY: unit
unit:
ifndef path
@pytest src/tesh $(verbosity) $(full_suite_args) $(pytest_args)
@$(PREFIX)pytest src/tesh $(verbosity) $(full_suite_args) $(pytest_args)
else
@pytest $(path)
@$(PREFIX)pytest $(path)
endif

.PHONY: tesh
tesh:
@tesh *.md
@$(PREFIX)tesh *.md

.PHONY: examples
examples:
@tesh examples/
ifeq ($(PREFIX),"poetry run ")
@echo "You need nix-shell to run 'make examples'"
else
@$(PREFIX)tesh examples/
endif

.PHONY: test
test: tests
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,13 @@ $ pip install tesh

## Developing `tesh`

We provide two development environments for people working on this project, one based on [Nix](https://nixos.org/) and one based on [Docker](https://www.docker.com/).
We provide two development environments for people working on this project, one based on [Nix](https://nixos.org/) and one based on [Poetry](https://www.docker.com/).

For Nix, run `nix develop` to enter the development environment.
For Docker, run `TODO` to enter the development environment.
For Nix, run `nix develop` to enter the development environment, where everything is ready for use.

For Poetry, run the following:
* `poetry install` to prepare the Python development environment
* `pre-commit install --config .pre-commit-config.impure.yaml`

Then you can run `make tests` to run all tests & checks.

Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
# Install the package in editable mode
# This allows executing `clan` from within the dev-shell using the current
# version of the code and its dependencies.
PYTHONPATH=${self'.packages.testEnv}/${self'.packages.testEnv.sitePackages} ${pkgs.python3Packages.pip}/bin/pip install \
PYTHONPATH=${pkgs.python3Packages.poetry-core}/${self'.packages.testEnv.sitePackages}:${self'.packages.testEnv}/${self'.packages.testEnv.sitePackages} ${pkgs.python3Packages.pip}/bin/pip install \
--no-deps \
--disable-pip-version-check \
--no-index \
Expand Down
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ pexpect = "*"


[tool.poetry.dev-dependencies]
poetry-core = "<1.1.0"

autoflake = "*"
black = "*"
codespell = "*"
Expand Down

0 comments on commit d23cc68

Please sign in to comment.