From c2ae7a26cdc9537b1b145862134f0edd80fb1eca Mon Sep 17 00:00:00 2001 From: kyleclo Date: Wed, 30 Oct 2024 13:51:34 -0700 Subject: [PATCH] init --- .github/CONTRIBUTING.md | 44 +++--- .github/ISSUE_TEMPLATE/bug_report.yml | 4 +- .github/ISSUE_TEMPLATE/documentation.yml | 4 +- .github/pull_request_template.md | 4 +- .github/workflows/main.yml | 2 +- .github/workflows/pr_checks.yml | 2 +- .github/workflows/setup.yml | 53 ------- Makefile | 4 +- README.md | 113 +------------- RELEASE_PROCESS.md | 2 +- docs/source/conf.py | 8 +- docs/source/index.md | 6 +- docs/source/installation.md | 12 +- {my_package => drawedumath}/__init__.py | 0 {my_package => drawedumath}/py.typed | 0 {my_package => drawedumath}/version.py | 0 pyproject.toml | 14 +- scripts/personalize.py | 179 ----------------------- scripts/prepare_changelog.py | 4 +- scripts/release.sh | 2 +- setup-requirements.txt | 3 - 21 files changed, 57 insertions(+), 403 deletions(-) delete mode 100644 .github/workflows/setup.yml rename {my_package => drawedumath}/__init__.py (100%) rename {my_package => drawedumath}/py.typed (100%) rename {my_package => drawedumath}/version.py (100%) delete mode 100644 scripts/personalize.py delete mode 100644 setup-requirements.txt diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index c5028c2..fe025ef 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -6,10 +6,10 @@ Thanks for considering contributing! Please read this document to learn the vari ### Did you find a bug? -First, do [a quick search](https://github.com/allenai/python-package-template/issues) to see whether your issue has already been reported. +First, do [a quick search](https://github.com/allenai/drawedumath/issues) to see whether your issue has already been reported. If your issue has already been reported, please comment on the existing issue. -Otherwise, open [a new GitHub issue](https://github.com/allenai/python-package-template/issues). Be sure to include a clear title +Otherwise, open [a new GitHub issue](https://github.com/allenai/drawedumath/issues). Be sure to include a clear title and description. The description should include as much relevant information as possible. The description should explain how to reproduce the erroneous behavior as well as the behavior you expect to see. Ideally you would include a code sample or an executable test case demonstrating the expected behavior. @@ -21,7 +21,7 @@ We use GitHub issues to track feature requests. Before you create a feature requ * Make sure you have a clear idea of the enhancement you would like. If you have a vague idea, consider discussing it first on a GitHub issue. * Check the documentation to make sure your feature does not already exist. -* Do [a quick search](https://github.com/allenai/python-package-template/issues) to see whether your feature has already been suggested. +* Do [a quick search](https://github.com/allenai/drawedumath/issues) to see whether your feature has already been suggested. When creating your request, please: @@ -41,31 +41,31 @@ When you're ready to contribute code to address an open issue, please follow the Then clone your fork locally with - git clone https://github.com/USERNAME/python-package-template.git + git clone https://github.com/USERNAME/drawedumath.git or - git clone git@github.com:USERNAME/python-package-template.git + git clone git@github.com:USERNAME/drawedumath.git - At this point the local clone of your fork only knows that it came from *your* repo, github.com/USERNAME/python-package-template.git, but doesn't know anything the *main* repo, [https://github.com/allenai/python-package-template.git](https://github.com/allenai/python-package-template). You can see this by running + At this point the local clone of your fork only knows that it came from *your* repo, github.com/USERNAME/drawedumath.git, but doesn't know anything the *main* repo, [https://github.com/allenai/drawedumath.git](https://github.com/allenai/drawedumath). You can see this by running git remote -v which will output something like this: - origin https://github.com/USERNAME/python-package-template.git (fetch) - origin https://github.com/USERNAME/python-package-template.git (push) + origin https://github.com/USERNAME/drawedumath.git (fetch) + origin https://github.com/USERNAME/drawedumath.git (push) - This means that your local clone can only track changes from your fork, but not from the main repo, and so you won't be able to keep your fork up-to-date with the main repo over time. Therefore you'll need to add another "remote" to your clone that points to [https://github.com/allenai/python-package-template.git](https://github.com/allenai/python-package-template). To do this, run the following: + This means that your local clone can only track changes from your fork, but not from the main repo, and so you won't be able to keep your fork up-to-date with the main repo over time. Therefore you'll need to add another "remote" to your clone that points to [https://github.com/allenai/drawedumath.git](https://github.com/allenai/drawedumath). To do this, run the following: - git remote add upstream https://github.com/allenai/python-package-template.git + git remote add upstream https://github.com/allenai/drawedumath.git Now if you do `git remote -v` again, you'll see - origin https://github.com/USERNAME/python-package-template.git (fetch) - origin https://github.com/USERNAME/python-package-template.git (push) - upstream https://github.com/allenai/python-package-template.git (fetch) - upstream https://github.com/allenai/python-package-template.git (push) + origin https://github.com/USERNAME/drawedumath.git (fetch) + origin https://github.com/USERNAME/drawedumath.git (push) + upstream https://github.com/allenai/drawedumath.git (fetch) + upstream https://github.com/allenai/drawedumath.git (push) Finally, you'll need to create a Python 3 virtual environment suitable for working on this project. There a number of tools out there that making working with virtual environments easier. The most direct way is with the [`venv` module](https://docs.python.org/3.7/library/venv.html) in the standard library, but if you're new to Python or you don't already have a recent Python 3 version installed on your machine, @@ -77,8 +77,8 @@ When you're ready to contribute code to address an open issue, please follow the Then you can create and activate a new Python environment by running: - conda create -n my-package python=3.9 - conda activate my-package + conda create -n drawedumath python=3.9 + conda activate drawedumath Once your virtual environment is activated, you can install your local clone in "editable mode" with @@ -93,7 +93,7 @@ When you're ready to contribute code to address an open issue, please follow the
Expand details 👇
- Once you've added an "upstream" remote pointing to [https://github.com/allenai/python-package-temlate.git](https://github.com/allenai/python-package-template), keeping your fork up-to-date is easy: + Once you've added an "upstream" remote pointing to [https://github.com/allenai/python-package-temlate.git](https://github.com/allenai/drawedumath), keeping your fork up-to-date is easy: git checkout main # if not already on main git pull --rebase upstream main @@ -119,7 +119,7 @@ When you're ready to contribute code to address an open issue, please follow the
Expand details 👇
- Our continuous integration (CI) testing runs [a number of checks](https://github.com/allenai/python-package-template/actions) for each pull request on [GitHub Actions](https://github.com/features/actions). You can run most of these tests locally, which is something you should do *before* opening a PR to help speed up the review process and make it easier for us. + Our continuous integration (CI) testing runs [a number of checks](https://github.com/allenai/drawedumath/actions) for each pull request on [GitHub Actions](https://github.com/features/actions). You can run most of these tests locally, which is something you should do *before* opening a PR to help speed up the review process and make it easier for us. First, you should run [`isort`](https://github.com/PyCQA/isort) and [`black`](https://github.com/psf/black) to make sure you code is formatted consistently. Many IDEs support code formatters as plugins, so you may be able to setup isort and black to run automatically everytime you save. @@ -137,9 +137,9 @@ When you're ready to contribute code to address an open issue, please follow the mypy . - We also strive to maintain high test coverage, so most contributions should include additions to [the unit tests](https://github.com/allenai/python-package-template/tree/main/tests). These tests are run with [`pytest`](https://docs.pytest.org/en/latest/), which you can use to locally run any test modules that you've added or changed. + We also strive to maintain high test coverage, so most contributions should include additions to [the unit tests](https://github.com/allenai/drawedumath/tree/main/tests). These tests are run with [`pytest`](https://docs.pytest.org/en/latest/), which you can use to locally run any test modules that you've added or changed. - For example, if you've fixed a bug in `my_package/a/b.py`, you can run the tests specific to that module with + For example, if you've fixed a bug in `drawedumath/a/b.py`, you can run the tests specific to that module with pytest -v tests/a/b_test.py @@ -152,9 +152,9 @@ When you're ready to contribute code to address an open issue, please follow the If the build fails, it's most likely due to small formatting issues. If the error message isn't clear, feel free to comment on this in your pull request. - And finally, please update the [CHANGELOG](https://github.com/allenai/python-package-template/blob/main/CHANGELOG.md) with notes on your contribution in the "Unreleased" section at the top. + And finally, please update the [CHANGELOG](https://github.com/allenai/drawedumath/blob/main/CHANGELOG.md) with notes on your contribution in the "Unreleased" section at the top. - After all of the above checks have passed, you can now open [a new GitHub pull request](https://github.com/allenai/python-package-template/pulls). + After all of the above checks have passed, you can now open [a new GitHub pull request](https://github.com/allenai/drawedumath/pulls). Make sure you have a clear description of the problem and the solution, and include a link to relevant issues. We look forward to reviewing your PR! diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 547ae3d..811545d 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -6,7 +6,7 @@ body: - type: markdown attributes: value: > - #### Before submitting a bug, please make sure the issue hasn't been already addressed by searching through [the existing and past issues](https://github.com/allenai/python-package-template/issues?q=is%3Aissue+sort%3Acreated-desc+). + #### Before submitting a bug, please make sure the issue hasn't been already addressed by searching through [the existing and past issues](https://github.com/allenai/drawedumath/issues?q=is%3Aissue+sort%3Acreated-desc+). - type: textarea attributes: label: 🐛 Describe the bug @@ -17,7 +17,7 @@ body: ```python # All necessary imports at the beginning - import my_package + import drawedumath # A succinct reproducing example trimmed down to the essential parts: assert False is True, "Oh no!" diff --git a/.github/ISSUE_TEMPLATE/documentation.yml b/.github/ISSUE_TEMPLATE/documentation.yml index 4a80bfd..5bf1c64 100644 --- a/.github/ISSUE_TEMPLATE/documentation.yml +++ b/.github/ISSUE_TEMPLATE/documentation.yml @@ -1,5 +1,5 @@ name: 📚 Documentation -description: Report an issue related to https://my-package.readthedocs.io/latest +description: Report an issue related to https://drawedumath.readthedocs.io/latest labels: 'documentation' body: @@ -7,7 +7,7 @@ body: attributes: label: 📚 The doc issue description: > - A clear and concise description of what content in https://my-package.readthedocs.io/latest is an issue. + A clear and concise description of what content in https://drawedumath.readthedocs.io/latest is an issue. validations: required: true - type: textarea diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index f55c016..7f88cec 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -10,9 +10,9 @@ Changes proposed in this pull request: ## Before submitting -- [ ] I've read and followed all steps in the [Making a pull request](https://github.com/allenai/python-package-template/blob/main/.github/CONTRIBUTING.md#making-a-pull-request) +- [ ] I've read and followed all steps in the [Making a pull request](https://github.com/allenai/drawedumath/blob/main/.github/CONTRIBUTING.md#making-a-pull-request) section of the `CONTRIBUTING` docs. - [ ] I've updated or added any relevant docstrings following the syntax described in the - [Writing docstrings](https://github.com/allenai/python-package-template/blob/main/.github/CONTRIBUTING.md#writing-docstrings) section of the `CONTRIBUTING` docs. + [Writing docstrings](https://github.com/allenai/drawedumath/blob/main/.github/CONTRIBUTING.md#writing-docstrings) section of the `CONTRIBUTING` docs. - [ ] If this PR fixes a bug, I've added a test that will fail without my fix. - [ ] If this PR adds a new feature, I've added tests that sufficiently cover my new functionality. diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1c87c01..b73639e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -97,7 +97,7 @@ jobs: if: always() run: | . .venv/bin/activate - pip uninstall -y my-package + pip uninstall -y drawedumath release: name: Release diff --git a/.github/workflows/pr_checks.yml b/.github/workflows/pr_checks.yml index 614553c..dd4958d 100644 --- a/.github/workflows/pr_checks.yml +++ b/.github/workflows/pr_checks.yml @@ -9,7 +9,7 @@ on: branches: - main paths: - - 'my_package/**' + - 'drawedumath/**' jobs: changelog: diff --git a/.github/workflows/setup.yml b/.github/workflows/setup.yml deleted file mode 100644 index 7aee5be..0000000 --- a/.github/workflows/setup.yml +++ /dev/null @@ -1,53 +0,0 @@ -name: Setup - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -on: - pull_request: - branches: - - main - push: - branches: - - main - -jobs: - test_personalize: - name: Personalize - runs-on: [ubuntu-latest] - timeout-minutes: 10 - steps: - - uses: actions/checkout@v3 - - - name: Setup Python - uses: actions/setup-python@v4 - with: - python-version: "3.8" - cache: "pip" - cache-dependency-path: "setup-requirements.txt" - - - name: Install prerequisites - run: | - pip install -r setup-requirements.txt - - - name: Run personalize script - run: | - python scripts/personalize.py --github-org epwalsh --github-repo new-repo --package-name new-package --yes - - - name: Verify changes - shell: bash - run: | - set -eo pipefail - # Check that 'new-package' replaced 'my-package' in some files. - grep -q 'new-package' pyproject.toml .github/workflows/main.yml .github/CONTRIBUTING.md - # Check that the new repo URL replaced the old one in some files. - grep -q 'https://github.com/epwalsh/new-repo' pyproject.toml .github/CONTRIBUTING.md - # Double check that there are no lingering mentions of old names. - for pattern in 'my[-_]package' 'https://github.com/allenai/python-package-template'; do - if find . -type f -not -path './.git/*' | xargs grep "$pattern"; then - echo "Found ${pattern} where it shouldn't be!" - exit 1 - fi - done - echo "All good!" diff --git a/Makefile b/Makefile index 214718f..8025854 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ .PHONY : docs docs : rm -rf docs/build/ - sphinx-autobuild -b html --watch my_package/ docs/source/ docs/build/ + sphinx-autobuild -b html --watch drawedumath/ docs/source/ docs/build/ .PHONY : run-checks run-checks : @@ -9,7 +9,7 @@ run-checks : black --check . ruff check . mypy . - CUDA_VISIBLE_DEVICES='' pytest -v --color=yes --doctest-modules tests/ my_package/ + CUDA_VISIBLE_DEVICES='' pytest -v --color=yes --doctest-modules tests/ drawedumath/ .PHONY : build build : diff --git a/README.md b/README.md index b8c2dec..eee22f7 100644 --- a/README.md +++ b/README.md @@ -1,112 +1 @@ -# python-package-template - -This is a template repository for Python package projects. - -## In this README :point_down: - -- [Features](#features) -- [Usage](#usage) - - [Initial setup](#initial-setup) - - [Creating releases](#creating-releases) -- [Projects using this template](#projects-using-this-template) -- [FAQ](#faq) -- [Contributing](#contributing) - -## Features - -This template repository comes with all of the boilerplate needed for: - -⚙️ Robust (and free) CI with [GitHub Actions](https://github.com/features/actions): - - Unit tests ran with [PyTest](https://docs.pytest.org) against multiple Python versions and operating systems. - - Type checking with [mypy](https://github.com/python/mypy). - - Linting with [ruff](https://astral.sh/ruff). - - Formatting with [isort](https://pycqa.github.io/isort/) and [black](https://black.readthedocs.io/en/stable/). - -🤖 [Dependabot](https://github.blog/2020-06-01-keep-all-your-packages-up-to-date-with-dependabot/) configuration to keep your dependencies up-to-date. - -📄 Great looking API documentation built using [Sphinx](https://www.sphinx-doc.org/en/master/) (run `make docs` to preview). - -🚀 Automatic GitHub and PyPI releases. Just follow the steps in [`RELEASE_PROCESS.md`](./RELEASE_PROCESS.md) to trigger a new release. - -## Usage - -### Initial setup - -1. [Create a new repository](https://github.com/allenai/python-package-template/generate) from this template with the desired name of your project. - - *Your project name (i.e. the name of the repository) and the name of the corresponding Python package don't necessarily need to match, but you might want to check on [PyPI](https://pypi.org/) first to see if the package name you want is already taken.* - -2. Create a Python 3.8 or newer virtual environment. - - *If you're not sure how to create a suitable Python environment, the easiest way is using [Miniconda](https://docs.conda.io/en/latest/miniconda.html). On a Mac, for example, you can install Miniconda using [Homebrew](https://brew.sh/):* - - ``` - brew install miniconda - ``` - - *Then you can create and activate a new Python environment by running:* - - ``` - conda create -n my-package python=3.9 - conda activate my-package - ``` - -3. Now that you have a suitable Python environment, you're ready to personalize this repository. Just run: - - ``` - pip install -r setup-requirements.txt - python scripts/personalize.py - ``` - - And then follow the prompts. - - :pencil: *NOTE: This script will overwrite the README in your repository.* - -4. Commit and push your changes, then make sure all GitHub Actions jobs pass. - -5. (Optional) If you plan on publishing your package to PyPI, add repository secrets for `PYPI_USERNAME` and `PYPI_PASSWORD`. To add these, go to "Settings" > "Secrets" > "Actions", and then click "New repository secret". - - *If you don't have PyPI account yet, you can [create one for free](https://pypi.org/account/register/).* - -6. (Optional) If you want to deploy your API docs to [readthedocs.org](https://readthedocs.org), go to the [readthedocs dashboard](https://readthedocs.org/dashboard/import/?) and import your new project. - - Then click on the "Admin" button, navigate to "Automation Rules" in the sidebar, click "Add Rule", and then enter the following fields: - - - **Description:** Publish new versions from tags - - **Match:** Custom Match - - **Custom match:** v[vV] - - **Version:** Tag - - **Action:** Activate version - - Then hit "Save". - - *After your first release, the docs will automatically be published to [your-project-name.readthedocs.io](https://your-project-name.readthedocs.io/).* - -### Creating releases - -Creating new GitHub and PyPI releases is easy. The GitHub Actions workflow that comes with this repository will handle all of that for you. -All you need to do is follow the instructions in [RELEASE_PROCESS.md](./RELEASE_PROCESS.md). - -## Projects using this template - -Here is an incomplete list of some projects that started off with this template: - -- [ai2-tango](https://github.com/allenai/tango) -- [cached-path](https://github.com/allenai/cached_path) -- [beaker-py](https://github.com/allenai/beaker-py) -- [gantry](https://github.com/allenai/beaker-gantry) -- [ip-bot](https://github.com/abe-101/ip-bot) -- [atty](https://github.com/mstuttgart/atty) - -☝️ *Want your work featured here? Just open a pull request that adds the link.* - -## FAQ - -#### Should I use this template even if I don't want to publish my package? - -Absolutely! If you don't want to publish your package, just delete the `docs/` directory and the `release` job in [`.github/workflows/main.yml`](https://github.com/allenai/python-package-template/blob/main/.github/workflows/main.yml). - -## Contributing - -If you find a bug :bug:, please open a [bug report](https://github.com/allenai/python-package-template/issues/new?assignees=&labels=bug&template=bug_report.md&title=). -If you have an idea for an improvement or new feature :rocket:, please open a [feature request](https://github.com/allenai/python-package-template/issues/new?assignees=&labels=Feature+request&template=feature_request.md&title=). +# drawedumath diff --git a/RELEASE_PROCESS.md b/RELEASE_PROCESS.md index f214ab4..5aa3891 100644 --- a/RELEASE_PROCESS.md +++ b/RELEASE_PROCESS.md @@ -2,7 +2,7 @@ ## Steps -1. Update the version in `my_package/version.py`. +1. Update the version in `drawedumath/version.py`. 3. Run the release script: diff --git a/docs/source/conf.py b/docs/source/conf.py index e574055..6006b0c 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -18,11 +18,11 @@ sys.path.insert(0, os.path.abspath("../../")) -from my_package import VERSION, VERSION_SHORT # noqa: E402 +from drawedumath import VERSION, VERSION_SHORT # noqa: E402 # -- Project information ----------------------------------------------------- -project = "my-package" +project = "drawedumath" copyright = f"{datetime.today().year}, Allen Institute for Artificial Intelligence" author = "Allen Institute for Artificial Intelligence" version = VERSION_SHORT @@ -82,7 +82,7 @@ # html_theme = "furo" -html_title = f"my-package v{VERSION}" +html_title = f"drawedumath v{VERSION}" # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, @@ -97,7 +97,7 @@ "footer_icons": [ { "name": "GitHub", - "url": "https://github.com/allenai/python-package-template", + "url": "https://github.com/allenai/drawedumath", "html": """ diff --git a/docs/source/index.md b/docs/source/index.md index 6fbe5e3..76b8388 100644 --- a/docs/source/index.md +++ b/docs/source/index.md @@ -1,4 +1,4 @@ -# **my-package** +# **drawedumath** ```{toctree} :maxdepth: 2 @@ -15,8 +15,8 @@ overview CHANGELOG CONTRIBUTING -License -GitHub Repository +License +GitHub Repository ``` ## Indices and tables diff --git a/docs/source/installation.md b/docs/source/installation.md index d997e0d..166624c 100644 --- a/docs/source/installation.md +++ b/docs/source/installation.md @@ -1,23 +1,23 @@ Installation ============ -**my-package** supports Python >= 3.8. +**drawedumath** supports Python >= 3.8. ## Installing with `pip` -**my-package** is available [on PyPI](https://pypi.org/project/my-package/). Just run +**drawedumath** is available [on PyPI](https://pypi.org/project/drawedumath/). Just run ```bash -pip install my-package +pip install drawedumath ``` ## Installing from source -To install **my-package** from source, first clone [the repository](https://github.com/allenai/python-package-template): +To install **drawedumath** from source, first clone [the repository](https://github.com/allenai/drawedumath): ```bash -git clone https://github.com/allenai/python-package-template.git -cd python-package-template +git clone https://github.com/allenai/drawedumath.git +cd drawedumath ``` Then run diff --git a/my_package/__init__.py b/drawedumath/__init__.py similarity index 100% rename from my_package/__init__.py rename to drawedumath/__init__.py diff --git a/my_package/py.typed b/drawedumath/py.typed similarity index 100% rename from my_package/py.typed rename to drawedumath/py.typed diff --git a/my_package/version.py b/drawedumath/version.py similarity index 100% rename from my_package/version.py rename to drawedumath/version.py diff --git a/pyproject.toml b/pyproject.toml index 8bf2ebe..085b45e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] # See https://setuptools.pypa.io/en/latest/userguide/quickstart.html for more project configuration options. -name = "my-package" +name = "drawedumath" dynamic = ["version"] readme = "README.md" classifiers = [ @@ -24,10 +24,10 @@ dependencies = [ license = {file = "LICENSE"} [project.urls] -Homepage = "https://github.com/allenai/python-package-template" -Repository = "https://github.com/allenai/python-package-template" -Changelog = "https://github.com/allenai/python-package-template/blob/main/CHANGELOG.md" -# Documentation = "https://my-package.readthedocs.io/" +Homepage = "https://github.com/allenai/drawedumath" +Repository = "https://github.com/allenai/drawedumath" +Changelog = "https://github.com/allenai/drawedumath/blob/main/CHANGELOG.md" +# Documentation = "https://drawedumath.readthedocs.io/" [project.optional-dependencies] dev = [ @@ -65,10 +65,10 @@ exclude = [ include-package-data = true [tool.setuptools.package-data] -my_package = ["py.typed"] +drawedumath = ["py.typed"] [tool.setuptools.dynamic] -version = {attr = "my_package.version.VERSION"} +version = {attr = "drawedumath.version.VERSION"} [tool.black] line-length = 100 diff --git a/scripts/personalize.py b/scripts/personalize.py deleted file mode 100644 index 9f5a4b5..0000000 --- a/scripts/personalize.py +++ /dev/null @@ -1,179 +0,0 @@ -""" -Run this script once after first creating your project from this template repo to personalize -it for own project. - -This script is interactive and will prompt you for various inputs. -""" - -import sys -from pathlib import Path -from typing import Generator, List, Tuple - -import click -from click_help_colors import HelpColorsCommand -from rich import print -from rich.markdown import Markdown -from rich.prompt import Confirm -from rich.syntax import Syntax -from rich.traceback import install - -install(show_locals=True, suppress=[click]) - -REPO_BASE = (Path(__file__).parent / "..").resolve() - -FILES_TO_REMOVE = { - REPO_BASE / ".github" / "workflows" / "setup.yml", - REPO_BASE / "setup-requirements.txt", - REPO_BASE / "scripts" / "personalize.py", -} - -PATHS_TO_IGNORE = { - REPO_BASE / "README.md", - REPO_BASE / ".git", - REPO_BASE / "docs" / "source" / "_static" / "favicon.ico", -} - -GITIGNORE_LIST = [ - line.strip() - for line in (REPO_BASE / ".gitignore").open(encoding="utf-8").readlines() - if line.strip() and not line.startswith("#") -] - -REPO_NAME_TO_REPLACE = "python-package-template" -BASE_URL_TO_REPLACE = "https://github.com/allenai/python-package-template" - - -@click.command( - cls=HelpColorsCommand, - help_options_color="green", - help_headers_color="yellow", - context_settings={"max_content_width": 115}, -) -@click.option( - "--github-org", - prompt="GitHub organization or user (e.g. 'allenai')", - help="The name of your GitHub organization or user.", -) -@click.option( - "--github-repo", - prompt="GitHub repository (e.g. 'python-package-template')", - help="The name of your GitHub repository.", -) -@click.option( - "--package-name", - prompt="Python package name (e.g. 'my-package')", - help="The name of your Python package.", -) -@click.option( - "-y", - "--yes", - is_flag=True, - help="Run the script without prompting for a confirmation.", - default=False, -) -@click.option( - "--dry-run", - is_flag=True, - hidden=True, - default=False, -) -def main( - github_org: str, github_repo: str, package_name: str, yes: bool = False, dry_run: bool = False -): - repo_url = f"https://github.com/{github_org}/{github_repo}" - package_actual_name = package_name.replace("_", "-") - package_dir_name = package_name.replace("-", "_") - - # Confirm before continuing. - print(f"Repository URL set to: [link={repo_url}]{repo_url}[/]") - print(f"Package name set to: [cyan]{package_actual_name}[/]") - if not yes: - yes = Confirm.ask("Is this correct?") - if not yes: - raise click.ClickException("Aborted, please run script again") - - # Personalize files. - replacements = [ - (BASE_URL_TO_REPLACE, repo_url), - (REPO_NAME_TO_REPLACE, github_repo), - ("my-package", package_actual_name), - ("my_package", package_dir_name), - ] - if dry_run: - for old, new in replacements: - print(f"Replacing '{old}' with '{new}'") - for path in iterfiles(REPO_BASE): - if path.resolve() not in FILES_TO_REMOVE: - personalize_file(path, dry_run, replacements) - - # Rename 'my_package' directory to `package_dir_name`. - if not dry_run: - (REPO_BASE / "my_package").replace(REPO_BASE / package_dir_name) - else: - print(f"Renaming 'my_package' directory to '{package_dir_name}'") - - # Start with a fresh README. - readme_contents = f"""# {package_actual_name}\n""" - if not dry_run: - with open(REPO_BASE / "README.md", mode="w+t", encoding="utf-8") as readme_file: - readme_file.write(readme_contents) - else: - print("Replacing README.md contents with:\n", Markdown(readme_contents)) - - install_example = Syntax("pip install -e '.[dev]'", "bash") - print( - "[green]\N{check mark} Success![/] You can now install your package locally in development mode with:\n", - install_example, - ) - - # Lastly, remove that we don't need. - for path in FILES_TO_REMOVE: - assert path.is_file(), path - if not dry_run: - if path.name == "personalize.py" and sys.platform.startswith("win"): - # We can't unlink/remove an open file on Windows. - print("You can remove the 'scripts/personalize.py' file now") - else: - path.unlink() - - -def iterfiles(dir: Path) -> Generator[Path, None, None]: - assert dir.is_dir() - for path in dir.iterdir(): - if path in PATHS_TO_IGNORE: - continue - - is_ignored_file = False - for gitignore_entry in GITIGNORE_LIST: - if path.relative_to(REPO_BASE).match(gitignore_entry): - is_ignored_file = True - break - if is_ignored_file: - continue - - if path.is_dir(): - yield from iterfiles(path) - else: - yield path - - -def personalize_file(path: Path, dry_run: bool, replacements: List[Tuple[str, str]]): - with path.open(mode="r+t", encoding="utf-8") as file: - filedata = file.read() - - should_update: bool = False - for old, new in replacements: - if filedata.count(old): - should_update = True - filedata = filedata.replace(old, new) - - if should_update: - if not dry_run: - with path.open(mode="w+t", encoding="utf-8") as file: - file.write(filedata) - else: - print(f"Updating {path}") - - -if __name__ == "__main__": - main() diff --git a/scripts/prepare_changelog.py b/scripts/prepare_changelog.py index 083eeda..31b219f 100644 --- a/scripts/prepare_changelog.py +++ b/scripts/prepare_changelog.py @@ -1,7 +1,7 @@ from datetime import datetime from pathlib import Path -from my_package.version import VERSION +from drawedumath.version import VERSION def main(): @@ -27,7 +27,7 @@ def main(): lines.insert(insert_index, "\n") lines.insert( insert_index + 1, - f"## [v{VERSION}](https://github.com/allenai/python-package-template/releases/tag/v{VERSION}) - " + f"## [v{VERSION}](https://github.com/allenai/drawedumath/releases/tag/v{VERSION}) - " f"{datetime.now().strftime('%Y-%m-%d')}\n", ) diff --git a/scripts/release.sh b/scripts/release.sh index b9a695e..13afbde 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -2,7 +2,7 @@ set -e -TAG=$(python -c 'from my_package.version import VERSION; print("v" + VERSION)') +TAG=$(python -c 'from drawedumath.version import VERSION; print("v" + VERSION)') read -p "Creating new release for $TAG. Do you want to continue? [Y/n] " prompt diff --git a/setup-requirements.txt b/setup-requirements.txt deleted file mode 100644 index 103b77f..0000000 --- a/setup-requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -click>=7.0,<9.0 -click-help-colors>=0.9.1,<0.10 -rich>=11.0,<14.0