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

Add a Python code formatter #38

Closed
2 tasks done
berinhard opened this issue Nov 20, 2019 · 11 comments
Closed
2 tasks done

Add a Python code formatter #38

berinhard opened this issue Nov 20, 2019 · 11 comments
Assignees
Labels
good first issue Good for newcomers

Comments

@berinhard
Copy link
Member

berinhard commented Nov 20, 2019

We should add Black to enforce some code styles to improve legibility and maintenance.

  • Add Black as a development requirement
  • Add it to the pre-commit config
@anapaulagomes
Copy link
Contributor

Nice! I think would be nice to add it to Travis as well, @berinhard.

@anapaulagomes anapaulagomes added the good first issue Good for newcomers label Nov 21, 2019
@anapaulagomes anapaulagomes self-assigned this Nov 21, 2019
@giovana-morais
Copy link
Contributor

hey there! i've talked to @anapaulagomes and i'd like to take this issue. (:

@berinhard
Copy link
Member Author

Sure @giovana-morais! Feel free to tackle this one and thanks for your help 👍

@giovana-morais
Copy link
Contributor

hey @berinhard and @anapaulagomes !
I've just added black to our pre-commit file, tested it and some files were reformatted. 🚀

now I'm trying to add it to Travis as well, but I never did this before and I'm kinda lost... should I add it to .travis.yml file? if so, where should I place it?

also, I thought about creating a CONTRIBUITING file or a section like that in the README, so we could explain a few things like "you have to add your ssh key to github, otherwise pre-commit won't work" (at least I had this problem hahah). what do you think? ☺️

@anapaulagomes
Copy link
Contributor

That's great, @giovana-morais! Yes, you should add this command to the section script (https://github.com/model-bakers/model_bakery/blob/master/.travis.yml).

The contribution guide is a great idea but I think we already have one in place in our docs: https://model-bakery.readthedocs.io/en/latest/#contributing-to-model-bakery. It may need to be updated though... 🤔 About this issue specifically, I think it's out of scope of this project.

Feel free to ping me if you have any questions. I'm commenting from my phone so I apologise if something is missing. Thank you!

@giovana-morais
Copy link
Contributor

giovana-morais commented Nov 23, 2019

Done! I added it before tox checks and now I'm running Travis CI in my branch to see if everything is okay in the build. I'm not sure if it's the best way to do so, but anyways. ahahah

I'm only having some trouble now because after black reformatted the source files, flake8 and pydocstyle are failing. Did this happen before? I can't commit the formatted files because of this. Sorry to bother D:

EDIT: I found out that when I try to build with Python 3.5 , pip install black won't work. Higher versions than that work, but then fail because the scripts are not formatted (yay!). Is there anything you know I can do to solve this?

@anapaulagomes
Copy link
Contributor

Done! I added it before tox checks and now I'm running Travis CI in my branch to see if everything is okay in the build. I'm not sure if it's the best way to do so, but anyways. ahahah

No worries, I think you're in the right path. :)

I'm only having some trouble now because after black reformatted the source files, flake8 and pydocstyle are failing. Did this happen before? I can't commit the formatted files because of this. Sorry to bother D:

So, I've checked and seems that flake8 is failing on our tests module at least. Would you be kind to fix the issues there? About pydocstyle, I'd say to skip it this time - only because to solve it we'd have to add comments to many public methods. You can skip it using SKIP=pydocstyle before your git commit command (like SKIP=pydocstyle git commit -m "").

EDIT: I found out that when I try to build with Python 3.5 , pip install black won't work. Higher versions than that work, but then fail because the scripts are not formatted (yay!). Is there anything you know I can do to solve this?

I'm glad that it works! 🎉 Just now I realized that I suggested you to add to the script section. Sorry about that. The ideal place would be tox.ini file, like we did for flake8:

model_bakery/tox.ini

Lines 1 to 6 in e57b42f

[tox]
envlist =
py35-django{111,20,21,22}-{postgresql,sqlite}
py36-django{111,20,21,22}-{postgresql,sqlite}
py37-django{111,20,21,22}-{postgresql,sqlite}
flake8

and https://github.com/model-bakers/model_bakery/pull/39/files

BUT it will run for every job... And still break for 3.5. So, I left a comment about this in my PR (#39 (comment)) (cc @amureki, @berinhard). Since I'm not a Travis knight, let's put this part on hold and see what they say.

Good job so far! @giovana-morais

@anapaulagomes
Copy link
Contributor

Ok, now (thanks to @amureki) we have separated job for flake8 (#40). You can use the same structure for black, @giovana-morais. 😬

@berinhard
Copy link
Member Author

Thanks @anapaulagomes for helping with this! I was traveling for the last few days with my family and I only got back to work today. Thanks @giovana-morais for all the effort as well!

@giovana-morais
Copy link
Contributor

Awesome! I've learned a lot so far. 😊

A few days ago, I've added black to tox.ini file and I tried to do tox -e black. It seemed to work fine. Also skipping pydocstyle helped me debug a lot. 👍

Right now I'm trying to correct the tests/ files in some way that both black and flake8 will pass the test, because apparently they are conflicting (when one succeeds, the other one fails). If all works, I'll separate the black job.

Thanks for all the support! ❤️

@anapaulagomes
Copy link
Contributor

Done #42. ✔️

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

No branches or pull requests

3 participants