Skip to content

Commit

Permalink
Run black with poetry in Github Actions workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
chriscarrollsmith committed Apr 24, 2024
1 parent 5ac7a14 commit a9414fb
Show file tree
Hide file tree
Showing 5 changed files with 879 additions and 37 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ jobs:
uses: snok/install-poetry@v1
- name: Format code with black
run: |
black imfp
black tests
poetry run black .
- name: Build README.md
run: |
poetry run python README_files/render.py
Expand Down
4 changes: 2 additions & 2 deletions README.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,7 @@
"\n",
"I would love to have your help in improving `imfp`. If you encounter a bug while using the library, please open an issue. Alternatively, fix the bug and open a pull request to the `dev` branch. Thanks in advance for your help!\n",
"\n",
"Note to maintainers: To deploy a new version of the package, increment the version number with `poetry version patch` (or `minor`/`major` for larger updates) and push to dev. Github Actions will automatically format the code with black, render the README, and run the unit tests. If the workflow completes successfully, open a PR to main. After merging, the workflow will test again as one last sanity check and then automatically deploy the new version to PyPi."
"Note to maintainers: To deploy a new version of the package, increment the version number with `poetry version patch` (or `minor`/`major` for larger updates) and push to dev. Github Actions will automatically format the code with black, render the README, and run the unit tests. If the workflow completes successfully, open a PR to main. After merging, the workflow will test again as one last sanity check and then automatically deploy the new version to PyPi. Currently, new Github releases must be created manually, but this will be automated in the future."
]
}
],
Expand All @@ -1133,7 +1133,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.12.0"
},
"orig_nbformat": 4
},
Expand Down
20 changes: 12 additions & 8 deletions README_files/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
import nbconvert
import nbformat


def remove_scoped_styles(markdown_content):
style_pattern = re.compile(r'<style scoped>.*?</style>', re.DOTALL)
return style_pattern.sub('', markdown_content)
style_pattern = re.compile(r"<style scoped>.*?</style>", re.DOTALL)
return style_pattern.sub("", markdown_content)


def replace_png_links(markdown_content):
png_pattern = re.compile(r'!\[png\]\(.*?\.png\)', re.DOTALL)
return png_pattern.sub('![png](README_files/plot.png)', markdown_content)
png_pattern = re.compile(r"!\[png\]\(.*?\.png\)", re.DOTALL)
return png_pattern.sub("![png](README_files/plot.png)", markdown_content)


def convert_notebook_to_markdown(input_file, output_file):
# Read the notebook
with open(input_file, 'r', encoding='utf-8') as f:
with open(input_file, "r", encoding="utf-8") as f:
nb_content = f.read()

# Parse the notebook content
Expand All @@ -30,15 +33,16 @@ def convert_notebook_to_markdown(input_file, output_file):
markdown_output = replace_png_links(markdown_output)

# Write the result to the output file
with open(output_file, 'w', encoding='utf-8') as f:
with open(output_file, "w", encoding="utf-8") as f:
f.write(markdown_output)


if __name__ == "__main__":
script_path = os.path.dirname(os.path.abspath(__file__))
project_root = os.path.dirname(script_path)

input_file = os.path.join(project_root, "README.ipynb")
output_file = os.path.join(project_root, "README.md")

convert_notebook_to_markdown(input_file, output_file)
print(f"Notebook {input_file} converted to Markdown {output_file}")
print(f"Notebook {input_file} converted to Markdown {output_file}")
Loading

0 comments on commit a9414fb

Please sign in to comment.