Skip to content

Commit

Permalink
chore: pull in CI config from poetry, reformat as needed
Browse files Browse the repository at this point in the history
  • Loading branch information
neersighted committed Sep 7, 2022
1 parent 9b64f71 commit 860c569
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 54 deletions.
20 changes: 18 additions & 2 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
[flake8]
max-line-length = 88
ignore = E501, E203, W503
min_python_version = 3.6.0
max-line-length = 120
ban-relative-imports = true
# flake8-use-fstring: https://github.com/MichaelKim0407/flake8-use-fstring#--percent-greedy-and---format-greedy
format-greedy = 0
inline-quotes = double
enable-extensions = TC, TC1
type-checking-exempt-modules = typing, typing-extensions
eradicate-whitelist-extend = ^-.*;
extend-ignore =
# E203: Whitespace before ':' (pycqa/pycodestyle#373)
E203,
# SIM106: Handle error-cases first
SIM106,
# ANN101: Missing type annotation for self in method
ANN101,
# ANN102: Missing type annotation for cls in classmethod
ANN102,
80 changes: 59 additions & 21 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,34 +1,72 @@
ci:
autofix_prs: false

repos:
- repo: https://github.com/psf/black
rev: 22.8.0
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: black
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-merge-conflict
- id: check-case-conflict
- id: check-json
- id: check-toml
- id: check-yaml
- id: pretty-format-json
args: [--autofix, --no-ensure-ascii, --no-sort-keys]
- id: check-ast
- id: debug-statements
- id: check-docstring-first

- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.9.0
hooks:
- id: flake8
additional_dependencies:
- id: python-check-mock-methods
- id: python-use-type-annotations
- id: python-check-blanket-noqa

- repo: https://github.com/asottile/yesqa
rev: v1.4.0
hooks:
- id: yesqa
additional_dependencies: &flake8_deps
# - flake8-annotations==2.9.0
- flake8-broken-line==0.5.0
- flake8-bugbear==22.7.1
- flake8-comprehensions==3.10.0
- flake8-eradicate==1.3.0
- flake8-quotes==3.3.1
- flake8-simplify==0.19.3
- flake8-tidy-imports==4.8.0
- flake8-type-checking==2.1.2
- flake8-typing-imports==1.12.0
- flake8-use-fstring==1.4
- pep8-naming==0.13.1

- repo: https://github.com/PyCQA/isort
- repo: https://github.com/asottile/pyupgrade
rev: v2.37.3
hooks:
- id: pyupgrade
args: [--py36-plus]

- repo: https://github.com/hadialqattan/pycln
rev: v2.1.1
hooks:
- id: pycln
args: [--all]

- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
- repo: https://github.com/psf/black
rev: 22.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: debug-statements
- id: pretty-format-json
args:
- --autofix
- id: check-json
- id: black

