diff --git a/Cargo.toml b/Cargo.toml index 9d713fa..c9ae970 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,106 +19,8 @@ include = [ "examples/**/*" ] -[package] -name = "typos-cli" -version = "1.13.20" -description = "Source Code Spelling Correction" -readme = "README.md" -categories = ["development-tools", "text-processing"] -keywords = ["development", "spelling"] -license.workspace = true -repository.workspace = true -edition.workspace = true -rust-version.workspace = true -include.workspace = true - -[package.metadata.maturin] -name = "typos" - -[package.metadata.docs.rs] -no-default-features = true - -[package.metadata.release] -pre-release-replacements = [ - {file="CHANGELOG.md", search="Unreleased", replace="{{version}}", min=1}, - {file="CHANGELOG.md", search="\\.\\.\\.HEAD", replace="...{{tag_name}}", exactly=1}, - {file="CHANGELOG.md", search="ReleaseDate", replace="{{date}}", min=1}, - {file="CHANGELOG.md", search="", replace="\n## [Unreleased] - ReleaseDate\n", exactly=1}, - {file="CHANGELOG.md", search="", replace="\n[Unreleased]: https://github.com/crate-ci/typos/compare/{{tag_name}}...HEAD", exactly=1}, - {file="docker/Dockerfile", search="ARG VERSION=.*", replace="ARG VERSION={{version}}", min=1}, - {file="docs/pre-commit.md", search="rev: .*", replace="rev: {{tag_name}}", exactly=1}, - {file="setup.py", search="TYPOS_VERSION = .*", replace="TYPOS_VERSION = '{{version}}'", exactly=1}, -] - -[features] -default = ["dict", "vars"] -dict = ["typos-dict"] -vars = ["typos-vars"] - - -[[bin]] -name = "typos" -path = "src/bin/typos-cli/main.rs" -doc = false - -[dependencies] -typos = { version = "^0.10", path = "crates/typos" } -varcon-core = { version = "^2.2.9", path = "crates/varcon-core" } -typos-dict = { version = "^0.9", path = "crates/typos-dict", optional = true } -typos-vars = { version = "^0.8", path = "crates/typos-vars", optional = true } -unicase = "2.6" -anyhow = "1.0" -clap = { version = "4.1.8", features = ["derive"] } -clap-verbosity-flag = "2.0" -ignore = "0.4" -serde = { version = "1.0", features = ["derive"] } -toml = "0.7.2" -log = "0.4" -env_logger = { version = "0.10", default-features = false, features = ["auto-color"] } -atty = "0.2.14" -yansi = "0.5.1" -concolor = { version = "0.0.12" } -concolor-clap = { version = "0.0.14", features = ["api_unstable"] } -bstr = "1.3" -once_cell = "1.17.1" -ahash = "0.8" -difflib = "0.4" -proc-exit = "2.0" -human-panic = "1.1.1" -content_inspector = "0.2.4" -unicode-segmentation = "1.10.1" -derive_more = "0.99.17" -derive_setters = "0.1" -itertools = "0.10" -serde_json = "1.0" -encoding = "0.2" -kstring = { version = "2.0.0", features = ["serde"] } -typed-arena = "2.0.2" -maplit = "1.0" -unicode-width = "0.1.10" -unic-emoji-char = "0.9.0" -thread_local = "1.1.7" -globset = "0.4.10" - -[dev-dependencies] -assert_fs = "1.0" -trycmd = "0.14.13" -criterion = "0.4" - [profile.dev] panic = "abort" [profile.release] panic = "abort" - -[[bench]] -name = "checks" -harness = false - -[[bench]] -name = "corrections" -harness = false - -[[bench]] -name = "tokenize" -harness = false diff --git a/crates/typos-cli/Cargo.toml b/crates/typos-cli/Cargo.toml new file mode 100644 index 0000000..e4f193f --- /dev/null +++ b/crates/typos-cli/Cargo.toml @@ -0,0 +1,98 @@ +[package] +name = "typos-cli" +version = "1.13.20" +description = "Source Code Spelling Correction" +readme = "../../README.md" +categories = ["development-tools", "text-processing"] +keywords = ["development", "spelling"] +license.workspace = true +repository.workspace = true +edition.workspace = true +rust-version.workspace = true +include.workspace = true + +[package.metadata.maturin] +name = "typos" + +[package.metadata.docs.rs] +no-default-features = true + +[package.metadata.release] +tag-prefix = "" +pre-release-replacements = [ + {file="../../CHANGELOG.md", search="Unreleased", replace="{{version}}", min=1}, + {file="../../CHANGELOG.md", search="\\.\\.\\.HEAD", replace="...{{tag_name}}", exactly=1}, + {file="../../CHANGELOG.md", search="ReleaseDate", replace="{{date}}", min=1}, + {file="../../CHANGELOG.md", search="", replace="\n## [Unreleased] - ReleaseDate\n", exactly=1}, + {file="../../CHANGELOG.md", search="", replace="\n[Unreleased]: https://github.com/crate-ci/typos/compare/{{tag_name}}...HEAD", exactly=1}, + {file="../../docker/Dockerfile", search="ARG VERSION=.*", replace="ARG VERSION={{version}}", min=1}, + {file="../../docs/pre-commit.md", search="rev: .*", replace="rev: {{tag_name}}", exactly=1}, + {file="../../setup.py", search="TYPOS_VERSION = .*", replace="TYPOS_VERSION = '{{version}}'", exactly=1}, +] + +[features] +default = ["dict", "vars"] +dict = ["typos-dict"] +vars = ["typos-vars"] + + +[[bin]] +name = "typos" +path = "src/bin/typos-cli/main.rs" +doc = false + +[dependencies] +typos = { version = "^0.10", path = "../typos" } +varcon-core = { version = "^2.2.9", path = "../varcon-core" } +typos-dict = { version = "^0.9", path = "../typos-dict", optional = true } +typos-vars = { version = "^0.8", path = "../typos-vars", optional = true } +unicase = "2.6" +anyhow = "1.0" +clap = { version = "4.1.8", features = ["derive"] } +clap-verbosity-flag = "2.0" +ignore = "0.4" +serde = { version = "1.0", features = ["derive"] } +toml = "0.7.2" +log = "0.4" +env_logger = { version = "0.10", default-features = false, features = ["auto-color"] } +atty = "0.2.14" +yansi = "0.5.1" +concolor = { version = "0.0.12" } +concolor-clap = { version = "0.0.14", features = ["api_unstable"] } +bstr = "1.3" +once_cell = "1.17.1" +ahash = "0.8" +difflib = "0.4" +proc-exit = "2.0" +human-panic = "1.1.1" +content_inspector = "0.2.4" +unicode-segmentation = "1.10.1" +derive_more = "0.99.17" +derive_setters = "0.1" +itertools = "0.10" +serde_json = "1.0" +encoding = "0.2" +kstring = { version = "2.0.0", features = ["serde"] } +typed-arena = "2.0.2" +maplit = "1.0" +unicode-width = "0.1.10" +unic-emoji-char = "0.9.0" +thread_local = "1.1.7" +globset = "0.4.10" + +[dev-dependencies] +assert_fs = "1.0" +trycmd = "0.14.13" +criterion = "0.4" + +[[bench]] +name = "checks" +harness = false + +[[bench]] +name = "corrections" +harness = false + +[[bench]] +name = "tokenize" +harness = false diff --git a/benches/checks.rs b/crates/typos-cli/benches/checks.rs similarity index 100% rename from benches/checks.rs rename to crates/typos-cli/benches/checks.rs diff --git a/benches/corrections.rs b/crates/typos-cli/benches/corrections.rs similarity index 100% rename from benches/corrections.rs rename to crates/typos-cli/benches/corrections.rs diff --git a/benches/data.rs b/crates/typos-cli/benches/data.rs similarity index 94% rename from benches/data.rs rename to crates/typos-cli/benches/data.rs index 39e6c3a..87dc68e 100644 --- a/benches/data.rs +++ b/crates/typos-cli/benches/data.rs @@ -28,7 +28,7 @@ fn main() { } "; -pub static CORPUS: &str = include_str!("../crates/typos-dict/assets/words.csv"); +pub static CORPUS: &str = include_str!("../../typos-dict/assets/words.csv"); pub static DATA: &[(&str, &str)] = &[ ("empty", EMPTY), diff --git a/benches/tokenize.rs b/crates/typos-cli/benches/tokenize.rs similarity index 100% rename from benches/tokenize.rs rename to crates/typos-cli/benches/tokenize.rs diff --git a/pyproject.toml b/crates/typos-cli/pyproject.toml similarity index 100% rename from pyproject.toml rename to crates/typos-cli/pyproject.toml diff --git a/src/bin/typos-cli/args.rs b/crates/typos-cli/src/bin/typos-cli/args.rs similarity index 100% rename from src/bin/typos-cli/args.rs rename to crates/typos-cli/src/bin/typos-cli/args.rs diff --git a/src/bin/typos-cli/main.rs b/crates/typos-cli/src/bin/typos-cli/main.rs similarity index 100% rename from src/bin/typos-cli/main.rs rename to crates/typos-cli/src/bin/typos-cli/main.rs diff --git a/src/bin/typos-cli/report.rs b/crates/typos-cli/src/bin/typos-cli/report.rs similarity index 100% rename from src/bin/typos-cli/report.rs rename to crates/typos-cli/src/bin/typos-cli/report.rs diff --git a/src/config.rs b/crates/typos-cli/src/config.rs similarity index 100% rename from src/config.rs rename to crates/typos-cli/src/config.rs diff --git a/src/default_types.rs b/crates/typos-cli/src/default_types.rs similarity index 100% rename from src/default_types.rs rename to crates/typos-cli/src/default_types.rs diff --git a/src/dict.rs b/crates/typos-cli/src/dict.rs similarity index 100% rename from src/dict.rs rename to crates/typos-cli/src/dict.rs diff --git a/src/file.rs b/crates/typos-cli/src/file.rs similarity index 100% rename from src/file.rs rename to crates/typos-cli/src/file.rs diff --git a/src/file_type.rs b/crates/typos-cli/src/file_type.rs similarity index 100% rename from src/file_type.rs rename to crates/typos-cli/src/file_type.rs diff --git a/src/lib.rs b/crates/typos-cli/src/lib.rs similarity index 100% rename from src/lib.rs rename to crates/typos-cli/src/lib.rs diff --git a/src/policy.rs b/crates/typos-cli/src/policy.rs similarity index 100% rename from src/policy.rs rename to crates/typos-cli/src/policy.rs diff --git a/src/report.rs b/crates/typos-cli/src/report.rs similarity index 100% rename from src/report.rs rename to crates/typos-cli/src/report.rs diff --git a/tests/cli_tests.rs b/crates/typos-cli/tests/cli_tests.rs similarity index 100% rename from tests/cli_tests.rs rename to crates/typos-cli/tests/cli_tests.rs diff --git a/tests/cmd/assumed-dir-failure.toml b/crates/typos-cli/tests/cmd/assumed-dir-failure.toml similarity index 100% rename from tests/cmd/assumed-dir-failure.toml rename to crates/typos-cli/tests/cmd/assumed-dir-failure.toml diff --git a/tests/cmd/double-escaped.stdin b/crates/typos-cli/tests/cmd/double-escaped.stdin similarity index 100% rename from tests/cmd/double-escaped.stdin rename to crates/typos-cli/tests/cmd/double-escaped.stdin diff --git a/tests/cmd/double-escaped.stdout b/crates/typos-cli/tests/cmd/double-escaped.stdout similarity index 100% rename from tests/cmd/double-escaped.stdout rename to crates/typos-cli/tests/cmd/double-escaped.stdout diff --git a/tests/cmd/double-escaped.toml b/crates/typos-cli/tests/cmd/double-escaped.toml similarity index 100% rename from tests/cmd/double-escaped.toml rename to crates/typos-cli/tests/cmd/double-escaped.toml diff --git a/tests/cmd/file-failure.toml b/crates/typos-cli/tests/cmd/file-failure.toml similarity index 58% rename from tests/cmd/file-failure.toml rename to crates/typos-cli/tests/cmd/file-failure.toml index 134c44c..0593893 100644 --- a/tests/cmd/file-failure.toml +++ b/crates/typos-cli/tests/cmd/file-failure.toml @@ -1,3 +1,3 @@ bin.name = "typos" -args = "README.md" +args = "../../README.md" status.code = 2 diff --git a/tests/cmd/relative-dir-failure.toml b/crates/typos-cli/tests/cmd/relative-dir-failure.toml similarity index 100% rename from tests/cmd/relative-dir-failure.toml rename to crates/typos-cli/tests/cmd/relative-dir-failure.toml diff --git a/tests/cmd/stdin-correct.stdin b/crates/typos-cli/tests/cmd/stdin-correct.stdin similarity index 100% rename from tests/cmd/stdin-correct.stdin rename to crates/typos-cli/tests/cmd/stdin-correct.stdin diff --git a/tests/cmd/stdin-correct.stdout b/crates/typos-cli/tests/cmd/stdin-correct.stdout similarity index 100% rename from tests/cmd/stdin-correct.stdout rename to crates/typos-cli/tests/cmd/stdin-correct.stdout diff --git a/tests/cmd/stdin-correct.toml b/crates/typos-cli/tests/cmd/stdin-correct.toml similarity index 100% rename from tests/cmd/stdin-correct.toml rename to crates/typos-cli/tests/cmd/stdin-correct.toml diff --git a/tests/cmd/stdin-failure-multiwidth.stdin b/crates/typos-cli/tests/cmd/stdin-failure-multiwidth.stdin similarity index 100% rename from tests/cmd/stdin-failure-multiwidth.stdin rename to crates/typos-cli/tests/cmd/stdin-failure-multiwidth.stdin diff --git a/tests/cmd/stdin-failure-multiwidth.stdout b/crates/typos-cli/tests/cmd/stdin-failure-multiwidth.stdout similarity index 100% rename from tests/cmd/stdin-failure-multiwidth.stdout rename to crates/typos-cli/tests/cmd/stdin-failure-multiwidth.stdout diff --git a/tests/cmd/stdin-failure-multiwidth.toml b/crates/typos-cli/tests/cmd/stdin-failure-multiwidth.toml similarity index 100% rename from tests/cmd/stdin-failure-multiwidth.toml rename to crates/typos-cli/tests/cmd/stdin-failure-multiwidth.toml diff --git a/tests/cmd/stdin-failure.stdin b/crates/typos-cli/tests/cmd/stdin-failure.stdin similarity index 100% rename from tests/cmd/stdin-failure.stdin rename to crates/typos-cli/tests/cmd/stdin-failure.stdin diff --git a/tests/cmd/stdin-failure.toml b/crates/typos-cli/tests/cmd/stdin-failure.toml similarity index 100% rename from tests/cmd/stdin-failure.toml rename to crates/typos-cli/tests/cmd/stdin-failure.toml diff --git a/tests/cmd/stdin-success.stdin b/crates/typos-cli/tests/cmd/stdin-success.stdin similarity index 100% rename from tests/cmd/stdin-success.stdin rename to crates/typos-cli/tests/cmd/stdin-success.stdin diff --git a/tests/cmd/stdin-success.toml b/crates/typos-cli/tests/cmd/stdin-success.toml similarity index 100% rename from tests/cmd/stdin-success.toml rename to crates/typos-cli/tests/cmd/stdin-success.toml diff --git a/setup.py b/setup.py index 2216e29..1bf17f2 100644 --- a/setup.py +++ b/setup.py @@ -1,167 +1,13 @@ -#!/usr/bin/env python3 -import hashlib -import http -import io -import os.path -import stat -import sys -import tarfile -import urllib.request -import zipfile -from distutils.command.build import build as orig_build -from distutils.core import Command -from typing import Tuple +from __future__ import annotations from setuptools import setup -from setuptools.command.install import install as orig_install - -TYPOS_VERSION = '1.13.20' -POSTFIX_SHA256 = { - 'linux': ( - 'x86_64-unknown-linux-musl.tar.gz', - '', # TODO: sha256 hexhash when we can generate it with release - ), - 'darwin': ( - 'x86_64-apple-darwin.tar.gz', - '', # TODO: sha256 hexhash when we can generate it with release - ), - 'win32': ( - 'x86_64-pc-windows-msvc.zip', - '', # TODO: sha256 hexhash when we can generate it with release - ), -} -POSTFIX_SHA256['cygwin'] = POSTFIX_SHA256['win32'] -PY_VERSION = '1' -def get_download_url() -> Tuple[str, str]: - postfix, sha256 = POSTFIX_SHA256[sys.platform] - url = ( - f'https://github.com/crate-ci/typos/releases/download/' - f'v{TYPOS_VERSION}/typos-v{TYPOS_VERSION}-{postfix}' - ) - return url, sha256 +TYPOS_VERSION = "1.13.20" -def download(url: str, sha256: str) -> bytes: - with urllib.request.urlopen(url) as resp: - code = resp.getcode() - if code != http.HTTPStatus.OK: - raise ValueError(f'HTTP failure. Code: {code}') - data = resp.read() - - if not sha256: - return data - - checksum = hashlib.sha256(data).hexdigest() - if checksum != sha256: - raise ValueError(f'sha256 mismatch, expected {sha256}, got {checksum}') - - return data - - -def extract(url: str, data: bytes) -> bytes: - with io.BytesIO(data) as bio: - if '.tar.' in url: - with tarfile.open(fileobj=bio) as tarf: - for info in tarf.getmembers(): - if info.isfile() and info.name.endswith('typos'): - return tarf.extractfile(info).read() - elif url.endswith('.zip'): - with zipfile.ZipFile(bio) as zipf: - for info in zipf.infolist(): - if info.filename.endswith('.exe'): - return zipf.read(info.filename) - - raise AssertionError(f'unreachable {url}') - - -def save_executable(data: bytes, base_dir: str): - exe = 'typos' if sys.platform != 'win32' else 'typos.exe' - output_path = os.path.join(base_dir, exe) - os.makedirs(base_dir) - - with open(output_path, 'wb') as fp: - fp.write(data) - - # Mark as executable. - # https://stackoverflow.com/a/14105527 - mode = os.stat(output_path).st_mode - mode |= stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH - os.chmod(output_path, mode) - - -class build(orig_build): - sub_commands = orig_build.sub_commands + [('fetch_binaries', None)] - - -class install(orig_install): - sub_commands = orig_install.sub_commands + [('install_typos', None)] - - -class fetch_binaries(Command): - build_temp = None - - def initialize_options(self): - pass - - def finalize_options(self): - self.set_undefined_options('build', ('build_temp', 'build_temp')) - - def run(self): - # save binary to self.build_temp - url, sha256 = get_download_url() - archive = download(url, sha256) - data = extract(url, archive) - save_executable(data, self.build_temp) - - -class install_typos(Command): - description = 'install the typos executable' - outfiles = () - build_dir = install_dir = None - - def initialize_options(self): - pass - - def finalize_options(self): - # this initializes attributes based on other commands' attributes - self.set_undefined_options('build', ('build_temp', 'build_dir')) - self.set_undefined_options( - 'install', ('install_scripts', 'install_dir'), - ) - - def run(self): - self.outfiles = self.copy_tree(self.build_dir, self.install_dir) - - def get_outputs(self): - return self.outfiles - - -command_overrides = { - 'install': install, - 'install_typos': install_typos, - 'build': build, - 'fetch_binaries': fetch_binaries, -} - - -try: - from wheel.bdist_wheel import bdist_wheel as orig_bdist_wheel -except ImportError: - pass -else: - class bdist_wheel(orig_bdist_wheel): - def finalize_options(self): - orig_bdist_wheel.finalize_options(self) - # Mark us as not a pure python package - self.root_is_pure = False - - def get_tag(self): - _, _, plat = orig_bdist_wheel.get_tag(self) - # We don't contain any python source, nor any python extensions - return 'py2.py3', 'none', plat - - command_overrides['bdist_wheel'] = bdist_wheel - -setup(version=f'{TYPOS_VERSION}.{PY_VERSION}', cmdclass=command_overrides) +setup( + name='pre_commit_placeholder_package', + version='0.0.0', + install_requires=[f'typos=={TYPOS_VERSION}'], +)