diff --git a/.copier-answers.yml b/.copier-answers.yml new file mode 100644 index 0000000..4bcd1c6 --- /dev/null +++ b/.copier-answers.yml @@ -0,0 +1,33 @@ +# Changes here will be overwritten by Copier +SelectCitation: +- AddCitationFile_flag +- AddCFFConvert_flag +SelectCodeQualityFeatures: +- AddLocalTests_flag +- SelectGitHubActions_flag +- AddLinting_flag +SelectCommunityFeatures: [] +SelectDocumentationFeatures: +- AddOnlineDocumentation_flag +- AddDevDoc_flag +- AddGitHubActionDocumentation_flag +SelectGitHubActions: +- AddGitHubActionBuild_flag +- AddLinkCheck_flag +SelectPublishReleaseFeatures: +- SelectCitation_flag +- AddZenodo_flag +_commit: 0.6.1 +_src_path: https://github.com/nlesc/python-template.git +copyright_holder: Christiaan Meijer +email: c.meijer@esciencecenter.nl +full_name: Christiaan Meijer +github_organization: DroneML +keywords: Segmentation, UNet, Active learning, Drone, Raster data, Spatial data +license: Apachev2 +package_name: segmentmytiff +package_short_description: Segment (georeferenced) raster data in an interactive fashion. + Retrain models in seconds. Only small amounts of labeled data necessary because + of our use of pretrained base models as feature extractors. +template_profile: ask +version: 0.1.0 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..93acbfe --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,63 @@ +name: Python package + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + + build: + name: Build for (${{ matrix.python-version }}, ${{ matrix.os }}) + runs-on: ${{ matrix.os }} + strategy: + fail-fast: true + matrix: + os: ['ubuntu-latest', 'macos-latest', 'windows-latest'] + python-version: ['3.10', '3.11', '3.12'] + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Python info + shell: bash -e {0} + run: | + which python + python --version + - name: Upgrade pip and install dependencies + run: | + python -m pip install --upgrade pip setuptools + python -m pip install .[dev,publishing] + - name: Run unit tests + run: python -m pytest -v + - name: Verify that we can build the package + run: python -m build + lint: + name: Linting build + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - uses: actions/checkout@v4 + - name: Set up Python 3.9 + uses: actions/setup-python@v5 + with: + python-version: 3.9 + - name: Python info + shell: bash -e {0} + run: | + which python + python --version + - name: Upgrade pip and install dependencies + run: | + python -m pip install --upgrade pip setuptools + python -m pip install .[dev,publishing] + - name: Check style against standards using ruff + run: | + ruff check + ruff format --check diff --git a/.github/workflows/cffconvert.yml b/.github/workflows/cffconvert.yml new file mode 100644 index 0000000..04fb9ea --- /dev/null +++ b/.github/workflows/cffconvert.yml @@ -0,0 +1,23 @@ +name: cffconvert + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + + verify: + name: "cffconvert" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + name: Check out a copy of the repository + + - name: Check whether the citation metadata from CITATION.cff is valid + uses: citation-file-format/cffconvert-github-action@2.0.0 + with: + args: "--validate" diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml new file mode 100644 index 0000000..f875b72 --- /dev/null +++ b/.github/workflows/documentation.yml @@ -0,0 +1,36 @@ +name: documentation + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + build-documentation: + name: Build documentation + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - uses: actions/checkout@v4 + - name: Set up Python 3.9 + uses: actions/setup-python@v5 + with: + python-version: 3.9 + - name: Python info + shell: bash -e {0} + run: | + which python + python --version + - name: Upgrade pip and install dependencies + run: | + python -m pip install --upgrade pip setuptools + python -m pip install .[dev,publishing] + - name: Install pandoc using apt + run: sudo apt install pandoc + - name: Build documentation + run: make coverage doctest html + working-directory: docs diff --git a/.github/workflows/link-check.yml b/.github/workflows/link-check.yml new file mode 100644 index 0000000..34781c3 --- /dev/null +++ b/.github/workflows/link-check.yml @@ -0,0 +1,38 @@ +name: link-check + +on: + workflow_dispatch: + push: + branches: + - main + pull_request: + branches: + - main + schedule: + - cron: '0 0 1 * *' # first day of every month at midnight + +permissions: + contents: read + issues: write + +jobs: + linkChecker: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Link Checker + id: lychee + uses: lycheeverse/lychee-action@v1 + + - name: Set Issue Title + id: set_title + run: echo "ISSUE_TITLE=Link Checker Report - $(date '+%Y-%m-%d')" >> $GITHUB_ENV + + - name: Create Issue From File + if: env.lychee_exit_code != 0 + uses: peter-evans/create-issue-from-file@v5 + with: + title: ${{ env.ISSUE_TITLE }} + content-filepath: ./lychee/out.md + labels: report, automated issue diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dd8a4fa --- /dev/null +++ b/.gitignore @@ -0,0 +1,69 @@ +# Byte-compiled / optimized / DLL files +*.py[cod] +*$py.class +__pycache__ + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg + +# jupyter notebook +.ipynb_checkpoints + +# Unit test / coverage reports +htmlcov/ +.coverage +.coverage.* +coverage.xml +.cache +.pytest_cache +.tox/ + +# Sphinx documentation +docs/_build + +# ide +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ +.spyderproject +.spyproject + +# Mac +.DS_Store + +# virtual environments +env +.env +env3 +.env3 +venv +.venv +venv3 +.venv3 +ENV/ +env.bak/ +venv.bak/ + +# vim +*.swp +*.swo +*.orig diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..0be5abf --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..4366885 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.readthedocs.yaml b/.readthedocs.yaml new file mode 100644 index 0000000..b2a5368 --- /dev/null +++ b/.readthedocs.yaml @@ -0,0 +1,7 @@ +version: 2 +python: + install: + - method: pip + path: . + extra_requirements: + - docs diff --git a/CITATION.cff b/CITATION.cff new file mode 100644 index 0000000..d58704d --- /dev/null +++ b/CITATION.cff @@ -0,0 +1,19 @@ +# YAML 1.2 +--- +cff-version: "1.2.0" +title: "segmentmytiff" +authors: + - family-names: Meijer + given-names: Christiaan + orcid: "https://orcid.org/0000-0000-0000-0000" +date-released: 2024-10-08 +version: "0.1.0" +repository-code: "https://github.com/DroneML/segmentmytiff" +keywords: + - "Segmentation" + - " UNet" + - " Active learning" + - " Drone" + - " Raster data" + - " Spatial data" +message: "If you use this software, please cite it using these metadata." diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a199ef9 --- /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 2024 Christiaan Meijer + + 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/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..f128825 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,4 @@ +include CITATION.cff +include LICENSE +include NOTICE +include README.md diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..ace62e5 --- /dev/null +++ b/NOTICE @@ -0,0 +1,2 @@ +This product includes segmentmytiff, software developed by +Christiaan Meijer. diff --git a/README.md b/README.md new file mode 100644 index 0000000..094b945 --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +[![Documentation Status](https://readthedocs.org/projects/segmentmytiff/badge/?version=latest)](https://segmentmytiff.readthedocs.io/en/latest/?badge=latest) [![build](https://github.com/DroneML/segmentmytiff/actions/workflows/build.yml/badge.svg)](https://github.com/DroneML/segmentmytiff/actions/workflows/build.yml) [![cffconvert](https://github.com/DroneML/segmentmytiff/actions/workflows/cffconvert.yml/badge.svg)](https://github.com/DroneML/segmentmytiff/actions/workflows/cffconvert.yml) + +## How to use segmentmytiff + +Segment (georeferenced) raster data in an interactive fashion. Retrain models in seconds. Only small amounts of labeled data necessary because of our use of pretrained base models as feature extractors. + +The project setup is documented in [project_setup.md](devdocs/project_setup.md). + +## Installation + +To install segmentmytiff from GitHub repository, do: + +```console +git clone git@github.com:DroneML/segmentmytiff.git +cd segmentmytiff +python -m pip install . +``` + +## Credits + +This package was created with [Copier](https://github.com/copier-org/copier) and the [NLeSC/python-template](https://github.com/NLeSC/python-template). diff --git a/devdocs/README.dev.md b/devdocs/README.dev.md new file mode 100644 index 0000000..1575455 --- /dev/null +++ b/devdocs/README.dev.md @@ -0,0 +1,186 @@ +# `segmentmytiff` developer documentation + +If you're looking for user documentation, go [here](../README.md). + +## Development install + +```shell +# Create a virtual environment, e.g. with +python -m venv env + +# activate virtual environment +source env/bin/activate + +# make sure to have a recent version of pip and setuptools +python -m pip install --upgrade pip setuptools + +# (from the project root directory) +# install segmentmytiff as an editable package +python -m pip install --no-cache-dir --editable . +# install development dependencies +python -m pip install --no-cache-dir --editable .[dev] +# install documentation dependencies only +python -m pip install --no-cache-dir --editable .[docs] +``` + +Afterwards check that the install directory is present in the `PATH` environment variable. + +## Running the tests + +There are two ways to run tests. + +The first way requires an activated virtual environment with the development tools installed: + +```shell +pytest -v +``` + +The second is to use `tox`, which can be installed separately (e.g. with `pip install tox`), i.e. not necessarily inside the virtual environment you use for installing `segmentmytiff`, but then builds the necessary virtual environments itself by simply running: + +```shell +tox +``` + +Testing with `tox` allows for keeping the testing environment separate from your development environment. +The development environment will typically accumulate (old) packages during development that interfere with testing; this problem is avoided by testing with `tox`. + +### Test coverage + +In addition to just running the tests to see if they pass, they can be used for coverage statistics, i.e. to determine how much of the package's code is actually executed during tests. +In an activated virtual environment with the development tools installed, inside the package directory, run: + +```shell +coverage run +``` + +This runs tests and stores the result in a `.coverage` file. +To see the results on the command line, run + +```shell +coverage report +``` + +`coverage` can also generate output in HTML and other formats; see `coverage help` for more information.## Running linters locally + +For linting and sorting imports we will use [ruff](https://beta.ruff.rs/docs/). Running the linters requires an +activated virtual environment with the development tools installed. + +```shell +# linter +ruff check . + +# linter with automatic fixing +ruff check . --fix +``` + +To fix readability of your code style you can use [yapf](https://github.com/google/yapf).## Generating the API docs + +```shell +cd docs +make html +``` + +The documentation will be in `docs/_build/html` + +If you do not have `make` use + +```shell +sphinx-build -b html docs docs/_build/html +``` + +To find undocumented Python objects run + +```shell +cd docs +make coverage +cat _build/coverage/python.txt +``` + +To [test snippets](https://www.sphinx-doc.org/en/master/usage/extensions/doctest.html) in documentation run + +```shell +cd docs +make doctest +``` + +## Versioning + +Bumping the version across all files is done with [bump-my-version](https://github.com/callowayproject/bump-my-version), e.g. + +```shell +bump-my-version bump major # bumps from e.g. 0.3.2 to 1.0.0 +bump-my-version bump minor # bumps from e.g. 0.3.2 to 0.4.0 +bump-my-version bump patch # bumps from e.g. 0.3.2 to 0.3.3 +``` + +## Making a release + +This section describes how to make a release in 3 parts: + +1. preparation +1. making a release on PyPI +1. making a release on GitHub + +### (1/3) Preparation + + +1. Verify that the information in [`CITATION.cff`](../CITATION.cff) is correct. +1. Make sure the [version has been updated](#versioning). +1. Run the unit tests with `pytest -v` + +### (2/3) PyPI + +In a new terminal: + +```shell +# OPTIONAL: prepare a new directory with fresh git clone to ensure the release +# has the state of origin/main branch +cd $(mktemp -d segmentmytiff.XXXXXX) +git clone git@github.com:DroneML/segmentmytiff . + +# make sure to have a recent version of pip and the publishing dependencies +python -m pip install --upgrade pip +python -m pip install .[publishing] + +# create the source distribution and the wheel +python -m build + +# upload to test pypi instance (requires credentials) +python -m twine upload --repository testpypi dist/* +``` + +Visit +[https://test.pypi.org/project/segmentmytiff](https://test.pypi.org/project/segmentmytiff) +and verify that your package was uploaded successfully. Keep the terminal open, we'll need it later. + +In a new terminal, without an activated virtual environment or an env directory: + +```shell +cd $(mktemp -d segmentmytiff-test.XXXXXX) + +# prepare a clean virtual environment and activate it +python -m venv env +source env/bin/activate + +# make sure to have a recent version of pip and setuptools +python -m pip install --upgrade pip + +# install from test pypi instance: +python -m pip -v install --no-cache-dir \ +--index-url https://test.pypi.org/simple/ \ +--extra-index-url https://pypi.org/simple segmentmytiff +``` + +Check that the package works as it should when installed from pypitest. + +Then upload to pypi.org with: + +```shell +# Back to the first terminal, +# FINAL STEP: upload to PyPI (requires credentials) +python -m twine upload dist/* +``` + +### (3/3) GitHub + +Don't forget to also make a [release on GitHub](https://github.com/DroneML/segmentmytiff/releases/new).GitHub-Zenodo integration will also trigger Zenodo into making a snapshot of your repository and sticking a DOI on it. \ No newline at end of file diff --git a/devdocs/badges.md b/devdocs/badges.md new file mode 100644 index 0000000..53b349d --- /dev/null +++ b/devdocs/badges.md @@ -0,0 +1,8 @@ +| fair-software.eu recommendations | | +| :-- | :-- | +| (1/5) code repository | [![github repo badge](https://img.shields.io/badge/github-repo-000.svg?logo=github&labelColor=gray&color=blue)](https://github.com/DroneML/segmentmytiff) | +| (2/5) license | [![github license badge](https://img.shields.io/github/license/DroneML/segmentmytiff)](https://github.com/DroneML/segmentmytiff) | +| (3/5) community registry | [![RSD](https://img.shields.io/badge/rsd-segmentmytiff-00a3e3.svg)](https://www.research-software.nl/software/segmentmytiff) [![workflow pypi badge](https://img.shields.io/pypi/v/segmentmytiff.svg?colorB=blue)](https://pypi.python.org/project/segmentmytiff/) | +| (4/5) citation | [![DOI](https://zenodo.org/badge/DOI/.svg)](https://doi.org/)| +| (5/5) checklist | [![workflow cii badge](https://bestpractices.coreinfrastructure.org/projects//badge)](https://bestpractices.coreinfrastructure.org/projects/) | +| howfairis | [![fair-software badge](https://img.shields.io/badge/fair--software.eu-%E2%97%8F%20%20%E2%97%8F%20%20%E2%97%8F%20%20%E2%97%8F%20%20%E2%97%8B-yellow)](https://fair-software.eu) | \ No newline at end of file diff --git a/devdocs/project_setup.md b/devdocs/project_setup.md new file mode 100644 index 0000000..bcb3ab8 --- /dev/null +++ b/devdocs/project_setup.md @@ -0,0 +1,100 @@ +# Project Setup + +Here we provide some details about the project setup. Most of the choices are explained in the +[guide](https://guide.esciencecenter.nl). Links to the relevant sections are included below. Feel free to remove this +text when the development of the software package takes off. + +For a quick reference on software development, we refer to [the software guide +checklist](https://guide.esciencecenter.nl/#/best_practices/checklist). + +## Python versions + +This repository is set up with Python versions: + +- 3.10 +- 3.11 +- 3.12 + +Add or remove Python versions based on project requirements. See [the +guide](https://guide.esciencecenter.nl/#/best_practices/language_guides/python) for more information about Python +versions. + +## Package management and dependencies + +You can use either pip or conda for installing dependencies and package management. This repository does not force you +to use one or the other, as project requirements differ. For advice on what to use, please check [the relevant section +of the +guide](https://guide.esciencecenter.nl/#/best_practices/language_guides/python?id=dependencies-and-package-management). + +- Runtime dependencies should be added to `pyproject.toml` in the `dependencies` list under `[project]`. +- Development dependencies, such as for testing or documentation, should be added to `pyproject.toml` in one of the lists under `[project.optional-dependencies]`. + +## Packaging/One command install + +You can distribute your code using PyPI. +[The guide](https://guide.esciencecenter.nl/#/best_practices/language_guides/python?id=building-and-packaging-code) can +help you decide which tool to use for packaging. + +## Testing and code coverage + +- Tests should be put in the `tests` folder. +- The `tests` folder contains: + - Example tests that you should replace with your own meaningful tests (file: `test_my_module.py`) +- The testing framework used is [PyTest](https://pytest.org) + - [PyTest introduction](https://pythontest.com/pytest-book/) + - PyTest is listed as a development dependency + - This is configured in `pyproject.toml` +- The project uses [GitHub action workflows](https://docs.github.com/en/actions) to automatically run tests on GitHub infrastructure against multiple Python versions + - Workflows can be found in [`.github/workflows`](.github/workflows/) +- [Relevant section in the guide](https://guide.esciencecenter.nl/#/best_practices/language_guides/python?id=testing) + +## Documentation + +- Documentation should be put in the [`docs/`](docs/) directory. The contents have been generated using `sphinx-quickstart` (Sphinx version 1.6.5). +- We recommend writing the documentation using Restructured Text (reST) and Google style docstrings. + - [Restructured Text (reST) and Sphinx CheatSheet](https://thomas-cokelaer.info/tutorials/sphinx/rest_syntax.html) + - [Google style docstring examples](http://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html). +- The documentation is set up with the ReadTheDocs Sphinx theme. + - Check out its [configuration options](https://sphinx-rtd-theme.readthedocs.io/en/latest/). +- [AutoAPI](https://sphinx-autoapi.readthedocs.io/) is used to generate documentation for the package Python objects. +- `.readthedocs.yaml` is the ReadTheDocs configuration file. When ReadTheDocs is building the documentation this package and its development dependencies are installed so the API reference can be rendered.- [Relevant section in the guide](https://guide.esciencecenter.nl/#/best_practices/language_guides/python?id=writingdocumentation) + +## Coding style conventions and code quality + +- [Relevant section in the NLeSC guide](https://guide.esciencecenter.nl/#/best_practices/language_guides/python?id=coding-style-conventions) and [README.dev.md](README.dev.md). + + + +## Package version number + +- We recommend using [semantic versioning](https://guide.esciencecenter.nl/#/best_practices/releases?id=semantic-versioning). +- For convenience, the package version is stored in a single place: `pyproject.toml` under the `tool.bumpversion` header. +- Don't forget to update the version number before [making a release](https://guide.esciencecenter.nl/#/best_practices/releases)! + +## Logging + +- We recommend using the logging module for getting useful information from your module (instead of using print). +- The project is set up with a logging example. +- [Relevant section in the guide](https://guide.esciencecenter.nl/#/best_practices/language_guides/python?id=logging) + + + +## CITATION.cff + +- To allow others to cite your software, add a `CITATION.cff` file +- It only makes sense to do this once there is something to cite (e.g., a software release with a DOI). +- Follow the [making software citable](https://guide.esciencecenter.nl/#/citable_software/making_software_citable) section in the guide. + + + + + +## MANIFEST.in + +- List non-Python files that should be included in a source distribution +- [Relevant section in the guide](https://guide.esciencecenter.nl/#/best_practices/language_guides/python?id=building-and-packaging-code) + +## NOTICE + +- List of attributions of this project and Apache-license dependencies +- [Relevant section in the guide](https://guide.esciencecenter.nl/#/best_practices/licensing?id=notice) diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..375a61d --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +SPHINXPROJ = segmentmytiff +SOURCEDIR = . +BUILDDIR = _build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/_templates/.gitignore b/docs/_templates/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..728fbb4 --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,85 @@ +# Configuration file for the Sphinx documentation builder. +# +# This file only contains a selection of the most common options. For a full +# list see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html +# + +# -- Path setup -------------------------------------------------------------- + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +# import os +# import sys +# sys.path.insert(0, os.path.abspath('.')) + +# -- Project information ----------------------------------------------------- + +project = u"segmentmytiff" +copyright = u"2024-10-08 10:55:54, Christiaan Meijer" +author = u"Christiaan Meijer" + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = "0.1.0" +# The full version, including alpha/beta/rc tags. +release = version + +# -- General configuration ------------------------------------------------ + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named "sphinx.ext.*") or your custom +# ones. +extensions = [ + "sphinx.ext.autodoc", + "sphinx.ext.coverage", + "sphinx.ext.doctest", + "sphinx.ext.intersphinx", + "sphinx.ext.mathjax", + "sphinx.ext.napoleon", + "sphinx.ext.todo", + "sphinx.ext.viewcode", + "autoapi.extension", + "myst_parser", +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ["_templates"] + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This patterns also effect to html_static_path and html_extra_path +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] + +# -- Use autoapi.extension to run sphinx-apidoc ------- + +autoapi_dirs = ['../src/segmentmytiff'] + +# -- Options for HTML output ---------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = "sphinx_rtd_theme" + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +# +# html_theme_options = {} + +# -- Options for Intersphinx + +intersphinx_mapping = {'python': ('https://docs.python.org/3', None), + # Commonly used libraries, uncomment when used in package + # 'numpy': ('http://docs.scipy.org/doc/numpy/', None), + # 'scipy': ('http://docs.scipy.org/doc/scipy/reference/', None), + # 'scikit-learn': ('https://scikit-learn.org/stable/', None), + # 'matplotlib': ('https://matplotlib.org/stable/', None), + # 'pandas': ('http://pandas.pydata.org/docs/', None), + } diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..4367427 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,18 @@ +.. segmentmytiff documentation master file, created by + sphinx-quickstart on Wed May 5 22:45:36 2021. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to segmentmytiff's documentation! +========================================================== + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 0000000..21497a1 --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,36 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=. +set BUILDDIR=_build +set SPHINXPROJ=segmentmytiff + +if "%1" == "" goto help + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 +) + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% + +:end +popd diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..c627389 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,138 @@ +# see documentation, e.g. +# - https://packaging.python.org/en/latest/specifications/declaring-project-metadata/#declaring-project-metadata +# - https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html +# - https://www.python.org/dev/peps/pep-0621/ + +[build-system] +requires = ["setuptools>=64.0.0", "setuptools-scm", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +authors = [ + { name = "Christiaan Meijer", email = "c.meijer@esciencecenter.nl" } +] +classifiers = [ + "Development Status :: 2 - Pre-Alpha", + "Intended Audience :: Developers", + "Intended Audience :: Science/Research", + "", + "Natural Language :: English", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", +] +dependencies = [] +description = "Segment (georeferenced) raster data in an interactive fashion. Retrain models in seconds. Only small amounts of labeled data necessary because of our use of pretrained base models as feature extractors." +keywords = ["Segmentation"," UNet"," Active learning"," Drone"," Raster data"," Spatial data"] +license = {file = "LICENSE"} +name = "segmentmytiff" +readme = {file = "README.md", content-type = "text/markdown"} +requires-python = ">=3.8" +version = "0.1.0" + +[project.optional-dependencies] +dev = [ + "build", # build is not only used in publishing (below), but also in the template's test suite + "bump-my-version", + "coverage [toml]", + "pytest", + "pytest-cov", + "ruff", + "sphinx", + "sphinx_rtd_theme", + "sphinx-autoapi", + "tox", + "myst_parser", +] +docs = [ + "sphinx", + "sphinx_rtd_theme", + "sphinx-autoapi", + "myst_parser", +] +publishing = [ + "build", + "twine", + "wheel", +] + +[project.urls] +Repository = "https://github.com/DroneML/segmentmytiff" +Issues = "https://github.com/DroneML/segmentmytiff/issues" +ReadTheDocs = "https://segmentmytiff.readthedocs.io" + +[tool.pytest.ini_options] +testpaths = ["tests"] + + +[tool.coverage.run] +branch = true +source = ["src/segmentmytiff"] +command_line = "-m pytest" + +[tool.tox] +legacy_tox_ini = """ +[tox] +envlist = py38,py39,py310,py311,py312 +skip_missing_interpreters = true +[testenv] +commands = pytest +extras = dev +""" + +[tool.ruff] +line-length = 120 +output-format = "concise" +extend-exclude = ["docs"] + +[tool.ruff.lint] +# Allow unused variables when underscore-prefixed. +dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" + +# Enable Pyflakes `E` and `F` codes by default. +select = ["ALL"] +ignore = [ + "ANN101", # Missing type annotation for `self` in method + "ANN102", # Missing type annotation for `cls` in classmethod + "ANN204", # Missing return type annotation for special (dunder) method + "FBT", # Using boolean function arguments + "TD", # TODOs + "FIX001", # Resolve FIXMEs + "FIX002", # Resolve TODOs + "B028", # No explicit `stacklevel` keyword argument found in warning + # No docstrings required in the following cases + "D100", # Missing module docstring + "D104", # Missing public package docstring + "D105", # Missing docstring in magic method + "D107", # Missing docstring in `__init__` +] +pydocstyle.convention = "google" + +[tool.ruff.lint.per-file-ignores] +# Tests can ignore a few extra rules +"tests/**.py" = [ + "ANN201", # Missing return type annotation for public function + "PT011", # Missing `match` parameter in `pytest.raises()` + "S101", # Use of assert is detected +] + +[tool.ruff.lint.isort] +known-first-party = ["segmentmytiff"] +force-single-line = true +no-lines-before = ["future","standard-library","third-party","first-party","local-folder"] + +[tool.bumpversion] +current_version = "0.1.0" + +[[tool.bumpversion.files]] +filename = "src/segmentmytiff/__init__.py" + +[[tool.bumpversion.files]] +filename = "pyproject.toml" + +[[tool.bumpversion.files]] +filename = "CITATION.cff" + +[[tool.bumpversion.files]] +filename = "docs/conf.py" diff --git a/src/segmentmytiff/__init__.py b/src/segmentmytiff/__init__.py new file mode 100644 index 0000000..6ee167b --- /dev/null +++ b/src/segmentmytiff/__init__.py @@ -0,0 +1,9 @@ +"""Documentation about segmentmytiff.""" + +import logging + +logging.getLogger(__name__).addHandler(logging.NullHandler()) + +__author__ = "Christiaan Meijer" +__email__ = "c.meijer@esciencecenter.nl" +__version__ = "0.1.0" diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_my_module.py b/tests/test_my_module.py new file mode 100644 index 0000000..760d832 --- /dev/null +++ b/tests/test_my_module.py @@ -0,0 +1,27 @@ +"""Tests for the segmentmytiff.my_module module.""" + +import pytest +from segmentmytiff.my_module import hello + + +def test_hello(): + """Example using assert.""" + assert hello("nlesc") == "Hello nlesc!" + + +def test_hello_with_error(): + """Example of testing for raised errors.""" + with pytest.raises(ValueError) as excinfo: + hello("nobody") + assert "Can not say hello to nobody" in str(excinfo.value) + + +@pytest.fixture +def some_name(): + """Example fixture.""" + return "Jane Smith" + + +def test_hello_with_fixture(some_name: str): + """Example using a fixture.""" + assert hello(some_name) == "Hello Jane Smith!"