Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle indentation #112

Closed
techtonik opened this issue Sep 3, 2019 · 4 comments · Fixed by #114
Closed

Handle indentation #112

techtonik opened this issue Sep 3, 2019 · 4 comments · Fixed by #114

Comments

@techtonik
Copy link
Contributor

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
Copy link
Owner

peterbe commented Sep 3, 2019

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 added a commit to techtonik/hashin that referenced this issue Sep 4, 2019
techtonik added a commit to techtonik/hashin that referenced this issue Sep 4, 2019
@techtonik
Copy link
Contributor Author

Yep, it appeared that indentations are manual - liberapay/liberapay.com#1566 (comment)

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

@techtonik
Copy link
Contributor Author

Refactored a bit. I think it is ready now.

peterbe pushed a commit that referenced this issue Sep 5, 2019
* Support indented requirements (fixes #112)

* Refactor amend_requirements_content()

Remove duplicate code from is_different_lines().

* Indent only non-empty lines

* Refactor and make linter happy

Rename new_lines to new_text where it is not list

* Add test for indented spec
@peterbe
Copy link
Owner

peterbe commented Sep 5, 2019

Released version 0.14.6 for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants