summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCoprDistGit <infra@openeuler.org>2023-04-11 04:43:50 +0000
committerCoprDistGit <infra@openeuler.org>2023-04-11 04:43:50 +0000
commit411d9500b1eff80b0084c47c67617be4b1714294 (patch)
tree713e62b5bb0aa7a0a76ac831ad1f668ebc41323d
parent687924543869bb924916bdc250ed5af56b0efda4 (diff)
automatic import of python-reorder-python-imports
-rw-r--r--.gitignore1
-rw-r--r--python-reorder-python-imports.spec709
-rw-r--r--sources1
3 files changed, 711 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index e69de29..a9b5639 100644
--- a/.gitignore
+++ b/.gitignore
@@ -0,0 +1 @@
+/reorder_python_imports-3.9.0.tar.gz
diff --git a/python-reorder-python-imports.spec b/python-reorder-python-imports.spec
new file mode 100644
index 0000000..702c305
--- /dev/null
+++ b/python-reorder-python-imports.spec
@@ -0,0 +1,709 @@
+%global _empty_manifest_terminate_build 0
+Name: python-reorder-python-imports
+Version: 3.9.0
+Release: 1
+Summary: Tool for reordering python imports
+License: MIT
+URL: https://github.com/asottile/reorder_python_imports
+Source0: https://mirrors.nju.edu.cn/pypi/web/packages/23/98/f2c8c5ee8cc406e1352b5aaad7b2f927b9a5a081ee2050eb302f5ec1b780/reorder_python_imports-3.9.0.tar.gz
+BuildArch: noarch
+
+Requires: python3-classify-imports
+
+%description
+Tool for automatically reordering python imports. Similar to `isort` but
+uses static analysis more.
+## Installation
+```bash
+pip install reorder-python-imports
+```
+## Console scripts
+Consult `reorder-python-imports --help` for the full set of options.
+`reorder-python-imports` takes filenames as positional arguments
+Common options:
+- `--py##-plus`: [see below](#removing-obsolete-__future__-imports).
+- `--add-import` / `--remove-import`: [see below](#adding--removing-imports).
+- `--replace-import`: [see below](#replacing-imports).
+- `--application-directories`: by default, `reorder-python-imports` assumes
+ your project is rooted at `.`. If this isn't true, tell it where your
+ import roots live. For example, when using the popular `./src` layout you'd
+ use `--application-directories=.:src` (note: multiple paths are separated
+ using a `:`).
+- `--unclassifiable-application-module`: (may be specified multiple times)
+ modules names that are considered application modules. this setting is
+ intended to be used for things like C modules which may not always appear on
+ the filesystem.
+## As a pre-commit hook
+See [pre-commit](https://github.com/pre-commit/pre-commit) for instructions
+Sample `.pre-commit-config.yaml`
+```yaml
+- repo: https://github.com/asottile/reorder_python_imports
+ rev: v3.9.0
+ hooks:
+ - id: reorder-python-imports
+```
+## What does it do?
+### Separates imports into three sections
+```python
+import sys
+import pyramid
+import reorder_python_imports
+```
+becomes (stdlib, third party, first party)
+```python
+import sys
+import pyramid
+import reorder_python_imports
+```
+### `import` imports before `from` imports
+```python
+from os import path
+import sys
+```
+becomes
+```python
+import sys
+from os import path
+```
+### Splits `from` imports
+```python
+from os.path import abspath, exists
+```
+becomes
+```python
+from os.path import abspath
+from os.path import exists
+```
+### Removes duplicate imports
+```python
+import os
+import os.path
+import sys
+import sys
+```
+becomes
+```python
+import os.path
+import sys
+```
+## Using `# noreorder`
+Lines containing and after lines which contain a `# noreorder` comment will
+be ignored. Additionally any imports that appear after non-whitespace
+non-comment lines will be ignored.
+For instance, these will not be changed:
+```python
+import sys
+try: # not import, not whitespace
+ import foo
+except ImportError:
+ pass
+```
+```python
+import sys
+import reorder_python_imports
+import matplotlib # noreorder
+matplotlib.use('Agg')
+import matplotlib.pyplot as plt
+```
+```python
+# noreorder
+import sys
+import pyramid
+import reorder_python_imports
+```
+## why this style?
+The style chosen by `reorder-python-imports` has a single aim: reduce merge
+conflicts.
+By having a single import per line, multiple contributors can
+add / remove imports from a single module without resulting in a conflict.
+Consider the following example which causes a merge conflict:
+```diff
+# developer 1
+-from typing import Dict, List
++from typing import Any, Dict, List
+```
+```diff
+# developer 2
+-from typing import Dict, List
++from typing import Dict, List, Tuple
+```
+no conflict with the style enforced by `reorder-python-imports`:
+```diff
++from typing import Any
+ from typing import Dict
+ from typing import List
++from typing import Tuple
+```
+## Adding / Removing Imports
+Let's say I want to enforce `absolute_import` across my codebase. I can use:
+`--add-import 'from __future__ import absolute_import'`.
+```console
+$ cat test.py
+print('Hello world')
+$ reorder-python-imports --add-import 'from __future__ import absolute_import' test.py
+Reordering imports in test.py
+$ cat test.py
+from __future__ import absolute_import
+print('Hello world')
+```
+Let's say I no longer care about supporting Python 2.5, I can remove
+`from __future__ import with_statement` with
+`--remove-import 'from __future__ import with_statement'`
+```console
+$ cat test.py
+from __future__ import with_statement
+with open('foo.txt', 'w') as foo_f:
+ foo_f.write('hello world')
+$ reorder-python-imports --remove-import 'from __future__ import with_statement' test.py
+Reordering imports in test.py
+$ cat test.py
+with open('foo.txt', 'w') as foo_f:
+ foo_f.write('hello world')
+```
+## Replacing imports
+Imports can be replaced with others automatically (if they provide the same
+names). This can be useful for factoring out compatibility libraries such
+as `six` (see below for automated `six` rewriting).
+This rewrite avoids `NameError`s as such it only occurs when:
+- the imported symbol is the same before and after
+- the import is a `from` import
+The argument is specified as `orig.mod=new.mod` or with an optional
+checked attribute `orig.mod=new.mod:attr`. The checked attribute is useful
+for renaming some imports from a module instead of a full module.
+For example:
+```bash
+# full module move
+--replace-import six.moves.queue=queue
+# specific attribute move
+--replace-import six.moves=io:StringIO
+```
+## Removing obsolete `__future__` imports
+The cli provides a few options to help "burn the bridges" with old python
+versions by removing `__future__` imports automatically. Each option implies
+all older versions.
+- `--py22-plus`: `nested_scopes`
+- `--py23-plus`: `generators`
+- `--py26-plus`: `with_statement`
+- `--py3-plus`: `division`, `absolute_import`, `print_function`,
+ `unicode_literals`
+- `--py37-plus`: `generator_stop`
+## Removing / rewriting obsolete `six` imports
+With `--py3-plus`, `reorder-python-imports` will also remove / rewrite imports
+from `six`. Rewrites follow the same rules as
+[replacing imports](#replacing-imports) above.
+For example:
+```diff
++import queue
++from io import StringIO
++from urllib.parse import quote_plus
++
+ import six.moves.urllib.parse
+-from six.moves import queue
+-from six.moves import range
+-from six.moves import StringIO
+-from six.moves.urllib.parse import quote_plus
+```
+## Rewriting mock imports
+With `--py3-plus`, `reorder-python-imports` will also rewrite various `mock` imports:
+```diff
+-from mock import patch
++from unittest.mock import patch
+```
+## Rewriting `mypy_extensions` and `typing_extension` imports
+With `--py36-plus` and higher, `reorder-python-imports` will also rewrite
+`mypy_extensions` and `typing_extensions` imports ported to `typing`.
+```diff
+-from mypy_extensions import TypedDict
++from typing import TypedDict
+```
+## Rewriting pep 585 typing imports
+With `--py39-plus` and higher, `reorder-python-imports` will replace imports
+which were moved out of the typing module in [pep 585].
+```diff
+-from typing import Sequence
++from collections.abc import Sequence
+```
+[pep 585]: https://www.python.org/dev/peps/pep-0585/
+
+%package -n python3-reorder-python-imports
+Summary: Tool for reordering python imports
+Provides: python-reorder-python-imports
+BuildRequires: python3-devel
+BuildRequires: python3-setuptools
+BuildRequires: python3-pip
+%description -n python3-reorder-python-imports
+Tool for automatically reordering python imports. Similar to `isort` but
+uses static analysis more.
+## Installation
+```bash
+pip install reorder-python-imports
+```
+## Console scripts
+Consult `reorder-python-imports --help` for the full set of options.
+`reorder-python-imports` takes filenames as positional arguments
+Common options:
+- `--py##-plus`: [see below](#removing-obsolete-__future__-imports).
+- `--add-import` / `--remove-import`: [see below](#adding--removing-imports).
+- `--replace-import`: [see below](#replacing-imports).
+- `--application-directories`: by default, `reorder-python-imports` assumes
+ your project is rooted at `.`. If this isn't true, tell it where your
+ import roots live. For example, when using the popular `./src` layout you'd
+ use `--application-directories=.:src` (note: multiple paths are separated
+ using a `:`).
+- `--unclassifiable-application-module`: (may be specified multiple times)
+ modules names that are considered application modules. this setting is
+ intended to be used for things like C modules which may not always appear on
+ the filesystem.
+## As a pre-commit hook
+See [pre-commit](https://github.com/pre-commit/pre-commit) for instructions
+Sample `.pre-commit-config.yaml`
+```yaml
+- repo: https://github.com/asottile/reorder_python_imports
+ rev: v3.9.0
+ hooks:
+ - id: reorder-python-imports
+```
+## What does it do?
+### Separates imports into three sections
+```python
+import sys
+import pyramid
+import reorder_python_imports
+```
+becomes (stdlib, third party, first party)
+```python
+import sys
+import pyramid
+import reorder_python_imports
+```
+### `import` imports before `from` imports
+```python
+from os import path
+import sys
+```
+becomes
+```python
+import sys
+from os import path
+```
+### Splits `from` imports
+```python
+from os.path import abspath, exists
+```
+becomes
+```python
+from os.path import abspath
+from os.path import exists
+```
+### Removes duplicate imports
+```python
+import os
+import os.path
+import sys
+import sys
+```
+becomes
+```python
+import os.path
+import sys
+```
+## Using `# noreorder`
+Lines containing and after lines which contain a `# noreorder` comment will
+be ignored. Additionally any imports that appear after non-whitespace
+non-comment lines will be ignored.
+For instance, these will not be changed:
+```python
+import sys
+try: # not import, not whitespace
+ import foo
+except ImportError:
+ pass
+```
+```python
+import sys
+import reorder_python_imports
+import matplotlib # noreorder
+matplotlib.use('Agg')
+import matplotlib.pyplot as plt
+```
+```python
+# noreorder
+import sys
+import pyramid
+import reorder_python_imports
+```
+## why this style?
+The style chosen by `reorder-python-imports` has a single aim: reduce merge
+conflicts.
+By having a single import per line, multiple contributors can
+add / remove imports from a single module without resulting in a conflict.
+Consider the following example which causes a merge conflict:
+```diff
+# developer 1
+-from typing import Dict, List
++from typing import Any, Dict, List
+```
+```diff
+# developer 2
+-from typing import Dict, List
++from typing import Dict, List, Tuple
+```
+no conflict with the style enforced by `reorder-python-imports`:
+```diff
++from typing import Any
+ from typing import Dict
+ from typing import List
++from typing import Tuple
+```
+## Adding / Removing Imports
+Let's say I want to enforce `absolute_import` across my codebase. I can use:
+`--add-import 'from __future__ import absolute_import'`.
+```console
+$ cat test.py
+print('Hello world')
+$ reorder-python-imports --add-import 'from __future__ import absolute_import' test.py
+Reordering imports in test.py
+$ cat test.py
+from __future__ import absolute_import
+print('Hello world')
+```
+Let's say I no longer care about supporting Python 2.5, I can remove
+`from __future__ import with_statement` with
+`--remove-import 'from __future__ import with_statement'`
+```console
+$ cat test.py
+from __future__ import with_statement
+with open('foo.txt', 'w') as foo_f:
+ foo_f.write('hello world')
+$ reorder-python-imports --remove-import 'from __future__ import with_statement' test.py
+Reordering imports in test.py
+$ cat test.py
+with open('foo.txt', 'w') as foo_f:
+ foo_f.write('hello world')
+```
+## Replacing imports
+Imports can be replaced with others automatically (if they provide the same
+names). This can be useful for factoring out compatibility libraries such
+as `six` (see below for automated `six` rewriting).
+This rewrite avoids `NameError`s as such it only occurs when:
+- the imported symbol is the same before and after
+- the import is a `from` import
+The argument is specified as `orig.mod=new.mod` or with an optional
+checked attribute `orig.mod=new.mod:attr`. The checked attribute is useful
+for renaming some imports from a module instead of a full module.
+For example:
+```bash
+# full module move
+--replace-import six.moves.queue=queue
+# specific attribute move
+--replace-import six.moves=io:StringIO
+```
+## Removing obsolete `__future__` imports
+The cli provides a few options to help "burn the bridges" with old python
+versions by removing `__future__` imports automatically. Each option implies
+all older versions.
+- `--py22-plus`: `nested_scopes`
+- `--py23-plus`: `generators`
+- `--py26-plus`: `with_statement`
+- `--py3-plus`: `division`, `absolute_import`, `print_function`,
+ `unicode_literals`
+- `--py37-plus`: `generator_stop`
+## Removing / rewriting obsolete `six` imports
+With `--py3-plus`, `reorder-python-imports` will also remove / rewrite imports
+from `six`. Rewrites follow the same rules as
+[replacing imports](#replacing-imports) above.
+For example:
+```diff
++import queue
++from io import StringIO
++from urllib.parse import quote_plus
++
+ import six.moves.urllib.parse
+-from six.moves import queue
+-from six.moves import range
+-from six.moves import StringIO
+-from six.moves.urllib.parse import quote_plus
+```
+## Rewriting mock imports
+With `--py3-plus`, `reorder-python-imports` will also rewrite various `mock` imports:
+```diff
+-from mock import patch
++from unittest.mock import patch
+```
+## Rewriting `mypy_extensions` and `typing_extension` imports
+With `--py36-plus` and higher, `reorder-python-imports` will also rewrite
+`mypy_extensions` and `typing_extensions` imports ported to `typing`.
+```diff
+-from mypy_extensions import TypedDict
++from typing import TypedDict
+```
+## Rewriting pep 585 typing imports
+With `--py39-plus` and higher, `reorder-python-imports` will replace imports
+which were moved out of the typing module in [pep 585].
+```diff
+-from typing import Sequence
++from collections.abc import Sequence
+```
+[pep 585]: https://www.python.org/dev/peps/pep-0585/
+
+%package help
+Summary: Development documents and examples for reorder-python-imports
+Provides: python3-reorder-python-imports-doc
+%description help
+Tool for automatically reordering python imports. Similar to `isort` but
+uses static analysis more.
+## Installation
+```bash
+pip install reorder-python-imports
+```
+## Console scripts
+Consult `reorder-python-imports --help` for the full set of options.
+`reorder-python-imports` takes filenames as positional arguments
+Common options:
+- `--py##-plus`: [see below](#removing-obsolete-__future__-imports).
+- `--add-import` / `--remove-import`: [see below](#adding--removing-imports).
+- `--replace-import`: [see below](#replacing-imports).
+- `--application-directories`: by default, `reorder-python-imports` assumes
+ your project is rooted at `.`. If this isn't true, tell it where your
+ import roots live. For example, when using the popular `./src` layout you'd
+ use `--application-directories=.:src` (note: multiple paths are separated
+ using a `:`).
+- `--unclassifiable-application-module`: (may be specified multiple times)
+ modules names that are considered application modules. this setting is
+ intended to be used for things like C modules which may not always appear on
+ the filesystem.
+## As a pre-commit hook
+See [pre-commit](https://github.com/pre-commit/pre-commit) for instructions
+Sample `.pre-commit-config.yaml`
+```yaml
+- repo: https://github.com/asottile/reorder_python_imports
+ rev: v3.9.0
+ hooks:
+ - id: reorder-python-imports
+```
+## What does it do?
+### Separates imports into three sections
+```python
+import sys
+import pyramid
+import reorder_python_imports
+```
+becomes (stdlib, third party, first party)
+```python
+import sys
+import pyramid
+import reorder_python_imports
+```
+### `import` imports before `from` imports
+```python
+from os import path
+import sys
+```
+becomes
+```python
+import sys
+from os import path
+```
+### Splits `from` imports
+```python
+from os.path import abspath, exists
+```
+becomes
+```python
+from os.path import abspath
+from os.path import exists
+```
+### Removes duplicate imports
+```python
+import os
+import os.path
+import sys
+import sys
+```
+becomes
+```python
+import os.path
+import sys
+```
+## Using `# noreorder`
+Lines containing and after lines which contain a `# noreorder` comment will
+be ignored. Additionally any imports that appear after non-whitespace
+non-comment lines will be ignored.
+For instance, these will not be changed:
+```python
+import sys
+try: # not import, not whitespace
+ import foo
+except ImportError:
+ pass
+```
+```python
+import sys
+import reorder_python_imports
+import matplotlib # noreorder
+matplotlib.use('Agg')
+import matplotlib.pyplot as plt
+```
+```python
+# noreorder
+import sys
+import pyramid
+import reorder_python_imports
+```
+## why this style?
+The style chosen by `reorder-python-imports` has a single aim: reduce merge
+conflicts.
+By having a single import per line, multiple contributors can
+add / remove imports from a single module without resulting in a conflict.
+Consider the following example which causes a merge conflict:
+```diff
+# developer 1
+-from typing import Dict, List
++from typing import Any, Dict, List
+```
+```diff
+# developer 2
+-from typing import Dict, List
++from typing import Dict, List, Tuple
+```
+no conflict with the style enforced by `reorder-python-imports`:
+```diff
++from typing import Any
+ from typing import Dict
+ from typing import List
++from typing import Tuple
+```
+## Adding / Removing Imports
+Let's say I want to enforce `absolute_import` across my codebase. I can use:
+`--add-import 'from __future__ import absolute_import'`.
+```console
+$ cat test.py
+print('Hello world')
+$ reorder-python-imports --add-import 'from __future__ import absolute_import' test.py
+Reordering imports in test.py
+$ cat test.py
+from __future__ import absolute_import
+print('Hello world')
+```
+Let's say I no longer care about supporting Python 2.5, I can remove
+`from __future__ import with_statement` with
+`--remove-import 'from __future__ import with_statement'`
+```console
+$ cat test.py
+from __future__ import with_statement
+with open('foo.txt', 'w') as foo_f:
+ foo_f.write('hello world')
+$ reorder-python-imports --remove-import 'from __future__ import with_statement' test.py
+Reordering imports in test.py
+$ cat test.py
+with open('foo.txt', 'w') as foo_f:
+ foo_f.write('hello world')
+```
+## Replacing imports
+Imports can be replaced with others automatically (if they provide the same
+names). This can be useful for factoring out compatibility libraries such
+as `six` (see below for automated `six` rewriting).
+This rewrite avoids `NameError`s as such it only occurs when:
+- the imported symbol is the same before and after
+- the import is a `from` import
+The argument is specified as `orig.mod=new.mod` or with an optional
+checked attribute `orig.mod=new.mod:attr`. The checked attribute is useful
+for renaming some imports from a module instead of a full module.
+For example:
+```bash
+# full module move
+--replace-import six.moves.queue=queue
+# specific attribute move
+--replace-import six.moves=io:StringIO
+```
+## Removing obsolete `__future__` imports
+The cli provides a few options to help "burn the bridges" with old python
+versions by removing `__future__` imports automatically. Each option implies
+all older versions.
+- `--py22-plus`: `nested_scopes`
+- `--py23-plus`: `generators`
+- `--py26-plus`: `with_statement`
+- `--py3-plus`: `division`, `absolute_import`, `print_function`,
+ `unicode_literals`
+- `--py37-plus`: `generator_stop`
+## Removing / rewriting obsolete `six` imports
+With `--py3-plus`, `reorder-python-imports` will also remove / rewrite imports
+from `six`. Rewrites follow the same rules as
+[replacing imports](#replacing-imports) above.
+For example:
+```diff
++import queue
++from io import StringIO
++from urllib.parse import quote_plus
++
+ import six.moves.urllib.parse
+-from six.moves import queue
+-from six.moves import range
+-from six.moves import StringIO
+-from six.moves.urllib.parse import quote_plus
+```
+## Rewriting mock imports
+With `--py3-plus`, `reorder-python-imports` will also rewrite various `mock` imports:
+```diff
+-from mock import patch
++from unittest.mock import patch
+```
+## Rewriting `mypy_extensions` and `typing_extension` imports
+With `--py36-plus` and higher, `reorder-python-imports` will also rewrite
+`mypy_extensions` and `typing_extensions` imports ported to `typing`.
+```diff
+-from mypy_extensions import TypedDict
++from typing import TypedDict
+```
+## Rewriting pep 585 typing imports
+With `--py39-plus` and higher, `reorder-python-imports` will replace imports
+which were moved out of the typing module in [pep 585].
+```diff
+-from typing import Sequence
++from collections.abc import Sequence
+```
+[pep 585]: https://www.python.org/dev/peps/pep-0585/
+
+%prep
+%autosetup -n reorder-python-imports-3.9.0
+
+%build
+%py3_build
+
+%install
+%py3_install
+install -d -m755 %{buildroot}/%{_pkgdocdir}
+if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
+if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
+if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
+if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
+pushd %{buildroot}
+if [ -d usr/lib ]; then
+ find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
+fi
+if [ -d usr/lib64 ]; then
+ find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
+fi
+if [ -d usr/bin ]; then
+ find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
+fi
+if [ -d usr/sbin ]; then
+ find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
+fi
+touch doclist.lst
+if [ -d usr/share/man ]; then
+ find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
+fi
+popd
+mv %{buildroot}/filelist.lst .
+mv %{buildroot}/doclist.lst .
+
+%files -n python3-reorder-python-imports -f filelist.lst
+%dir %{python3_sitelib}/*
+
+%files help -f doclist.lst
+%{_docdir}/*
+
+%changelog
+* Tue Apr 11 2023 Python_Bot <Python_Bot@openeuler.org> - 3.9.0-1
+- Package Spec generated
diff --git a/sources b/sources
new file mode 100644
index 0000000..9851fff
--- /dev/null
+++ b/sources
@@ -0,0 +1 @@
+c7e7488f9711d0b562eda61fbf9cece5 reorder_python_imports-3.9.0.tar.gz