Skip to content

Commit

Permalink
Switch from flit to poetry
Browse files Browse the repository at this point in the history
  • Loading branch information
i80and committed Nov 22, 2022
1 parent fb24d27 commit 16e6d7c
Show file tree
Hide file tree
Showing 7 changed files with 1,073 additions and 78 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ jobs:
with:
python-version: '3.11'
architecture: 'x64'
- name: Setup poetry
run: python3 -m pip install poetry
- name: Install dependencies
run: python3 -m poetry install
- name: Run tests
run: make test
env:
FLIT_ROOT_INSTALL: "1"
- name: Build package
id: build_package
run: make package
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
architecture: 'x64'
- name: Setup poetry
run: python3 -m pip install poetry
- name: Install dependencies
run: python3 -m poetry install
- name: Run tests
run: make test
env:
FLIT_ROOT_INSTALL: "1"
- name: Build package
id: build_package
run: make package
21 changes: 12 additions & 9 deletions HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,34 +95,37 @@ Helper functions to help the Parser in navigating through the reStructuredText.

## Developing Snooty

1. Run the following to install the necessary tools:
1. Install [Poetry](https://python-poetry.org/docs/)

2. Set up the project's dependencies.

```shell
python3 -m pip install flit virtualenv
poetry install
```

2. Make your changes to the source code.
3. Make your changes to the source code.

3. Run `make test` and `make format ` to check that the tests pass and fix your formatting. This will also install the prerequirements defined in pyproject.toml.
4. Run `make test` and `make format ` to check that the tests pass and fix your formatting. This will also install the prerequirements defined in pyproject.toml.

4. Use [Flit](https://flit.readthedocs.io/en/latest/) to install Snooty. The module will be symlinked (via `-s`) to allow for testing changes without reinstalling the module.
5. You can activate a shell where the `snooty` command is available by running:

```shell
flit install -s
poetry shell

snooty build <docs_property_path>
```

### Running tests

To run tests for a specific file:

```shell
. .venv/bin/activate
pytest snooty/test_<file>.py
poetry run pytest snooty/test_<file>.py
```

### Code Coverage

Install [Coverage](https://coverage.readthedocs.io/en/v4.5.x/). After running tests via `make format test`, run:
Install [Coverage](https://coverage.readthedocs.io/). After running tests via `make format test`, run:

```shell
coverage html
Expand Down
42 changes: 14 additions & 28 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,42 +1,31 @@
.PHONY: help lint format test clean flit-publish package cut-release performance-report
.PHONY: help lint format test clean package cut-release performance-report

SYSTEM_PYTHON=$(shell which python3)
PLATFORM=$(shell printf '%s_%s' "$$(uname -s | tr '[:upper:]' '[:lower:]')" "$$(uname -m)")
VERSION=$(shell git describe --tags)
PUSH_TO=$(shell git remote -v | grep -m1 -E 'github.com(:|/)mongodb/snooty-parser.git' | cut -f 1)
PACKAGE_NAME=snooty-${VERSION}-${PLATFORM}.zip
export SOURCE_DATE_EPOCH = $(shell date +%s)

help: ## Show this help message
@grep -E '^[a-zA-Z_.0-9-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'

.venv/.EXISTS: pyproject.toml
-rm -r .venv snootycli.py
"$(SYSTEM_PYTHON)" -m venv .venv
. .venv/bin/activate && \
python3 -m pip install --upgrade pip && \
python3 -m pip install flit && \
flit install -s --deps=develop
touch $@

lint: .venv/.EXISTS ## Run all linting
. .venv/bin/activate && python3 -m mypy --strict snooty tools
. .venv/bin/activate && python3 -m pyflakes snooty tools
. .venv/bin/activate && python3 -m black snooty tools --check
lint: ## Run all linting
poetry run mypy --strict snooty tools
poetry run pyflakes snooty tools
poetry run black snooty tools --check
tools/lint_changelog.py CHANGELOG.md

format: .venv/.EXISTS ## Format source code with black
. .venv/bin/activate && python3 -m isort snooty tools
. .venv/bin/activate && python3 -m black snooty tools
format: ## Format source code with black
poetry run isort snooty tools
poetry run black snooty tools

test: lint ## Run unit tests
. .venv/bin/activate && python3 -X dev -m pytest --cov=snooty
poetry run python3 -X dev -m pytest --cov=snooty

dist/snooty/.EXISTS: .venv/.EXISTS pyproject.toml snooty/*.py snooty/gizaparser/*.py
dist/snooty/.EXISTS: pyproject.toml snooty/*.py snooty/gizaparser/*.py
-rm -rf snooty.dist dist
mkdir dist
echo 'from snooty import main; main.main()' > snootycli.py
. .venv/bin/activate && python3 -m PyInstaller -n snooty snootycli.py
poetry run python3 -m PyInstaller -n snooty snootycli.py
rm snootycli.py
install -m644 snooty/config.toml snooty/rstspec.toml LICENSE* dist/snooty/
touch $@
Expand All @@ -52,13 +41,10 @@ dist/${PACKAGE_NAME}.asc: dist/snooty-${VERSION}-${PLATFORM}.zip ## Build and si
gpg --armor --detach-sig $^

clean: ## Remove all build artifacts
-rm -r snooty.tar.zip* snootycli.py .venv
-rm -r snooty.tar.zip* snootycli.py
-rm -rf dist
-rm -rf .docs

flit-publish: test ## Deploy the package to pypi
SOURCE_DATE_EPOCH="$$SOURCE_DATE_EPOCH" flit publish

package: dist/${PACKAGE_NAME}

cut-release: ## Release a new version of snooty. Must provide BUMP_TO_VERSION
Expand Down Expand Up @@ -86,7 +72,7 @@ cut-release: ## Release a new version of snooty. Must provide BUMP_TO_VERSION
@echo "Release will be created at: /~https://github.com/mongodb/snooty-parser/releases/tag/v${BUMP_TO_VERSION}"

DOCS_COMMIT=1c6dfe71fd45fbdcdf5c7b73f050f615f4279064
performance-report: .venv/.EXISTS ## Fetch a sample corpus, and generate a timing report for each part of the parse
performance-report: ## Fetch a sample corpus, and generate a timing report for each part of the parse
if [ ! -d .docs ]; then git clone /~https://github.com/mongodb/docs.git .docs; fi
cd .docs; if [ `git rev-parse HEAD` != "${DOCS_COMMIT}" ]; then git fetch && git reset --hard "${DOCS_COMMIT}"; fi
. .venv/bin/activate && python3 -m snooty.performance_report .docs
poetry run python3 -m snooty.performance_report .docs
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The Snooty Parser
=================
Loading

0 comments on commit 16e6d7c

Please sign in to comment.