From 2fe81df5af98d347fc44405e6d2b10ed2e852bd8 Mon Sep 17 00:00:00 2001 From: Charles Marsh Date: Wed, 10 Aug 2022 15:41:53 -0400 Subject: [PATCH] Enable Maturin --- .gitignore | 168 ++++++++++++++++++++- Cargo.toml | 5 + README.md | 50 +++++- pyproject.toml | 3 + src/bin/{main.rs => rust_python_linter.rs} | 6 +- 5 files changed, 221 insertions(+), 11 deletions(-) create mode 100644 pyproject.toml rename src/bin/{main.rs => rust_python_linter.rs} (95%) diff --git a/.gitignore b/.gitignore index 9b4eae7c8ee64..64bd14b164f79 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,6 @@ # Local cache .cache -# IntelliJ -.idea - ### # Rust.gitignore ### @@ -22,3 +19,168 @@ Cargo.lock # MSVC Windows builds of rustc generate these, which store debugging information *.pdb + +### +# Python.gitignore +### + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +.idea/ diff --git a/Cargo.toml b/Cargo.toml index 7c38e8ca0fda8..01a82f993c3f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,10 @@ name = "rust-python-linter" version = "0.1.0" edition = "2021" +[lib] +name = "rust_python_linter" +crate-type = ["cdylib", "lib"] + [dependencies] anyhow = { version = "1.0.60" } bincode = { version = "1.3.3" } @@ -19,3 +23,4 @@ rustpython-parser = { git = "https://github.com/RustPython/RustPython.git", rev serde = { version = "1.0.143", features = ["derive"] } serde_json = { version = "1.0.83" } walkdir = { version = "2.3.2" } +pyo3 = { version = "0.16.5", features = ["extension-module", "abi3-py37"] } diff --git a/README.md b/README.md index ef88d14af4282..0557c4b40f598 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,56 @@ # rust-python-linter -A [Pyflakes](https://github.com/PyCQA/pyflakes)-inspired Python linter, written in Rust. +A performance-focused, [Pyflakes](https://github.com/PyCQA/pyflakes)-inspired Python linter, written +in Rust. -Supports: +Features: -- Python 3.10 -- True parallelism +- Python 3.10 compatibility - [ESLint](https://eslint.org/docs/latest/user-guide/command-line-interface#caching)-inspired - caching + cache semantics +- [TypeScript](https://www.typescriptlang.org/docs/handbook/configuring-watch.html) + -inspired `--watch` semantics +## Installation + +Available as [`rust-python-linter`](https://pypi.org/project/rust-python-linter/) on PyPI: + +```shell +pip install rust-python-linter +``` + +## Usage + +To run the linter, try any of the following: + +```shell +rust_python_linter path/to/code/to/check.py +# ...or... +rust_python_linter path/to/code/ +# ...or... +rust_python_linter path/to/code/*.py +``` + +You can also run in `--watch` mode to automatically re-run the linter on-change with, e.g.: + +```shell +rust_python_linter path/to/code/ --watch ``` + +## Development + +As the name suggests, `rust-python-linter` is implemented in Rust: + +```shell cargo fmt cargo clippy cargo run resources/test/src ``` + +## Deployment + +`rust-python-linter` is released for Python using [`maturin`](https://github.com/PyO3/maturin): + +```shell +maturin publish +``` diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000000000..5d44682cdc160 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["maturin>=0.13,<0.14"] +build-backend = "maturin" diff --git a/src/bin/main.rs b/src/bin/rust_python_linter.rs similarity index 95% rename from src/bin/main.rs rename to src/bin/rust_python_linter.rs index 81b4cee07ef91..115818c9cb595 100644 --- a/src/bin/main.rs +++ b/src/bin/rust_python_linter.rs @@ -2,14 +2,14 @@ use std::path::PathBuf; use std::sync::mpsc::channel; use std::time::{Duration, Instant}; +use ::rust_python_linter::fs::collect_python_files; +use ::rust_python_linter::linter::check_path; +use ::rust_python_linter::message::Message; use anyhow::Result; use clap::{Parser, ValueHint}; use log::{debug, error}; use notify::{watcher, RecursiveMode, Watcher}; use rayon::prelude::*; -use rust_python_linter::fs::collect_python_files; -use rust_python_linter::linter::check_path; -use rust_python_linter::message::Message; use walkdir::DirEntry; #[derive(Debug, Parser)]