-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from MichaelKim0407/develop
release 1.1
- Loading branch information
Showing
12 changed files
with
192 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# This workflows will upload a Python Package using Twine when a release is created | ||
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries | ||
|
||
name: Upload Python Package | ||
|
||
on: | ||
release: | ||
types: [created] | ||
|
||
jobs: | ||
deploy: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.x' | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install setuptools twine | ||
- name: Build and publish | ||
env: | ||
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} | ||
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} | ||
run: | | ||
python setup.py sdist | ||
twine upload dist/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,5 +16,8 @@ dist/ | |
.pytest_cache/ | ||
.coverage | ||
|
||
# mypy | ||
.mypy_cache/ | ||
|
||
# System | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = '1.0' | ||
__version__ = '1.1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import re as _re | ||
import token as _token | ||
|
||
from flake8.options.manager import ( | ||
OptionManager as _OptionManager, | ||
) | ||
|
||
from .base import ( | ||
BaseLogicalLineChecker as _Base, | ||
) | ||
|
||
FSTRING_REGEX = _re.compile(r'^([a-zA-Z]*?[fF][a-zA-Z]*?){1}["\']') | ||
NON_FSTRING_REGEX = _re.compile( | ||
r'^[a-zA-Z]*(?:\'\'\'|\'|"""|")(.*?{.+?}.*)(?:\'|\'\'\'|"|""")$', | ||
) | ||
|
||
|
||
class MissingPrefixDetector(_Base): | ||
name = 'use-fstring-prefix' | ||
version = '1.0' | ||
ignore_format = False | ||
off_by_default = True | ||
|
||
def __getitem__(self, i: int) -> bool: | ||
token = self.tokens[i] | ||
if token.exact_type != _token.STRING: | ||
return False | ||
|
||
if FSTRING_REGEX.search(token.string): # already is an f-string | ||
return False | ||
|
||
if not self.ignore_format: | ||
# look ahead for % or .format and skip if present | ||
for next_i, next_token in enumerate(self.tokens[i + 1:], i + 1): | ||
if next_token.exact_type == _token.STRING: | ||
continue | ||
if next_token.exact_type == _token.PERCENT: | ||
return False | ||
if next_token.exact_type == _token.DOT: | ||
try: | ||
next_token = self.tokens[next_i + 1] | ||
if next_token.exact_type != _token.NAME: | ||
break | ||
if next_token.string == 'format': | ||
return False | ||
except IndexError: | ||
pass | ||
break | ||
|
||
value = token.string.replace('{{', '').replace('}}', '') | ||
return NON_FSTRING_REGEX.search(value) is not None | ||
|
||
def __call__(self, i: int) -> str: | ||
return 'FS003 f-string missing prefix' | ||
|
||
@classmethod | ||
def add_options(cls, option_manager: _OptionManager): | ||
option_manager.add_option( | ||
f'--{cls.OPTION_NAME}', | ||
action='store_true', | ||
default=False, | ||
parse_from_config=True, | ||
) | ||
|
||
@classmethod | ||
def parse_options(cls, options): | ||
option_var = cls.OPTION_NAME.replace('-', '_') | ||
cls.ignore_format = vars(options)[option_var] | ||
|
||
OPTION_NAME = 'fstring-ignore-format' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters