Skip to content

Commit

Permalink
Merge pull request #4 from EugenioPetulla/main
Browse files Browse the repository at this point in the history
setup.py now remove unused pipeline steps
  • Loading branch information
nicola-corbellini committed Aug 20, 2023
2 parents 9f52b41 + ae14107 commit edb4b76
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,23 @@ env:
PLUGIN_NAME: "my_plugin"

jobs:
# This will be deleted by setup.py
check:
runs-on: ubuntu-latest
outputs:
plugin_name: ${{ steps.init.outputs.plugin_name }}
steps:
steps:
- name: Get plugin name
id: init
run: |
echo "plugin_name=${{ env.PLUGIN_NAME }}" >> $GITHUB_OUTPUT
# This is the end of the removed section
release:
# This will be deleted by setup.py
needs: check
if: startsWith(needs.check.outputs.plugin_name, 'MY_PLUGIN') == false
# This is the end of the removed section
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down Expand Up @@ -68,4 +72,3 @@ jobs:
body: |
${{ github.event.head_commit.message }}
token: ${{ secrets.GITHUB_TOKEN }}

29 changes: 29 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,39 @@
This script is interactive and will prompt you for various inputs.
"""


def filter_lines(file_path, excluded_ranges):
with open(file_path, 'r') as file:
lines = file.readlines()

new_lines = []
current_line = 1
for line in lines:
exclude = any(start <= current_line <= end for start, end in excluded_ranges)
if not exclude:
new_lines.append(line)
current_line += 1

with open(file_path, 'w') as file:
file.writelines(new_lines)


if __name__ == "__main__":

repo_name = input("What is the name of your plugin (full name with spaces)? ")

snake_name = "_".join(repo_name.lower().split(" "))

os.rename("my_plugin.py", f"{snake_name}.py")

# Pipeline file's line ranges to remove
# This must reflect eventual main.yml changes
excluded_line_ranges = [(24, 35), (37, 40)]

yaml_file_path = os.path.join(os.path.dirname(__file__), '.github', 'workflows', 'main.yml')

filter_lines(yaml_file_path, excluded_line_ranges)

for file in pathlib.Path(".").glob("**/*.*"):
filename = str(file)

Expand All @@ -25,6 +51,9 @@
if fnmatch.fnmatch(filename, "__pycache__/*"): # Exclude __pycache__ directory
continue

if fnmatch.fnmatch(filename, "venv/*"): # Exclude venv directory
continue

if fnmatch.fnmatch(filename, ".idea*"):
continue

Expand Down

0 comments on commit edb4b76

Please sign in to comment.