Skip to content

Commit

Permalink
Merge pull request #46 from geronimo-iia/features/py12
Browse files Browse the repository at this point in the history
support python 12
  • Loading branch information
geronimo-iia authored Aug 25, 2024
2 parents bc54698 + a83a62b commit 816a6d2
Show file tree
Hide file tree
Showing 15 changed files with 798 additions and 748 deletions.
17 changes: 0 additions & 17 deletions .cookiecutter.yaml

This file was deleted.

9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# top-most EditorConfig file
root = true

# All types of files configuration
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
trim_trailing_whitespace = true
6 changes: 3 additions & 3 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8, 3.9.16, 3.10.11, 3.11.3]
python-version: [3.8, 3.9.18, 3.10.13, 3.11.7, 3.12.1]

steps:
- uses: actions/checkout@v4
Expand All @@ -29,8 +29,8 @@ jobs:
- name: Install dependencies
run: make install
- name: Check Python package
run: make check
run: poetry poe check
- name: Test Python package
run: make test
run: poetry poe test


6 changes: 4 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ jobs:
run: make install
- run: poetry config pypi-token.pypi "${{ secrets.PYPI_TOKEN }}"
- name: Build and publish to pypi
run: make publish
run: poetry poe publish
- name: Build and publish Documentation
run: make publish-docs
run: |
poetry poe docs
poetry poe docs-publish
- name: Create Release
id: create_release
uses: actions/create-release@v1
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Change Log

## 2.1.0


- add support for python 3.12

- build System:

- update poetry declaration
- use poe plugin (simplify makefile)
- use pyright for analysis (remove mypi)

## 2.0.1

Security fix (dev tools)
Expand Down
111 changes: 58 additions & 53 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Contributing

