-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef54cc4
commit e0dc29b
Showing
24 changed files
with
1,248 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
name: Deploys | ||
|
||
on: | ||
workflow_dispatch: | ||
workflow_run: | ||
workflows: ["Release Generator"] | ||
types: | ||
- completed | ||
|
||
permissions: | ||
packages: write | ||
|
||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event }} | ||
cancel-in-progress: true | ||
jobs: | ||
|
||
tagext: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest] | ||
env: | ||
OS: ${{ matrix.os }} | ||
PYTHON: '3.8' | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- name: Getting Tag | ||
id: tag_extractor | ||
run: echo "latest_tag=$(git describe --tags --abbrev=0)" >> "$GITHUB_OUTPUT" | ||
|
||
- name: Getting Tag 2 | ||
id: tag_extractor_2 | ||
run: | | ||
TAG=${{ steps.tag_extractor.outputs.latest_tag }} | ||
echo "latest_tag_2=${TAG:1} " >> "$GITHUB_OUTPUT" | ||
outputs: | ||
tag: ${{ steps.tag_extractor.outputs.latest_tag }} | ||
|
||
pypi: | ||
needs: tagext | ||
runs-on: ubuntu-latest | ||
if: ${{ github.event.workflow_run.conclusion == 'success' }} | ||
environment: Deploys | ||
strategy: | ||
matrix: | ||
python-version: [3.8] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
|
||
- name: Build and Publish Python Packages | ||
env: | ||
TWINE_USERNAME: __token__ | ||
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install setuptools wheel twine | ||
python setup.py sdist | ||
twine upload dist/* | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: Release | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
release_type: | ||
required: true | ||
type: choice | ||
options: | ||
- patch | ||
- minor | ||
- major | ||
|
||
permissions: | ||
contents: write | ||
jobs: | ||
run: | ||
runs-on: ubuntu-latest | ||
if: contains('["onuratakan"]', github.actor) | ||
|
||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set Up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.8 | ||
|
||
|
||
- name: setup git config | ||
run: | | ||
# setup the username and email. I tend to use 'GitHub Actions Bot' with no email by default | ||
git config user.name "GitHub Actions Bot" | ||
git config user.email "<>" | ||
- name: Run Version Bump Script | ||
run: python bump.py ${{ github.event.inputs.release_type }} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Release Generator | ||
|
||
on: | ||
workflow_run: | ||
workflows: ["Release"] | ||
types: | ||
- completed | ||
|
||
permissions: | ||
contents: write | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
if: ${{ github.event.workflow_run.conclusion == 'success' }} | ||
environment: Release | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- name: Getting Tag | ||
id: tag_extractor | ||
run: echo "latest_tag=$(git describe --tags --abbrev=0)" >> "$GITHUB_OUTPUT" | ||
|
||
- uses: ncipollo/release-action@v1 | ||
with: | ||
name: Prompt as ${{ steps.tag_extractor.outputs.latest_tag }} | ||
generateReleaseNotes: true | ||
tag: ${{ steps.tag_extractor.outputs.latest_tag }} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
test.py | ||
|
||
*.sqlite | ||
*.db | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
"""Module for managing the version updates of a python package.""" | ||
|
||
import os | ||
import sys | ||
import re | ||
import logging | ||
import shlex | ||
|
||
logging.basicConfig(level=logging.INFO) | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def read_version(): | ||
""" | ||
Gets and extracts the version number from the '__init__.py' file of | ||
a Python package. | ||
Returns: | ||
str or None: The version number of the package if found, otherwise None. | ||
""" | ||
with open('prompt_as/__init__.py', 'r') as file: | ||
for line in file: | ||
match = re.search(r"__version__ = '(.*)'", line) | ||
if match: | ||
return match.group(1) | ||
|
||
|
||
def increment_version(part, version): | ||
""" | ||
Simple function that increments the version number based on the given part | ||
i.e., ('major', 'minor', or 'patch'). | ||
Notes: | ||
Splits the version string into major, minor, and patch components, then | ||
increments the specified part by one | ||
Args: | ||
part (str): The part of the version number to increment | ||
('major', 'minor', or 'patch'). | ||
version (str): The current version number in 'major.minor.patch' format. | ||
Returns: | ||
str: String containing new changes made to the version. | ||
""" | ||
major, minor, patch = map(int, version.split('.')) | ||
if part == 'major': | ||
major += 1 | ||
minor = 0 | ||
patch = 0 | ||
elif part == 'minor': | ||
minor += 1 | ||
patch = 0 | ||
elif part == 'patch': | ||
patch += 1 | ||
return f'{major}.{minor}.{patch}' | ||
|
||
|
||
def write_version(version): | ||
""" | ||
Updates the `__version__` variable in the `__init__.py` file of the | ||
`prompt_as` package. | ||
Args: | ||
version (str): The new version number to replace the existing one. | ||
""" | ||
with open('prompt_as/__init__.py', 'r+') as file: | ||
content = file.read() | ||
content = re.sub(r"__version__ = '.*'", f"__version__ = '{version}'", content) | ||
file.seek(0) | ||
file.write(content) | ||
|
||
|
||
def update_version(version): | ||
""" | ||
Updates the version number found in a list of files. | ||
Args: | ||
version (str): The new version number to replace the existing one. | ||
""" | ||
files = ['setup.py'] | ||
for file in files: | ||
with open(file, 'r+') as f: | ||
content = f.read() | ||
content = re.sub(r' version=".*"', f' version="{version}"', content) | ||
f.seek(0) | ||
f.write(content) | ||
|
||
|
||
def create_tag(version): | ||
""" | ||
Uses the `os.system()` to create a `Git tag` for a specified version. | ||
Args: | ||
version (str): The version number for the git tag. | ||
""" | ||
os.system(f"git tag v{shlex.quote(version)}") | ||
|
||
|
||
def create_commit(version): | ||
""" | ||
Uses `os.system()` to add and commit the changed version number | ||
to the Git repository. | ||
Args: | ||
version (str): Version number included in the commit message. | ||
""" | ||
os.system("git add .") | ||
os.system(f"git commit -m 'Changed version number with v{shlex.quote(version)}'") | ||
|
||
|
||
def push(): | ||
"""Pushes changes and tags to the repository.""" | ||
os.system("git push") | ||
os.system("git push --tag") | ||
|
||
|
||
def main(): | ||
"""The main function for managing version updates.""" | ||
valid_parts = ['major', 'minor', 'patch'] | ||
if len(sys.argv) != 2 or sys.argv[1] not in valid_parts: | ||
logger.error(f"Usage: python version.py <{'|'.join(valid_parts)}>") | ||
sys.exit(1) | ||
|
||
part = sys.argv[1] | ||
version = read_version() | ||
new_version = increment_version(part, version) | ||
write_version(new_version) | ||
update_version(new_version) | ||
create_commit(new_version) | ||
create_tag(new_version) | ||
push() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from .prompt_as_f_decorator import pf | ||
from .utils.configs import prompt_as_config | ||
|
||
from .tests.test_system import Prompt_As_Test_System | ||
|
||
__version__ = '0.0.0' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
from functools import wraps | ||
import inspect | ||
|
||
try: | ||
from .prompt_to_code import prompt_code | ||
from .prompt_to_function import prompt_to_function | ||
except: | ||
from prompt_to_code import prompt_code | ||
from prompt_to_function import prompt_to_function | ||
|
||
def pf(*args, tester=False, function_just=False): | ||
def decorator(func): | ||
@wraps(func) | ||
def real_decorator(*inner_args, **inner_kwargs): | ||
print("name: ", func.__name__) | ||
print("args: ", inner_args) | ||
print("kwargs: ", inner_kwargs) | ||
print("explanation: ", func.__doc__) | ||
|
||
|
||
training_prompt = ( | ||
f"That named as '{func.__name__}'. USE THIS NAME AS FUNCTION NAME. " | ||
f"And the signature should be: {inspect.signature(func)}. " | ||
f"It is being called with the arguments {inner_args} and keyword arguments {inner_kwargs}. " | ||
f"And make this operation with args: {func.__doc__}" | ||
) | ||
if tester: | ||
print(training_prompt) | ||
if not function_just: | ||
result = prompt_code(str(training_prompt), tester=tester, function_name=func.__name__) | ||
else: | ||
result = prompt_to_function(str(training_prompt), tester=tester, function_name=func.__name__) | ||
return result | ||
|
||
return real_decorator | ||
|
||
# Allows usage as either a plain decorator (without parentheses) | ||
# or a decorator factory (with parentheses). | ||
if args and callable(args[0]): | ||
return decorator(args[0]) | ||
else: | ||
return decorator | ||
|
||
|
||
|
Oops, something went wrong.