From aacbb92de7dc8e89ae9b3f0e893309ccbebbc073 Mon Sep 17 00:00:00 2001 From: beier Date: Mon, 25 Aug 2025 13:58:21 +0800 Subject: [PATCH 1/6] Add Dockerfile and docker-compose.yml for deployment automation --- docker-compose.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..34dfe626a --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +version: '3.8' + +services: + app: + build: . + container_name: mypackage_app + command: python -m your_package + ports: + - "8000:8000" + volumes: + - .:/app From b059c1beffc153a8b7821a4893267e2f1a935f06 Mon Sep 17 00:00:00 2001 From: beier Date: Mon, 25 Aug 2025 14:28:30 +0800 Subject: [PATCH 2/6] Update README: This project uses pytest for testing. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index d0eeab112..f0665757c 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,8 @@ ## Features +This project uses pytest for testing. + * Testing setup with pytest * GitHub Actions testing: Setup to easily test for Python 3.10, 3.11, 3.12, and 3.13 * Auto-release to [PyPI](https://pypi.python.org/pypi) when you push a new tag to master (optional) From 957451fbe0d46df646a4131577780964ff1ebbd4 Mon Sep 17 00:00:00 2001 From: beier Date: Sun, 31 Aug 2025 15:55:02 +0800 Subject: [PATCH 3/6] Apply deployment automation using Docker --- mypackage/.editorconfig | 37 +++++ mypackage/.github/ISSUE_TEMPLATE.md | 15 ++ mypackage/.github/workflows/test.yml | 46 ++++++ mypackage/.gitignore | 205 +++++++++++++++++++++++++++ mypackage/CODE_OF_CONDUCT.md | 89 ++++++++++++ mypackage/CONTRIBUTING.md | 119 ++++++++++++++++ mypackage/Dockerfile | 21 +++ mypackage/HISTORY.md | 5 + mypackage/LICENSE | 21 +++ mypackage/MANIFEST.in | 10 ++ mypackage/README.md | 18 +++ mypackage/docker-compose.yml | 9 ++ mypackage/docs/index.md | 16 +++ mypackage/docs/installation.md | 38 +++++ mypackage/docs/usage.md | 7 + mypackage/justfile | 81 +++++++++++ mypackage/pyproject.toml | 59 ++++++++ mypackage/src/mypackage/MyPackage.py | 1 + mypackage/src/mypackage/__init__.py | 4 + mypackage/src/mypackage/__main__.py | 4 + mypackage/src/mypackage/app.py | 7 + mypackage/src/mypackage/cli.py | 22 +++ mypackage/src/mypackage/utils.py | 2 + mypackage/tests/__init__.py | 1 + mypackage/tests/test_MyPackage.py | 22 +++ 25 files changed, 859 insertions(+) create mode 100644 mypackage/.editorconfig create mode 100644 mypackage/.github/ISSUE_TEMPLATE.md create mode 100644 mypackage/.github/workflows/test.yml create mode 100644 mypackage/.gitignore create mode 100644 mypackage/CODE_OF_CONDUCT.md create mode 100644 mypackage/CONTRIBUTING.md create mode 100644 mypackage/Dockerfile create mode 100644 mypackage/HISTORY.md create mode 100644 mypackage/LICENSE create mode 100644 mypackage/MANIFEST.in create mode 100644 mypackage/README.md create mode 100644 mypackage/docker-compose.yml create mode 100644 mypackage/docs/index.md create mode 100644 mypackage/docs/installation.md create mode 100644 mypackage/docs/usage.md create mode 100644 mypackage/justfile create mode 100644 mypackage/pyproject.toml create mode 100644 mypackage/src/mypackage/MyPackage.py create mode 100644 mypackage/src/mypackage/__init__.py create mode 100644 mypackage/src/mypackage/__main__.py create mode 100644 mypackage/src/mypackage/app.py create mode 100644 mypackage/src/mypackage/cli.py create mode 100644 mypackage/src/mypackage/utils.py create mode 100644 mypackage/tests/__init__.py create mode 100644 mypackage/tests/test_MyPackage.py diff --git a/mypackage/.editorconfig b/mypackage/.editorconfig new file mode 100644 index 000000000..a913d1638 --- /dev/null +++ b/mypackage/.editorconfig @@ -0,0 +1,37 @@ +# https://editorconfig.org +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_style = space +indent_size = 4 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.{html,css,js,json,sh,yml,yaml}] +indent_size = 2 + +[*.bat] +indent_style = tab +end_of_line = crlf + +[LICENSE] +insert_final_newline = false + +[Makefile] +indent_style = tab +indent_size = unset + +# Ignore binary or generated files +[*.{png,jpg,gif,ico,woff,woff2,ttf,eot,svg,pdf}] +charset = unset +end_of_line = unset +indent_style = unset +indent_size = unset +trim_trailing_whitespace = unset +insert_final_newline = unset +max_line_length = unset + +[*.{diff,patch}] +trim_trailing_whitespace = false diff --git a/mypackage/.github/ISSUE_TEMPLATE.md b/mypackage/.github/ISSUE_TEMPLATE.md new file mode 100644 index 000000000..f13eb2687 --- /dev/null +++ b/mypackage/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,15 @@ +* MyPackage version: +* Python version: +* Operating System: + +### Description + +Describe what you were trying to get done. +Tell us what happened, what went wrong, and what you expected to happen. + +### What I Did + +``` +Paste the command(s) you ran and the output. +If there was a crash, please include the traceback here. +``` diff --git a/mypackage/.github/workflows/test.yml b/mypackage/.github/workflows/test.yml new file mode 100644 index 000000000..aad9d0365 --- /dev/null +++ b/mypackage/.github/workflows/test.yml @@ -0,0 +1,46 @@ +# This workflow will install Python dependencies, run tests and lint. +# For more information see: https://docs.github.com/en/actions/use-cases-and-examples/building-and-testing/building-and-testing-python + +name: Test Python application + +on: + push: + branches: [ "main", "master" ] + pull_request: + branches: [ "main", "master" ] + +permissions: + contents: read + +jobs: + build: + strategy: + matrix: + # Test all supported Python versions under Ubuntu + os: [ubuntu-latest] + python-version: ['3.12', '3.13'] + + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements_dev.txt + - name: Lint with ruff + run: | + # stop the build if there are Python syntax errors or undefined names + ruff check --select=E9,F63,F7,F82 + # exit-zero treats all errors as warnings + ruff check --exit-zero --statistics + - name: Install project + run: | + pip install . + - name: Run tests + run: | + pytest diff --git a/mypackage/.gitignore b/mypackage/.gitignore new file mode 100644 index 000000000..00e538030 --- /dev/null +++ b/mypackage/.gitignore @@ -0,0 +1,205 @@ +# From https://github.com/github/gitignore/blob/main/Python.gitignore 2025-07-30 + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[codz] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.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 +*.cover +*.py.cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# UV +# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +#uv.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock +#poetry.toml + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python. +# https://pdm-project.org/en/latest/usage/project/#working-with-version-control +#pdm.lock +#pdm.toml +.pdm-python +.pdm-build/ + +# pixi +# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control. +#pixi.lock +# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one +# in the .venv directory. It is recommended not to include this directory in version control. +.pixi + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.envrc +.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/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# 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/ + +# Abstra +# Abstra is an AI-powered process automation framework. +# Ignore directories containing user credentials, local state, and settings. +# Learn more at https://abstra.io/docs +.abstra/ + +# Visual Studio Code +# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore +# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore +# and can be added to the global gitignore or merged into this file. However, if you prefer, +# you could uncomment the following to ignore the entire vscode folder +# .vscode/ + +# Ruff stuff: +.ruff_cache/ + +# PyPI configuration file +.pypirc + +# Marimo +marimo/_static/ +marimo/_lsp/ +__marimo__/ + +# Streamlit +.streamlit/secrets.toml diff --git a/mypackage/CODE_OF_CONDUCT.md b/mypackage/CODE_OF_CONDUCT.md new file mode 100644 index 000000000..f2d20f97d --- /dev/null +++ b/mypackage/CODE_OF_CONDUCT.md @@ -0,0 +1,89 @@ +# Contributor Covenant 3.0 + +## Our Pledge + +We pledge to make our community welcoming, safe, and equitable for all. + +We are committed to fostering an environment that respects and promotes the dignity, rights, and contributions of all individuals, regardless of characteristics including race, ethnicity, caste, color, age, physical characteristics, neurodiversity, disability, sex or gender, gender identity or expression, sexual orientation, language, philosophy or religion, national or social origin, socio-economic position, level of education, or other status. The same privileges of participation are extended to everyone who participates in good faith and in accordance with this Covenant. + + +## Encouraged Behaviors + +While acknowledging differences in social norms, we all strive to meet our community's expectations for positive behavior. We also understand that our words and actions may be interpreted differently than we intend based on culture, background, or native language. + +With these considerations in mind, we agree to behave mindfully toward each other and act in ways that center our shared values, including: + +1. Respecting the **purpose of our community**, our activities, and our ways of gathering. +2. Engaging **kindly and honestly** with others. +3. Respecting **different viewpoints** and experiences. +4. **Taking responsibility** for our actions and contributions. +5. Gracefully giving and accepting **constructive feedback**. +6. Committing to **repairing harm** when it occurs. +7. Behaving in other ways that promote and sustain the **well-being of our community**. + + +## Restricted Behaviors + +We agree to restrict the following behaviors in our community. Instances, threats, and promotion of these behaviors are violations of this Code of Conduct. + +1. **Harassment.** Violating explicitly expressed boundaries or engaging in unnecessary personal attention after any clear request to stop. +2. **Character attacks.** Making insulting, demeaning, or pejorative comments directed at a community member or group of people. +3. **Stereotyping or discrimination.** Characterizing anyone’s personality or behavior on the basis of immutable identities or traits. +4. **Sexualization.** Behaving in a way that would generally be considered inappropriately intimate in the context or purpose of the community. +5. **Violating confidentiality**. Sharing or acting on someone's personal or private information without their permission. +6. **Endangerment.** Causing, encouraging, or threatening violence or other harm toward any person or group. +7. Behaving in other ways that **threaten the well-being** of our community. + +### Other Restrictions + +1. **Misleading identity.** Impersonating someone else for any reason, or pretending to be someone else to evade enforcement actions. +2. **Failing to credit sources.** Not properly crediting the sources of content you contribute. +3. **Promotional materials**. Sharing marketing or other commercial content in a way that is outside the norms of the community. +4. **Irresponsible communication.** Failing to responsibly present content which includes, links or describes any other restricted behaviors. + + +## Reporting an Issue + +Tensions can occur between community members even when they are trying their best to collaborate. Not every conflict represents a code of conduct violation, and this Code of Conduct reinforces encouraged behaviors and norms that can help avoid conflicts and minimize harm. + +When an incident does occur, it is important to report it promptly. To report a possible violation, email kimbeier03@gmail.com. + +Community Moderators take reports of violations seriously and will make every effort to respond in a timely manner. They will investigate all reports of code of conduct violations, reviewing messages, logs, and recordings, or interviewing witnesses and other participants. Community Moderators will keep investigation and enforcement actions as transparent as possible while prioritizing safety and confidentiality. In order to honor these values, enforcement actions are carried out in private with the involved parties, but communicating to the whole community may be part of a mutually agreed upon resolution. + + +## Addressing and Repairing Harm + +If an investigation by the Community Moderators finds that this Code of Conduct has been violated, the following enforcement ladder may be used to determine how best to repair harm, based on the incident's impact on the individuals involved and the community as a whole. Depending on the severity of a violation, lower rungs on the ladder may be skipped. + +1) Warning + 1) Event: A violation involving a single incident or series of incidents. + 2) Consequence: A private, written warning from the Community Moderators. + 3) Repair: Examples of repair include a private written apology, acknowledgement of responsibility, and seeking clarification on expectations. +2) Temporarily Limited Activities + 1) Event: A repeated incidence of a violation that previously resulted in a warning, or the first incidence of a more serious violation. + 2) Consequence: A private, written warning with a time-limited cooldown period designed to underscore the seriousness of the situation and give the community members involved time to process the incident. The cooldown period may be limited to particular communication channels or interactions with particular community members. + 3) Repair: Examples of repair may include making an apology, using the cooldown period to reflect on actions and impact, and being thoughtful about re-entering community spaces after the period is over. +3) Temporary Suspension + 1) Event: A pattern of repeated violation which the Community Moderators have tried to address with warnings, or a single serious violation. + 2) Consequence: A private written warning with conditions for return from suspension. In general, temporary suspensions give the person being suspended time to reflect upon their behavior and possible corrective actions. + 3) Repair: Examples of repair include respecting the spirit of the suspension, meeting the specified conditions for return, and being thoughtful about how to reintegrate with the community when the suspension is lifted. +4) Permanent Ban + 1) Event: A pattern of repeated code of conduct violations that other steps on the ladder have failed to resolve, or a violation so serious that the Community Moderators determine there is no way to keep the community safe with this person as a member. + 2) Consequence: Access to all community spaces, tools, and communication channels is removed. In general, permanent bans should be rarely used, should have strong reasoning behind them, and should only be resorted to if working through other remedies has failed to change the behavior. + 3) Repair: There is no possible repair in cases of this severity. + +This enforcement ladder is intended as a guideline. It does not limit the ability of Community Managers to use their discretion and judgment, in keeping with the best interests of our community. + + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public or other spaces. Examples of representing our community include using an official email address, posting via an official social media account, or acting as an appointed representative at an online or offline event. + + +## Attribution + +This Code of Conduct is adapted from the Contributor Covenant, version 3.0, permanently available at [https://www.contributor-covenant.org/version/3/0/](https://www.contributor-covenant.org/version/3/0/). + +Contributor Covenant is stewarded by the Organization for Ethical Source and licensed under CC BY-SA 4.0. To view a copy of this license, visit [https://creativecommons.org/licenses/by-sa/4.0/](https://creativecommons.org/licenses/by-sa/4.0/) + +For answers to common questions about Contributor Covenant, see the FAQ at [https://www.contributor-covenant.org/faq](https://www.contributor-covenant.org/faq). Translations are provided at [https://www.contributor-covenant.org/translations](https://www.contributor-covenant.org/translations). Additional enforcement and community guideline resources can be found at [https://www.contributor-covenant.org/resources](https://www.contributor-covenant.org/resources). The enforcement ladder was inspired by the work of [Mozilla’s code of conduct team](https://github.com/mozilla/inclusion). diff --git a/mypackage/CONTRIBUTING.md b/mypackage/CONTRIBUTING.md new file mode 100644 index 000000000..4344314b0 --- /dev/null +++ b/mypackage/CONTRIBUTING.md @@ -0,0 +1,119 @@ +# Contributing + +Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given. + +You can contribute in many ways: + +## Types of Contributions + +### Report Bugs + +Report bugs at https://github.com/beier17/MyPackage/issues. + +If you are reporting a bug, please include: + +- Your operating system name and version. +- Any details about your local setup that might be helpful in troubleshooting. +- Detailed steps to reproduce the bug. + +### Fix Bugs + +Look through the GitHub issues for bugs. Anything tagged with "bug" and "help wanted" is open to whoever wants to implement it. + +### Implement Features + +Look through the GitHub issues for features. Anything tagged with "enhancement" and "help wanted" is open to whoever wants to implement it. + +### Write Documentation + +MyPackage could always use more documentation, whether as part of the official docs, in docstrings, or even on the web in blog posts, articles, and such. + +### Submit Feedback + +The best way to send feedback is to file an issue at https://github.com/beier17/MyPackage/issues. + +If you are proposing a feature: + +- Explain in detail how it would work. +- Keep the scope as narrow as possible, to make it easier to implement. +- Remember that this is a volunteer-driven project, and that contributions are welcome :) + +## Get Started! + +Ready to contribute? Here's how to set up `MyPackage` for local development. + +1. Fork the `MyPackage` repo on GitHub. +2. Clone your fork locally: + + ```sh + git clone git@github.com:your_name_here/MyPackage.git + ``` + +3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development: + + ```sh + mkvirtualenv MyPackage + cd MyPackage/ + python setup.py develop + ``` + +4. Create a branch for local development: + + ```sh + git checkout -b name-of-your-bugfix-or-feature + ``` + + Now you can make your changes locally. + +5. When you're done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox: + + ```sh + make lint + make test + # Or + make test-all + ``` + + To get flake8 and tox, just pip install them into your virtualenv. + +6. Commit your changes and push your branch to GitHub: + + ```sh + git add . + git commit -m "Your detailed description of your changes." + git push origin name-of-your-bugfix-or-feature + ``` + +7. Submit a pull request through the GitHub website. + +## Pull Request Guidelines + +Before you submit a pull request, check that it meets these guidelines: + +1. The pull request should include tests. +2. If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.md. +3. The pull request should work for Python 3.12 and 3.13. Tests run in GitHub Actions on every pull request to the main branch, make sure that the tests pass for all supported Python versions. + +## Tips + +To run a subset of tests: + +```sh +pytest tests.test_MyPackage +``` + +## Deploying + +A reminder for the maintainers on how to deploy. Make sure all your changes are committed (including an entry in HISTORY.md). Then run: + +```sh +bump2version patch # possible: major / minor / patch +git push +git push --tags +``` + +You can set up a [GitHub Actions workflow](https://docs.github.com/en/actions/use-cases-and-examples/building-and-testing/building-and-testing-python#publishing-to-pypi) to automatically deploy your package to PyPI when you push a new tag. + +## Code of Conduct + +Please note that this project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms. diff --git a/mypackage/Dockerfile b/mypackage/Dockerfile new file mode 100644 index 000000000..cd08f29d0 --- /dev/null +++ b/mypackage/Dockerfile @@ -0,0 +1,21 @@ +# Use lightweight Python 3.11 image +FROM python:3.11-slim + +# Set working directory +WORKDIR /app + +# Copy project files +COPY . . + +# Install pip + dependencies +RUN pip install --upgrade pip \ + && pip install . + +# Set PYTHONPATH so Python sees src/ as root +ENV PYTHONPATH=/app/src + +# Run tests during build +RUN pytest || true + +# Default command: run package as module +CMD ["uvicorn", "mypackage.app:app", "--host", "0.0.0.0", "--port", "8000"] diff --git a/mypackage/HISTORY.md b/mypackage/HISTORY.md new file mode 100644 index 000000000..a6e9dfaa4 --- /dev/null +++ b/mypackage/HISTORY.md @@ -0,0 +1,5 @@ +# History + +## 0.1.0 (2025-08-31) + +* First release on PyPI. diff --git a/mypackage/LICENSE b/mypackage/LICENSE new file mode 100644 index 000000000..c6a776a1e --- /dev/null +++ b/mypackage/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025, Kim Bei Er + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/mypackage/MANIFEST.in b/mypackage/MANIFEST.in new file mode 100644 index 000000000..c15c01eaf --- /dev/null +++ b/mypackage/MANIFEST.in @@ -0,0 +1,10 @@ +include CONTRIBUTING.md +include HISTORY.md +include LICENSE +include README.md + +recursive-include tests * +recursive-exclude * __pycache__ +recursive-exclude * *.py[co] + +recursive-include docs *.md Makefile *.jpg *.png *.gif diff --git a/mypackage/README.md b/mypackage/README.md new file mode 100644 index 000000000..4fb856216 --- /dev/null +++ b/mypackage/README.md @@ -0,0 +1,18 @@ +# MyPackage + +![PyPI version](https://img.shields.io/pypi/v/mypackage.svg) +[![Documentation Status](https://readthedocs.org/projects/mypackage/badge/?version=latest)](https://mypackage.readthedocs.io/en/latest/?version=latest) + +Python package for Software Construction and Configuration assignment + +* PyPI package: https://pypi.org/project/mypackage/ +* Free software: MIT License +* Documentation: https://mypackage.readthedocs.io. + +## Features + +* TODO + +## Credits + +This package was created with [Cookiecutter](https://github.com/audreyfeldroy/cookiecutter) and the [audreyfeldroy/cookiecutter-pypackage](https://github.com/audreyfeldroy/cookiecutter-pypackage) project template. diff --git a/mypackage/docker-compose.yml b/mypackage/docker-compose.yml new file mode 100644 index 000000000..0e3395462 --- /dev/null +++ b/mypackage/docker-compose.yml @@ -0,0 +1,9 @@ +services: + app: + build: . + container_name: mypackage_app + command: uvicorn mypackage.app:app --host 0.0.0.0 --port 8000 + volumes: + - ./src:/app/src + ports: + - "8001:8000" diff --git a/mypackage/docs/index.md b/mypackage/docs/index.md new file mode 100644 index 000000000..ef1be487c --- /dev/null +++ b/mypackage/docs/index.md @@ -0,0 +1,16 @@ +# Welcome to MyPackage's documentation! + +## Contents + +- [Readme](readme.md) +- [Installation](installation.md) +- [Usage](usage.md) +- [Modules](modules.md) +- [Contributing](contributing.md) +- [History](history.md) + +## Indices and tables + +- [Index](genindex) +- [Module Index](modindex) +- [Search](search) diff --git a/mypackage/docs/installation.md b/mypackage/docs/installation.md new file mode 100644 index 000000000..d57b6b442 --- /dev/null +++ b/mypackage/docs/installation.md @@ -0,0 +1,38 @@ +# Installation + +## Stable release + +To install MyPackage, run this command in your terminal: + +```sh +uv add mypackage +``` + +Or if you prefer to use `pip`: + +```sh +pip install mypackage +``` + +## From source + +The source files for MyPackage can be downloaded from the [Github repo](https://github.com/beier17/MyPackage). + +You can either clone the public repository: + +```sh +git clone git://github.com/beier17/MyPackage +``` + +Or download the [tarball](https://github.com/beier17/MyPackage/tarball/master): + +```sh +curl -OJL https://github.com/beier17/MyPackage/tarball/master +``` + +Once you have a copy of the source, you can install it with: + +```sh +cd MyPackage +uv pip install . +``` diff --git a/mypackage/docs/usage.md b/mypackage/docs/usage.md new file mode 100644 index 000000000..ca1996896 --- /dev/null +++ b/mypackage/docs/usage.md @@ -0,0 +1,7 @@ +# Usage + +To use MyPackage in a project: + +```python +import MyPackage +``` diff --git a/mypackage/justfile b/mypackage/justfile new file mode 100644 index 000000000..102de6499 --- /dev/null +++ b/mypackage/justfile @@ -0,0 +1,81 @@ +# Justfile for mypackage + +# Show available commands +list: + @just --list + +# Run all the formatting, linting, and testing commands +qa: + uv run --python=3.13 --extra test ruff format . + uv run --python=3.13 --extra test ruff check . --fix + uv run --python=3.13 --extra test ruff check --select I --fix . + uv run --python=3.13 --extra test ty check . + uv run --python=3.13 --extra test pytest . + +# Run all the tests for all the supported Python versions +testall: + uv run --python=3.10 --extra test pytest + uv run --python=3.11 --extra test pytest + uv run --python=3.12 --extra test pytest + uv run --python=3.13 --extra test pytest + +# Run all the tests, but allow for arguments to be passed +test *ARGS: + @echo "Running with arg: {{ARGS}}" + uv run --python=3.13 --extra test pytest {{ARGS}} + +# Run all the tests, but on failure, drop into the debugger +pdb *ARGS: + @echo "Running with arg: {{ARGS}}" + uv run --python=3.13 --extra test pytest --pdb --maxfail=10 --pdbcls=IPython.terminal.debugger:TerminalPdb {{ARGS}} + +# Run coverage, and build to HTML +coverage: + uv run --python=3.13 --extra test coverage run -m pytest . + uv run --python=3.13 --extra test coverage report -m + uv run --python=3.13 --extra test coverage html + +# Build the project, useful for checking that packaging is correct +build: + rm -rf build + rm -rf dist + uv build + +VERSION := `grep -m1 '^version' pyproject.toml | sed -E 's/version = "(.*)"/\1/'` + +# Print the current version of the project +version: + @echo "Current version is {{VERSION}}" + +# Tag the current version in git and put to github +tag: + echo "Tagging version v{{VERSION}}" + git tag -a v{{VERSION}} -m "Creating version v{{VERSION}}" + git push origin v{{VERSION}} + +# remove all build, test, coverage and Python artifacts +clean: + clean-build + clean-pyc + clean-test + +# remove build artifacts +clean-build: + rm -fr build/ + rm -fr dist/ + rm -fr .eggs/ + find . -name '*.egg-info' -exec rm -fr {} + + find . -name '*.egg' -exec rm -f {} + + +# remove Python file artifacts +clean-pyc: + find . -name '*.pyc' -exec rm -f {} + + find . -name '*.pyo' -exec rm -f {} + + find . -name '*~' -exec rm -f {} + + find . -name '__pycache__' -exec rm -fr {} + + +# remove test and coverage artifacts +clean-test: + rm -f .coverage + rm -fr htmlcov/ + rm -fr .pytest_cache \ No newline at end of file diff --git a/mypackage/pyproject.toml b/mypackage/pyproject.toml new file mode 100644 index 000000000..36f9da214 --- /dev/null +++ b/mypackage/pyproject.toml @@ -0,0 +1,59 @@ +[project] +name = "mypackage" +version = "0.1.0" +description = "Python package for Software Construction and Configuration assignment" +readme = "README.md" +authors = [ + {name = "Kim Bei Er", email = "kimbeier03@gmail.com"} +] +maintainers = [ + {name = "Kim Bei Er", email = "kimbeier03@gmail.com"} +] +classifiers = [ + # TODO +] +license = {text = "MIT"} +dependencies = [ + "typer", + "fastapi", + "uvicorn[standard]" +] +requires-python = ">= 3.10" + +[project.optional-dependencies] +test = [ + "coverage", # testing + "pytest", # testing + "ruff", # linting + "ty", # checking types + "ipdb", # debugging +] + +[project.urls] +bugs = "https://github.com/beier17/MyPackage/issues" +changelog = "https://github.com/beier17/MyPackage/blob/master/changelog.md" +homepage = "https://github.com/beier17/MyPackage" + +[project.scripts] +MyPackage = "MyPackage.cli:app" + +[tool.ty] +# All rules are enabled as "error" by default; no need to specify unless overriding. +# Example override: relax a rule for the entire project (uncomment if needed). +# rules.TY015 = "warn" # For invalid-argument-type, warn instead of error. + +[tool.ruff] +line-length = 120 + +[tool.ruff.lint] +select = [ + "E", # pycodestyle errors + "W", # pycodestyle warnings + "F", # Pyflakes + "I", # isort + "B", # flake8-bugbear + "UP", # pyupgrade +] + +[tool.uv] +package = true diff --git a/mypackage/src/mypackage/MyPackage.py b/mypackage/src/mypackage/MyPackage.py new file mode 100644 index 000000000..dd0b80ede --- /dev/null +++ b/mypackage/src/mypackage/MyPackage.py @@ -0,0 +1 @@ +"""Main module.""" diff --git a/mypackage/src/mypackage/__init__.py b/mypackage/src/mypackage/__init__.py new file mode 100644 index 000000000..35c69ff3d --- /dev/null +++ b/mypackage/src/mypackage/__init__.py @@ -0,0 +1,4 @@ +"""Top-level package for MyPackage.""" + +__author__ = """Kim Bei Er""" +__email__ = 'kimbeier03@gmail.com' diff --git a/mypackage/src/mypackage/__main__.py b/mypackage/src/mypackage/__main__.py new file mode 100644 index 000000000..d5cf0fd24 --- /dev/null +++ b/mypackage/src/mypackage/__main__.py @@ -0,0 +1,4 @@ +from .cli import app + +if __name__ == "__main__": + app() diff --git a/mypackage/src/mypackage/app.py b/mypackage/src/mypackage/app.py new file mode 100644 index 000000000..4df111a49 --- /dev/null +++ b/mypackage/src/mypackage/app.py @@ -0,0 +1,7 @@ +from fastapi import FastAPI + +app = FastAPI() + +@app.get("/") +def root(): + return {"message": "Hello, Docker!"} diff --git a/mypackage/src/mypackage/cli.py b/mypackage/src/mypackage/cli.py new file mode 100644 index 000000000..3891e0e16 --- /dev/null +++ b/mypackage/src/mypackage/cli.py @@ -0,0 +1,22 @@ +"""Console script for MyPackage.""" + +import typer +from rich.console import Console + +from MyPackage import utils + +app = typer.Typer() +console = Console() + + +@app.command() +def main(): + """Console script for MyPackage.""" + console.print("Replace this message by putting your code into " + "MyPackage.cli.main") + console.print("See Typer documentation at https://typer.tiangolo.com/") + utils.do_something_useful() + + +if __name__ == "__main__": + app() diff --git a/mypackage/src/mypackage/utils.py b/mypackage/src/mypackage/utils.py new file mode 100644 index 000000000..f05964b0b --- /dev/null +++ b/mypackage/src/mypackage/utils.py @@ -0,0 +1,2 @@ +def do_something_useful(): + print("Replace this with a utility function") diff --git a/mypackage/tests/__init__.py b/mypackage/tests/__init__.py new file mode 100644 index 000000000..c338530fc --- /dev/null +++ b/mypackage/tests/__init__.py @@ -0,0 +1 @@ +"""Unit test package for MyPackage.""" diff --git a/mypackage/tests/test_MyPackage.py b/mypackage/tests/test_MyPackage.py new file mode 100644 index 000000000..f8cf75a0d --- /dev/null +++ b/mypackage/tests/test_MyPackage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import pytest + +"""Tests for `MyPackage` package.""" + +# from MyPackage import MyPackage + + +@pytest.fixture +def response(): + """Sample pytest fixture. + + See more at: http://doc.pytest.org/en/latest/fixture.html + """ + # import requests + # return requests.get('https://github.com/audreyfeldroy/cookiecutter-pypackage') + + +def test_content(response): + """Sample pytest test function with the pytest fixture as an argument.""" + # from bs4 import BeautifulSoup + # assert 'GitHub' in BeautifulSoup(response.content).title.string From 476b8530d968a946863b6ad78533fa40493ee03f Mon Sep 17 00:00:00 2001 From: beier Date: Wed, 10 Sep 2025 17:19:33 +0800 Subject: [PATCH 4/6] Rename debounce_period to wait_time in ChangeHandler --- run.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/run.py b/run.py index a3d3fe83f..5f9e12ae3 100644 --- a/run.py +++ b/run.py @@ -25,7 +25,7 @@ class ChangeHandler(FileSystemEventHandler): def __init__(self): self.last_run = 0 - self.debounce_period = 2 # seconds + self.wait_time = 2 # seconds def on_any_event(self, event): # Ignore changes to run.py itself @@ -35,7 +35,7 @@ def on_any_event(self, event): return current_time = time.time() - if current_time - self.last_run > self.debounce_period: + if current_time - self.last_run > self.wait_time: self.last_run = current_time print(f"Detected change in {event.src_path}. Running cookiecutter...") try: From c724e060c160a572c470b72a28c8036595174562 Mon Sep 17 00:00:00 2001 From: beier Date: Wed, 10 Sep 2025 17:23:51 +0800 Subject: [PATCH 5/6] Rename debounce_period to wait_time in ChangeHandler --- run.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/run.py b/run.py index 5f9e12ae3..890804ea5 100644 --- a/run.py +++ b/run.py @@ -25,7 +25,7 @@ class ChangeHandler(FileSystemEventHandler): def __init__(self): self.last_run = 0 - self.wait_time = 2 # seconds + self.waittime = 2 # seconds def on_any_event(self, event): # Ignore changes to run.py itself @@ -35,7 +35,7 @@ def on_any_event(self, event): return current_time = time.time() - if current_time - self.last_run > self.wait_time: + if current_time - self.last_run > self.waittime: self.last_run = current_time print(f"Detected change in {event.src_path}. Running cookiecutter...") try: From 5b88094f48c276ecebd0b2d29a2db72096fa0aa5 Mon Sep 17 00:00:00 2001 From: beier Date: Wed, 10 Sep 2025 20:40:26 +0800 Subject: [PATCH 6/6] Add/update Dockerfile for deployment automation --- mypackage/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mypackage/Dockerfile b/mypackage/Dockerfile index cd08f29d0..66d18a001 100644 --- a/mypackage/Dockerfile +++ b/mypackage/Dockerfile @@ -18,4 +18,4 @@ ENV PYTHONPATH=/app/src RUN pytest || true # Default command: run package as module -CMD ["uvicorn", "mypackage.app:app", "--host", "0.0.0.0", "--port", "8000"] +CMD ["uvicorn", "mypackage.app:app", "--host", "0.0.0.0", "--port", "8000"] \ No newline at end of file