From ed6e11148f5ae2c70c742895d4cdf1963656d365 Mon Sep 17 00:00:00 2001 From: James Mulhall <62727053+mullach@users.noreply.github.com> Date: Tue, 31 Oct 2023 14:38:32 -0700 Subject: [PATCH 01/12] recreated ALLFED folder structure --- .flake8 | 2 + .github/workflows/docs.yml | 64 +++++++++ .github/workflows/lint_action.yml | 37 +++++ .github/workflows/testing.yml | 35 +++++ LICENSE | 201 +++++++++++++++++++++++++++ automate_mkdocs.py | 222 ++++++++++++++++++++++++++++++ data/readme.txt | 1 + docs/readme.txt | 1 + docs/sources/index.md | 102 ++++++++++++++ environment.yml | 11 ++ mkdocs.yml | 28 ++++ mkgendocs.yml | 11 ++ requirements.txt | 6 + results/readme.txt | 1 + scripts/readme.txt | 1 + setup.py | 6 + src/readme.txt | 1 + tests/readme.txt | 1 + tests/test_function_to_test.py | 6 + 19 files changed, 737 insertions(+) create mode 100644 .flake8 create mode 100644 .github/workflows/docs.yml create mode 100644 .github/workflows/lint_action.yml create mode 100644 .github/workflows/testing.yml create mode 100644 LICENSE create mode 100644 automate_mkdocs.py create mode 100644 data/readme.txt create mode 100644 docs/readme.txt create mode 100644 docs/sources/index.md create mode 100644 environment.yml create mode 100644 mkdocs.yml create mode 100644 mkgendocs.yml create mode 100644 requirements.txt create mode 100644 results/readme.txt create mode 100644 scripts/readme.txt create mode 100644 setup.py create mode 100644 src/readme.txt create mode 100644 tests/readme.txt create mode 100644 tests/test_function_to_test.py diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..7da1f96 --- /dev/null +++ b/.flake8 @@ -0,0 +1,2 @@ +[flake8] +max-line-length = 100 diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 0000000..b21b4a5 --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,64 @@ +name: Docs + +on: + # Trigger the workflow on push or pull request, + # but only for the main branch + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + build: + name: Docs + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.9"] + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Autogenerate new documentation + continue-on-error: true + run: | + pip install -e . + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + pip install pyyaml + python automate_mkdocs.py + git add . + - name: Update and Build GH Pages + run: | + python -m pip install --upgrade pip + pip install mkdocs==1.2.3 + pip install mkgendocs==0.9.0 + pip install markupsafe==2.0.1 + pip install jinja2==2.11 + gendocs --config mkgendocs.yml + - name: deploy + run: | + mkdocs gh-deploy --force --clean --verbose + + - name: Commit any changes to docs + continue-on-error: true + run: | + git config --local user.name "github-actions[bot]" + git add ./docs + git commit -m "Auto-updating the docs" + + + - name: Push the changes to master + continue-on-error: true + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: main + force: true + + + diff --git a/.github/workflows/lint_action.yml b/.github/workflows/lint_action.yml new file mode 100644 index 0000000..5169118 --- /dev/null +++ b/.github/workflows/lint_action.yml @@ -0,0 +1,37 @@ +name: Lint + +on: + # Trigger the workflow on push or pull request, + # but only for the main branch + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + run-linters: + name: Run linters + runs-on: ubuntu-latest + + steps: + - name: Check out Git repository + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v1 + with: + python-version: 3.9 + + - name: Install Python dependencies + run: pip install black flake8 + + - name: Run linters + uses: wearerequired/lint-action@v2 + with: + auto_fix: true + black: true + black_auto_fix: true + flake8: true + flake8_auto_fix: false diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml new file mode 100644 index 0000000..db8f299 --- /dev/null +++ b/.github/workflows/testing.yml @@ -0,0 +1,35 @@ +name: Tests + +on: + # Trigger the workflow on push or pull request, + # but only for the main branch + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + build: + name: Running Tests + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.9"] + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pytest + pip install -e . + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Test with pytest + run: | + pytest + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..261eeb9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/automate_mkdocs.py b/automate_mkdocs.py new file mode 100644 index 0000000..95b8bcc --- /dev/null +++ b/automate_mkdocs.py @@ -0,0 +1,222 @@ +"""Automates Python scripts formatting, linting and Mkdocs documentation.""" + +import ast +import importlib +import json +import yaml +from collections import defaultdict +from pathlib import Path +from typing import Union + + +def add_val(indices, value, data): + if not len(indices): + return + element = data + for index in indices[:-1]: + element = element[index] + element[indices[-1]] = value + + +def automate_mkdocs_from_docstring( + mkdocs_dir: Union[str, Path], mkgendocs_f: str, repo_dir: Path, match_string: str +) -> dict: + """Automates the -pages for mkgendocs package by adding all Python functions in a + directory to the mkgendocs config. + Args: + mkdocs_dir (typing.Union[str, pathlib.Path]): textual directory for + the hierarchical directory & navigation in Mkdocs + mkgendocs_f (str): The configurations file for the mkgendocs package + repo_dir (pathlib.Path): textual directory to search for Python functions in + match_string (str): the text to be matches, after which the functions will be + added in mkgendocs format + Example: + >>> + >>> automate_mkdocs_from_docstring('scripts', repo_dir=Path.cwd(), match_string='pages:') + Returns: + list: list of created markdown files and their relative paths + + """ + p = repo_dir.glob("**/*.py") + scripts = [x for x in p if x.is_file()] + + if ( + Path.cwd() != repo_dir + ): # look for mkgendocs.yml in the parent file if a subdirectory is used + repo_dir = repo_dir.parent + + functions = defaultdict(dict) + structure = fix(defaultdict)() + full_repo_dir = str(repo_dir) + "/" + for script in scripts: + + with open(script, "r") as source: + tree = ast.parse(source.read()) + funcs = {"classes": [], "functions": []} + for child in ast.iter_child_nodes(tree): + try: + if isinstance( + child, (ast.FunctionDef, ast.ClassDef, ast.AsyncFunctionDef) + ): + if child.name not in ["main"]: + + relative_path = ( + str(script) + .replace(full_repo_dir, "") + .replace("/", ".") + .replace(".py", "") + ) + module = importlib.import_module(relative_path) + f_ = getattr(module, child.name) + function = f_.__name__ + if isinstance(child, (ast.ClassDef)): + funcs["classes"].append(function) + if isinstance(child, (ast.FunctionDef, ast.AsyncFunctionDef)): + funcs["functions"].append(function) + + except Exception as e: + print("trouble on importing " + script.stem) + print("did not document " + child.name) + print(str(e)) + if not funcs["classes"]: + funcs.pop("classes") + if not funcs["functions"]: + funcs.pop("functions") + if funcs: + functions[script] = funcs + with open(f"{repo_dir}/{mkgendocs_f}", "r+") as mkgen_config: + insert_string = "" + for path, function_names in functions.items(): + relative_path = str(path).replace(full_repo_dir, "").replace(".py", "") + insert_string += ( + f' - page: "{mkdocs_dir}/{relative_path}.md"\n ' + f'source: "{relative_path}.py"\n' # functions:\n' + ) + page = f"{mkdocs_dir}/{relative_path}" + split_page = page.split("/") + split_page = [" - " + s for s in split_page] + page += f".md" + + add_val(split_page, page, structure) + for class_name, class_list in function_names.items(): + insert_string += f" {class_name}:\n" + f_string = "" + for f in class_list: + insert_f_string = f" - {f}\n" + f_string += insert_f_string + + insert_string += f_string + insert_string += "\n" + + contents = mkgen_config.readlines() + if match_string in contents[-1]: + contents.append(insert_string) + else: + + for index, line in enumerate(contents): + if match_string in line and insert_string not in contents[index + 1]: + + contents = contents[: index + 1] + contents.append(insert_string) + break + + with open(f"{repo_dir}/{mkgendocs_f}", "w") as mkgen_config: + mkgen_config.writelines(contents) + + return structure + + +def automate_nav_structure( + mkdocs_dir: Union[str, Path], + mkdocs_f: str, + repo_dir: Path, + match_string: str, + structure: dict, +) -> str: + """Automates the -pages for mkgendocs package by adding all Python + functions in a directory to the mkgendocs config. + Args: + mkdocs_dir (typing.Union[str, pathlib.Path]): textual directory for + the hierarchical directory & navigation in Mkdocs + mkgendocs_f (str): The configurations file for the mkgendocs package + repo_dir (pathlib.Path): textual directory to search for Python functions in + match_string (str): the text to be matches, after which the functions + will be added in mkgendocs format + Example: + >>> + >>> automate_mkdocs_from_docstring('scripts', repo_dir=Path.cwd(), match_string='pages:') + Returns: + str: feedback message + + """ + insert_string = yaml.safe_dump(json.loads(json.dumps(structure, indent=4))).replace( + "'", "" + ) + # print(structure) + with open(f"{repo_dir}/{mkdocs_f}", "r+") as mkgen_config: + assert mkgen_config is not None + contents = mkgen_config.readlines() + if match_string in contents[-1]: + contents.append(insert_string) + else: + + for index, line in enumerate(contents): + if match_string in line and insert_string not in contents[index + 1]: + + contents = contents[: index + 1] + contents.append(insert_string) + break + + with open(f"{repo_dir}/{mkdocs_f}", "w") as mkgen_config: + mkgen_config.writelines(contents) + + +def fix(f): + """Allows creation of arbitrary length dict item + + Args: + f (type): Description of parameter `f`. + + Returns: + type: Description of returned object. + + """ + return lambda *args, **kwargs: f(fix(f), *args, **kwargs) + + +def indent(string: str) -> int: + """Count the indentation in whitespace characters. + Args: + string (str): text with indents + Returns: + int: Number of whitespace indentations + + """ + return sum(4 if char == "\t" else 1 for char in string[: -len(string.lstrip())]) + + +def main(): + """Execute when running this script.""" + # This is the path the script will look for code to document + python_tips_dir = Path.cwd().joinpath("src") + # This is the path the script will look for mkgendocs.yml + root_dir = Path.cwd() + + structure = automate_mkdocs_from_docstring( + mkdocs_dir="modules", + mkgendocs_f="mkgendocs.yml", + repo_dir=python_tips_dir, + match_string="pages:\n", + ) + + automate_nav_structure( + mkdocs_dir="modules", + mkdocs_f="mkdocs.yml", + repo_dir=root_dir, + match_string="- Home: index.md\n", + structure=structure, + ) + + +if __name__ == "__main__": + main() diff --git a/data/readme.txt b/data/readme.txt new file mode 100644 index 0000000..1b7b100 --- /dev/null +++ b/data/readme.txt @@ -0,0 +1 @@ +data: Where you put raw data for your project. You usually won’t sync this to source control, unless you use very small, text-based datasets (< 10 MBs). diff --git a/docs/readme.txt b/docs/readme.txt new file mode 100644 index 0000000..8128cbf --- /dev/null +++ b/docs/readme.txt @@ -0,0 +1 @@ +docs: Where you put documentation, including Markdown and reStructuredText (reST). Calling it docs makes it easy to publish documentation online through Github pages. diff --git a/docs/sources/index.md b/docs/sources/index.md new file mode 100644 index 0000000..450c370 --- /dev/null +++ b/docs/sources/index.md @@ -0,0 +1,102 @@ +# ALLFED-Repository-Template +Use this as template when you start a new project by clicking "Use this template" in the top right. + + +## ALLFED Python Style Guide +All code written for ALLFED should follow the [PEP 8 Style Guide for Python](https://peps.python.org/pep-0008/). Especially important are: +* Keep the code well documented +* Every function needs a docstring in this form: +``` +def count_line(f, line): + """ + Counts the number of times a line occurs. Case-sensitive. + + Arguments: + f (file): the file to scan + line (str): the line to count + + Returns: + int: the number of times the line occurs. + """ +``` +* Write [decoupled code](https://goodresearch.dev/decoupled.html), e.g. Functions should do exactly one thing and be as short as possible +* Naming conventions: + - Snake case for variables and module: variable_name, my_module.py + - Camel case for class name: MyClass + - Camel case with spaces for jupyter notebook: Analyze Brain Data.ipynb +* Delete dead code! Don't outcomment code you don't use anymore, but delete it instead. If you need to find it again, that's what we have git for. +* Use Jupyter Notebooks only for explanations and visualization. The actual programming should be happening in `.py` files. +* This repository is automatically set up with Github Actions/[Lint Action](https://github.com/marketplace/actions/lint-action) that will format your code using black and check for problems with flake8 ([without E203, W503](https://black.readthedocs.io/en/stable/faq.html#why-are-flake8-s-e203-and-w503-violated)). If either of them fails, you will not be able to merge your files unless you fix it. If this creates problem you cannot solve contact: florian@allfed.info +* You can deactivate the branch protection that makes sure that only correct and styled code can be merged, but it is not recommended. + + +To make this easier you can use linter (auto-formatter) that change your code to be formatted in PEP 8 when you safe it. E.g. [here for Spyder](https://stackoverflow.com/questions/51463223/how-to-use-pep8-module-using-spyder) or [VS Code](https://code.visualstudio.com/docs/python/linting). + +## Testing +We want to create reliable code. This means, as much of the code needs to be automatically tested, to make sure that everything runs as intended. Therefore, every possible function should have some kind of `assert` that tests if it works. We use pytest [pytest](https://docs.pytest.org/en/7.1.x/) as our main test suit. All tests that you put in the tests folder in here are automatically run every time you push code. You can read more about testing [here](https://goodresearch.dev/testing.html). To adapt the testing.yml to your repository you just have to adapt the requirements in requirements.txt. Everything else should work on its own. You can find an example of how a test file should look like in the tests folder. Once you go the testing set up, also make sure to add the testing badge to the readme of your repository. Simply change the URL to your repository in this badge: + +![Testing](https://github.com/allfed/allfed-repository-template/actions/workflows/testing.yml/badge.svg) + + +## Documenting in small projects +Documenting your code is only one part of the documentation we want to create. Every larger repository needs: +* a readme file that explains what the repository is for and how it is organized, which should contain: + - A one-sentence description of your project + - A longer description of your project + - Installation instructions + - General orientation to the codebase and usage instructions + - Links to papers + - Links to extended docs + - License + +* a tutorial Jupyter Notebook to explain how the repository is supposed to be used + + +## Documenting in big projects +All the things for the small projects, but also: +* An automated documentation via Gitub Actions. This is already set up in this repository. Is uses the code from [this post](https://towardsdatascience.com/easily-automate-and-never-touch-your-documentation-again-a98c91ce1b95) and combines it with [this one](https://blog.elmah.io/deploying-a-mkdocs-documentation-site-with-github-actions/). It also is setup that it will only look for python files in the src folder. So, make sure that everything is in there (you can changes this behavior in the main function of `automate_mkdocs.py`). To get it running do the following + * go to Settings --> Pages + * select deploy from a branch as source + * select gh-pages as branch at root (for this option to pop up the `docs.yml` file has to have run succesfully at least once) + * The end result will look something [like this](https://florianjehn.github.io/Seaweed-Growth-Model/) + * The automated documentation part is still a bit wip, if you run into problems contact florian@allfed.info +* Create a [visual representation](https://goodresearch.dev/_images/pcbi.1007358.g002.PNG_L.png) of how the different files interact with each other + +## Making the repository citable +All ALLFED repositories should be citable by release. For this we use [Zenodo](https://zenodo.org/). This has to be activated by an Admin (so either Florian or Morgan). Once you have a manuscript where you need to cite the repository let them know and they will activate it. This will also create a doi badge, which should be included in the readme, like this: + +--- + + +[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.6865646.svg)](https://doi.org/10.5281/zenodo.6865646) + + +--- + +## Project Skeleton +This repository already has the folder structure we use for repositories. Every folder has an additional readme, to tell you what needs to go in there. + +## Making the repository a pip installable Python package +For some repositories it makes sense to make them installable via pip (e.g. a model we want to share easily). In this case you can use the explanation [here](https://goodresearch.dev/setup.html). This repository already contains a setup.py that can be used for that. + +## Environment +Every ALLFED project is run in its own virtual environment. Therefore, every project needs an `environment.yml` file. The one in this repository is only an example and should not be used for any actual project. To create and organize virtual environments we use [conda](https://docs.conda.io/en/latest/miniconda.html). + +## Requirements +Every ALLFED project needs a requirements file that specifies what packages are needed to run the project. You can find an example file in the repository. If you use a lot of packages you can use [pipreqg](https://allfed.github.io/Seaweed-Growth-Model/) to find them all. + +## License +ALLFED publishes its code in Open Access. For this we use the [**Apache 2.0 License**](https://www.planetcrust.com/what-does-apache-2-0-license-mean). This license allows very free use of the code, but makes sure that ALLFED cannot be sued if something goes wrong with the code. The license template in this repository needs to be adapted when a new project is created. You can include the following license badge in your readme: + +[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) + +## Gitignore +The [.gitignore file](https://git-scm.com/docs/gitignore) is the default one for Python. Make sure you change it when using another programming language. + +## Further reading/Misc +* [Best Practices for Scientific Computing](https://journals.plos.org/plosbiology/article?id=10.1371/journal.pbio.1001745) +* [General course to get to know the Python skills needed to the work at ALLFED](https://github.com/florianjehn/python-for-environmental-science) +* We are using [Github Copilot](https://github.com/features/copilot) to write faster and cleaner code. If you would also like to have a license contact finance@allfed.info + +## Acknowledgment +This is strongly based on the ["Good Research Code Handbook"](https://goodresearch.dev/index.html). If something here confuses you, it makes sense to read about it there. Pretty good explanations. diff --git a/environment.yml b/environment.yml new file mode 100644 index 0000000..64d21bd --- /dev/null +++ b/environment.yml @@ -0,0 +1,11 @@ +name: cb +channels: + - conda-forge + - defaults +dependencies: + - python=3.8 + - numpy=1.21.2 + - pip + - pip: + - tqdm==4.62.3 + diff --git a/mkdocs.yml b/mkdocs.yml new file mode 100644 index 0000000..0b58c4a --- /dev/null +++ b/mkdocs.yml @@ -0,0 +1,28 @@ +site_name: My Super Cool Respository + + +# Repository +repo_name: My Super Cool Respository +repo_url: https://github.com/allfed/My Super-Cool-Respository +edit_uri: "" +# Copyright +copyright: Me + +docs_dir: "docs/sources" + +plugins: + - search + +theme: + name: 'readthedocs' + custom_dir: 'docs' + palette: + primary: 'white' + logo: 'assets/images/logo_full.svg' + favicon: 'assets/images/favicon.svg' + features: + - navigation.tabs + - navigation.tabs.sticky + - instant +nav: + diff --git a/mkgendocs.yml b/mkgendocs.yml new file mode 100644 index 0000000..8d9a562 --- /dev/null +++ b/mkgendocs.yml @@ -0,0 +1,11 @@ +site_name: My Super Cool Respository + + +# Repository +repo_name: My Super Cool Respository +repo: https://github.com/allfed/My-Super-Cool-Respository +# Copyright +copyright: ALLFED + +#This specifies the autogeneration portion +pages: diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..4355f56 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +pandas>=1.4.3 +setuptools>=61.2.0 +pytest>=7.1.2 +numpy>=1.23.1 +matplotlib>=3.5.1 +mkdocs diff --git a/results/readme.txt b/results/readme.txt new file mode 100644 index 0000000..aede27e --- /dev/null +++ b/results/readme.txt @@ -0,0 +1 @@ +results: Where you put results, including checkpoints, hdf5 files, pickle files, as well as figures and tables. If these files are heavy, you won’t put these under source control. diff --git a/scripts/readme.txt b/scripts/readme.txt new file mode 100644 index 0000000..e7c528c --- /dev/null +++ b/scripts/readme.txt @@ -0,0 +1 @@ +scripts: Where you put scripts - Python and bash alike - as well as .ipynb notebooks. diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..161f66e --- /dev/null +++ b/setup.py @@ -0,0 +1,6 @@ +from setuptools import find_packages, setup + +setup( + name="src", + packages=find_packages(), +) diff --git a/src/readme.txt b/src/readme.txt new file mode 100644 index 0000000..503277b --- /dev/null +++ b/src/readme.txt @@ -0,0 +1 @@ +src: Where you put reusable Python modules for your project. This is the kind of python code that you import. diff --git a/tests/readme.txt b/tests/readme.txt new file mode 100644 index 0000000..2cbb868 --- /dev/null +++ b/tests/readme.txt @@ -0,0 +1 @@ +tests: Where you put tests for your code. diff --git a/tests/test_function_to_test.py b/tests/test_function_to_test.py new file mode 100644 index 0000000..55ecd26 --- /dev/null +++ b/tests/test_function_to_test.py @@ -0,0 +1,6 @@ +def test_some_function(): + """ + This function tests the some_function function. + It should always return true + """ + assert some_function() is True From 262c14bfadda126825d2cdce08352ec7c22da595 Mon Sep 17 00:00:00 2001 From: James Mulhall <62727053+mullach@users.noreply.github.com> Date: Tue, 31 Oct 2023 17:40:16 -0700 Subject: [PATCH 02/12] added numerical fn, plotting fn, tests, and repo package files --- scripts/example_script.ipynb | 68 ++++++++++++++++++++++++++++++++++++ src/__init__.py | 0 src/numerical.py | 16 +++++++++ src/plotting.py | 28 +++++++++++++++ tests/test_numerical.py | 17 +++++++++ 5 files changed, 129 insertions(+) create mode 100644 scripts/example_script.ipynb create mode 100644 src/__init__.py create mode 100644 src/numerical.py create mode 100644 src/plotting.py create mode 100644 tests/test_numerical.py diff --git a/scripts/example_script.ipynb b/scripts/example_script.ipynb new file mode 100644 index 0000000..2440f59 --- /dev/null +++ b/scripts/example_script.ipynb @@ -0,0 +1,68 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Example script which imports and calls numerical.py from src" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "from src.numerical import multiply" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Calling multiply(4,6) should return 4*6=24" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "24" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "multiply(4, 6)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "trainingenv", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/numerical.py b/src/numerical.py new file mode 100644 index 0000000..b2b9c06 --- /dev/null +++ b/src/numerical.py @@ -0,0 +1,16 @@ +""" +File contains a single function to return the product of two numbers. +""" + + +def multiply(x, y): + """ + Calculates the product of x and y. + Arguments: + x (int or float): first number to be multiplied + y (int or float): second number to be multiplied + Returns: + product (int or float): product of x and y + """ + product = x * y + return product diff --git a/src/plotting.py b/src/plotting.py new file mode 100644 index 0000000..bb71015 --- /dev/null +++ b/src/plotting.py @@ -0,0 +1,28 @@ +""" +File contains a single function to plot a scatter plot following ALLFED Guidelines. +""" +import matplotlib.pyplot as plt +import numpy as np + +# Set style +plt.style.use( + "https://raw.githubusercontent.com/allfed/ALLFED-matplotlib-style-sheet/main/ALLFED.mplstyle" +) + + +def scatterplot(N): + """ + Plots a matplotlib scatterplot using random data. + + Arguments: + N (int): number of random datapoints to plot + Returns: + None + """ + x = np.random.rand(N) + y = np.random.rand(N) + plt.scatter(x, y) + plt.ylabel("Y-Axis") + plt.xlabel("X-Axis") + plt.title("Example Data") + plt.show() diff --git a/tests/test_numerical.py b/tests/test_numerical.py new file mode 100644 index 0000000..ebb5d9c --- /dev/null +++ b/tests/test_numerical.py @@ -0,0 +1,17 @@ +from src.numerical import multiply + + +def test_multiply_int(): + """ + Tests multiply function using integer inputs. + """ + test_case = multiply(4, 6) + assert test_case == 24 + + +def test_multiply_float(): + """ + Tests multiply function using float inputs. + """ + test_case = multiply(2.5, 3.0) + assert test_case == 7.5 From 6853d8320850b8942ec5830cb0baf2fc86fbdd9c Mon Sep 17 00:00:00 2001 From: James Mulhall <62727053+mullach@users.noreply.github.com> Date: Tue, 31 Oct 2023 18:12:04 -0700 Subject: [PATCH 03/12] added automation for docs and testing, added environment.yml --- environment.yml | 123 ++++++++++++++++++++++++++++++++++++---- mkdocs.yml | 8 +-- mkgendocs.yml | 6 +- tests/test_numerical.py | 4 ++ 4 files changed, 123 insertions(+), 18 deletions(-) diff --git a/environment.yml b/environment.yml index 64d21bd..7c7bbeb 100644 --- a/environment.yml +++ b/environment.yml @@ -1,11 +1,112 @@ -name: cb -channels: - - conda-forge - - defaults -dependencies: - - python=3.8 - - numpy=1.21.2 - - pip - - pip: - - tqdm==4.62.3 - +name: trainingenv +channels: + - conda-forge + - defaults +dependencies: + - asttokens=2.4.1=pyhd8ed1ab_0 + - backcall=0.2.0=pyh9f0ad1d_0 + - backports=1.0=pyhd8ed1ab_3 + - backports.functools_lru_cache=1.6.5=pyhd8ed1ab_0 + - blas=1.0=mkl + - brotli=1.0.9=h2bbff1b_7 + - brotli-bin=1.0.9=h2bbff1b_7 + - bzip2=1.0.8=he774522_0 + - ca-certificates=2023.08.22=haa95532_0 + - colorama=0.4.6=pyhd8ed1ab_0 + - comm=0.1.4=pyhd8ed1ab_0 + - contourpy=1.0.5=py311h59b6b97_0 + - cycler=0.11.0=pyhd3eb1b0_0 + - debugpy=1.6.7=py311hd77b12b_0 + - decorator=5.1.1=pyhd8ed1ab_0 + - exceptiongroup=1.1.3=pyhd8ed1ab_0 + - executing=2.0.1=pyhd8ed1ab_0 + - expat=2.5.0=hd77b12b_0 + - fonttools=4.25.0=pyhd3eb1b0_0 + - freetype=2.12.1=ha860e81_0 + - giflib=5.2.1=h8cc25b3_3 + - icu=73.1=h6c2663c_0 + - importlib-metadata=6.8.0=pyha770c72_0 + - importlib_metadata=6.8.0=hd8ed1ab_0 + - iniconfig=1.1.1=pyhd3eb1b0_0 + - intel-openmp=2023.1.0=h59b6b97_46319 + - ipykernel=6.26.0=pyha63f2e9_0 + - ipython=8.16.1=pyh5737063_0 + - jedi=0.19.1=pyhd8ed1ab_0 + - jpeg=9e=h2bbff1b_1 + - jupyter_client=8.5.0=pyhd8ed1ab_0 + - jupyter_core=5.5.0=py311h1ea47a8_0 + - kiwisolver=1.4.4=py311hd77b12b_0 + - krb5=1.20.1=h5b6d351_0 + - lerc=3.0=hd77b12b_0 + - libbrotlicommon=1.0.9=h2bbff1b_7 + - libbrotlidec=1.0.9=h2bbff1b_7 + - libbrotlienc=1.0.9=h2bbff1b_7 + - libclang=14.0.6=default_hb5a9fac_1 + - libclang13=14.0.6=default_h8e68704_1 + - libdeflate=1.17=h2bbff1b_1 + - libffi=3.4.4=hd77b12b_0 + - libpng=1.6.39=h8cc25b3_0 + - libpq=12.15=h906ac69_1 + - libsodium=1.0.18=h8d14728_1 + - libtiff=4.5.1=hd77b12b_0 + - libwebp=1.3.2=hbc33d0d_0 + - libwebp-base=1.3.2=h2bbff1b_0 + - lz4-c=1.9.4=h2bbff1b_0 + - matplotlib=3.8.0=py311haa95532_0 + - matplotlib-base=3.8.0=py311hf62ec03_0 + - matplotlib-inline=0.1.6=pyhd8ed1ab_0 + - mkl=2023.1.0=h6b88ed4_46357 + - mkl-service=2.4.0=py311h2bbff1b_1 + - mkl_fft=1.3.8=py311h2bbff1b_0 + - mkl_random=1.2.4=py311h59b6b97_0 + - munkres=1.1.4=py_0 + - nest-asyncio=1.5.8=pyhd8ed1ab_0 + - numpy=1.26.0=py311hdab7c0b_0 + - numpy-base=1.26.0=py311hd01c5d8_0 + - openjpeg=2.4.0=h4fc8c34_0 + - openssl=3.0.11=h2bbff1b_2 + - packaging=23.1=py311haa95532_0 + - parso=0.8.3=pyhd8ed1ab_0 + - pickleshare=0.7.5=py_1003 + - pillow=10.0.1=py311h045eedc_0 + - pip=23.3=py311haa95532_0 + - platformdirs=3.11.0=pyhd8ed1ab_0 + - pluggy=1.0.0=py311haa95532_1 + - ply=3.11=py311haa95532_0 + - prompt-toolkit=3.0.39=pyha770c72_0 + - prompt_toolkit=3.0.39=hd8ed1ab_0 + - psutil=5.9.0=py311h2bbff1b_0 + - pure_eval=0.2.2=pyhd8ed1ab_0 + - pygments=2.16.1=pyhd8ed1ab_0 + - pyparsing=3.0.9=py311haa95532_0 + - pyqt=5.15.10=py311hd77b12b_0 + - pyqt5-sip=12.13.0=py311h2bbff1b_0 + - pytest=7.4.0=py311haa95532_0 + - python=3.11.5=he1021f5_0 + - python-dateutil=2.8.2=pyhd3eb1b0_0 + - python_abi=3.11=2_cp311 + - pywin32=305=py311h2bbff1b_0 + - pyzmq=25.1.0=py311hd77b12b_0 + - qt-main=5.15.2=h19c9488_10 + - setuptools=68.0.0=py311haa95532_0 + - sip=6.7.12=py311hd77b12b_0 + - six=1.16.0=pyhd3eb1b0_1 + - sqlite=3.41.2=h2bbff1b_0 + - stack_data=0.6.2=pyhd8ed1ab_0 + - tbb=2021.8.0=h59b6b97_0 + - tk=8.6.12=h2bbff1b_0 + - tornado=6.3.3=py311h2bbff1b_0 + - traitlets=5.13.0=pyhd8ed1ab_0 + - typing-extensions=4.8.0=hd8ed1ab_0 + - typing_extensions=4.8.0=pyha770c72_0 + - tzdata=2023c=h04d1e81_0 + - vc=14.2=h21ff451_1 + - vs2015_runtime=14.27.29016=h5e58377_2 + - wcwidth=0.2.9=pyhd8ed1ab_0 + - wheel=0.37.1=pyhd3eb1b0_0 + - xz=5.4.2=h8cc25b3_0 + - zeromq=4.3.4=h0e60522_1 + - zipp=3.17.0=pyhd8ed1ab_0 + - zlib=1.2.13=h8cc25b3_0 + - zstd=1.5.5=hd43e919_0 +prefix: C:\Users\james\anaconda3\envs\trainingenv diff --git a/mkdocs.yml b/mkdocs.yml index 0b58c4a..4c2c914 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -1,12 +1,12 @@ -site_name: My Super Cool Respository +site_name: Github Training Repository # Repository -repo_name: My Super Cool Respository -repo_url: https://github.com/allfed/My Super-Cool-Respository +repo_name: Github Training Repository +repo_url: https://github.com/mullach/Github-Training-Repository edit_uri: "" # Copyright -copyright: Me +copyright: ALLFED docs_dir: "docs/sources" diff --git a/mkgendocs.yml b/mkgendocs.yml index 8d9a562..a454bf1 100644 --- a/mkgendocs.yml +++ b/mkgendocs.yml @@ -1,9 +1,9 @@ -site_name: My Super Cool Respository +site_name: Github-Training-Repository # Repository -repo_name: My Super Cool Respository -repo: https://github.com/allfed/My-Super-Cool-Respository +repo_name: Github-Training-Repository +repo: https://github.com/mullach/Github-Training-Repository # Copyright copyright: ALLFED diff --git a/tests/test_numerical.py b/tests/test_numerical.py index ebb5d9c..52c189e 100644 --- a/tests/test_numerical.py +++ b/tests/test_numerical.py @@ -1,3 +1,7 @@ +""" +Tests for src/numerical.py +""" + from src.numerical import multiply From 5897906eaf9fed85aef18d7b381db3a5ebdd609e Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 1 Nov 2023 01:17:36 +0000 Subject: [PATCH 04/12] Auto-updating the docs --- docs/sources/index.md | 146 ++++++++------------------ docs/sources/modules/src/numerical.md | 24 +++++ docs/sources/modules/src/plotting.md | 23 ++++ mkgendocs.yml | 10 ++ 4 files changed, 101 insertions(+), 102 deletions(-) create mode 100644 docs/sources/modules/src/numerical.md create mode 100644 docs/sources/modules/src/plotting.md diff --git a/docs/sources/index.md b/docs/sources/index.md index 450c370..0933268 100644 --- a/docs/sources/index.md +++ b/docs/sources/index.md @@ -1,102 +1,44 @@ -# ALLFED-Repository-Template -Use this as template when you start a new project by clicking "Use this template" in the top right. - - -## ALLFED Python Style Guide -All code written for ALLFED should follow the [PEP 8 Style Guide for Python](https://peps.python.org/pep-0008/). Especially important are: -* Keep the code well documented -* Every function needs a docstring in this form: -``` -def count_line(f, line): - """ - Counts the number of times a line occurs. Case-sensitive. - - Arguments: - f (file): the file to scan - line (str): the line to count - - Returns: - int: the number of times the line occurs. - """ -``` -* Write [decoupled code](https://goodresearch.dev/decoupled.html), e.g. Functions should do exactly one thing and be as short as possible -* Naming conventions: - - Snake case for variables and module: variable_name, my_module.py - - Camel case for class name: MyClass - - Camel case with spaces for jupyter notebook: Analyze Brain Data.ipynb -* Delete dead code! Don't outcomment code you don't use anymore, but delete it instead. If you need to find it again, that's what we have git for. -* Use Jupyter Notebooks only for explanations and visualization. The actual programming should be happening in `.py` files. -* This repository is automatically set up with Github Actions/[Lint Action](https://github.com/marketplace/actions/lint-action) that will format your code using black and check for problems with flake8 ([without E203, W503](https://black.readthedocs.io/en/stable/faq.html#why-are-flake8-s-e203-and-w503-violated)). If either of them fails, you will not be able to merge your files unless you fix it. If this creates problem you cannot solve contact: florian@allfed.info -* You can deactivate the branch protection that makes sure that only correct and styled code can be merged, but it is not recommended. - - -To make this easier you can use linter (auto-formatter) that change your code to be formatted in PEP 8 when you safe it. E.g. [here for Spyder](https://stackoverflow.com/questions/51463223/how-to-use-pep8-module-using-spyder) or [VS Code](https://code.visualstudio.com/docs/python/linting). - -## Testing -We want to create reliable code. This means, as much of the code needs to be automatically tested, to make sure that everything runs as intended. Therefore, every possible function should have some kind of `assert` that tests if it works. We use pytest [pytest](https://docs.pytest.org/en/7.1.x/) as our main test suit. All tests that you put in the tests folder in here are automatically run every time you push code. You can read more about testing [here](https://goodresearch.dev/testing.html). To adapt the testing.yml to your repository you just have to adapt the requirements in requirements.txt. Everything else should work on its own. You can find an example of how a test file should look like in the tests folder. Once you go the testing set up, also make sure to add the testing badge to the readme of your repository. Simply change the URL to your repository in this badge: - -![Testing](https://github.com/allfed/allfed-repository-template/actions/workflows/testing.yml/badge.svg) - - -## Documenting in small projects -Documenting your code is only one part of the documentation we want to create. Every larger repository needs: -* a readme file that explains what the repository is for and how it is organized, which should contain: - - A one-sentence description of your project - - A longer description of your project - - Installation instructions - - General orientation to the codebase and usage instructions - - Links to papers - - Links to extended docs - - License - -* a tutorial Jupyter Notebook to explain how the repository is supposed to be used - - -## Documenting in big projects -All the things for the small projects, but also: -* An automated documentation via Gitub Actions. This is already set up in this repository. Is uses the code from [this post](https://towardsdatascience.com/easily-automate-and-never-touch-your-documentation-again-a98c91ce1b95) and combines it with [this one](https://blog.elmah.io/deploying-a-mkdocs-documentation-site-with-github-actions/). It also is setup that it will only look for python files in the src folder. So, make sure that everything is in there (you can changes this behavior in the main function of `automate_mkdocs.py`). To get it running do the following - * go to Settings --> Pages - * select deploy from a branch as source - * select gh-pages as branch at root (for this option to pop up the `docs.yml` file has to have run succesfully at least once) - * The end result will look something [like this](https://florianjehn.github.io/Seaweed-Growth-Model/) - * The automated documentation part is still a bit wip, if you run into problems contact florian@allfed.info -* Create a [visual representation](https://goodresearch.dev/_images/pcbi.1007358.g002.PNG_L.png) of how the different files interact with each other - -## Making the repository citable -All ALLFED repositories should be citable by release. For this we use [Zenodo](https://zenodo.org/). This has to be activated by an Admin (so either Florian or Morgan). Once you have a manuscript where you need to cite the repository let them know and they will activate it. This will also create a doi badge, which should be included in the readme, like this: - ---- - - -[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.6865646.svg)](https://doi.org/10.5281/zenodo.6865646) - - ---- - -## Project Skeleton -This repository already has the folder structure we use for repositories. Every folder has an additional readme, to tell you what needs to go in there. - -## Making the repository a pip installable Python package -For some repositories it makes sense to make them installable via pip (e.g. a model we want to share easily). In this case you can use the explanation [here](https://goodresearch.dev/setup.html). This repository already contains a setup.py that can be used for that. - -## Environment -Every ALLFED project is run in its own virtual environment. Therefore, every project needs an `environment.yml` file. The one in this repository is only an example and should not be used for any actual project. To create and organize virtual environments we use [conda](https://docs.conda.io/en/latest/miniconda.html). - -## Requirements -Every ALLFED project needs a requirements file that specifies what packages are needed to run the project. You can find an example file in the repository. If you use a lot of packages you can use [pipreqg](https://allfed.github.io/Seaweed-Growth-Model/) to find them all. - -## License -ALLFED publishes its code in Open Access. For this we use the [**Apache 2.0 License**](https://www.planetcrust.com/what-does-apache-2-0-license-mean). This license allows very free use of the code, but makes sure that ALLFED cannot be sued if something goes wrong with the code. The license template in this repository needs to be adapted when a new project is created. You can include the following license badge in your readme: - -[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) - -## Gitignore -The [.gitignore file](https://git-scm.com/docs/gitignore) is the default one for Python. Make sure you change it when using another programming language. - -## Further reading/Misc -* [Best Practices for Scientific Computing](https://journals.plos.org/plosbiology/article?id=10.1371/journal.pbio.1001745) -* [General course to get to know the Python skills needed to the work at ALLFED](https://github.com/florianjehn/python-for-environmental-science) -* We are using [Github Copilot](https://github.com/features/copilot) to write faster and cleaner code. If you would also like to have a license contact finance@allfed.info - -## Acknowledgment -This is strongly based on the ["Good Research Code Handbook"](https://goodresearch.dev/index.html). If something here confuses you, it makes sense to read about it there. Pretty good explanations. +# Github-Training-Repository +This repository is meant to be used to train new hires/volunteers on how to use Github. Reading the material and finishing the exercise should take around 6-8 hours. + +Before you get started, please check that your actual name is visible on your Github profile. This way we know which account belongs to whom and when we make repositories citable your real name will be used and not your nickname. + +Also, if you read this and you are not yet part of the ALLFED group on Github, please let Florian know your account name, so it can be added. + +# Preparation Material +Please look at all those materials before you start the exercise. + +* [Good enough practices in scientific computing](https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1005510): This gives a good overview of why we need to adhere to good coding practices and what the general idea is +* [Good Research Code Handbook](https://goodresearch.dev/): Explanation of how to implement good coding practices in Python +* [Fundamentals of Git and Github](https://www.youtube.com/watch?v=8Dd7KRpKeaE) +* [How to use Github with Github Desktop](https://www.youtube.com/watch?v=8Dd7KRpKeaE) +* [Getting started with anaconda and conda](https://youtu.be/YJC6ldI3hWk) (if you feel like conda is too slow, check out [mamba](https://mamba.readthedocs.io/en/latest/) instead) +* [ALLFED Repository Template Readme](https://github.com/allfed/ALLFED-Repository-Template) +* [Overview of Python](https://www.youtube.com/watch?v=kqtD5dpn9C8) +* [Automated Testing](https://blog.deepjyoti30.dev/tests-github-python) +* [ChatGPT](https://chat.openai.com/chat) is pretty good at answering programming questions +* It is recommended to use [VS Code](https://www.youtube.com/watch?v=B-s71n0dHUk) as your code editor +* The [Seaweed Growth Model Repository](https://github.com/allfed/Seaweed-Growth-Model) can be seen as an example of how ALLFED repositories should look like. You can check how things are done there, if something here confuses you + +# Exercise +1. Fork this repository +2. Clone it to your local computer +3. Recreate the folder structure as described in the [ALLFED Guidelines](https://github.com/allfed/ALLFED-Repository-Template) +4. Create a local virtual environment for the repository + * When you try to install/change things make sure are [activating it first!](https://goodresearch.dev/setup.html?highlight=activate#conda). If something related to virtual environments isn't working, always make sure that it is really activated. +5. Create two files in the src folder: numerical.py and plotting.py +6. Write a function in numerical.py that takes at least one argument and returns a numerical value +7. Write a function in plotting.py that creates a scatter plot and uses the [ALLFED Style Sheet](https://github.com/allfed/ALLFED-matplotlib-style-sheet) +8. Make your repository an installable package as described in [Good Research Code Handbook](https://goodresearch.dev/setup.html) +9. Add a Jupyter Notebook in your scripts folder and import numerical.py and call it +11. Write two test for numerical.py +12. Make sure that the documenation of all code follows the [ALLFED Guidelines](https://github.com/allfed/ALLFED-Repository-Template#allfed-python-style-guide) + * If you set-up automated documentation, you can see the status in the [pages setting](https://github.com/allfed/Seaweed-Growth-Model/settings/pages) +14. Automate the tests, so they run on every commit (you can just copy the files needed for that from [the template](https://github.com/allfed/ALLFED-Repository-Template) + * The files used for testing in Github Actions are hidden files. You might need to change the settings of your operation system to show you the hidden files. + * you can play around with pytest in your terminal in VS Code +15. Create an environment.yml that specifies how your virtual environment can be recreated and save it in the repository +16. Send back a pull request, so we know you have finished this training +17. Check back in with Morgan or Florian if you have any questions (florian@allfed.info or morgan@allfed.info) + +If you get stuck at any point please reach out to one of the data scientists (either florian@allfed.info or morgan@allfed.info). diff --git a/docs/sources/modules/src/numerical.md b/docs/sources/modules/src/numerical.md new file mode 100644 index 0000000..c695d1d --- /dev/null +++ b/docs/sources/modules/src/numerical.md @@ -0,0 +1,24 @@ +# + + +### multiply +[source](https://github.com/mullach/Github-Training-Repository/blob/master/src/numerical.py/#L6) +```python +.multiply( + x, y +) +``` + +--- +Calculates the product of x and y. + +**Arguments** + +* **x** (int or float) : first number to be multiplied +* **y** (int or float) : second number to be multiplied + + +**Returns** + +* **product** (int or float) : product of x and y + diff --git a/docs/sources/modules/src/plotting.md b/docs/sources/modules/src/plotting.md new file mode 100644 index 0000000..a44d5d4 --- /dev/null +++ b/docs/sources/modules/src/plotting.md @@ -0,0 +1,23 @@ +# + + +### scatterplot +[source](https://github.com/mullach/Github-Training-Repository/blob/master/src/plotting.py/#L13) +```python +.scatterplot( + N +) +``` + +--- +Plots a matplotlib scatterplot using random data. + + +**Arguments** + +* **N** (int) : number of random datapoints to plot + + +**Returns** + +None diff --git a/mkgendocs.yml b/mkgendocs.yml index a454bf1..d0eabb5 100644 --- a/mkgendocs.yml +++ b/mkgendocs.yml @@ -9,3 +9,13 @@ copyright: ALLFED #This specifies the autogeneration portion pages: + - page: "modules/src/numerical.md" + source: "src/numerical.py" + functions: + - multiply + + - page: "modules/src/plotting.md" + source: "src/plotting.py" + functions: + - scatterplot + From a4e6a5e067a490c18f3942325186b67c1bb83b31 Mon Sep 17 00:00:00 2001 From: James Mulhall <62727053+mullach@users.noreply.github.com> Date: Tue, 31 Oct 2023 18:28:56 -0700 Subject: [PATCH 05/12] removed f-string notation in automate_mkdocs, deleted test_function_to_test --- automate_mkdocs.py | 8 +------- tests/test_function_to_test.py | 6 ------ 2 files changed, 1 insertion(+), 13 deletions(-) delete mode 100644 tests/test_function_to_test.py diff --git a/automate_mkdocs.py b/automate_mkdocs.py index 95b8bcc..11e6bd9 100644 --- a/automate_mkdocs.py +++ b/automate_mkdocs.py @@ -49,7 +49,6 @@ def automate_mkdocs_from_docstring( structure = fix(defaultdict)() full_repo_dir = str(repo_dir) + "/" for script in scripts: - with open(script, "r") as source: tree = ast.parse(source.read()) funcs = {"classes": [], "functions": []} @@ -59,7 +58,6 @@ def automate_mkdocs_from_docstring( child, (ast.FunctionDef, ast.ClassDef, ast.AsyncFunctionDef) ): if child.name not in ["main"]: - relative_path = ( str(script) .replace(full_repo_dir, "") @@ -95,7 +93,7 @@ def automate_mkdocs_from_docstring( page = f"{mkdocs_dir}/{relative_path}" split_page = page.split("/") split_page = [" - " + s for s in split_page] - page += f".md" + page += ".md" # removed f-string notation; possibly will result in future errors add_val(split_page, page, structure) for class_name, class_list in function_names.items(): @@ -112,10 +110,8 @@ def automate_mkdocs_from_docstring( if match_string in contents[-1]: contents.append(insert_string) else: - for index, line in enumerate(contents): if match_string in line and insert_string not in contents[index + 1]: - contents = contents[: index + 1] contents.append(insert_string) break @@ -159,10 +155,8 @@ def automate_nav_structure( if match_string in contents[-1]: contents.append(insert_string) else: - for index, line in enumerate(contents): if match_string in line and insert_string not in contents[index + 1]: - contents = contents[: index + 1] contents.append(insert_string) break diff --git a/tests/test_function_to_test.py b/tests/test_function_to_test.py deleted file mode 100644 index 55ecd26..0000000 --- a/tests/test_function_to_test.py +++ /dev/null @@ -1,6 +0,0 @@ -def test_some_function(): - """ - This function tests the some_function function. - It should always return true - """ - assert some_function() is True From 385d2864af2a24c550c7b842de6c6f527a67219a Mon Sep 17 00:00:00 2001 From: James Mulhall <62727053+mullach@users.noreply.github.com> Date: Wed, 1 Nov 2023 11:50:15 -0700 Subject: [PATCH 06/12] slimmed down environment.yml --- environment.yml | 113 ++--------------------------------------------- requirements.txt | 6 --- 2 files changed, 4 insertions(+), 115 deletions(-) delete mode 100644 requirements.txt diff --git a/environment.yml b/environment.yml index 7c7bbeb..3e8973f 100644 --- a/environment.yml +++ b/environment.yml @@ -1,112 +1,7 @@ -name: trainingenv +name: slimenv channels: - - conda-forge - defaults dependencies: - - asttokens=2.4.1=pyhd8ed1ab_0 - - backcall=0.2.0=pyh9f0ad1d_0 - - backports=1.0=pyhd8ed1ab_3 - - backports.functools_lru_cache=1.6.5=pyhd8ed1ab_0 - - blas=1.0=mkl - - brotli=1.0.9=h2bbff1b_7 - - brotli-bin=1.0.9=h2bbff1b_7 - - bzip2=1.0.8=he774522_0 - - ca-certificates=2023.08.22=haa95532_0 - - colorama=0.4.6=pyhd8ed1ab_0 - - comm=0.1.4=pyhd8ed1ab_0 - - contourpy=1.0.5=py311h59b6b97_0 - - cycler=0.11.0=pyhd3eb1b0_0 - - debugpy=1.6.7=py311hd77b12b_0 - - decorator=5.1.1=pyhd8ed1ab_0 - - exceptiongroup=1.1.3=pyhd8ed1ab_0 - - executing=2.0.1=pyhd8ed1ab_0 - - expat=2.5.0=hd77b12b_0 - - fonttools=4.25.0=pyhd3eb1b0_0 - - freetype=2.12.1=ha860e81_0 - - giflib=5.2.1=h8cc25b3_3 - - icu=73.1=h6c2663c_0 - - importlib-metadata=6.8.0=pyha770c72_0 - - importlib_metadata=6.8.0=hd8ed1ab_0 - - iniconfig=1.1.1=pyhd3eb1b0_0 - - intel-openmp=2023.1.0=h59b6b97_46319 - - ipykernel=6.26.0=pyha63f2e9_0 - - ipython=8.16.1=pyh5737063_0 - - jedi=0.19.1=pyhd8ed1ab_0 - - jpeg=9e=h2bbff1b_1 - - jupyter_client=8.5.0=pyhd8ed1ab_0 - - jupyter_core=5.5.0=py311h1ea47a8_0 - - kiwisolver=1.4.4=py311hd77b12b_0 - - krb5=1.20.1=h5b6d351_0 - - lerc=3.0=hd77b12b_0 - - libbrotlicommon=1.0.9=h2bbff1b_7 - - libbrotlidec=1.0.9=h2bbff1b_7 - - libbrotlienc=1.0.9=h2bbff1b_7 - - libclang=14.0.6=default_hb5a9fac_1 - - libclang13=14.0.6=default_h8e68704_1 - - libdeflate=1.17=h2bbff1b_1 - - libffi=3.4.4=hd77b12b_0 - - libpng=1.6.39=h8cc25b3_0 - - libpq=12.15=h906ac69_1 - - libsodium=1.0.18=h8d14728_1 - - libtiff=4.5.1=hd77b12b_0 - - libwebp=1.3.2=hbc33d0d_0 - - libwebp-base=1.3.2=h2bbff1b_0 - - lz4-c=1.9.4=h2bbff1b_0 - - matplotlib=3.8.0=py311haa95532_0 - - matplotlib-base=3.8.0=py311hf62ec03_0 - - matplotlib-inline=0.1.6=pyhd8ed1ab_0 - - mkl=2023.1.0=h6b88ed4_46357 - - mkl-service=2.4.0=py311h2bbff1b_1 - - mkl_fft=1.3.8=py311h2bbff1b_0 - - mkl_random=1.2.4=py311h59b6b97_0 - - munkres=1.1.4=py_0 - - nest-asyncio=1.5.8=pyhd8ed1ab_0 - - numpy=1.26.0=py311hdab7c0b_0 - - numpy-base=1.26.0=py311hd01c5d8_0 - - openjpeg=2.4.0=h4fc8c34_0 - - openssl=3.0.11=h2bbff1b_2 - - packaging=23.1=py311haa95532_0 - - parso=0.8.3=pyhd8ed1ab_0 - - pickleshare=0.7.5=py_1003 - - pillow=10.0.1=py311h045eedc_0 - - pip=23.3=py311haa95532_0 - - platformdirs=3.11.0=pyhd8ed1ab_0 - - pluggy=1.0.0=py311haa95532_1 - - ply=3.11=py311haa95532_0 - - prompt-toolkit=3.0.39=pyha770c72_0 - - prompt_toolkit=3.0.39=hd8ed1ab_0 - - psutil=5.9.0=py311h2bbff1b_0 - - pure_eval=0.2.2=pyhd8ed1ab_0 - - pygments=2.16.1=pyhd8ed1ab_0 - - pyparsing=3.0.9=py311haa95532_0 - - pyqt=5.15.10=py311hd77b12b_0 - - pyqt5-sip=12.13.0=py311h2bbff1b_0 - - pytest=7.4.0=py311haa95532_0 - - python=3.11.5=he1021f5_0 - - python-dateutil=2.8.2=pyhd3eb1b0_0 - - python_abi=3.11=2_cp311 - - pywin32=305=py311h2bbff1b_0 - - pyzmq=25.1.0=py311hd77b12b_0 - - qt-main=5.15.2=h19c9488_10 - - setuptools=68.0.0=py311haa95532_0 - - sip=6.7.12=py311hd77b12b_0 - - six=1.16.0=pyhd3eb1b0_1 - - sqlite=3.41.2=h2bbff1b_0 - - stack_data=0.6.2=pyhd8ed1ab_0 - - tbb=2021.8.0=h59b6b97_0 - - tk=8.6.12=h2bbff1b_0 - - tornado=6.3.3=py311h2bbff1b_0 - - traitlets=5.13.0=pyhd8ed1ab_0 - - typing-extensions=4.8.0=hd8ed1ab_0 - - typing_extensions=4.8.0=pyha770c72_0 - - tzdata=2023c=h04d1e81_0 - - vc=14.2=h21ff451_1 - - vs2015_runtime=14.27.29016=h5e58377_2 - - wcwidth=0.2.9=pyhd8ed1ab_0 - - wheel=0.37.1=pyhd3eb1b0_0 - - xz=5.4.2=h8cc25b3_0 - - zeromq=4.3.4=h0e60522_1 - - zipp=3.17.0=pyhd8ed1ab_0 - - zlib=1.2.13=h8cc25b3_0 - - zstd=1.5.5=hd43e919_0 -prefix: C:\Users\james\anaconda3\envs\trainingenv + - python=3.11 + - numpy + - matplotlib diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 4355f56..0000000 --- a/requirements.txt +++ /dev/null @@ -1,6 +0,0 @@ -pandas>=1.4.3 -setuptools>=61.2.0 -pytest>=7.1.2 -numpy>=1.23.1 -matplotlib>=3.5.1 -mkdocs From 25616fb468c97e77e4da06c50dce6b2ff82feb19 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 1 Nov 2023 18:50:55 +0000 Subject: [PATCH 07/12] Auto-updating the docs --- docs/sources/modules/src/plotting.md | 23 ----------------------- mkgendocs.yml | 5 ----- 2 files changed, 28 deletions(-) delete mode 100644 docs/sources/modules/src/plotting.md diff --git a/docs/sources/modules/src/plotting.md b/docs/sources/modules/src/plotting.md deleted file mode 100644 index a44d5d4..0000000 --- a/docs/sources/modules/src/plotting.md +++ /dev/null @@ -1,23 +0,0 @@ -# - - -### scatterplot -[source](https://github.com/mullach/Github-Training-Repository/blob/master/src/plotting.py/#L13) -```python -.scatterplot( - N -) -``` - ---- -Plots a matplotlib scatterplot using random data. - - -**Arguments** - -* **N** (int) : number of random datapoints to plot - - -**Returns** - -None diff --git a/mkgendocs.yml b/mkgendocs.yml index d0eabb5..9ccdabe 100644 --- a/mkgendocs.yml +++ b/mkgendocs.yml @@ -14,8 +14,3 @@ pages: functions: - multiply - - page: "modules/src/plotting.md" - source: "src/plotting.py" - functions: - - scatterplot - From d67b7c0ee0fed26a8a705e58f1a0dc0cbf2c57b8 Mon Sep 17 00:00:00 2001 From: James Mulhall <62727053+mullach@users.noreply.github.com> Date: Wed, 1 Nov 2023 12:03:25 -0700 Subject: [PATCH 08/12] Revert "slimmed down environment.yml" This reverts commit 385d2864af2a24c550c7b842de6c6f527a67219a. --- environment.yml | 113 +++++++++++++++++++++++++++++++++++++++++++++-- requirements.txt | 6 +++ 2 files changed, 115 insertions(+), 4 deletions(-) create mode 100644 requirements.txt diff --git a/environment.yml b/environment.yml index 3e8973f..7c7bbeb 100644 --- a/environment.yml +++ b/environment.yml @@ -1,7 +1,112 @@ -name: slimenv +name: trainingenv channels: + - conda-forge - defaults dependencies: - - python=3.11 - - numpy - - matplotlib + - asttokens=2.4.1=pyhd8ed1ab_0 + - backcall=0.2.0=pyh9f0ad1d_0 + - backports=1.0=pyhd8ed1ab_3 + - backports.functools_lru_cache=1.6.5=pyhd8ed1ab_0 + - blas=1.0=mkl + - brotli=1.0.9=h2bbff1b_7 + - brotli-bin=1.0.9=h2bbff1b_7 + - bzip2=1.0.8=he774522_0 + - ca-certificates=2023.08.22=haa95532_0 + - colorama=0.4.6=pyhd8ed1ab_0 + - comm=0.1.4=pyhd8ed1ab_0 + - contourpy=1.0.5=py311h59b6b97_0 + - cycler=0.11.0=pyhd3eb1b0_0 + - debugpy=1.6.7=py311hd77b12b_0 + - decorator=5.1.1=pyhd8ed1ab_0 + - exceptiongroup=1.1.3=pyhd8ed1ab_0 + - executing=2.0.1=pyhd8ed1ab_0 + - expat=2.5.0=hd77b12b_0 + - fonttools=4.25.0=pyhd3eb1b0_0 + - freetype=2.12.1=ha860e81_0 + - giflib=5.2.1=h8cc25b3_3 + - icu=73.1=h6c2663c_0 + - importlib-metadata=6.8.0=pyha770c72_0 + - importlib_metadata=6.8.0=hd8ed1ab_0 + - iniconfig=1.1.1=pyhd3eb1b0_0 + - intel-openmp=2023.1.0=h59b6b97_46319 + - ipykernel=6.26.0=pyha63f2e9_0 + - ipython=8.16.1=pyh5737063_0 + - jedi=0.19.1=pyhd8ed1ab_0 + - jpeg=9e=h2bbff1b_1 + - jupyter_client=8.5.0=pyhd8ed1ab_0 + - jupyter_core=5.5.0=py311h1ea47a8_0 + - kiwisolver=1.4.4=py311hd77b12b_0 + - krb5=1.20.1=h5b6d351_0 + - lerc=3.0=hd77b12b_0 + - libbrotlicommon=1.0.9=h2bbff1b_7 + - libbrotlidec=1.0.9=h2bbff1b_7 + - libbrotlienc=1.0.9=h2bbff1b_7 + - libclang=14.0.6=default_hb5a9fac_1 + - libclang13=14.0.6=default_h8e68704_1 + - libdeflate=1.17=h2bbff1b_1 + - libffi=3.4.4=hd77b12b_0 + - libpng=1.6.39=h8cc25b3_0 + - libpq=12.15=h906ac69_1 + - libsodium=1.0.18=h8d14728_1 + - libtiff=4.5.1=hd77b12b_0 + - libwebp=1.3.2=hbc33d0d_0 + - libwebp-base=1.3.2=h2bbff1b_0 + - lz4-c=1.9.4=h2bbff1b_0 + - matplotlib=3.8.0=py311haa95532_0 + - matplotlib-base=3.8.0=py311hf62ec03_0 + - matplotlib-inline=0.1.6=pyhd8ed1ab_0 + - mkl=2023.1.0=h6b88ed4_46357 + - mkl-service=2.4.0=py311h2bbff1b_1 + - mkl_fft=1.3.8=py311h2bbff1b_0 + - mkl_random=1.2.4=py311h59b6b97_0 + - munkres=1.1.4=py_0 + - nest-asyncio=1.5.8=pyhd8ed1ab_0 + - numpy=1.26.0=py311hdab7c0b_0 + - numpy-base=1.26.0=py311hd01c5d8_0 + - openjpeg=2.4.0=h4fc8c34_0 + - openssl=3.0.11=h2bbff1b_2 + - packaging=23.1=py311haa95532_0 + - parso=0.8.3=pyhd8ed1ab_0 + - pickleshare=0.7.5=py_1003 + - pillow=10.0.1=py311h045eedc_0 + - pip=23.3=py311haa95532_0 + - platformdirs=3.11.0=pyhd8ed1ab_0 + - pluggy=1.0.0=py311haa95532_1 + - ply=3.11=py311haa95532_0 + - prompt-toolkit=3.0.39=pyha770c72_0 + - prompt_toolkit=3.0.39=hd8ed1ab_0 + - psutil=5.9.0=py311h2bbff1b_0 + - pure_eval=0.2.2=pyhd8ed1ab_0 + - pygments=2.16.1=pyhd8ed1ab_0 + - pyparsing=3.0.9=py311haa95532_0 + - pyqt=5.15.10=py311hd77b12b_0 + - pyqt5-sip=12.13.0=py311h2bbff1b_0 + - pytest=7.4.0=py311haa95532_0 + - python=3.11.5=he1021f5_0 + - python-dateutil=2.8.2=pyhd3eb1b0_0 + - python_abi=3.11=2_cp311 + - pywin32=305=py311h2bbff1b_0 + - pyzmq=25.1.0=py311hd77b12b_0 + - qt-main=5.15.2=h19c9488_10 + - setuptools=68.0.0=py311haa95532_0 + - sip=6.7.12=py311hd77b12b_0 + - six=1.16.0=pyhd3eb1b0_1 + - sqlite=3.41.2=h2bbff1b_0 + - stack_data=0.6.2=pyhd8ed1ab_0 + - tbb=2021.8.0=h59b6b97_0 + - tk=8.6.12=h2bbff1b_0 + - tornado=6.3.3=py311h2bbff1b_0 + - traitlets=5.13.0=pyhd8ed1ab_0 + - typing-extensions=4.8.0=hd8ed1ab_0 + - typing_extensions=4.8.0=pyha770c72_0 + - tzdata=2023c=h04d1e81_0 + - vc=14.2=h21ff451_1 + - vs2015_runtime=14.27.29016=h5e58377_2 + - wcwidth=0.2.9=pyhd8ed1ab_0 + - wheel=0.37.1=pyhd3eb1b0_0 + - xz=5.4.2=h8cc25b3_0 + - zeromq=4.3.4=h0e60522_1 + - zipp=3.17.0=pyhd8ed1ab_0 + - zlib=1.2.13=h8cc25b3_0 + - zstd=1.5.5=hd43e919_0 +prefix: C:\Users\james\anaconda3\envs\trainingenv diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..4355f56 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +pandas>=1.4.3 +setuptools>=61.2.0 +pytest>=7.1.2 +numpy>=1.23.1 +matplotlib>=3.5.1 +mkdocs From 8aed75a709e808bfa8a3e04e9ed71c58720def59 Mon Sep 17 00:00:00 2001 From: James Mulhall <62727053+mullach@users.noreply.github.com> Date: Wed, 1 Nov 2023 12:07:31 -0700 Subject: [PATCH 09/12] brought back reqs --- environment.yml | 113 ++---------------------------------------------- 1 file changed, 4 insertions(+), 109 deletions(-) diff --git a/environment.yml b/environment.yml index 7c7bbeb..3e8973f 100644 --- a/environment.yml +++ b/environment.yml @@ -1,112 +1,7 @@ -name: trainingenv +name: slimenv channels: - - conda-forge - defaults dependencies: - - asttokens=2.4.1=pyhd8ed1ab_0 - - backcall=0.2.0=pyh9f0ad1d_0 - - backports=1.0=pyhd8ed1ab_3 - - backports.functools_lru_cache=1.6.5=pyhd8ed1ab_0 - - blas=1.0=mkl - - brotli=1.0.9=h2bbff1b_7 - - brotli-bin=1.0.9=h2bbff1b_7 - - bzip2=1.0.8=he774522_0 - - ca-certificates=2023.08.22=haa95532_0 - - colorama=0.4.6=pyhd8ed1ab_0 - - comm=0.1.4=pyhd8ed1ab_0 - - contourpy=1.0.5=py311h59b6b97_0 - - cycler=0.11.0=pyhd3eb1b0_0 - - debugpy=1.6.7=py311hd77b12b_0 - - decorator=5.1.1=pyhd8ed1ab_0 - - exceptiongroup=1.1.3=pyhd8ed1ab_0 - - executing=2.0.1=pyhd8ed1ab_0 - - expat=2.5.0=hd77b12b_0 - - fonttools=4.25.0=pyhd3eb1b0_0 - - freetype=2.12.1=ha860e81_0 - - giflib=5.2.1=h8cc25b3_3 - - icu=73.1=h6c2663c_0 - - importlib-metadata=6.8.0=pyha770c72_0 - - importlib_metadata=6.8.0=hd8ed1ab_0 - - iniconfig=1.1.1=pyhd3eb1b0_0 - - intel-openmp=2023.1.0=h59b6b97_46319 - - ipykernel=6.26.0=pyha63f2e9_0 - - ipython=8.16.1=pyh5737063_0 - - jedi=0.19.1=pyhd8ed1ab_0 - - jpeg=9e=h2bbff1b_1 - - jupyter_client=8.5.0=pyhd8ed1ab_0 - - jupyter_core=5.5.0=py311h1ea47a8_0 - - kiwisolver=1.4.4=py311hd77b12b_0 - - krb5=1.20.1=h5b6d351_0 - - lerc=3.0=hd77b12b_0 - - libbrotlicommon=1.0.9=h2bbff1b_7 - - libbrotlidec=1.0.9=h2bbff1b_7 - - libbrotlienc=1.0.9=h2bbff1b_7 - - libclang=14.0.6=default_hb5a9fac_1 - - libclang13=14.0.6=default_h8e68704_1 - - libdeflate=1.17=h2bbff1b_1 - - libffi=3.4.4=hd77b12b_0 - - libpng=1.6.39=h8cc25b3_0 - - libpq=12.15=h906ac69_1 - - libsodium=1.0.18=h8d14728_1 - - libtiff=4.5.1=hd77b12b_0 - - libwebp=1.3.2=hbc33d0d_0 - - libwebp-base=1.3.2=h2bbff1b_0 - - lz4-c=1.9.4=h2bbff1b_0 - - matplotlib=3.8.0=py311haa95532_0 - - matplotlib-base=3.8.0=py311hf62ec03_0 - - matplotlib-inline=0.1.6=pyhd8ed1ab_0 - - mkl=2023.1.0=h6b88ed4_46357 - - mkl-service=2.4.0=py311h2bbff1b_1 - - mkl_fft=1.3.8=py311h2bbff1b_0 - - mkl_random=1.2.4=py311h59b6b97_0 - - munkres=1.1.4=py_0 - - nest-asyncio=1.5.8=pyhd8ed1ab_0 - - numpy=1.26.0=py311hdab7c0b_0 - - numpy-base=1.26.0=py311hd01c5d8_0 - - openjpeg=2.4.0=h4fc8c34_0 - - openssl=3.0.11=h2bbff1b_2 - - packaging=23.1=py311haa95532_0 - - parso=0.8.3=pyhd8ed1ab_0 - - pickleshare=0.7.5=py_1003 - - pillow=10.0.1=py311h045eedc_0 - - pip=23.3=py311haa95532_0 - - platformdirs=3.11.0=pyhd8ed1ab_0 - - pluggy=1.0.0=py311haa95532_1 - - ply=3.11=py311haa95532_0 - - prompt-toolkit=3.0.39=pyha770c72_0 - - prompt_toolkit=3.0.39=hd8ed1ab_0 - - psutil=5.9.0=py311h2bbff1b_0 - - pure_eval=0.2.2=pyhd8ed1ab_0 - - pygments=2.16.1=pyhd8ed1ab_0 - - pyparsing=3.0.9=py311haa95532_0 - - pyqt=5.15.10=py311hd77b12b_0 - - pyqt5-sip=12.13.0=py311h2bbff1b_0 - - pytest=7.4.0=py311haa95532_0 - - python=3.11.5=he1021f5_0 - - python-dateutil=2.8.2=pyhd3eb1b0_0 - - python_abi=3.11=2_cp311 - - pywin32=305=py311h2bbff1b_0 - - pyzmq=25.1.0=py311hd77b12b_0 - - qt-main=5.15.2=h19c9488_10 - - setuptools=68.0.0=py311haa95532_0 - - sip=6.7.12=py311hd77b12b_0 - - six=1.16.0=pyhd3eb1b0_1 - - sqlite=3.41.2=h2bbff1b_0 - - stack_data=0.6.2=pyhd8ed1ab_0 - - tbb=2021.8.0=h59b6b97_0 - - tk=8.6.12=h2bbff1b_0 - - tornado=6.3.3=py311h2bbff1b_0 - - traitlets=5.13.0=pyhd8ed1ab_0 - - typing-extensions=4.8.0=hd8ed1ab_0 - - typing_extensions=4.8.0=pyha770c72_0 - - tzdata=2023c=h04d1e81_0 - - vc=14.2=h21ff451_1 - - vs2015_runtime=14.27.29016=h5e58377_2 - - wcwidth=0.2.9=pyhd8ed1ab_0 - - wheel=0.37.1=pyhd3eb1b0_0 - - xz=5.4.2=h8cc25b3_0 - - zeromq=4.3.4=h0e60522_1 - - zipp=3.17.0=pyhd8ed1ab_0 - - zlib=1.2.13=h8cc25b3_0 - - zstd=1.5.5=hd43e919_0 -prefix: C:\Users\james\anaconda3\envs\trainingenv + - python=3.11 + - numpy + - matplotlib From 60ef02946223b58ab6abc4605709db38aca2b75a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 1 Nov 2023 19:08:49 +0000 Subject: [PATCH 10/12] Auto-updating the docs --- docs/sources/modules/src/plotting.md | 23 +++++++++++++++++++++++ mkgendocs.yml | 5 +++++ 2 files changed, 28 insertions(+) create mode 100644 docs/sources/modules/src/plotting.md diff --git a/docs/sources/modules/src/plotting.md b/docs/sources/modules/src/plotting.md new file mode 100644 index 0000000..a44d5d4 --- /dev/null +++ b/docs/sources/modules/src/plotting.md @@ -0,0 +1,23 @@ +# + + +### scatterplot +[source](https://github.com/mullach/Github-Training-Repository/blob/master/src/plotting.py/#L13) +```python +.scatterplot( + N +) +``` + +--- +Plots a matplotlib scatterplot using random data. + + +**Arguments** + +* **N** (int) : number of random datapoints to plot + + +**Returns** + +None diff --git a/mkgendocs.yml b/mkgendocs.yml index 9ccdabe..d0eabb5 100644 --- a/mkgendocs.yml +++ b/mkgendocs.yml @@ -14,3 +14,8 @@ pages: functions: - multiply + - page: "modules/src/plotting.md" + source: "src/plotting.py" + functions: + - scatterplot + From 9a9c4138eb89f64d9d181c7e1fedd6c2e2d7929f Mon Sep 17 00:00:00 2001 From: James Mulhall <62727053+mullach@users.noreply.github.com> Date: Wed, 1 Nov 2023 12:14:23 -0700 Subject: [PATCH 11/12] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 0933268..a15729d 100644 --- a/README.md +++ b/README.md @@ -42,3 +42,6 @@ Please look at all those materials before you start the exercise. 17. Check back in with Morgan or Florian if you have any questions (florian@allfed.info or morgan@allfed.info) If you get stuck at any point please reach out to one of the data scientists (either florian@allfed.info or morgan@allfed.info). + +# Documentation +Automated docs are available [here](https://mullach.github.io/Github-Training-Repository/) for the completed training. From 84b38c3d8eac8ead554c0dbaf367237c6944ffd9 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 1 Nov 2023 19:15:10 +0000 Subject: [PATCH 12/12] Auto-updating the docs --- docs/sources/index.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/sources/index.md b/docs/sources/index.md index 0933268..a15729d 100644 --- a/docs/sources/index.md +++ b/docs/sources/index.md @@ -42,3 +42,6 @@ Please look at all those materials before you start the exercise. 17. Check back in with Morgan or Florian if you have any questions (florian@allfed.info or morgan@allfed.info) If you get stuck at any point please reach out to one of the data scientists (either florian@allfed.info or morgan@allfed.info). + +# Documentation +Automated docs are available [here](https://mullach.github.io/Github-Training-Repository/) for the completed training.