peterbe / hashin

Helping you write hashed entries for packages in your requirements.txt
https://www.peterbe.com/plog/hashin
MIT License
105 stars 27 forks source link

Handle indentation #112

Closed techtonik closed 5 years ago

techtonik commented 5 years ago

Would be nice if hashin could handle indented files like this one:

https://github.com/liberapay/liberapay.com/blob/master/requirements_base.txt

boto3==1.9.85 \
    --hash=sha256:acfd27967cf1ba7f9d83ad6fc2011764541e4c295fe0d896ea7b495cc2f03336 \
    --hash=sha256:96296871863e0245b04931df7dd5c583e53cadbe1d54197829b34b03b0d048a8

    botocore==1.12.85 \
        --hash=sha256:af727d4af0cf1ddbf84eaf1cc9d0160ff066eac7f9e6a2fe6a75ccbed4452c98 \
        --hash=sha256:c381fd05b777f41a608ea0846a8d8ecc32077a83e456d05e824cce8d6b213e32

Right now it just inserts a new entry below:

$ hashin -r ../../../requirements_base.txt botocore -d
--- Old
+++ New
@@ -258,3 +258,6 @@
     asn1crypto==0.24.0 \
         --hash=sha256:2f1adbb7546ed199e3c90ef23ec95c5cf3585bac7d11fb7eb562a3fe89c64e87 \
         --hash=sha256:9d5c20441baf0cb60a4ac34cc447c6c189024b6b4c6cd7877034f4965c464e49
+botocore==1.12.221 \
+    --hash=sha256:6d49deff062d2ae0f03fc26b56df8b1bb9e8b136657bcd8d84c986a4068fb784 \
+    --hash=sha256:bbee3fdcbe56ca53e2c32c6c12d174fa9b4ffe27b633183c29bd5aec9e200bae
peterbe commented 5 years ago

What are those indentations? Is that something you maintain manually? I guess you could write a function that, when iterating over the existing lines, keeps a variable filled with the found current indentation.

techtonik commented 5 years ago

Yep, it appeared that indentations are manual - https://github.com/liberapay/liberapay.com/issues/1566#issuecomment-527623500

I am working on a patch. It already works, but needs a refactor - #114.

techtonik commented 5 years ago

Refactored a bit. I think it is ready now.

peterbe commented 5 years ago

Released version 0.14.6 for this.