• spuds_in_town@fediverser.communick.devB
        link
        fedilink
        English
        arrow-up
        1
        ·
        1 year ago

        Yeah I get it that it’s one of -those- issues. I can live with the trailing comma at the end of a line, but a trailing comma on its own line triggers me badly, it tells my subconscious that “something is missing here”.

        I understand the argument around diffs, but I spend way longer looking at code than I do diffs of code.

        • anentropic@fediverser.communick.devB
          link
          fedilink
          English
          arrow-up
          1
          ·
          1 year ago

          (Replying just for the chit chat - no criticism of opposite views implied)

          For me it’s not even about the diffs, but like if you want to bulk edit the lines with a multi cursor, or copy and paste to add some new lines, it helps if they’re all uniform

            • anentropic@fediverser.communick.devB
              link
              fedilink
              English
              arrow-up
              1
              ·
              1 year ago

              I’m sorry you got downvoted, I totally get that trailing commas are ‘grammatically’ wrong and would look weird.

              But I find these kind of common edits a bit of a pain in formats like JSON or SQL which don’t allow trailing comma. So I was happy to use a linter which enforces them, and then I got very used to them being there.

    • muntoo@fediverser.communick.devB
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 year ago

      Trailing commas:

      1. generate cleaner diffs,
      2. facilitate reordering,
      3. facilitate adding a new item at the end without needing to edit the previous one,
      4. are visually consistent,
      • Ph0X@fediverser.communick.devB
        link
        fedilink
        English
        arrow-up
        1
        ·
        1 year ago

        I know some people love Black for its lack of configuration, but if Ruff adds a couple more config, then it’ll definitely be my go to formatter.

        I’m not about to fuck up my entire projects formatting to match one persons opinion.

    • theAndrewWiggins@fediverser.communick.devB
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 year ago

      I’m personally using pixi and ruff. Pixi is the first tool in the python ecosystem to solve all my package management woes (and runs fast). They’re conda based though (but they’re working on doing solves across pypi and conda).

    • fatbob42@fediverser.communick.devB
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 year ago

      I don’t think that’s significantly CPU-bound, although you can certainly slow it down with a bad dependency-resolution algorithm (as pipenv did).

        • epage@fediverser.communick.devB
          link
          fedilink
          English
          arrow-up
          1
          ·
          1 year ago

          The question isn’t a matter of creating a unified tool but of figuring out why past attempts (e.g. poetry) haven’t taken off more and if those problems can be avoided.

            • theAndrewWiggins@fediverser.communick.devB
              link
              fedilink
              English
              arrow-up
              1
              ·
              1 year ago

              I see typechecking as the next natural extension to this. Won’t be easy, it’s probably the trickiest thing to do well, but it would be the ultimate python tool if it did that. It’s a natural extension point as well, since they have the parsing down.

            • epage@fediverser.communick.devB
              link
              fedilink
              English
              arrow-up
              1
              ·
              1 year ago

              For me, a big problem with poetry is the author’s insistence on being as strict as cargo on dependency resolution when the Python ecosystem doesn’t have the culture to go with it. You need to be able to override bad transitive dependencies.

        • SuspiciousScript@fediverser.communick.devB
          link
          fedilink
          English
          arrow-up
          1
          ·
          1 year ago

          It’s not about the speed, which is trivial

          Tell that to Anaconda/Poetry. If I remember correctly, there’s some deficiency with Python packaging that makes dependency solving harder for than it is for other languages.

          • muntoo@fediverser.communick.devB
            link
            fedilink
            English
            arrow-up
            1
            ·
            1 year ago

            I believe it’s because when the metadata is missing, you need to download the entire package and try installing it to check compatibility.

            Of course, this could still be mitigated by generating metadata / precomputing dependencies, or creating and hosting “mini” package proxies for dependency resolution only for the big packages, or many other engineering solutions, if the poetry devs were sufficiently motivated.

            No one’s saying that we have to solve the Halting Problem (or similar) to get massive speedups in many cases.

            • SuspiciousScript@fediverser.communick.devB
              link
              fedilink
              English
              arrow-up
              1
              ·
              1 year ago

              I believe it’s because when the metadata is missing, you need to download each version of an entire massive package and try installing it to check compatibility. Repeated for every possible version, backwards until one works.

              I think you’re right; that definitely seems to be poetry’s behaviour. So that’s clearly IO-bound. On the other hand, Anaconda got massive speedups by switching to a better dependency solver. Dependency resolution is basically SAT, after all.

    • Mezzos@fediverser.communick.devB
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 year ago

      I’ve been largely avoiding Black for years, purely because I’m obsessive about coding style and I love how clean Python looks with single quotes (I understand why they made the choice to enforce one style, but I’ve discovered I can be very stubborn!). I would always use linters to check for PEP8 violations, but I’d then fix the style myself.

      Unironically the fact that the Ruff autoformatter allows single quotes has made the difference in convincing me to adopt it (although it also helps that Ruff is already my preferred linter!).

    • jackerhack@fediverser.communick.devB
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 year ago

      I use Black with quote normalisation disabled. My projects have a rule about string quotes:

      1. Single quotes for symbols that must be an exact match for a symbol elsewhere. Dict hashes, equality match, etc. These will be in API contracts (think JSON APIs), so any change will require care.

      2. Double quotes for user-facing strings, including friendly error/warning messages and i18n strings. These are meant to be periodically revised to improve usability.

      3. Exceptions are allowed when a string contains quote characters. Backslash escapes are uglier.

      Quote normalisation makes it harder for developers to recognise the purpose of a string.

  • GrumpyZer0@fediverser.communick.devB
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    I have a question for all of you fine folks here. I use a library (aws-cdk-lib) that has objects that take many many keyword arguments. We usually put each argument on its own line. I’ve found that these are much easier to read with spaces around the equal sign. But I’ve never seen this mentioned anywhere when looking at formatters. Is this just me? Or is this something that some formatters support?

  • Beliskner64@fediverser.communick.devB
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    Question: Black has Darker for formatting just the code in a diff. Does Ruff have something similar? I want to start using it in my CI pipelines, but I don’t too much noise when changing just a small part of a large module.

    • alexisprince@fediverser.communick.devB
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 year ago

      Genuine question, do you have a reason for not just formatting the entire codebase in a single commit and adding that commit to the a .git-blame-ignore-revs file for maintaining a still useful ability to blame through your history?

      • its_a_gibibyte@fediverser.communick.devB
        link
        fedilink
        English
        arrow-up
        1
        ·
        1 year ago

        Anyone in a decent size company that wants to start improving their code formatting without going through the steps to get permission to change “everyone else’s code”.

        Similarly, it bothers me that Black doesn’t support range formatting (Darker is an independent project). They’ve basically told everyone to format the whole file or leave.

        • ErikBjare@fediverser.communick.devB
          link
          fedilink
          English
          arrow-up
          1
          ·
          1 year ago

          They’ve basically told everyone to format the whole file or leave.

          Which is totally understandable, if you know how Black works. The Darker authors themselves cite “good reasons” why black doesn’t in their README.

      • Beliskner64@fediverser.communick.devB
        link
        fedilink
        English
        arrow-up
        1
        ·
        1 year ago

        There are several reasons:

        1. As many people are working on the same codebase simultaneously, reformatting the whole thing will create many conflicts
        2. There are still some places where Black’s formatting in undesired (especially in DS/ML code where you may find data structures formatted as a matrix) and we’d want to exclude those either via configuration, or with the # fmt: off/on comment directives, but I’ll only see those when I review them in a PR. If I reformat the entire project in one commit it will be harder to spot.
        3. As Black is evolving so may the formatting, or maybe we’ll change some default configuration in the future (like string normalization) and then I’d have to reformat the whole thing again.
          • Beliskner64@fediverser.communick.devB
            link
            fedilink
            English
            arrow-up
            1
            ·
            1 year ago

            Works, yes. But I’m talking about formatting that just looks wrong with black. Try format something like a long enough numpy matrix, pandas dataframe, or just a list of lists, and you’ll see how black just makes things unreadable.

  • TravisJungroth@fediverser.communick.devB
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    This is awesome. Ruff is quickly becoming one tool that will cover 80% of projects just with the defaults. I know a lot of people need other very fancy rules and a ton of config, but a lot of projects don’t.

    • james_pic@fediverser.communick.devB
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 year ago

      TBH, I’ve worked with people who have very fancy rules and a ton of config, but I’ve never been convinced they need them. It usually either stems from the tools they’re using not having good defaults, or from the people themselves being total control freaks. Black’s superpower is its ability to completely shut down discussions with control freaks.

  • binaryriot@fediverser.communick.devB
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    I have to admit… compared to some older ruff I had on disk it now reports like double of “errors”. 99% of them irrelevant to actual issues. It’s over reporting silly things so much it has become useless to use. It may or may not report something critical between all the noise, but it’s hard to see the tree because of the forest, so to speak.

    I guess this is that new “black” stuff?


    If I was to make my code compatible to what it wants I couldn’t use/read it anymore. :) Probably my programs would stop working too:

    T201 `print` found
    

    I guess I have to comment that out.

    ERA001 Found commented-out code
    

    Oups. I guess I just rm *.py to fix the madness. 😎

    • Gloomy-Fix-4393@fediverser.communick.devB
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 year ago

      sounds like you haven’t learned most of what is being taught by the greats such as Uncle Bob and his clean code talks.

      print() in almost every case should probably be logger.log() if it is important.

      comments, doc strings aside, are usually (almost always?) a “code smell”.

      • binaryriot@fediverser.communick.devB
        link
        fedilink
        English
        arrow-up
        1
        ·
        1 year ago

        “Clean code” is always about preference. I like code I can read and understand. If I want extra comments or keep some commented code to make a thought process about a coding decision more clear then that’s not a bad thing, IMHO.

        And if print() is such a bad thing, why wasn’t it deprecated for Python 3? Again this probably just comes down to preference again. I just print a final result of a program to stdout (which can be binary data, or some SVG, or just some lines of information). That has nothing to do with “logging”, IMHO.

        I don’t know who Uncle Bob is. 😳

      • binaryriot@fediverser.communick.devB
        link
        fedilink
        English
        arrow-up
        1
        ·
        1 year ago

        My projects are usually just standalone scripts, so no pyproject.toml.

        I use a global “.pylintrc” in my home directory for pylint, which I occasionally copy over to project folders that get synced to public github repositories, but that’s it.

        Personally I would prefer this to be just the .py file, not all the other fluff one needs to add: https://github.com/the-real-tokai/grablinks

        • legobmw99@fediverser.communick.devB
          link
          fedilink
          English
          arrow-up
          1
          ·
          1 year ago

          I think that one off standalone scripts are probably not the use case linters (especially ones like ruff that prioritize speed on large code bases) have in mind

    • Rand_alThor_@fediverser.communick.devB
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 year ago

      You enable all Rules on a personal project? Why?

      Anyway time for you to get some humbleness and realize the fault lies with the person in the chair. You. Not even reading the first page of the documentation or following it learning best practices to pick or not pick. Then coming a making an obviously uninformed comment.

      https://en.m.wiktionary.org/wiki/PEBCAK

      Btw both of those seem like useful errors.

    • ogtfo@fediverser.communick.devB
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 year ago

      If your project has a significant enough scope that a tool like ruff is warranted, you really should have proposer logging setup instead of print statement, and you should be relying on your version control instead of commenting out code.

      • binaryriot@fediverser.communick.devB
        link
        fedilink
        English
        arrow-up
        1
        ·
        1 year ago

        I only experimented with it briefly (the old version and the new version I downloaded today). I don’t remember configuring anything, so I assume it runs like that by default:

        $ ruff config
        allowed-confusables
        builtins
        cache-dir
        dummy-variable-rgx
        exclude
        extend
        extend-exclude
        extend-ignore
        extend-select
        external
        fix
        fix-only
        fixable
        format
        force-exclude
        ignore
        ignore-init-module-imports
        line-length
        required-version
        respect-gitignore
        select
        show-source
        show-fixes
        src
        namespace-packages
        target-version
        task-tags
        typing-modules
        unfixable
        update-check
        flake8-annotations
        flake8-bandit
        flake8-bugbear
        flake8-builtins
        flake8-comprehensions
        flake8-errmsg
        flake8-quotes
        flake8-self
        flake8-tidy-imports
        flake8-type-checking
        flake8-gettext
        flake8-implicit-str-concat
        flake8-import-conventions
        flake8-pytest-style
        flake8-unused-arguments
        isort
        mccabe
        pep8-naming
        pycodestyle
        pydocstyle
        pylint
        pyupgrade
        per-file-ignores
        

        Certainly this will become more useful toned down to sane limits, but it needs time/ research/ reading lots of documentation(?) to sort that out. A more sane default would be nice, IMHO.

          • binaryriot@fediverser.communick.devB
            link
            fedilink
            English
            arrow-up
            1
            ·
            1 year ago

            That’s interesting.

            After some digging I found a “ruff.toml” in an unusual place for a unix’y command line tool (~/Library/Application Support/ruff/ruff.toml)

            select = ["ALL"]
            ignore = []
            fixable = []
            unfixable = []
            

            I don’t know what put it there, certainly not my doing as far as I can remember. But that explains some things, I guess. 😱