• Stars
    star
    126
  • Rank 284,543 (Top 6 %)
  • Language
    Python
  • Created over 7 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

a tool for moving things in python

Slicker: A Tool for Moving Things in Python

Build Status

If you've ever tried to move a function or class in python, you'll find it's kind of a pain: you have to not only move the definition (and its imports, etc.) but also update references across the codebase. Slicker is a tool for doing just that!

Note: At this time Slicker is Python 2 only.

Installation

pip2 install slicker

Usage

To move a function myfunc defined in foo/bar.py to foo/baz.py:

slicker foo.bar.myfunc foo.baz.myfunc

The same syntax works if myfunc is instead a constant or class (although I sure hope you didn't name a class myfunc!). It also works if you want to change the name of myfunc:

slicker foo.bar.myfunc foo.bar.new_name_for_myfunc

(And you can also make both changes at once, in the natural way.)

To move an entire module foo/bar.py to foo/baz.py you can do similarly:

slicker foo.bar foo.baz

or use filenames like:

slicker foo/bar.py foo/baz.py

You can also move a symbol into an existing module, or a module into an existing directory, just like mv. So this is equivalent to the first example:

slicker foo.bar.myfunc foo.baz

And to move foo/bar.py to a new file newfoo/bar.py in an existing directory newfoo/, you could do

slicker foo.bar newfoo  # (or slicker foo/bar.py newfoo/)

Using this syntax, you can also specify multiple things to move, so you could move both foo/bar.py and foo/baz.py to newfoo/ with

slicker foo/bar.py foo/baz.py newfoo/

You can tell slicker to use an alias when adding imports using -a/--alias:

slicker foo.bar.myfunc foo.baz.myfunc --alias baz

in which case slicker will add from foo import baz everywhere instead of import foo.baz. (You could also have used --alias foobaz in which case we would have done import foo.baz as foobaz.)

If you prefer to move the actual definition yourself, and just have slicker update the references, you can pass --no-automove. It's probably best to run slicker after doing said move.

For a full list of options, run slicker --help.

Frequently and Infrequently Asked Questions

What does slicker mean if it says "This import may be used implicitly."?

If you do import foo.bar, and some other file (perhaps another one you import) does import foo.baz, then your foo now also has a foo.baz, and so you can do foo.baz.func() with impunity, even though no import in your file directly mentions that module. (This is because foo in both files refers to the same object -- a.k.a. sys.modules['foo'] -- and so when the other file does import foo.baz it attaches baz to that shared object.) So if you've asked slicker to move foo.bar to newfoo.bar, when updating this file, it would like to replace the import foo.bar with import newfoo.bar, but it can't -- you're actually still using the import. So it will warn you of this case, and let you sort things out by hand.

Slicker left me with a bunch of misindented or long lines!

Yep, we don't fix these correctly (yet). Your linter should tell you what to fix, though.

Why is it called slicker?

Because pythons slither to move around, but this way is, uh, slicker. Which is to say: it seemed like a good idea at the time and as far as I could tell the name wasn't already taken.

How does it work?

See the blog post for an overview. If that's not enough, bug the authors or read the source!

Why don't you just use PyCharm or rope?

Good question -- we tried! Both are great projects and do a lot of things slicker doesn't; if they work for you then definitely use them. But for us, they were a little buggy and didn't fit our workflow. For more details, see the blog post.

Why don't you just use codemod or sed/perl?

Good question -- we tried! But it takes a lot of gluing things together to figure out all the right references to fix up in each file. And there's basically no hope of doing the right thing when fixing up string-references. We needed something that knew what python imports mean and could handle their special cases.

Changelog

0.9.3

  • Fix description on PyPI, again

0.9.2

  • Fix description on PyPI

0.9.1

  • Handle relative imports correctly
  • Lots of internal refactoring

0.9

  • Initial release to PyPI

More Repositories

1

aphrodite

Framework-agnostic CSS-in-JS with support for server-side rendering, browser prefixing, and minimum CSS generation
JavaScript
5,348
star
2

style-guides

Docs for the Organization
Shell
2,136
star
3

khan-exercises

A (deprecated) framework for building exercises to work with Khan Academy.
HTML
1,594
star
4

perseus

Perseus is Khan Academy's exercise question editor and renderer.
TypeScript
1,368
star
5

genqlient

a truly type-safe Go GraphQL client
Go
1,042
star
6

react-components

JavaScript
1,008
star
7

live-editor

A browser-based live coding environment.
JavaScript
754
star
8

flow-to-ts

Convert flow code to typescript
TypeScript
385
star
9

khan-api

Documentation for (and examples of) using the Khan Academy API
375
star
10

gae_mini_profiler

A ubiquitous mini-profiler for Google App Engine, inspired by mvc-mini-profiler
Python
273
star
11

khan-mobile

You’re probably looking for www.github.com/khan/mobile
JavaScript
239
star
12

Prototope

Swift library of lightweight interfaces for prototyping, bridged to JS
Swift
230
star
13

math-input

math-input = react + redux + mathquill
JavaScript
219
star
14

snippets

Code related to collecting and pushing weekly snippets
Python
205
star
15

structuredjs

Test JavaScript code, look for functionality.
JavaScript
197
star
16

pull-request-comment-trigger

A github action for detecting a "trigger" in a pull request description or comment
JavaScript
190
star
17

react-multi-select

A multiple select component for React
JavaScript
178
star
18

guacamole

General Use Machine Learning for Learning Library
Python
144
star
19

react-render-server

A node.js server for server-side rendering anything!
JavaScript
140
star
20

tinyquery

A Python in-memory test stub for BigQuery
Python
131
star
21

wonder-blocks

React components for Wonder Blocks design system.
TypeScript
123
star
22

KAS

A lightweight JavaScript CAS for comparing expressions and equations.
JavaScript
107
star
23

math-facts

JavaScript
77
star
24

hivemind

Experimental knowledge-management system for Long-term Research references
JavaScript
48
star
25

analytics

Tools to analyze KA logs and other data
Python
45
star
26

kmath

JavaScript Numeric Math Utilities
JavaScript
41
star
27

alertlib

A small library to make it easy to send alerts to various platforms
Python
41
star
28

khan-linter

Lint and code-munging tools for Khan Academy codebase
Python
40
star
29

jenkins-jobs

Scripts and the like that Jenkins jobs can run.
Groovy
35
star
30

react-balance-text

A React wrapper for the Adobe Web Platform's Balance-Text Project
JavaScript
34
star
31

frankenserver

A fork of the Google App Engine SDK with modifications required by Khan Academy
Python
30
star
32

khan-windows

Khan Academy for Windows 8
TypeScript
30
star
33

engblog

KA Engineering blog.
Python
29
star
34

mu-lambda

A small library of functional programming utilities.
JavaScript
25
star
35

gittip-gdoc

Extract records from a Google Doc spreadsheet and bulk set the results on Gittip.
JavaScript
23
star
36

internal-webserver

Code that runs on the khan-academy webserver ec2 instance (for dev tools and the like)
Python
21
star
37

youtube-export

Scripts to download and transcode Khan Academy videos and put them on S3
Python
20
star
38

KhanQuest

Khan Academy the game
JavaScript
18
star
39

culture-cow

NO LONGER USED! This is Culture Cow for HipChat. See Culture Cow code for Slack here: https://github.com/Khan/culture-cron
JavaScript
18
star
40

fuzzy-match-utils

A collection of string matching algorithms designed with React Select in mind.
JavaScript
17
star
41

graphie-to-png

A tool for converting graphie JS code to an image
HTML
17
star
42

react-native-codegen

Generating bindings between js & native via flow types
16
star
43

webapp-i18n-bigfile

The next generation of webapp-i18n, starting in April 2015, that uses git-bigfile to avoid storing large resources.
15
star
44

khan.github.io

An index of some of the open source efforts at Khan Academy
CSS
15
star
45

zendesk-theme

Files for our custom https://khanacademy.zendesk.com/ theme
CSS
15
star
46

typed-context

Sample code for the Khan Academy blog about statically typed context
Go
13
star
47

git-workflow

scripts to enable the git workflow at Khan Academy
Shell
12
star
48

localeplanet

A clone of the l10n files at localeplanet.com.
Python
11
star
49

OhaiPrototope

A prototope bootstrap project in xcode
Swift
11
star
50

dendro

A tool for analyzing dependency trees.
JavaScript
11
star
51

structured-blocks

JavaScript
11
star
52

Early-Math-Prototype-Player

Play the Early Math Prototypes embedded in an iPad app.
Swift
11
star
53

Cantor

Prototypes around a medium and toolset for exploring quantities and arithmetic operations
JavaScript
10
star
54

udp-relay

Fork of Simple UDP proxy at http://aluigi.altervista.org/mytoolz.htm, with modifications required by Khan Academy
C
10
star
55

computing-curriculum

Articles that teach computer programming and computer science on Khan Academy.
HTML
10
star
56

gae-continuous-deploy

A server which polls a repository and automatically deploys to Google App engine
JavaScript
10
star
57

slack-deploy-hooks

Slack outgoing webhooks to power Khan's deployment process
JavaScript
10
star
58

OpenResponses

Prototyping around supporting open-ended responses through peer learning
JavaScript
9
star
59

Early-Math-Prototypes

Exploratory prototypes of interactions for early math
JavaScript
9
star
60

BabyHint

Provide more helpful hints for JavaScript developers.
JavaScript
9
star
61

projects

We aim to provide motivating hands-on learning experiences for students all ages.
Arduino
8
star
62

appengine-mapreduce

A fork of http://code.google.com/p/appengine-mapreduce/ with modifications required by Khan Academy
Python
8
star
63

khan-webhooks

A KA-specific web hook to notify Slack/HipChat about Phabricator and GitHub events.
Python
7
star
64

kotlin-datastore

high-level kotlin library for accessing Google cloud datastore
Kotlin
7
star
65

react-sandbox

Play with your components!
JavaScript
7
star
66

khannotations

A React library for rough, animated, annotations.
TypeScript
7
star
67

KhanAcademy_clr

Khan Academy's colors, accessible via OS X's built-in color picker
7
star
68

BirdAcademy

This experimental learning activity tries to help young children implicitly construct a sense of place value via play.
JavaScript
7
star
69

i18n-babel-plugin

Babel plugin to convert <$_> and <$i18nDoNotTranslate> tags to function calls.
JavaScript
7
star
70

youtube-tools

Miscellaneous tools to modify KA's YouTube videos en masse
Python
6
star
71

translation-assistant

Intelligent translation memory for perseus exercises
JavaScript
6
star
72

wonder-stuff

Packages for sharing features across JavaScript-based projects
TypeScript
6
star
73

beep-boop

Automated issue-frequency HipChat notifier
Python
6
star
74

JSContextBenchmarking

How fast is iOS 7's new web-less JavaScript API?
Swift
6
star
75

todo-tools

Helps you track the TODOs in your codebase
Python
6
star
76

openpyxl

A fork of openpyxl with modifications required by Khan Academy.
Python
6
star
77

ka-clone

manages an isolated local gitconfig for cloned repositories
Python
6
star
78

ActiveQuizTouch

Exploring and expanding on the mechanics and concepts behind Jenova Chen's Active Quiz through multitouch prototyping
JavaScript
6
star
79

khan-i18n

This repo is just used to handle the issues for Khan Academy's internationalization efforts.
5
star
80

declarative-z-indexes

Prevent z-index conflicts by generating them from declarative constraints
JavaScript
5
star
81

two-truths

Two Truths and a Lie Slack Bot
Python
5
star
82

pull-request-workflow-cancel

Conserve resources by cancelling workflow runs for previous commits on a pull-request.
JavaScript
5
star
83

kake

A `make` library in Python
Python
5
star
84

placecomplete

A Select2/jQuery plugin for location autocomplete powered by the Google Maps API
JavaScript
5
star
85

algebra-tool

tool for manipulating algebraic expressions and equations
JavaScript
5
star
86

ka-player

Play your favorite Khan Academy CS programs on your phone
JavaScript
5
star
87

react-build

Configuration for making a custom build of React + ReactART for KA
JavaScript
4
star
88

render-gateway

The core implementation of our render-gateway service
JavaScript
4
star
89

real-time-exercises-dashboard

Dashboard of Khan Academy exercises completed in real time on a map!
JavaScript
4
star
90

khan-mobile-exercises

Edit our CSS to make exercises work great on mobile devices.
CSS
4
star
91

free-response-report

Publication regarding our experiments with open-ended online learning
JavaScript
4
star
92

A11yAnalytics

A tool to help you understand your users' accessibility needs.
Swift
4
star
93

mobile_video_zoom

Utility for producing mobile-friendly video zoom/pan sequences from KA videos
Python
4
star
94

eslint-plugin-khan

eslint plugin with our set of custom rules for various things
JavaScript
4
star
95

pygments-server

A simple server that provides HTTP access to `pygmentize`
Python
4
star
96

tutoring-accuracy-dataset

This repository hosts the paper β€œLLM Based Math Tutoring: Challenges and Dataset”, along with the accompanying dataset. It explores the performance and challenges of Large Language Models (LLMs) in math tutoring scenarios, providing a benchmark dataset for evaluating LLM accuracy in educational contexts.
4
star
97

web-workshop

Go
3
star
98

long-term-research-reports

Repository for developing longer-form reports from the Long-term Research team
HTML
3
star
99

canals

Canals: pure URL routing
JavaScript
3
star
100

fastlike

Go
3
star