-
Notifications
You must be signed in to change notification settings - Fork 56
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
use literalinclude in code-style-linting-format #259
Conversation
Tagging #250 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ucodery i think i just need you to help me understand how this is implemented? i think the idea is super cool. i just don't fully understand how a user will interact with the code samples and pre commit hooks in our guidebook. Thank you for this!! it's really great to have more real world examples here and frankly the stravalib examples are way to complex for our goals in this guidebook!
hooks: | ||
- id: flake8 | ||
|
||
# Black for auto code formatting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ucodery i've been thinking a bit about what code formatters we want to recommend. I know we suggested black and flake8 but that was last year! it seems to me a lot of people are using ruff these days! we just moved to it at stravalib a few months ago.
do you think we should consider a future issue / task for the future of suggesting ruff in place of these since it does so many things and creates a simpler / faster config?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have also moved a few project to ruff this year. I think it is a great tool, and like hatch it enmpaases a lot of tasks that previously required a medley of tools and decisions by users, which can be great for beginners. I think we should however raise this in a new issue/ discussion.
rev: 22.12.0 | ||
hooks: | ||
- id: black | ||
language_version: python3.8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
language_version: python3.8 | |
language_version: python3.10 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just porting the examples as they were originally written.
@@ -36,3 +36,14 @@ docs = [ | |||
"sphinx", | |||
"pydata-sphinx-theme" | |||
] | |||
|
|||
[tool.ruff] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh.. i may be confused. here you do have ruff. please help me understand this config!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the guide originally had examples for both black and ruff, in different sections, as it covers both. There is nothing wrong about having a pyproject.toml with both, the project will work just fine (although yes, confusing) even if the tools are set up to use conflicting settings. The tool
table is just a place to stick settings. It makes no guarantees or standards about what tools are chosen or how they interact or anything.
Parameters: | ||
celsius (float): Temperature in Celsius. | ||
|
||
Returns: | ||
float: Temperature in Fahrenheit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we prefer to use numpy style docstrings and suggest that in our guidebook.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jeremy, i think i understand what you are doing - in terms of having things in "other" formats. so you can likely ignore ALL of my inline suggestions -- BUT i don't understand how it's implemented in the guidebook. if you can give me instructions on how this would be run or how someone interacts with it that would be great!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was not trying to be different, again I just ported the examples as they already existed.
|
||
def fahrenheit_to_celsius(fahrenheit): | ||
""" | ||
Convert temperature from Fahrenheit to Celsius. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use numpy style here and throughout! thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here are you showing other docstring formats? will those be used elsewhere in our guidebook?
from examplePy.temperature import fahrenheit_to_celsius | ||
import pandas | ||
from typing import Sequence |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if we follow isort / pep8 we'd want examplePy to be the last import?
or were you doing this intentionally to allow isort to take action is a user tries to run it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did this intentionally in order to make a counter example. Notice that this module is named temporal-raw
(illegal python name, not allowed as an import target) while the package also has same-but ordered module named temporal
.
|
||
def calc_annual_mean(df: pandas.DataFrame): | ||
"""Function to calculate the mean temperature for each year and the final mean""" | ||
# TODO: make this a bit more robust so we can write integration test examples?? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a comment from me? i kind of recall talking about tests but also we could potentially remove the todo here in the example package?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is from you 😄 ec0255c4
@@ -0,0 +1,15 @@ | |||
from examplePy.temperature import fahrenheit_to_celsius | |||
import pandas |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import pandas | |
import pandas as pd |
import pandas | ||
from typing import Sequence | ||
|
||
def calc_annual_mean(df: pandas.DataFrame): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def calc_annual_mean(df: pandas.DataFrame): | |
def calc_annual_mean(df: pd.DataFrame): |
or just import DataFrame from pandas above?
from stravalib import exc | ||
from stravalib import unithelper as uh | ||
``` | ||
:::{literalinclude} ../examples/pure-hatch/src/examplePy/temporal.py |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahhhh i think this answers my question above about the imports. i haven't run this locally. maybe you can help me understand what will happen here in our guidebook with code examples that have formatting issues. will isort run? or would we tell the user to have it run as a small demo that they could implement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nothing runs, literalinclude
takes the contents of some file (temporal.py
) and replaces the directive with those contents somewhere between reading the md
file and producing the final html
. It is just a way to organize content apart from markdown files. Especially re-used content.
ok i see now @ucodery IGNORE all of my comments. this looks great. I think i have one request but i'm not sure how to implement this. What you are adding is really cool. essentially someone can test out how linters work. i feel like we want instructions around doing this. I also feel like we could ask some of the myst folks about better ways to make it more clearly interactive. because what you have done here is really really great. so take aways
|
A few clarifications: These example projects are not yet full projects (I think any would build, but e.g. pure-hatch contains no python code right now). #248 is open for getting us to multiple really usable example projects. These literalinclude PRs I've been making are just the first steps and are only about moving toml and python code that already existed in markdown into their own files; like taking a jupyter monolith and extracting some pure python modules. I'm not trying to make any drastic changes, and I consider it a success when I make 0 changes to the rendered site after literalinclude. So although I agree that the python world has moved fast and a lot has changed in just the last year, I think those changes should be considered in separate issues. As for how readers will interact with these examples, right now they are still just code blocks in the guide. Nothing here makes examples runnable. In order to test any of it out a reader would likely have to clone the repo and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you for this @ucodery i appreciate your patience with my (really off base review). i think i lost track of the scope of what you are doing. let's merge this!!
No description provided.