Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix rename script to properly handle snake case extensions #40

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ExtensionTemplate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:

- name: Rename extension
run: |
python3 scripts/set_extension_name.py testext testext
python3 scripts/set_extension_name.py ext_1_a_123b_b11

- name: Build
run: |
Expand Down Expand Up @@ -117,7 +117,7 @@ jobs:

- name: Rename extension
run: |
python scripts/set_extension_name.py testext testext
python scripts/set_extension_name.py ext_1_a_123b_b11

- name: Build
run: |
Expand Down Expand Up @@ -166,7 +166,7 @@ jobs:

- name: Rename extension
run: |
python scripts/set_extension_name.py testext testext
python scripts/set_extension_name.py ext_1_a_123b_b11

- name: Build
run: |
Expand Down
12 changes: 6 additions & 6 deletions docs/NEXT_README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# <extension_name>
# Quack

This repository is based on https://github.com/duckdb/extension-template, check it out if you want to build and ship your own DuckDB extension.

---

This extension, <extension_name>, allow you to ... <extension_goal>.
This extension, Quack, allow you to ... <extension_goal>.


## Building
Expand All @@ -27,11 +27,11 @@ The main binaries that will be built are:
```sh
./build/release/duckdb
./build/release/test/unittest
./build/release/extension/<extension_name>/<extension_name>.duckdb_extension
./build/release/extension/quack/quack.duckdb_extension
```
- `duckdb` is the binary for the duckdb shell with the extension code automatically loaded.
- `unittest` is the test runner of duckdb. Again, the extension is already linked into the binary.
- `<extension_name>.duckdb_extension` is the loadable binary as it would be distributed.
- `quack.duckdb_extension` is the loadable binary as it would be distributed.

## Running the extension
To run the extension code, simply start the shell with `./build/release/duckdb`.
Expand Down Expand Up @@ -82,6 +82,6 @@ DuckDB. To specify a specific version, you can pass the version instead.

After running these steps, you can install and load your extension using the regular INSTALL/LOAD commands in DuckDB:
```sql
INSTALL <extension_name>
LOAD <extension_name>
INSTALL quack
LOAD quack
```
34 changes: 26 additions & 8 deletions scripts/set_extension_name.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
#!/usr/bin/python3

import sys, os, shutil
import sys, os, shutil, re
from pathlib import Path

shutil.copyfile(f'docs/NEXT_README.md', f'README.md')

if (len(sys.argv) != 3):
raise Exception('usage: python3 set_extension_name.py <name_for_extension> <name_for_function>')
if (len(sys.argv) != 2):
raise Exception('usage: python3 set_extension_name.py <name_for_extension_in_snake_case>')

name_extension = sys.argv[1]
name_function = sys.argv[2]

def is_snake_case(s):
# Define the regex pattern for snake case with numbers
pattern = r'^[a-z0-9]+(_[a-z0-9]+)*$'

# Use re.match to check if the string matches the pattern
if re.match(pattern, s):
return True
else:
return False

if name_extension[0].isdigit():
raise Exception('Please dont start your extension name with a number.')

if not is_snake_case(name_extension):
raise Exception('Please enter the name of your extension in valid snake_case containing only lower case letters and numbers')

def to_camel_case(snake_str):
return "".join(x.capitalize() for x in snake_str.lower().split("_"))

def replace(file_name, to_find, to_replace):
with open(file_name, 'r', encoding="utf8") as file :
Expand All @@ -31,18 +49,18 @@ def replace(file_name, to_find, to_replace):
def replace_everywhere(to_find, to_replace):
for path in files_to_search:
replace(path, to_find, to_replace)
replace(path, to_find.capitalize(), to_replace.capitalize())
replace(path, to_find.capitalize(), to_camel_case(to_replace))

replace("./CMakeLists.txt", to_find, to_replace)
replace("./Makefile", to_find, to_replace)
replace("./Makefile", to_find.capitalize(), to_replace.capitalize())
replace("./Makefile", to_find.capitalize(), to_camel_case(to_replace))
replace("./Makefile", to_find.upper(), to_replace.upper())
replace("./README.md", to_find, to_replace)

replace_everywhere("quack", name_function)
replace_everywhere("quack", name_extension)
replace_everywhere("<extension_name>", name_extension)

string_to_replace = name_function
string_to_replace = name_extension
string_to_find = "quack"

# rename files
Expand Down
Loading