- repo: https://github.com/asottile/pyupgrade
rev: v2.34.0
- repo: https://github.com/pycqa/flake8
rev: 5.0.4
hooks:
- id: pyupgrade
args: [--py36-plus]
- id: flake8
additional_dependencies: *flake8_deps
45 changes: 19 additions & 26 deletions install-poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
It will perform the following steps:
* Create a new virtual environment using the built-in venv module, or the virtualenv zipapp if venv is unavailable.
This will be created at a platform-specific path (or `$POETRY_HOME` if `$POETRY_HOME` is set:
This will be created at a platform-specific path (or `$POETRY_HOME` if set):
- `~/Library/Application Support/pypoetry` on macOS
- `$XDG_DATA_HOME/pypoetry` on Linux/Unix (`$XDG_DATA_HOME` is `~/.local/share` if unset)
- `$XDG_DATA_HOME/pypoetry` on Linux/Unix (`XDG_DATA_HOME` is `~/.local/share` by default)
- `%APPDATA%\pypoetry` on Windows
* Update pip inside the virtual environment to avoid bugs in older versions.
* Install the latest (or a given) version of Poetry inside this virtual environment using pip.
Expand Down Expand Up @@ -90,7 +90,7 @@ def style(fg, bg, options):
for option in options:
codes.append(OPTIONS[option])

return "\033[{}m".format(";".join(map(str, codes)))
return f"\033[{';'.join(map(str, codes))}m"


STYLES = {
Expand All @@ -107,8 +107,8 @@ def is_decorated():
if WINDOWS:
return (
os.getenv("ANSICON") is not None
or "ON" == os.getenv("ConEmuANSI")
or "xterm" == os.getenv("Term")
or os.getenv("ConEmuANSI") == "ON"
or os.getenv("Term") == "xterm"
)

if not hasattr(sys.stdout, "fileno"):
Expand Down Expand Up @@ -532,8 +532,9 @@ def _is_self_upgrade_supported(x):
self._write(
colorize(
"warning",
f"You are installing {version}. When using the current installer, this version does not support "
f"updating using the 'self update' command. Please use 1.1.7 or later.",
f"You are installing {version}. When using the current installer,"
" this version does not support updating using the 'self update'"
" command. Please use 1.1.7 or later.",
)
)
if not self._accept_all:
Expand All @@ -558,9 +559,7 @@ def install(self, version):
Installs Poetry in $POETRY_HOME.
"""
self._write(
"Installing {} ({})".format(
colorize("info", "Poetry"), colorize("info", version)
)
f"Installing {colorize('info', 'Poetry')} ({colorize('info', version)})"
)

with self.make_env(version) as env:
Expand All @@ -573,9 +572,7 @@ def install(self, version):

def uninstall(self) -> int:
if not self.data_dir.exists():
self._write(
"{} is not currently installed.".format(colorize("info", "Poetry"))
)
self._write(f"{colorize('info', 'Poetry')} is not currently installed.")

return 1

Expand All @@ -585,12 +582,10 @@ def uninstall(self) -> int:

if version:
self._write(
"Removing {} ({})".format(
colorize("info", "Poetry"), colorize("b", version)
)
f"Removing {colorize('info', 'Poetry')} ({colorize('b', version)})"
)
else:
self._write("Removing {}".format(colorize("info", "Poetry")))
self._write(f"Removing {colorize('info', 'Poetry')}")

shutil.rmtree(str(self.data_dir))
for script in ["poetry", "poetry.bat", "poetry.exe"]:
Expand All @@ -601,11 +596,8 @@ def uninstall(self) -> int:

def _install_comment(self, version: str, message: str):
self._overwrite(
"Installing {} ({}): {}".format(
colorize("info", "Poetry"),
colorize("b", version),
colorize("comment", message),
)
f"Installing {colorize('info', 'Poetry')} ({colorize('b', version)}):"
f" {colorize('comment', message)}"
)

@contextmanager
Expand Down Expand Up @@ -708,11 +700,12 @@ def display_post_message_windows(self, version: str) -> None:
def get_windows_path_var(self) -> Optional[str]:
import winreg

with winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER) as root:
with winreg.OpenKey(root, "Environment", 0, winreg.KEY_ALL_ACCESS) as key:
path, _ = winreg.QueryValueEx(key, "PATH")
with winreg.ConnectRegistry(
None, winreg.HKEY_CURRENT_USER
) as root, winreg.OpenKey(root, "Environment", 0, winreg.KEY_ALL_ACCESS) as key:
path, _ = winreg.QueryValueEx(key, "PATH")

return path
return path

def display_post_message_fish(self, version: str) -> None:
fish_user_paths = subprocess.check_output(
Expand Down
10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[tool.isort]
py_version = 36
profile = "black"
force_single_line = true
atomic = true
lines_after_imports = 2
combine_as_imports = true
lines_between_types = 1
filter_files = true
lines_after_imports = 2


[tool.black]
line-length = 88
include = '\.pyi?$'
target-version = ['py36']
preview = true

0 comments on commit 860c569

Please sign in to comment.