From 18440d57dddc0723c7bc21a3be1a6ae7e60d3527 Mon Sep 17 00:00:00 2001 From: autobump Date: Mon, 13 Mar 2023 14:49:20 +0000 Subject: [PATCH 01/12] =?UTF-8?q?Bump=20version:=200.0.0.dev1=20=E2=86=92?= =?UTF-8?q?=200.0.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyflybygen/__about__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyflybygen/__about__.py b/pyflybygen/__about__.py index 90da1db..6d1bde0 100644 --- a/pyflybygen/__about__.py +++ b/pyflybygen/__about__.py @@ -1,4 +1,4 @@ # SPDX-FileCopyrightText: 2023-present Waylon S. Walker # # SPDX-License-Identifier: MIT -__version__ = "0.0.0.dev1" +__version__ = "0.0.0" From 6950680ee9eaf0cd5ecb843833a6a6b355aa010c Mon Sep 17 00:00:00 2001 From: "Waylon S. Walker" Date: Mon, 13 Mar 2023 10:08:14 -0500 Subject: [PATCH 02/12] ignore .gitignore --- .gitignore | 3 +++ pyflybygen/cli/app.py | 12 +++++++++--- pyproject.toml | 5 +++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 19e0f43..e1a3186 100644 --- a/.gitignore +++ b/.gitignore @@ -496,6 +496,9 @@ poetry.toml # ruff .ruff_cache/ +# LSP config files +pyrightconfig.json + ### SublimeText ### # Cache files for Sublime Text *.tmlanguage.cache diff --git a/pyflybygen/cli/app.py b/pyflybygen/cli/app.py index 300b39b..687dcd5 100644 --- a/pyflybygen/cli/app.py +++ b/pyflybygen/cli/app.py @@ -1,6 +1,7 @@ from pathlib import Path import more_itertools +import pathspec import typer from pyflybygen.cli.common import verbose_callback @@ -49,9 +50,14 @@ def main( help="show the log messages", ), ) -> None: - imports = more_itertools.flatten( - [get_imports(p.read_text()) for p in Path(".").glob("**/*.py")] - ) + + lines = [] + if Path(".gitignore").exists(): + lines.extend(Path(".gitignore").read_text().splitlines()) + spec = pathspec.PathSpec.from_lines("gitwildmatch", lines) + files = Path(".").glob("**/*.py") + files = [file for file in files if not spec.match_file(str(file))] + imports = more_itertools.flatten([get_imports(p.read_text()) for p in files]) print("\n".join(set(imports))) diff --git a/pyproject.toml b/pyproject.toml index 8db8537..012e08c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,8 +30,7 @@ dependencies = [ "anyconfig", "tree_sitter_languages", 'more_itertools', - 'coverage', - 'coverage-rich', + 'pathspec', ] dynamic = ["version"] @@ -58,6 +57,8 @@ dependencies = [ "pytest-rich", "ruff", "black", + 'coverage', + 'coverage-rich', ] [tool.hatch.envs.default.scripts] test = "coverage run -m pytest" From cf757847ad510c6294f5da8f92a71ac746c165bb Mon Sep 17 00:00:00 2001 From: "Waylon S. Walker" Date: Mon, 13 Mar 2023 10:14:34 -0500 Subject: [PATCH 03/12] remove relative imports --- pyflybygen/cli/app.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pyflybygen/cli/app.py b/pyflybygen/cli/app.py index 687dcd5..88b4245 100644 --- a/pyflybygen/cli/app.py +++ b/pyflybygen/cli/app.py @@ -49,6 +49,10 @@ def main( callback=verbose_callback, help="show the log messages", ), + relative_imports: bool = typer.Option( + False, + help="include relative imports", + ), ) -> None: lines = [] @@ -58,6 +62,8 @@ def main( files = Path(".").glob("**/*.py") files = [file for file in files if not spec.match_file(str(file))] imports = more_itertools.flatten([get_imports(p.read_text()) for p in files]) + if not relative_imports: + imports = [i for i in imports if "from ." not in i] print("\n".join(set(imports))) From 6b811ec0c6a9d3e3abf4f4a13f064f904ac15828 Mon Sep 17 00:00:00 2001 From: "Waylon S. Walker" Date: Mon, 13 Mar 2023 10:14:56 -0500 Subject: [PATCH 04/12] remove tmp --- tmp.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tmp.py b/tmp.py index 7f7b969..fb6bacf 100644 --- a/tmp.py +++ b/tmp.py @@ -1,5 +1,7 @@ from pathlib import Path +from .pyflybygen import pyflybygen + statements = """ from __future__ import (absolute_import, division) From f86cb023f105aa06df1ce4b425fec8dd3d6d307f Mon Sep 17 00:00:00 2001 From: "Waylon S. Walker" Date: Mon, 13 Mar 2023 10:16:55 -0500 Subject: [PATCH 05/12] rename template string --- ...ge_name}}-copier-answers.yml => .pyflybygen-copier-answers.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .{{package_name}}-copier-answers.yml => .pyflybygen-copier-answers.yml (100%) diff --git a/.{{package_name}}-copier-answers.yml b/.pyflybygen-copier-answers.yml similarity index 100% rename from .{{package_name}}-copier-answers.yml rename to .pyflybygen-copier-answers.yml From a9861eb082dfe1be39de7594cfd4aadef872085f Mon Sep 17 00:00:00 2001 From: "Waylon S. Walker" Date: Mon, 13 Mar 2023 10:16:59 -0500 Subject: [PATCH 06/12] rename template string --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a81e53d..6141d67 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ Generates pyflyby configurations for your project based on existing imports. -[![PyPI - Version](https://img.shields.io/pypi/v/{{ package_name }}.svg)](https://pypi.org/project/{{ package_name }}) -[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/{{ package_name }}.svg)](https://pypi.org/project/{{ package_name }}) +[![PyPI - Version](https://img.shields.io/pypi/v/pyflybygen.svg)](https://pypi.org/project/pyflybygen) +[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pyflybygen.svg)](https://pypi.org/project/pyflybygen) --- From b37a4b6e5968c3e758aeec44c79fd648a6abcbdd Mon Sep 17 00:00:00 2001 From: "Waylon S. Walker" Date: Mon, 13 Mar 2023 10:18:24 -0500 Subject: [PATCH 07/12] format with black --- pyflybygen/cli/app.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pyflybygen/cli/app.py b/pyflybygen/cli/app.py index 88b4245..2592fcd 100644 --- a/pyflybygen/cli/app.py +++ b/pyflybygen/cli/app.py @@ -54,7 +54,6 @@ def main( help="include relative imports", ), ) -> None: - lines = [] if Path(".gitignore").exists(): lines.extend(Path(".gitignore").read_text().splitlines()) From 623c41e2363fb2137e76d20ca2142f275a8e2b08 Mon Sep 17 00:00:00 2001 From: "Waylon S. Walker" Date: Mon, 13 Mar 2023 10:19:24 -0500 Subject: [PATCH 08/12] changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb014a6..6d9836c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.1.0 + +- feat ignore files in .gitignore +- feat `--relative-imports` flag + ## 0.0.0 init From e653516b75f03eade2dce36701f5204e63762cd3 Mon Sep 17 00:00:00 2001 From: autobump Date: Mon, 13 Mar 2023 15:21:01 +0000 Subject: [PATCH 09/12] =?UTF-8?q?Bump=20version:=200.0.0.dev1=20=E2=86=92?= =?UTF-8?q?=200.0.0.dev2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyflybygen/__about__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyflybygen/__about__.py b/pyflybygen/__about__.py index 90da1db..e56aada 100644 --- a/pyflybygen/__about__.py +++ b/pyflybygen/__about__.py @@ -1,4 +1,4 @@ # SPDX-FileCopyrightText: 2023-present Waylon S. Walker # # SPDX-License-Identifier: MIT -__version__ = "0.0.0.dev1" +__version__ = "0.0.0.dev2" From 186ff6d40a05443d7dc4e85746fc291fe425c03c Mon Sep 17 00:00:00 2001 From: "Waylon S. Walker" Date: Mon, 13 Mar 2023 10:22:47 -0500 Subject: [PATCH 10/12] bump version --- pyflybygen/__about__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyflybygen/__about__.py b/pyflybygen/__about__.py index e56aada..c4aeeaf 100644 --- a/pyflybygen/__about__.py +++ b/pyflybygen/__about__.py @@ -1,4 +1,4 @@ # SPDX-FileCopyrightText: 2023-present Waylon S. Walker # # SPDX-License-Identifier: MIT -__version__ = "0.0.0.dev2" +__version__ = "0.1.0" From 1d1fe05aecefdf1bb63fd4ed15eea2b674991ae7 Mon Sep 17 00:00:00 2001 From: autobump Date: Mon, 13 Mar 2023 15:24:08 +0000 Subject: [PATCH 11/12] =?UTF-8?q?Bump=20version:=200.1.0=20=E2=86=92=200.2?= =?UTF-8?q?.0.dev0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyflybygen/__about__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyflybygen/__about__.py b/pyflybygen/__about__.py index c4aeeaf..8d280de 100644 --- a/pyflybygen/__about__.py +++ b/pyflybygen/__about__.py @@ -1,4 +1,4 @@ # SPDX-FileCopyrightText: 2023-present Waylon S. Walker # # SPDX-License-Identifier: MIT -__version__ = "0.1.0" +__version__ = "0.2.0.dev0" From 7c7877795fe0598138a4cf7d1f16235b4c95e8b3 Mon Sep 17 00:00:00 2001 From: Waylon Walker Date: Tue, 14 Mar 2023 08:15:19 -0500 Subject: [PATCH 12/12] 0.1.0 add support for .gitignore and --relative-imports (#1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ignore .gitignore * remove relative imports * remove tmp * rename template string * rename template string * format with black * changelog * Bump version: 0.0.0.dev1 → 0.0.0.dev2 * bump version * Bump version: 0.1.0 → 0.2.0.dev0 * Bump version: 0.2.0.dev0 → 0.2.0.dev1 --------- Co-authored-by: autobump --- .gitignore | 3 +++ ...nswers.yml => .pyflybygen-copier-answers.yml | 0 CHANGELOG.md | 5 +++++ README.md | 4 ++-- pyflybygen/__about__.py | 2 +- pyflybygen/cli/app.py | 17 ++++++++++++++--- pyproject.toml | 5 +++-- tmp.py | 2 ++ 8 files changed, 30 insertions(+), 8 deletions(-) rename .{{package_name}}-copier-answers.yml => .pyflybygen-copier-answers.yml (100%) diff --git a/.gitignore b/.gitignore index 19e0f43..e1a3186 100644 --- a/.gitignore +++ b/.gitignore @@ -496,6 +496,9 @@ poetry.toml # ruff .ruff_cache/ +# LSP config files +pyrightconfig.json + ### SublimeText ### # Cache files for Sublime Text *.tmlanguage.cache diff --git a/.{{package_name}}-copier-answers.yml b/.pyflybygen-copier-answers.yml similarity index 100% rename from .{{package_name}}-copier-answers.yml rename to .pyflybygen-copier-answers.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index eb014a6..6d9836c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.1.0 + +- feat ignore files in .gitignore +- feat `--relative-imports` flag + ## 0.0.0 init diff --git a/README.md b/README.md index a81e53d..6141d67 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ Generates pyflyby configurations for your project based on existing imports. -[![PyPI - Version](https://img.shields.io/pypi/v/{{ package_name }}.svg)](https://pypi.org/project/{{ package_name }}) -[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/{{ package_name }}.svg)](https://pypi.org/project/{{ package_name }}) +[![PyPI - Version](https://img.shields.io/pypi/v/pyflybygen.svg)](https://pypi.org/project/pyflybygen) +[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pyflybygen.svg)](https://pypi.org/project/pyflybygen) --- diff --git a/pyflybygen/__about__.py b/pyflybygen/__about__.py index 6d1bde0..fbb820c 100644 --- a/pyflybygen/__about__.py +++ b/pyflybygen/__about__.py @@ -1,4 +1,4 @@ # SPDX-FileCopyrightText: 2023-present Waylon S. Walker # # SPDX-License-Identifier: MIT -__version__ = "0.0.0" +__version__ = "0.2.0.dev1" diff --git a/pyflybygen/cli/app.py b/pyflybygen/cli/app.py index 300b39b..2592fcd 100644 --- a/pyflybygen/cli/app.py +++ b/pyflybygen/cli/app.py @@ -1,6 +1,7 @@ from pathlib import Path import more_itertools +import pathspec import typer from pyflybygen.cli.common import verbose_callback @@ -48,10 +49,20 @@ def main( callback=verbose_callback, help="show the log messages", ), + relative_imports: bool = typer.Option( + False, + help="include relative imports", + ), ) -> None: - imports = more_itertools.flatten( - [get_imports(p.read_text()) for p in Path(".").glob("**/*.py")] - ) + lines = [] + if Path(".gitignore").exists(): + lines.extend(Path(".gitignore").read_text().splitlines()) + spec = pathspec.PathSpec.from_lines("gitwildmatch", lines) + files = Path(".").glob("**/*.py") + files = [file for file in files if not spec.match_file(str(file))] + imports = more_itertools.flatten([get_imports(p.read_text()) for p in files]) + if not relative_imports: + imports = [i for i in imports if "from ." not in i] print("\n".join(set(imports))) diff --git a/pyproject.toml b/pyproject.toml index 8db8537..012e08c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,8 +30,7 @@ dependencies = [ "anyconfig", "tree_sitter_languages", 'more_itertools', - 'coverage', - 'coverage-rich', + 'pathspec', ] dynamic = ["version"] @@ -58,6 +57,8 @@ dependencies = [ "pytest-rich", "ruff", "black", + 'coverage', + 'coverage-rich', ] [tool.hatch.envs.default.scripts] test = "coverage run -m pytest" diff --git a/tmp.py b/tmp.py index 7f7b969..fb6bacf 100644 --- a/tmp.py +++ b/tmp.py @@ -1,5 +1,7 @@ from pathlib import Path +from .pyflybygen import pyflybygen + statements = """ from __future__ import (absolute_import, division)