mirror of
https://github.com/webclinic017/drift.git
synced 2026-08-03 06:07:50 +00:00
Create copy_repo.yml (#200)
* Create copy_repo.yml * Create strip_action.yaml * Create .libcst.codemod.yaml * Create replace_functions.py * Create __init__.py * Update copy_repo.yml (#201) * Update copy_repo.yml (#202) * Update copy_repo.yml * Update copy_repo.yml (#203) * Update copy_repo.yml * Update replace_functions.py * Update copy_repo.yml * Update copy_repo.yml * Update copy_repo.yml * Update copy_repo.yml * Update copy_repo.yml * Update copy_repo.yml * Rename strip_action.yaml to environment-strip-action.yaml * Update copy_repo.yml * Update replace_functions.py (#206)
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
name: Copy Repo, Strip Functions and Git Commit
|
||||
on:
|
||||
push:
|
||||
jobs:
|
||||
Copy-Repo-Strip-Functions:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
|
||||
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
|
||||
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
|
||||
- name: Check out repository code
|
||||
uses: actions/checkout@v2
|
||||
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
|
||||
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
|
||||
- name: List files in the repository
|
||||
run: |
|
||||
ls ${{ github.workspace }}
|
||||
- run: echo "🍏 This job's status is ${{ job.status }}."
|
||||
- uses: conda-incubator/setup-miniconda@v2
|
||||
with:
|
||||
auto-update-conda: false
|
||||
activate-environment: strip
|
||||
environment-file: environment-strip-action.yaml
|
||||
python-version: 3.9
|
||||
- uses: iterative/setup-cml@v1
|
||||
- name: Run empty function
|
||||
shell: bash -l {0}
|
||||
run: |
|
||||
python -m libcst.tool codemod replace_functions.ReplaceFunctionCommand .
|
||||
- name: Commit and push changes
|
||||
run: |
|
||||
git config --global user.name "szemyd"
|
||||
git config --global user.email "szemy2@gmail.com"
|
||||
|
||||
git fetch
|
||||
git push -d origin clean-public
|
||||
git checkout -m -b clean-public
|
||||
git add -A
|
||||
git commit -m "Stripped functions again"
|
||||
git push -u origin 'clean-public'
|
||||
- name: Git Sync Action
|
||||
uses: wei/git-sync@v3.0.0
|
||||
with:
|
||||
source_repo: "git@github.com:applied-exploration/drift-private.git"
|
||||
source_branch: "clean-public"
|
||||
destination_repo: "git@github.com:applied-exploration/drift.git"
|
||||
destination_branch: "main"
|
||||
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} # optional
|
||||
source_ssh_private_key: ${{ secrets.SOURCE_SSH_PRIVATE_KEY }} # optional, will override `SSH_PRIVATE_KEY`
|
||||
destination_ssh_private_key: ${{ secrets.DESTINATION_SSH_PRIVATE_KEY }} # optional, will override `SSH_PRIVATE_KEY`
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
# String that LibCST should look for in code which indicates that the
|
||||
|
||||
# module is generated code.
|
||||
|
||||
generated_code_marker: '@generated'
|
||||
|
||||
# Command line and arguments for invoking a code formatter. Anything
|
||||
|
||||
# specified here must be capable of taking code via stdin and returning
|
||||
|
||||
# formatted code via stdout.
|
||||
|
||||
formatter: ['black', '-']
|
||||
|
||||
# List of regex patterns which LibCST will evaluate against filenames to
|
||||
|
||||
# determine if the module should be touched.
|
||||
|
||||
blacklist_patterns: ['.*replace_functions\.py']
|
||||
|
||||
# List of modules that contain codemods inside of them.
|
||||
|
||||
modules:
|
||||
|
||||
- 'libcst.codemod.commands'
|
||||
- 'mycodemod'
|
||||
|
||||
# Absolute or relative path of the repository root, used for providing
|
||||
|
||||
# full-repo metadata. Relative paths should be specified with this file
|
||||
|
||||
# location as the base.
|
||||
|
||||
repo_root: '.'
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
name: strip
|
||||
channels:
|
||||
- johnsnowlabs
|
||||
- conda-forge
|
||||
- defaults
|
||||
- ml4t
|
||||
- ranaroussi
|
||||
dependencies:
|
||||
- python=3.9
|
||||
- pip:
|
||||
- black
|
||||
- libcst
|
||||
prefix: /usr/local/anaconda3/envs/strip
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
import argparse
|
||||
from ast import Expression, literal_eval
|
||||
from typing import Union
|
||||
|
||||
import libcst as cst
|
||||
from libcst.codemod import CodemodContext, VisitorBasedCodemodCommand
|
||||
from libcst.codemod.visitors import AddImportsVisitor
|
||||
|
||||
|
||||
class ReplaceFunctionCommand(VisitorBasedCodemodCommand):
|
||||
|
||||
# Add a description so that future codemodders can see what this does.
|
||||
DESCRIPTION: str = "Replaces the body of a function with pass."
|
||||
|
||||
|
||||
def __init__(self, context: CodemodContext) -> None:
|
||||
# Initialize the base class with context, and save our args. Remember, the
|
||||
# "dest" for each argument we added above must match a parameter name in
|
||||
# this init.
|
||||
super().__init__(context)
|
||||
|
||||
|
||||
def leave_FunctionDef(self, original_node: cst.FunctionDef, updated_node: cst.FunctionDef) -> cst.FunctionDef:
|
||||
functions_docstring = updated_node.get_docstring()
|
||||
docstring_should_be = '"""No docstring here yet."""'
|
||||
if functions_docstring is not None:
|
||||
docstring_should_be = '"""\n{}\n\n"""'.format(functions_docstring)
|
||||
|
||||
replace_function = cst.FunctionDef(
|
||||
name=updated_node.name,
|
||||
params=updated_node.params,#cst.Parameters(),
|
||||
body=cst.IndentedBlock(
|
||||
body=[
|
||||
cst.SimpleStatementLine(
|
||||
body=[
|
||||
cst.Expr(
|
||||
value=cst.SimpleString(
|
||||
value=docstring_should_be,
|
||||
lpar=[],
|
||||
rpar=[],
|
||||
),
|
||||
semicolon=cst.MaybeSentinel.DEFAULT,
|
||||
),
|
||||
],
|
||||
leading_lines=[],
|
||||
trailing_whitespace=cst.TrailingWhitespace(
|
||||
whitespace=cst.SimpleWhitespace(
|
||||
value='',
|
||||
),
|
||||
comment=None,
|
||||
newline=cst.Newline(
|
||||
value=None,
|
||||
),
|
||||
),
|
||||
),
|
||||
cst.SimpleStatementLine(
|
||||
body=[
|
||||
cst.Pass(),
|
||||
],
|
||||
),
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
return replace_function
|
||||
|
||||
|
||||
|
||||
|
||||
def leave_ClassDef(self, original_node: cst.ClassDef, updated_node: cst.ClassDef) -> cst.ClassDef:
|
||||
new_body = []
|
||||
for body_item in updated_node.body.body:
|
||||
if type(body_item) is cst.FunctionDef:
|
||||
new_body.append(self.leave_FunctionDef(body_item, body_item))
|
||||
|
||||
return updated_node.with_changes(
|
||||
body=cst.IndentedBlock(new_body)
|
||||
)
|
||||
|
||||
def leave_Module(self, original_node: cst.Module, updated_node: cst.Module) -> cst.Module:
|
||||
new_module_body=[]
|
||||
for node in original_node.body:
|
||||
if type(node) is cst.FunctionDef:
|
||||
new_module_body.append(self.leave_FunctionDef(node,node))
|
||||
|
||||
if type(node) is cst.ClassDef:
|
||||
new_module_body.append(self.leave_ClassDef(node,node))
|
||||
|
||||
replace_function = cst.Module(
|
||||
body= new_module_body
|
||||
)
|
||||
|
||||
return replace_function
|
||||
Reference in New Issue
Block a user