This project is based on [Geronimo-iaa's Python Template](https://github.com/geronimo-iia/python-module-template).
This project is based on [Geronimo-iaa's Python Module Template](https://github.com/geronimo-iia/python-module-template).
This is a cookiecutter template for a typical Python library following modern packaging conventions.
It utilizes popular libraries to fully automate all development and deployment tasks.

Expand All @@ -14,7 +14,7 @@ You will need:
* Python 3.8"+
* [Pyenv](https://github.com/pyenv/pyenv#installation)
* [poetry](https://python-poetry.org/)
* Make with find, sed
* Make


### Make Installation
Expand All @@ -32,65 +32,70 @@ Follow [https://github.com/pyenv/pyenv#installation](https://github.com/pyenv/py

### Python Installation

Do:

`$ pyenv install 3.8`

Note for [MacOS 10.14 user](https://github.com/pyenv/pyenv/issues/544):

```bash
SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk MACOSX_DEPLOYMENT_TARGET=10.14 pyenv install 3.8
```

### Poetry Installation: [https://poetry.eustace.io/docs/#installation](https://poetry.eustace.io/docs/#installation)

Poetry will manage our dependencies and create our virtual environment for us.

### Integration With Visual Studio Code

Even if we use fabulous tool like pyenv, poetry, ... at the end, we just want to go on, and code.

So here, few detail of my installation.

- .bashrc

```bash
# init pyenv with default python version
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init -)"
fi

# add poetry in path
export PATH="$HOME/.poetry/bin:$PATH"

# Add Visual Studio Code (code)
export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
```

- poetry configuration: all is let with default

- How Launch Visual Studio Code within virtual environment created by poetry ?
After do a ```make install```, you have to do:

```bash
poetry shell
code .
```

`poetry shell` will activate project virtual environment.

## Make Target list

| Name | Comment |
|--------------|------------------------------------------------------------------------------------------|
| | |
| debug-info | Show poetry debug info |
| install | Install project dependencies |
| check | Run linters and static analysis |
| test | Run unit tests |
| build | Builds the source and wheels archives |
| build-docs | Builds site documentation. |
| publish | Publishes the package, previously built with the build command, to the remote repository |
| publish-docs | Build and publish site documentation. |
| clean | Delete all generated and temporary files |
| | |

| Name | Comment |
| ----------------------- | ----------------------------------------------------------------------------------------------- |
| make install | Install project dependencies |
| make configure | Configure poetry |
| make tag | Create and push a tag based on current project version. This will launch github release action. |
| make next-patch-version | Increment patch version of the project. |
| | |


## Poe Target list


| Name | Comment |
| ----------------------- | ---------------------------------------------------------------------------------------- |
| poetry poe check | Run linters and static analysis |
| poetry poe test | Run unit tests |
| poetry poe build | Builds the source and wheels archives (and run check & test target) |
| poetry poe publish | Publishes the package, previously built with the build command, to the remote repository |
| poetry poe docs | Builds site documentation. |
| poetry poe docs-publish | Build and publish site documentation. |
| poetry poe clean | Delete all generated and temporary files |
| poetry poe requirements | Generate requirements.txt |
| | |

You could retrieve those commands with `poetry poe`. It will output something like this :

```
Poe the Poet - A task runner that works well with poetry.
version 0.25.0
Result: No task specified.
USAGE
poetry poe [-h] [-v | -q] [--root PATH] [--ansi | --no-ansi] task [task arguments]
GLOBAL OPTIONS
-h, --help Show this help page and exit
--version Print the version and exit
-v, --verbose Increase command output (repeatable)
-q, --quiet Decrease command output (repeatable)
-d, --dry-run Print the task contents but don't actually run it
--root PATH Specify where to find the pyproject.toml
--ansi Force enable ANSI output
--no-ansi Force disable ANSI output
CONFIGURED TASKS
build Build module
publish Publish module
check Run Linter
test Run unit tests
docs Build site documentation
docs-publish Publish site documentation
clean Remove all generated and temporary files
requirements Generate requirements.txt
```
87 changes: 5 additions & 82 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,25 +1,8 @@
# Project settings
PACKAGE := networkx_query
REPOSITORY := geronimo-iia/networkx-query
PACKAGES := $(PACKAGE) tests
MODULES := $(wildcard $(PACKAGE)/*.py)

# const
.DEFAULT_GOAL := help
FAILURES := .pytest_cache/v/cache/lastfailed
DIST_FILES := dist/*.tar.gz dist/*.whl

GIT_COMMIT_SHA := $(shell git rev-parse HEAD)

# MAIN TASKS ##################################################################

.PHONY: all
all: install

.PHONY: debug-info
debug-info: ## Show poetry debug info
poetry debug:info

.PHONY: help
help: all
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
Expand All @@ -30,65 +13,28 @@ install: .install .cache ## Install project dependencies

.install: poetry.lock
$(MAKE) configure
poetry install
poetry install --with docs
poetry check
@touch $@

poetry.lock: pyproject.toml
$(MAKE) configure
poetry lock
$(MAKE) requirements.txt
@touch $@

.cache:
@mkdir -p .cache

.PHONY: requirements.txt
requirements.txt: ## Generate requirements.txt and requirements-dev.txt
@poetry export --without-hashes -f requirements.txt > requirements.txt
@sed '1d' requirements.txt


.PHONY: configure
configure:
@poetry config virtualenvs.in-project true
@poetry self add poetry-plugin-export
@poetry self add 'poethepoet[poetry_plugin]'
@poetry run python -m pip install --upgrade pip
@poetry run python -m pip install --upgrade setuptools

# CHECKS ######################################################################

.PHONY: check
check: install ## Run linters and static analysis
poetry run isort $(PACKAGES)
poetry run black $(PACKAGES)
poetry run ruff check $(PACKAGES)
poetry run mypy --show-error-codes --config-file pyproject.toml $(PACKAGE)

# TESTS #######################################################################

.PHONY: test
test: install ## Run unit tests
@if test -e $(FAILURES); then poetry run pytest tests --last-failed --exitfirst; fi
@rm -rf $(FAILURES)
poetry run pytest


# BUILD #######################################################################

DIST_FILES := dist/*.tar.gz dist/*.whl

.PHONY: build
build: install check test $(DIST_FILES) ## Builds the source and wheels archives
$(DIST_FILES): $(MODULES) pyproject.toml
@rm -f $(DIST_FILES)
poetry build

# RELEASE #####################################################################

.PHONY: publish
publish: build ## Publishes the package, previously built with the build command, to the remote repository
$(MAKE) configure
poetry publish

# git util #####################################################################

.PHONY: next-patch-version
next-patch-version: ## Increment patch version
Expand All @@ -109,26 +55,3 @@ tag: ## Tags current repository
git tag "v$$PROJECT_RELEASE" ; \
git push origin "v$$PROJECT_RELEASE"

.PHONY: release
release: next-patch-version publish

# DOC #########################################################################

.PHONY: build-docs
build-docs: ## Build and publish sit documentation.
@poetry run mkdocs build --clean


.PHONY: publish-docs
publish-docs: ## Build and publish sit documentation.
@git fetch origin gh-pages
@poetry run mkdocs gh-deploy --clean


# CLEANUP #####################################################################

.PHONY: clean
clean: ## Delete all generated and temporary files
@rm -rf *.spec dist build .eggs *.egg-info .install .cache .coverage htmlcov .mypy_cache .pytest_cache site .ruff_cache
@find $(PACKAGES) -type d -name '__pycache__' -exec rm -rf {} +

1 change: 1 addition & 0 deletions networkx_query/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""networkx-query."""

from pkg_resources import DistributionNotFound, get_distribution

from .definition import Evaluator, ParserException
Expand Down
1 change: 1 addition & 0 deletions networkx_query/definition.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Define type and structure for query language."""

from enum import Enum, unique
from typing import Any, Callable, List, NamedTuple, Optional, Tuple, Type, Union

Expand Down
3 changes: 2 additions & 1 deletion networkx_query/parser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Main parser and compile function."""

from collections import deque
from typing import Dict, List, Optional

Expand Down Expand Up @@ -30,7 +31,7 @@ def parse(expra: Dict, stack: Optional[deque] = None) -> ItemAST:
_stack = stack if stack else deque()

_stack.append(expra)
for (op, v) in expra.items():
for op, v in expra.items():
if op not in NETWORKX_OPERATORS_REGISTERY:
raise ParserException(f'Unsupported "{op}" operator', _stack)
operator = NETWORKX_OPERATORS_REGISTERY[op]
Expand Down
1 change: 1 addition & 0 deletions networkx_query/query.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""networkx-query public interace definition."""

from typing import Any, Dict, Iterable, Tuple

from networkx import Graph
Expand Down
Loading

0 comments on commit 816a6d2

Please sign in to comment.