diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 85d7e1f..c5f2725 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -28,6 +28,7 @@ jobs: - js - jupyter - rust + # - rustjswasm os: - ubuntu-latest - macos-latest diff --git a/Makefile b/Makefile index b88d130..dad8dee 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ SED = sed -i '' -e endif -.PHONY: gen-python gen-cpp gen-js gen-jupyter gen-rust +.PHONY: gen-python gen-cpp gen-js gen-jupyter gen-rust gen-rustjswasm gen-python: ## regenerate the python template from scratch mkdir -p ../python-template && cd ../python-template && rm -rf ./* && rm -rf .copier-answers.yaml .gitignore .github .gitattributes copier copy -w . ../python-template --data-file examples/python.yaml @@ -44,7 +44,12 @@ gen-rust: ## regenerate the rust template from scratch copier copy -w . ../python-template-rust --data-file examples/rust.yaml cd ../python-template-rust && $(SED) 's#_src_path: .#_src_path: https://github.com/python-project-templates/base.git#g' ./.copier-answers.yaml -.PHONY: test-python test-cpp test-js test-jupyter test-rust +gen-rustjswasm: ## regenerate the rustjswasm template from scratch + mkdir -p ../python-template-rustjswasm && cd ../python-template-rustjswasm && rm -rf ./* && rm -rf .copier-answers.yaml .gitignore .github .gitattributes + copier copy -w . ../python-template-rustjswasm --data-file examples/rustjswasm.yaml + cd ../python-template-rustjswasm && $(SED) 's#_src_path: .#_src_path: https://github.com/python-project-templates/base.git#g' ./.copier-answers.yaml + +.PHONY: test-python test-cpp test-js test-jupyter test-rust test-rustjswasm test-python: cd ../python-template && git config --global user.name "github-actions" && git config --global user.email "41898282+github-actions[bot]@users.noreply.github.c@example.com" && git init && git add . && git commit -m "initial commit" cd ../python-template && make develop @@ -82,3 +87,12 @@ test-rust: cd ../python-template-rust && make checks cd ../python-template-rust && make test +test-rustjswasm: + cd ../python-template-rust && git config --global user.name "github-actions" && git config --global user.email "41898282+github-actions[bot]@users.noreply.github.c@example.com" && git init && git add . && git commit -m "initial commit" + cd ../python-template-rust && make develop + cd ../python-template-rust && git add Cargo.lock && git commit -m "lockfile" + cd ../python-template-rust && make lint + cd ../python-template-rust && make checks + cd ../python-template-rust && make test + + diff --git a/examples/rustjswasm.yaml b/examples/rustjswasm.yaml new file mode 100644 index 0000000..6672bfe --- /dev/null +++ b/examples/rustjswasm.yaml @@ -0,0 +1,10 @@ +--- +add_docs: true +add_wiki: true +add_extension: rustjswasm +email: 3105306+timkpaine@users.noreply.github.com +github: python-project-templates +project_description: A Rust-Python project template +project_name: python template rust +python_version_primary: '3.9' +team: Python Project Template Authors diff --git a/rustjswasm/.gitattributes b/rustjswasm/.gitattributes new file mode 100644 index 0000000..e3e8131 --- /dev/null +++ b/rustjswasm/.gitattributes @@ -0,0 +1,16 @@ +examples/* linguist-documentation +docs/* linguist-documentation +*.ipynb linguist-documentation +Makefile linguist-documentation + +*.css text=auto eol=lf +*.html text=auto eol=lf +*.js text=auto eol=lf +*.json text=auto eol=lf +*.less text=auto eol=lf +*.md text=auto eol=lf +*.py text=auto eol=lf +*.rs text=auto eol=lf +*.toml text=auto eol=lf +*.ts text=auto eol=lf +*.yaml text=auto eol=lf diff --git a/rustjswasm/.github/CODE_OF_CONDUCT.md.jinja b/rustjswasm/.github/CODE_OF_CONDUCT.md.jinja new file mode 100644 index 0000000..ebc86d7 --- /dev/null +++ b/rustjswasm/.github/CODE_OF_CONDUCT.md.jinja @@ -0,0 +1,76 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, sex characteristics, gender identity and expression, +level of experience, education, socio-economic status, nationality, personal +appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at {{email}}. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see +https://www.contributor-covenant.org/faq diff --git a/rustjswasm/.github/ISSUE_TEMPLATE/bug_report.md b/rustjswasm/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..dd84ea7 --- /dev/null +++ b/rustjswasm/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,38 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS] + - Browser [e.g. chrome, safari] + - Version [e.g. 22] + +**Smartphone (please complete the following information):** + - Device: [e.g. iPhone6] + - OS: [e.g. iOS8.1] + - Browser [e.g. stock browser, safari] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/rustjswasm/.github/ISSUE_TEMPLATE/feature_request.md b/rustjswasm/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..bbcbbe7 --- /dev/null +++ b/rustjswasm/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/rustjswasm/.github/dependabot.yaml b/rustjswasm/.github/dependabot.yaml new file mode 100644 index 0000000..aa772f6 --- /dev/null +++ b/rustjswasm/.github/dependabot.yaml @@ -0,0 +1,33 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + labels: + - "part: github_actions" + + - package-ecosystem: "pip" + directory: "/" + schedule: + interval: "monthly" + labels: + - "lang: python" + - "part: dependencies" + + - package-ecosystem: "npm" + directory: "/js" + schedule: + interval: "monthly" + labels: + - "lang: javascript" + - "part: dependencies" + + - package-ecosystem: "cargo" + directory: "/" + schedule: + interval: "monthly" + labels: + - "lang: rust" + - "part: dependencies" + diff --git a/rustjswasm/.github/workflows/build.yaml.jinja b/rustjswasm/.github/workflows/build.yaml.jinja new file mode 100644 index 0000000..4adf9a3 --- /dev/null +++ b/rustjswasm/.github/workflows/build.yaml.jinja @@ -0,0 +1,108 @@ +name: Build Status + +on: + push: + branches: + - main + tags: + - v* + paths-ignore: + - LICENSE + - README.md + pull_request: + branches: + - main + workflow_dispatch: + +concurrency: + group: {% raw %}${{ github.workflow }}-${{ github.head_ref || github.run_id }}{% endraw %} + cancel-in-progress: true + +permissions: + contents: read + checks: write + pull-requests: write + +jobs: + build: + runs-on: {% raw %}${{ matrix.os }}{% endraw %} + + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + python-version: ["{{python_version_primary}}"] + node-version: [20.x] + + steps: + - uses: actions/checkout@v4 + + - uses: actions-ext/python/setup@main + with: + version: {% raw %}${{ matrix.python-version }}{% endraw %} + + - uses: actions-ext/rust/setup@main + + - uses: actions-ext/node/setup@main + with: + version: 20.x + + - name: Install dependencies + run: make develop + + - name: Lint + run: make lint + + - name: Checks + run: make checks + if: matrix.os == 'ubuntu-latest' + + - name: Build + run: make build + + - name: Test + run: make coverage + + - name: Upload test results (Python) + uses: actions/upload-artifact@v4 + with: + name: {% raw %}test-results-${{ matrix.os }}-${{ matrix.python-version }}{% endraw %} + path: '**/junit.xml' + if: {% raw %}${{ always() }}{% endraw %} + + - name: Publish Unit Test Results + uses: EnricoMi/publish-unit-test-result-action@v2 + with: + files: '**/junit.xml' + if: matrix.os == 'ubuntu-latest' + + - name: Upload coverage + uses: codecov/codecov-action@v5 + with: + token: {% raw %}${{ secrets.CODECOV_TOKEN }}{% endraw %} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + with: + platforms: all + if: runner.os == 'Linux' && runner.arch == 'X64' + + - name: Make dist + run: | + make dist-rs + make dist-py-sdist + make dist-py-wheel + make dist-check + if: matrix.os == 'ubuntu-latest' + + - name: Make dist + run: | + make dist-py-wheel + make dist-check + env: + CIBW_ENVIRONMENT_MACOS: MACOSX_DEPLOYMENT_TARGET=11.0 + if: matrix.os != 'ubuntu-latest' + + - uses: actions/upload-artifact@v4 + with: + name: {% raw %}dist-${{matrix.os}}{% endraw %} + path: dist diff --git a/rustjswasm/.github/workflows/copier.yaml b/rustjswasm/.github/workflows/copier.yaml new file mode 100644 index 0000000..871b414 --- /dev/null +++ b/rustjswasm/.github/workflows/copier.yaml @@ -0,0 +1,17 @@ +name: Copier Updates + +on: + workflow_dispatch: + schedule: + - cron: "0 5 * * 0" + +jobs: + update: + permissions: + contents: write + pull-requests: write + runs-on: ubuntu-latest + steps: + - uses: actions-ext/copier-update@main + with: + token: ${{ secrets.WORKFLOW_TOKEN }} diff --git a/rustjswasm/.github/workflows/{% if add_docs %}docs.yaml{% endif %}.jinja b/rustjswasm/.github/workflows/{% if add_docs %}docs.yaml{% endif %}.jinja new file mode 100644 index 0000000..c9d5c99 --- /dev/null +++ b/rustjswasm/.github/workflows/{% if add_docs %}docs.yaml{% endif %}.jinja @@ -0,0 +1,24 @@ +name: Docs +on: + push: + branches: + - main + workflow_dispatch: +permissions: + contents: write +jobs: + docs: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions-ext/python/setup@main + - uses: actions-ext/rust/setup@main + - uses: actions-ext/node/setup@main + - run: uv pip install . + - run: uv pip install yardang + - run: yardang build + - uses: peaceiris/actions-gh-pages@v4 + with: + publish_branch: gh-pages + github_token: {% raw %}${{ secrets.GITHUB_TOKEN }}{% endraw %} + publish_dir: docs/html diff --git a/rustjswasm/.github/workflows/{% if add_wiki %}wiki.yaml{% endif %}.jinja b/rustjswasm/.github/workflows/{% if add_wiki %}wiki.yaml{% endif %}.jinja new file mode 100644 index 0000000..d5f3b74 --- /dev/null +++ b/rustjswasm/.github/workflows/{% if add_wiki %}wiki.yaml{% endif %}.jinja @@ -0,0 +1,27 @@ +name: Publish Docs + +on: + push: + branches: + - main + paths: + - "docs/**" + - "README.md" + workflow_dispatch: + +concurrency: + group: docs + cancel-in-progress: true + +permissions: + contents: write + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: cp README.md docs/wiki/Home.md + - uses: Andrew-Chen-Wang/github-wiki-action@v5 + with: + path: docs/wiki diff --git a/rustjswasm/.gitignore.jinja b/rustjswasm/.gitignore.jinja new file mode 100644 index 0000000..9de3414 --- /dev/null +++ b/rustjswasm/.gitignore.jinja @@ -0,0 +1,153 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.a +*.so +*.obj +*.dll +*.exp +*.lib + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +junit.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# PyBuilder +target/ + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# Documentation +/site +index.md +docs/_build/ +docs/src/_build/ +docs/api +docs/index.md +docs/html +docs/jupyter_execute +index.md + +# JS +js/coverage +js/dist +js/lib +js/node_modules +js/*.tgz + +# Jupyter +.ipynb_checkpoints +.autoversion +{{module}}/nbextension +{{module}}/labextension + +# Mac +.DS_Store + +# Rust +target diff --git a/rustjswasm/.vscode/settings.json b/rustjswasm/.vscode/settings.json new file mode 100644 index 0000000..dab99f9 --- /dev/null +++ b/rustjswasm/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "eslint.workingDirectories": ["./js"] +} \ No newline at end of file diff --git a/rustjswasm/Cargo.toml.jinja b/rustjswasm/Cargo.toml.jinja new file mode 100644 index 0000000..5403f72 --- /dev/null +++ b/rustjswasm/Cargo.toml.jinja @@ -0,0 +1,19 @@ +[package] +name = "{{module}}_py" +version = "0.1.0" +edition = "2021" +publish = false + +[lib] +name = "{{module}}" +path = "src/lib.rs" +crate-type = ["cdylib"] + +[dependencies] +{{module}} = { path = "./rust", version = "*" } +pyo3 = { version = "0.22", features = ["abi3-py39", "extension-module", "multiple-pymethods"] } +strum = "0.24.1" + +[profile.release] +panic = 'abort' +lto = true diff --git a/rustjswasm/LICENSE.jinja b/rustjswasm/LICENSE.jinja new file mode 100644 index 0000000..ee2a86d --- /dev/null +++ b/rustjswasm/LICENSE.jinja @@ -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 2025 {{team}} + + 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/rustjswasm/Makefile.jinja b/rustjswasm/Makefile.jinja new file mode 100644 index 0000000..1f69b83 --- /dev/null +++ b/rustjswasm/Makefile.jinja @@ -0,0 +1,212 @@ +######### +# BUILD # +######### +.PHONY: develop-py develop-js develop-rs develop +develop-py: + uv pip install -e .[develop] + +develop-js: requirements-js + +develop-rs: + make -C rust develop + +develop: develop-rs develop-js develop-py ## setup project for development + +.PHONY: requirements-py requirements-js requirements-rs requirements +requirements-py: ## install prerequisite python build requirements + python -m pip install --upgrade pip toml + python -m pip install `python -c 'import toml; c = toml.load("pyproject.toml"); print("\n".join(c["build-system"]["requires"]))'` + python -m pip install `python -c 'import toml; c = toml.load("pyproject.toml"); print(" ".join(c["project"]["optional-dependencies"]["develop"]))'` + +requirements-js: ## install prerequisite javascript build requirements + cd js; pnpm install && npx playwright install + +requirements-rs: ## install prerequisite rust build requirements + make -C rust requirements + +requirements: requirements-rs requirements-js requirements-py ## setup project for development + +.PHONY: build-py build-js build-rs build dev +build-py: + maturin build + +build-js: + cd js; pnpm build + +build-rs: + make -C rust build + +dev: build ## lightweight in-place build for iterative dev + $(_CP_COMMAND) + +build: build-rs build-js build-py ## build the project + +.PHONY: install +install: ## install python library + uv pip install . + +UNAME := $(shell uname) +ifeq ($(UNAME), Darwin) + _CP_COMMAND := cp target/debug/lib{{module}}.dylib {{module}}/{{module}}.abi3.so +else + _CP_COMMAND := cp target/debug/lib{{module}}.so {{module}}/{{module}}.abi3.so +endif + +######### +# LINTS # +######### +.PHONY: lint-py lint-js lint-rs lint-docs lint lints +lint-py: ## run python linter with ruff + python -m ruff check {{module}} + python -m ruff format --check {{module}} + +lint-js: ## run js linter + cd js; pnpm lint + +lint-rs: ## run rust linter + make -C rust lint + +lint-docs: ## lint docs with mdformat and codespell + python -m mdformat --check README.md {% if add_wiki %}docs/wiki/{% endif %} + python -m codespell_lib README.md {% if add_wiki %}docs/wiki/{% endif %} + +lint: lint-rs lint-js lint-py lint-docs ## run project linters + +# alias +lints: lint + +.PHONY: fix-py fix-js fix-rs fix-docs fix format +fix-py: ## fix python formatting with ruff + python -m ruff check --fix {{module}} + python -m ruff format {{module}} + +fix-js: ## fix js formatting + cd js; pnpm fix + +fix-rs: ## fix rust formatting + make -C rust fix + +fix-docs: ## autoformat docs with mdformat and codespell + python -m mdformat README.md {% if add_wiki %}docs/wiki/{% endif %} + python -m codespell_lib --write README.md {% if add_wiki %}docs/wiki/{% endif %} + +fix: fix-rs fix-js fix-py fix-docs ## run project autoformatters + +# alias +format: fix + +################ +# Other Checks # +################ +.PHONY: check-manifest checks check + +check-manifest: ## check python sdist manifest with check-manifest + check-manifest -v + +checks: check-manifest + +# alias +check: checks + +######### +# TESTS # +######### +.PHONY: test-py tests-py coverage-py +test-py: ## run python tests + python -m pytest -v {{module}}/tests + +# alias +tests-py: test-py + +coverage-py: ## run python tests and collect test coverage + python -m pytest -v {{module}}/tests --cov={{module}} --cov-report term-missing --cov-report xml + +.PHONY: test-js tests-js coverage-js +test-js: ## run js tests + cd js; pnpm test + +# alias +tests-js: test-js + +coverage-js: test-js ## run js tests and collect test coverage + +.PHONY: test-rs tests-rs coverage-rs +test-rs: ## run rust tests + make -C rust test + +# alias +tests-rs: test-rs + +coverage-rs: ## run rust tests and collect test coverage + make -C rust coverage + +.PHONY: test coverage tests +test: test-py test-js test-rs ## run all tests +coverage: coverage-py coverage-js coverage-rs ## run all tests and collect test coverage + +# alias +tests: test + +########### +# VERSION # +########### +.PHONY: show-version patch minor major + +show-version: ## show current library version + @bump-my-version show current_version + +patch: ## bump a patch version + @bump-my-version bump patch + +minor: ## bump a minor version + @bump-my-version bump minor + +major: ## bump a major version + @bump-my-version bump major + +######## +# DIST # +######## +.PHONY: dist-py-wheel dist-py-sdist dist-rs dist-check dist publish + +dist-py-wheel: # build python wheel + python -m cibuildwheel --output-dir dist + +dist-py-sdist: # build python sdist + python -m build --sdist -o dist + +dist-js: # build js dists + cd js; pnpm pack + +dist-rs: # build rust dists + make -C rust dist + +dist-check: ## run python dist checker with twine + python -m twine check dist/* + +dist: clean build dist-rs dist-js dist-py-wheel dist-py-sdist dist-check ## build all dists + +publish: dist # publish python assets + +######### +# CLEAN # +######### +.PHONY: deep-clean clean + +deep-clean: ## clean everything from the repository + git clean -fdx + +clean: ## clean the repository + rm -rf .coverage coverage cover htmlcov logs build dist *.egg-info + +############################################################################################ + +.PHONY: help + +# Thanks to Francoise at marmelab.com for this +.DEFAULT_GOAL := help +help: + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' + +print-%: + @echo '$*=$($*)' diff --git a/rustjswasm/README.md.jinja b/rustjswasm/README.md.jinja new file mode 100644 index 0000000..d8ce83b --- /dev/null +++ b/rustjswasm/README.md.jinja @@ -0,0 +1,13 @@ +# {{project_name}} + +{{project_description}} + +[![Build Status](https://github.com/{{github}}/{{project_name_formatted}}/actions/workflows/build.yaml/badge.svg?branch=main&event=push)](https://github.com/{{github}}/{{project_name_formatted}}/actions/workflows/build.yaml) +[![codecov](https://codecov.io/gh/{{github}}/{{project_name_formatted}}/branch/main/graph/badge.svg)](https://codecov.io/gh/{{github}}/{{project_name_formatted}}) +[![License](https://img.shields.io/github/license/{{github}}/{{project_name_formatted}})](https://github.com/{{github}}/{{project_name_formatted}}) +[![PyPI](https://img.shields.io/pypi/v/{{project_name_formatted}}.svg)](https://pypi.python.org/pypi/{{project_name_formatted}}) + +## Overview + +> [!NOTE] +> This library was generated using [copier](https://copier.readthedocs.io/en/stable/) from the [Base Python Project Template repository](https://github.com/python-project-templates/base). diff --git a/rustjswasm/js/.eslintrc.js b/rustjswasm/js/.eslintrc.js new file mode 100644 index 0000000..1882e1e --- /dev/null +++ b/rustjswasm/js/.eslintrc.js @@ -0,0 +1,59 @@ +module.exports = { + parser: "@babel/eslint-parser", + extends: ["airbnb-base", "prettier", "plugin:json/recommended"], + plugins: ["prettier", "jest"], + env: { + browser: true, + commonjs: true, + es6: true, + node: true, + jasmine: true, + jest: true, + "jest/globals": true, + }, + parserOptions: { + ecmaVersion: 2017, + ecmaFeatures: {}, + sourceType: "module", + experimentalObjectRestSpread: true, + }, + rules: { + "prettier/prettier": [ + "error", + { + printWidth: 200, + tabWidth: 2, + bracketSpacing: false, + }, + ], + "max-len": [ + "warn", + { + code: 200, + comments: 200, + ignoreTrailingComments: true, + }, + ], + camelcase: "off", + "class-methods-use-this": "off", + "constructor-super": "error", + indent: "off", + "linebreak-style": ["error", "unix"], + "no-const-assign": "error", + "no-nested-ternary": "warn", + "no-this-before-super": "error", + "no-undef": "error", + "no-underscore-dangle": "off", + "no-unreachable": "error", + "no-unused-vars": "warn", + "object-curly-spacing": "off", + quotes: "off", + "spaced-comment": "off", + "valid-typeof": "error", + + "import/extensions": "off", + "import/no-unresolved": "off", + "import/prefer-default-export": "off", + "import/no-extraneous-dependencies": "off", + }, +}; \ No newline at end of file diff --git a/rustjswasm/js/babel.config.js b/rustjswasm/js/babel.config.js new file mode 100644 index 0000000..e7f0622 --- /dev/null +++ b/rustjswasm/js/babel.config.js @@ -0,0 +1,12 @@ +module.exports = { + presets: [ + [ + "@babel/preset-env", + { + targets: { + node: "current", + }, + }, + ], + ], + }; \ No newline at end of file diff --git a/rustjswasm/js/jest.config.js b/rustjswasm/js/jest.config.js new file mode 100644 index 0000000..764a009 --- /dev/null +++ b/rustjswasm/js/jest.config.js @@ -0,0 +1,32 @@ +const esModules = [ + "@finos", + "@jupyter", + "@jupyterlab", + "@jupyter-widgets", + "@microsoft", + "@rjsf", + "delaunator", + "exenv-es6", + "internmap", + "lib0", + "lodash-es", + "nanoid", + "robust-predicates", + "y-protocols", +].join("|"); + +module.exports = { + moduleDirectories: ["node_modules", "src", "tests"], + moduleNameMapper: { + "\\.(css|less|sass|scss)$": "/tests/styleMock.js", + "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "/tests/fileMock.js", + }, + reporters: [ "default", "jest-junit" ], + setupFiles: ["/tests/setup.js"], + testEnvironment: "jsdom", + transform: { + "^.+\\.jsx?$": "babel-jest", + ".+\\.(css|styl|less|sass|scss)$": "jest-transform-css", + }, + transformIgnorePatterns: [`/node_modules/.pnpm/(?!(${esModules}))`], +}; diff --git a/rustjswasm/js/package.json.jinja b/rustjswasm/js/package.json.jinja new file mode 100644 index 0000000..85b6ac1 --- /dev/null +++ b/rustjswasm/js/package.json.jinja @@ -0,0 +1,76 @@ +{ + "name": "{{project_name_formatted}}", + "version": "0.1.0", + "description": "{{project_description}}", + "repository": "git@github.com:{{github}}/{{project_name_formatted}}.git", + "author": "{{team}} <{{email}}>", + "license": "Apache-2.0", + "keywords": [ + "jupyter", + "jupyterlab", + "jupyterlab-extension" + ], + "main": "lib/index.js", + "files": [ + "lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}", + "style/**/*.css" + ], + "jupyterlab": { + "extension": "lib/index.js", + "outputDir": "../{{module}}/labextension", + "discovery": { + "server": { + "base": { + "name": "{{module}}" + }, + "managers": [ + "pip" + ] + } + } + }, + "scripts": { + "build:babel": "babel src/ --source-maps --out-dir lib/", + "build:nbextension": "mkdirp ../{{module}}/nbextension/static/ && cpy --flat 'src/notebook.js' '../{{module}}/nbextension/static/'", + "build:labextension": "rimraf ../{{module}}/labextension && jupyter labextension build .", + "build": "pnpm clean && pnpm build:babel && pnpm build:labextension && pnpm build:nbextension", + "clean": "rimraf lib", + "fix": "pnpm lint --fix", + "lint": "eslint -c .eslintrc.js --ext .js src/ tests/", + "preinstall": "npx only-allow pnpm", + "prepublishOnly": "pnpm run build", + "test": "jest --coverage --collectCoverageFrom=src/*.{js}" + }, + "dependencies": { + "@jupyterlab/application": "^4.4.2", + "@jupyterlab/apputils": "^4.5.2", + "@jupyterlab/notebook": "^4.4.2", + "@jupyterlab/services": "^7.4.2", + "@lumino/disposable": "^2.1.4" + }, + "devDependencies": { + "@babel/cli": "^7.27.2", + "@babel/core": "^7.27.1", + "@babel/eslint-parser": "^7.27.1", + "@babel/preset-env": "^7.27.2", + "@jupyterlab/builder": "^4.4.2", + "babel-jest": "^29.7.0", + "cpy-cli": "^5.0.0", + "eslint": "^8.57.1", + "eslint-config-airbnb": "^19.0.4", + "eslint-config-airbnb-base": "^15.0.0", + "eslint-config-prettier": "^10.1.5", + "eslint-plugin-import": "^2.31.0", + "eslint-plugin-jest": "^28.11.0", + "eslint-plugin-json": "^3.1.0", + "eslint-plugin-prettier": "^5.4.0", + "isomorphic-fetch": "^3.0.0", + "jest": "^29.7.0", + "jest-environment-jsdom": "^29.7.0", + "jest-junit": "^16.0.0", + "jest-transform-css": "^6.0.2", + "mkdirp": "^3.0.1", + "prettier": "^3.5.3", + "rimraf": "^6.0.1" + } +} diff --git a/rustjswasm/js/src/index.js.jinja b/rustjswasm/js/src/index.js.jinja new file mode 100644 index 0000000..44b4e24 --- /dev/null +++ b/rustjswasm/js/src/index.js.jinja @@ -0,0 +1,17 @@ +import "../style/index.css"; + +async function activate(app) { + // eslint-disable-next-line no-console + console.log("JupyterLab extension {{project_name_formatted}} is activated!"); +} + +const extension = { + activate, + autoStart: true, + id: "{{project_name_formatted}}", + optional: [], + requires: [], +}; + +export default extension; +export {activate as _activate}; diff --git a/rustjswasm/js/src/notebook.js b/rustjswasm/js/src/notebook.js new file mode 100644 index 0000000..e69de29 diff --git a/rustjswasm/js/style/index.css b/rustjswasm/js/style/index.css new file mode 100644 index 0000000..e69de29 diff --git a/rustjswasm/js/tests/activate.test.js b/rustjswasm/js/tests/activate.test.js new file mode 100644 index 0000000..97638e7 --- /dev/null +++ b/rustjswasm/js/tests/activate.test.js @@ -0,0 +1,9 @@ +import "isomorphic-fetch"; + +import {_activate} from "../src/index"; + +describe("Checks activate", () => { + test("Check activate", () => { + expect(_activate); + }); +}); diff --git a/rustjswasm/js/tests/assetsTransformer.js b/rustjswasm/js/tests/assetsTransformer.js new file mode 100644 index 0000000..24a24d5 --- /dev/null +++ b/rustjswasm/js/tests/assetsTransformer.js @@ -0,0 +1,5 @@ +import {basename} from "path"; + +export function process(src, filename) { + return `module.exports = ${JSON.stringify(basename(filename))};`; +} diff --git a/rustjswasm/js/tests/export.test.js b/rustjswasm/js/tests/export.test.js new file mode 100644 index 0000000..ddef5cf --- /dev/null +++ b/rustjswasm/js/tests/export.test.js @@ -0,0 +1,9 @@ +import "isomorphic-fetch"; + +import * as extension from "../src/index"; + +describe("Checks exports", () => { + test("Check extension", () => { + expect(extension); + }); +}); diff --git a/rustjswasm/js/tests/fileMock.js b/rustjswasm/js/tests/fileMock.js new file mode 100644 index 0000000..0a445d0 --- /dev/null +++ b/rustjswasm/js/tests/fileMock.js @@ -0,0 +1 @@ +module.exports = "test-file-stub"; diff --git a/rustjswasm/js/tests/setup.js b/rustjswasm/js/tests/setup.js new file mode 100644 index 0000000..99f6af5 --- /dev/null +++ b/rustjswasm/js/tests/setup.js @@ -0,0 +1,17 @@ +Object.defineProperty(window, "DragEvent", { + value: class DragEvent {}, +}); + +Object.defineProperty(window, "matchMedia", { + writable: true, + value: jest.fn().mockImplementation((query) => ({ + matches: false, + media: query, + onchange: null, + addListener: jest.fn(), // Deprecated + removeListener: jest.fn(), // Deprecated + addEventListener: jest.fn(), + removeEventListener: jest.fn(), + dispatchEvent: jest.fn(), + })), +}); diff --git a/rustjswasm/js/tests/styleMock.js b/rustjswasm/js/tests/styleMock.js new file mode 100644 index 0000000..f053ebf --- /dev/null +++ b/rustjswasm/js/tests/styleMock.js @@ -0,0 +1 @@ +module.exports = {}; diff --git a/rustjswasm/pyproject.toml.jinja b/rustjswasm/pyproject.toml.jinja new file mode 100644 index 0000000..2ed40e9 --- /dev/null +++ b/rustjswasm/pyproject.toml.jinja @@ -0,0 +1,184 @@ +[build-system] +requires = ["hatchling", "hatch-js", "hatch-rs"] +build-backend = "hatchling.build" + +[project] +name = "{{project_name_formatted}}" +authors = [{name = "{{team}}", email = "{{email}}"}] +description = "{{project_description}}" +readme = "README.md" +license = { text = "Apache-2.0" } +version = "0.1.0" +requires-python = ">=3.9" +keywords = [] + +classifiers = [ + "Development Status :: 3 - Alpha", + "Programming Language :: Rust", + "Programming Language :: Python", + "Programming Language :: Python :: Implementation :: CPython", + "Programming Language :: Python :: Implementation :: PyPy", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", +] + +dependencies = [] + +[project.optional-dependencies] +develop = [ + "build", + "bump-my-version", + "check-manifest", + "cibuildwheel", + "codespell>=2.4,<2.5", + "hatch-jupyter-builder", + "hatchling", + "mdformat>=0.7.22,<0.8", + "mdformat-tables>=1", + "pytest", + "pytest-cov", + "ruff", + "twine", + "wheel", +] + +[project.scripts] + +[project.urls] +Repository = "https://github.com/{{github}}/{{project_name_formatted}}" +Homepage = "https://github.com/{{github}}/{{project_name_formatted}}" + +[tool.bumpversion] +current_version = "0.1.0" +commit = true +tag = true +commit_args = "-s" + +[[tool.bumpversion.files]] +filename = "{{module}}/__init__.py" +search = '__version__ = "{current_version}"' +replace = '__version__ = "{new_version}"' + +[[tool.bumpversion.files]] +filename = "pyproject.toml" +search = 'version = "{current_version}"' +replace = 'version = "{new_version}"' + +[[tool.bumpversion.files]] +filename = "js/package.json" +search = '"version": "{current_version}"' +replace = '"version": "{new_version}"' + +[[tool.bumpversion.files]] +filename = "Cargo.toml" +search = 'version = "{current_version}"' +replace = 'version = "{new_version}"' + +[[tool.bumpversion.files]] +filename = "rust/Cargo.toml" +search = 'version = "{current_version}"' +replace = 'version = "{new_version}"' + +[tool.check-manifest] +ignore = [ + ".copier-answers.yaml", + "js/pnpm-lock.yaml", + "Makefile", + ".vscode/*", + "docs/**/*", + "js/dist/**/*", + "rust/.config/*", + "rust/Cargo.lock", + "rust/README.md", +] + +[tool.cibuildwheel] +before-build = "curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain=stable --profile=minimal -y" +build = "cp39-*" +skip = "*musllinux*" +test-command = "pytest -vvv {project}/{{module}}/tests" +test-requires = ["pytest", "pytest-cov", "pytest-sugar", "pytest-xdist"] + +[tool.cibuildwheel.linux] +before-build = """ +curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain=stable --profile=minimal -y +rustup target add aarch64-unknown-linux-gnu +rustup target add x86_64-unknown-linux-gnu +rustup show +""" +environment = {PATH="$HOME/.cargo/bin:$PATH", CARGO_TERM_COLOR="always"} +archs = "x86_64 aarch64" + +[tool.cibuildwheel.macos] +before-build = """ +curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain=stable --profile=minimal -y +rustup target add aarch64-apple-darwin +rustup target add x86_64-apple-darwin +rustup show +""" +environment = {PATH="$HOME/.cargo/bin:$PATH", CARGO_TERM_COLOR="always", MACOS_DEPLOYMENT_TARGET=11.0} +archs = "x86_64 arm64" + +[tool.cibuildwheel.windows] +before-build = """ +curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain=stable --profile=minimal -y +rustup target add x86_64-pc-windows-msvc +rustup target add aarch64-pc-windows-msvc +rustup show +""" +environment = {PATH="$UserProfile\\.cargo\bin;$PATH", CARGO_TERM_COLOR="always"} +archs = "AMD64 ARM64" + +[tool.coverage.run] +branch = true +omit = [ + "{{module}}/tests/integration/", +] +[tool.coverage.report] +exclude_also = [ + "raise NotImplementedError", + "if __name__ == .__main__.:", + "@(abc\\.)?abstractmethod", +] +ignore_errors = true +fail_under = 50 + +[tool.hatch.build.hooks.jupyter-builder] +build-function = "hatch_jupyter_builder.npm_builder" +ensured-targets = [ + "{{module}}/extension/cdn/index.js", +] +skip-if-exists = [ + "{{module}}/extension/cdn/index.js", +] +dependencies = [ + "hatch-jupyter-builder", +] + +[tool.hatch.build.hooks.jupyter-builder.build-kwargs] +path = "js" +build_cmd = "build" +npm = "pnpm" + +[tool.pytest.ini_options] +addopts = ["-vvv", "--junitxml=junit.xml"] +testpaths = "{{module}}/tests" + +[tool.ruff] +line-length = 150 + +[tool.ruff.lint] +extend-select = ["I"] + +[tool.ruff.lint.isort] +combine-as-imports = true +default-section = "third-party" +known-first-party = ["{{module}}"] +section-order = ["future", "standard-library", "third-party", "first-party", "local-folder"] + +[tool.ruff.lint.per-file-ignores] +"__init__.py" = ["F401", "F403"] diff --git a/rustjswasm/rust/.config/nextest.toml b/rustjswasm/rust/.config/nextest.toml new file mode 100644 index 0000000..88457dc --- /dev/null +++ b/rustjswasm/rust/.config/nextest.toml @@ -0,0 +1,2 @@ +[profile.default.junit] +path = "junit.xml" diff --git a/rustjswasm/rust/Cargo.lock.jinja b/rustjswasm/rust/Cargo.lock.jinja new file mode 100644 index 0000000..1c3581a --- /dev/null +++ b/rustjswasm/rust/Cargo.lock.jinja @@ -0,0 +1,89 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "{{module}}" +version = "0.1.0" +dependencies = [ + "serde", + "serde_json", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "serde" +version = "1.0.204" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.204" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.120" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e0d21c9a8cae1235ad58a00c11cb40d4b1e5c784f1ef2c537876ed6ffd8b7c5" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "syn" +version = "2.0.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b146dcf730474b4bcd16c311627b31ede9ab149045db4d6088b3becaea046462" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/rustjswasm/rust/Cargo.toml.jinja b/rustjswasm/rust/Cargo.toml.jinja new file mode 100644 index 0000000..42be352 --- /dev/null +++ b/rustjswasm/rust/Cargo.toml.jinja @@ -0,0 +1,22 @@ +[package] +name = "{{module}}" +version = "0.1.0" +authors = ["{{team}} <{{email}}>"] +edition = "2021" +license = "Apache-2.0" +readme = "../README.md" +repository = "https://github.com/{{github}}/{{project_name}}" +description = "{{description}}" + +[lib] +name = "{{module}}" +path = "src/lib.rs" +crate-type = ["rlib"] + +[dependencies] +serde = { version = "1.0", features = ["derive"] } +serde_json = "1" + +[profile.test.junit] +path = "junit.xml" + diff --git a/rustjswasm/rust/Makefile.jinja b/rustjswasm/rust/Makefile.jinja new file mode 100644 index 0000000..9951d42 --- /dev/null +++ b/rustjswasm/rust/Makefile.jinja @@ -0,0 +1,55 @@ + +.PHONY: requirements develop build +requirements: ## install required dev dependencies + rustup component add rustfmt + rustup component add clippy + cargo install cargo-nextest + cargo install cargo-llvm-cov + +develop: requirements ## install required dev dependencies + +build: ## build release + cargo build --release --all-features + +.PHONY: lint lints fix format +lint: ## run Clippy for linting, rustfmt for autoformat checks + cargo clippy --all-features + cargo fmt --all -- --check +# alias +lints: lint + +fix: ## fix code with rustfmt + cargo fmt --all +#alias +format: fix + +.PHONY: check checks +check: + cargo check --all-features +# alias +checks: check + +.PHONY: test tests test-ci tests-ci +test: ## run the tests + cargo llvm-cov nextest --cobertura --output-path junit.xml + +# alias +tests: test + +coverage: + cargo llvm-cov nextest --lcov --output-path coverage + +.PHONY: dist publish +dist: ## create dist + cargo publish --dry-run --allow-dirty + +publish: ## publish to cargo + cargo publish + +# Thanks to Francoise at marmelab.com for this +.DEFAULT_GOAL := help +help: + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' + +print-%: + @echo '$*=$($*)' diff --git a/rustjswasm/rust/src/lib.rs.jinja b/rustjswasm/rust/src/lib.rs.jinja new file mode 100644 index 0000000..ade1079 --- /dev/null +++ b/rustjswasm/rust/src/lib.rs.jinja @@ -0,0 +1,34 @@ +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct Example { + pub stuff: String, +} + +impl Example { + pub fn new(value: String) -> Self { + Example { stuff: value } + } +} + +/**********************************/ +#[cfg(test)] +mod example_tests { + use super::*; + + #[test] + fn test_new() { + let e = Example::new(String::from("test")); + assert_eq!(e.stuff, String::from("test")); + } + + #[test] + fn test_clone_and_eq() { + let e = Example::new(String::from("test")); + assert_eq!(e, e.clone()); + } + + #[test] + fn test_debug() { + let e = Example::new(String::from("test")); + assert_eq!(format!("{e:?}"), "Example { stuff: \"test\" }"); + } +} diff --git a/rustjswasm/src/example/mod.rs.jinja b/rustjswasm/src/example/mod.rs.jinja new file mode 100644 index 0000000..c9df21c --- /dev/null +++ b/rustjswasm/src/example/mod.rs.jinja @@ -0,0 +1,32 @@ +use pyo3::prelude::*; + +use {{module}}::Example as BaseExample; + + +#[pyclass] +pub struct Example { + pub example: BaseExample, +} + +#[pymethods] +impl Example { + #[new] + fn py_new(value: String) -> PyResult { + Ok( + Example { + example: BaseExample { + stuff: value.as_str().to_string() + }, + } + ) + + } + + fn __str__(&self) -> PyResult { + Ok(format!("{}", self.example.stuff)) + } + + fn __repr__(&self) -> PyResult { + Ok(format!("Example<{}>", self.example.stuff)) + } +} diff --git a/rustjswasm/src/lib.rs.jinja b/rustjswasm/src/lib.rs.jinja new file mode 100644 index 0000000..9dae75b --- /dev/null +++ b/rustjswasm/src/lib.rs.jinja @@ -0,0 +1,13 @@ +use pyo3::prelude::*; + +mod example; + +pub use example::Example; + + +#[pymodule] +fn {{module}}(_py: Python, m: &Bound) -> PyResult<()> { + // Example + m.add_class::().unwrap(); + Ok(()) +} diff --git a/rustjswasm/{% if add_wiki %}docs{% endif %}/wiki/Installation.md.jinja b/rustjswasm/{% if add_wiki %}docs{% endif %}/wiki/Installation.md.jinja new file mode 100644 index 0000000..aa61725 --- /dev/null +++ b/rustjswasm/{% if add_wiki %}docs{% endif %}/wiki/Installation.md.jinja @@ -0,0 +1,19 @@ +## Pre-requisites + +You need Python >=3.9 on your machine to install `{{project_name_formatted}}`. + +## Install with `pip` + +```bash +pip install {{project_name_formatted}} +``` + +## Install with `conda` + +```bash +conda install {{project_name_formatted}} --channel conda-forge +``` + +## Source installation + +For other platforms and for development installations, [build `{{project_name_formatted}}` from source](Build-from-Source). diff --git a/rustjswasm/{% if add_wiki %}docs{% endif %}/wiki/_Footer.md.jinja b/rustjswasm/{% if add_wiki %}docs{% endif %}/wiki/_Footer.md.jinja new file mode 100644 index 0000000..4a5fb4b --- /dev/null +++ b/rustjswasm/{% if add_wiki %}docs{% endif %}/wiki/_Footer.md.jinja @@ -0,0 +1 @@ +_This wiki is autogenerated. To made updates, open a PR against the original source file in [`docs/wiki`](https://github.com/{{github}}/{{project_name_formatted}}/tree/main/docs/wiki)._ diff --git a/rustjswasm/{% if add_wiki %}docs{% endif %}/wiki/_Sidebar.md.jinja b/rustjswasm/{% if add_wiki %}docs{% endif %}/wiki/_Sidebar.md.jinja new file mode 100644 index 0000000..988b1ac --- /dev/null +++ b/rustjswasm/{% if add_wiki %}docs{% endif %}/wiki/_Sidebar.md.jinja @@ -0,0 +1,16 @@ + + +**[Home](Home)** + +**Get Started** + +- [Installation](Installation) +- [Contributing](Contribute) +- [Development Setup](Local-Development-Setup) +- [Build from Source](Build-from-Source) diff --git a/rustjswasm/{% if add_wiki %}docs{% endif %}/wiki/contribute/Build-from-Source.md.jinja b/rustjswasm/{% if add_wiki %}docs{% endif %}/wiki/contribute/Build-from-Source.md.jinja new file mode 100644 index 0000000..78ceceb --- /dev/null +++ b/rustjswasm/{% if add_wiki %}docs{% endif %}/wiki/contribute/Build-from-Source.md.jinja @@ -0,0 +1,127 @@ +`{{project_name_formatted}}` is written in Python and Rust. While prebuilt wheels are provided for end users, it is also straightforward to build `{{project_name_formatted}}` from either the Python [source distribution](https://packaging.python.org/en/latest/specifications/source-distribution-format/) or the GitHub repository. + +- [Make commands](#make-commands) +- [Prerequisites](#prerequisites) +- [Clone](#clone) +- [Install Python dependencies](#install-python-dependencies) +- [Build](#build) +- [Lint and Autoformat](#lint-and-autoformat) +- [Testing](#testing) + +## Make commands + +As a convenience, `{{project_name_formatted}}` uses a `Makefile` for commonly used commands. You can print the main available commands by running `make` with no arguments + +```bash +> make + +build build the library +clean clean the repository +fix run autofixers +install install library +lint run lints +test run the tests +``` + +## Prerequisites + +`{{project_name_formatted}}` has a few system-level dependencies which you can install from your machine package manager. Other package managers like `conda`, `nix`, etc, should also work fine. + +## Clone + +Clone the repo with: + +```bash +git clone https://github.com/{{github}}/{{project_name_formatted}}.git +cd {{project_name_formatted}} +``` + +## Install Rust + +Follow the instructions for [installing Rust](https://rustup.rs) for your system. + +## Install Python dependencies + +Python build and develop dependencies are specified in the `pyproject.toml`, but you can manually install them: + +```bash +make requirements +``` + +Note that these dependencies would otherwise be installed normally as part of [PEP517](https://peps.python.org/pep-0517/) / [PEP518](https://peps.python.org/pep-0518/). + +## Build + +Build the python project in the usual manner: + +```bash +make build +``` + +## Lint and Autoformat + +`{{project_name_formatted}}` has linting and auto formatting. + +| Language | Linter | Autoformatter | Description | +| :------- | :---------- | :------------ | :---------- | +| Python | `ruff` | `ruff` | Style | +| Python | `ruff` | `ruff` | Imports | +| Rust | `clippy` | `clippy` | Style | +| Markdown | `mdformat` | `mdformat` | Style | +| Markdown | `codespell` | | Spelling | + +**Python Linting** + +```bash +make lint-py +``` + +**Python Autoformatting** + +```bash +make fix-py +``` + +**Rust Linting** + +```bash +make lint-rs +``` + +**Rust Autoformatting** + +```bash +make fix-rs +``` + +**Documentation Linting** + +```bash +make lint-docs +``` + +**Documentation Autoformatting** + +```bash +make fix-docs +``` + +## Testing + +`{{project_name_formatted}}` has both Python and JavaScript tests. The bulk of the functionality is tested in Python, which can be run via `pytest`. First, install the Python development dependencies with + +```bash +make develop +``` + +**Python** + +```bash +make test-py +``` + +**Rust** + +```bash +make test-rs +``` diff --git a/rustjswasm/{% if add_wiki %}docs{% endif %}/wiki/contribute/Contribute.md.jinja b/rustjswasm/{% if add_wiki %}docs{% endif %}/wiki/contribute/Contribute.md.jinja new file mode 100644 index 0000000..7deea95 --- /dev/null +++ b/rustjswasm/{% if add_wiki %}docs{% endif %}/wiki/contribute/Contribute.md.jinja @@ -0,0 +1,15 @@ +Contributions are welcome on this project. We distribute under the terms of the [Apache 2.0 license](https://github.com/{{github}}/{{project_name_formatted}}/blob/main/LICENSE). + +> [!NOTE] +> +> `{{project_name_formatted}}` requires [Developer Certificate of Origin](https://en.wikipedia.org/wiki/Developer_Certificate_of_Origin) for all contributions. +> This is enforced by a [Probot GitHub App](https://probot.github.io/apps/dco/), which checks that commits are "signed". +> Read [instructions to configure commit signing](Local-Development-Setup#configure-commit-signing). + +For **bug reports** or **small feature requests**, please open an issue on our [issues page](https://github.com/{{github}}/{{project_name_formatted}}/issues). + +For **questions** or to discuss **larger changes or features**, please use our [discussions page](https://github.com/{{github}}/{{project_name_formatted}}/discussions). + +For **contributions**, please see our [developer documentation](Local-Development-Setup). We have `help wanted` and `good first issue` tags on our issues page, so these are a great place to start. + +For **documentation updates**, make PRs that update the pages in `/docs/wiki`. The documentation is pushed to the GitHub wiki automatically through a GitHub workflow. Note that direct updates to this wiki will be overwritten. diff --git a/rustjswasm/{% if add_wiki %}docs{% endif %}/wiki/contribute/Local-Development-Setup.md.jinja b/rustjswasm/{% if add_wiki %}docs{% endif %}/wiki/contribute/Local-Development-Setup.md.jinja new file mode 100644 index 0000000..897872a --- /dev/null +++ b/rustjswasm/{% if add_wiki %}docs{% endif %}/wiki/contribute/Local-Development-Setup.md.jinja @@ -0,0 +1,55 @@ +## Table of Contents + +- [Table of Contents](#table-of-contents) +- [Step 1: Build from Source](#step-1-build-from-source) +- [Step 2: Configuring Git and GitHub for Development](#step-2-configuring-git-and-github-for-development) + - [Create your fork](#create-your-fork) + - [Configure remotes](#configure-remotes) + - [Authenticating with GitHub](#authenticating-with-github) +- [Guidelines](#guidelines) + +## Step 1: Build from Source + +To work on `{{project_name_formatted}}`, you are going to need to build it from source. See +[Build from Source](Build-from-Source) for +detailed build instructions. + +Once you've built `{{project_name_formatted}}` from a `git` clone, you will also need to +configure `git` and your GitHub account for `{{project_name_formatted}}` development. + +## Step 2: Configuring Git and GitHub for Development + +### Create your fork + +The first step is to create a personal fork of `{{project_name_formatted}}`. To do so, click +the "fork" button at https://github.com/{{github}}/{{project_name_formatted}}, or just navigate +[here](https://github.com/{{github}}/{{project_name_formatted}}/fork) in your browser. Set the +owner of the repository to your personal GitHub account if it is not +already set that way and click "Create fork". + +### Configure remotes + +Next, you should set some names for the `git` remotes corresponding to +main {{github}} repository and your fork. See the [GitHub Docs](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/configuring-a-remote-repository-for-a-fork) for more information. + +### Authenticating with GitHub + +If you have not already configured `ssh` access to GitHub, you can find +instructions to do so +[here](https://docs.github.com/en/authentication/connecting-to-github-with-ssh), +including instructions to create an SSH key if you have not done +so. Authenticating with SSH is usually the easiest route. If you are working in +an environment that does not allow SSH connections to GitHub, you can look into +[configuring a hardware +passkey](https://docs.github.com/en/authentication/authenticating-with-a-passkey/about-passkeys) +or adding a [personal access +token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens) +to avoid the need to type in your password every time you push to your fork. + +## Guidelines + +After developing a change locally, ensure that both [lints](Build-from-Source#lint-and-autoformat) and [tests](Build-from-Source#testing) pass. Commits should be squashed into logical units, and all commits must be signed (e.g. with the `-s` git flag). We require [Developer Certificate of Origin](https://en.wikipedia.org/wiki/Developer_Certificate_of_Origin) for all contributions. + +If your work is still in-progress, open a [draft pull request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests#draft-pull-requests). Otherwise, open a normal pull request. It might take a few days for a maintainer to review and provide feedback, so please be patient. If a maintainer asks for changes, please make said changes and squash your commits if necessary. If everything looks good to go, a maintainer will approve and merge your changes for inclusion in the next release. + +Please note that non substantive changes, large changes without prior discussion, etc, are not accepted and pull requests may be closed. diff --git a/rustjswasm/{{_copier_conf.answers_file}}.jinja b/rustjswasm/{{_copier_conf.answers_file}}.jinja new file mode 100644 index 0000000..a537c26 --- /dev/null +++ b/rustjswasm/{{_copier_conf.answers_file}}.jinja @@ -0,0 +1,2 @@ +# Changes here will be overwritten by Copier +{{ _copier_answers|to_nice_yaml }} \ No newline at end of file diff --git a/rustjswasm/{{module}}/__init__.py b/rustjswasm/{{module}}/__init__.py new file mode 100644 index 0000000..3dc1f76 --- /dev/null +++ b/rustjswasm/{{module}}/__init__.py @@ -0,0 +1 @@ +__version__ = "0.1.0" diff --git a/rustjswasm/{{module}}/tests/test_all.py.jinja b/rustjswasm/{{module}}/tests/test_all.py.jinja new file mode 100644 index 0000000..cd7454a --- /dev/null +++ b/rustjswasm/{{module}}/tests/test_all.py.jinja @@ -0,0 +1,5 @@ +from {{module}} import * # noqa + + +def test_all(): + assert True