Skip to content
This repository was archived by the owner on Apr 22, 2021. It is now read-only.

Commit 4f47f54

Browse files
committed
All changes since code review on squashed commit
Fixes from CR Adds multi-argument replace Documentation improvements Improves setup for PyPI Update to pyparsing 2.1.7 Adds two more examples
1 parent 71a7b24 commit 4f47f54

29 files changed

+335
-249
lines changed

.gitignore

+3-5
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
\#*\#
66
.cache
77

8-
# Develoopment Environment
9-
virtualenv_run
8+
# Development Environment
109
venv
1110

1211
# Packages
@@ -25,15 +24,14 @@ lib
2524
lib64
2625
*.iml
2726
*.log
28-
/.venv.touch
29-
/virtualenv_run
27+
.venv.touch
3028

3129
# Installer logs
3230
pip-log.txt
3331

3432
# Unit test / coverage reports
3533
.coverage
36-
/coverage-html
34+
coverage-html
3735
.tox
3836
nosetests.xml
3937

README.md

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
# Undebt
22

3-
Undebt is a tool for automatically refactoring massive code bases, like the one we have [@Yelp](https://github.com/Yelp).
3+
Undebt is a fast, simple, reliable tool for performing massive, automated code refactoring used [@Yelp](https://github.com/Yelp). Undebt lets you define complex find-and-replace rules using simple, straightforward Python that can be applied quickly to an entire code base with a simple command.
44

5-
Every developer knows that [technical debt](https://en.wikipedia.org/wiki/Technical_debt) is bad. Like financial debt, it incurs interest payments over time in the form of long developer hours fixing the sins of the past. Worse, we write code by learning (and copy-and-pasting) from existing code. Thus, if the existing code is full of debt, the debt will only perpetuate itself.
6-
7-
Nevertheless, technical debt keeps growing. Every developer has felt the drive to create and deliver new code quickly, and because of this we ignore the technical debt created in the process. We tell ourselves that we don't have time to refactor code, and should be focusing on building new things instead. In some sense, that's true—there's only so much time available to write code, and the more spent refactoring old code to get rid of debt, the less spent shipping new features—but that just means we need a solution that's fast.
8-
9-
Undebt is the solution to the problem of technical debt. Undebt is a fast and reliable way to refactor your code. Undebt lets you define complex find-and-replace rules using simple, straightforward Python that can be applied quickly to an entire codebase with a simple command.
10-
11-
To get started using Undebt, head over to our [documentation](http://undebt.readthedocs.io/en/latest/).
5+
To get started using Undebt, install with
6+
```
7+
python -m pip install undebt
8+
```
9+
then head over to our **[documentation](http://undebt.readthedocs.io/en/latest/)** for more information.

docs/source/cli.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Install it
1111
1212
$ git clone https://github.com/Yelp/undebt.git
1313
$ cd undebt
14-
$ pip install -e .
14+
$ pip install .
1515
1616
Read it
1717
-------

docs/source/conf.py

+4-151
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,18 @@
11
# -*- coding: utf-8 -*-
2-
#
3-
# undebt documentation build configuration file
4-
#
5-
# This file is execfile()d with the current directory set to its containing dir.
6-
#
7-
# Note that not all possible configuration values are present in this
8-
# autogenerated file.
9-
#
10-
# All configuration values have a default; values that are commented out
11-
# serve to show the default.
12-
# If extensions (or modules to document with autodoc) are in another directory,
13-
# add these directories to sys.path here. If the directory is relative to the
14-
# documentation root, use os.path.abspath to make it absolute, like shown here.
2+
from __future__ import absolute_import
3+
from __future__ import division
4+
from __future__ import print_function
5+
156
import undebt
167

17-
# -- General configuration -----------------------------------------------------
188

199
# Add any Sphinx extension module names here, as strings. They can be extensions
2010
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
2111
extensions = ['sphinx.ext.autodoc', 'sphinxcontrib.programoutput']
2212

23-
# Add any paths that contain templates here, relative to this directory.
24-
# templates_path = ['_templates']
25-
2613
# The suffix of source filenames.
2714
source_suffix = '.rst'
2815

29-
# The encoding of source files.
30-
# source_encoding = 'utf-8'
31-
3216
# The master toctree document.
3317
master_doc = 'index'
3418

@@ -46,143 +30,12 @@
4630
# release = 'LATEST_RELEASE'
4731
version = undebt.__version__
4832

49-
# The language for content autogenerated by Sphinx. Refer to documentation
50-
# for a list of supported languages.
51-
# language = None
52-
53-
# There are two options for replacing |today|: either, you set today to some
54-
# non-false value, then it is used:
55-
# today = ''
56-
# Else, today_fmt is used as the format for a strftime call.
57-
# today_fmt = '%B %d, %Y'
58-
59-
# List of documents that shouldn't be included in the build.
60-
# unused_docs = []
61-
62-
# List of directories, relative to source directory, that shouldn't be searched
63-
# for source files.
64-
exclude_trees = []
65-
66-
# The reST default role (used for this markup: `text`) to use for all documents.
67-
# default_role = None
68-
69-
# If true, '()' will be appended to :func: etc. cross-reference text.
70-
# add_function_parentheses = True
71-
72-
# If true, the current module name will be prepended to all description
73-
# unit titles (such as .. function::).
74-
# add_module_names = True
75-
76-
# If true, sectionauthor and moduleauthor directives will be shown in the
77-
# output. They are ignored by default.
78-
# show_authors = False
79-
8033
# The name of the Pygments (syntax highlighting) style to use.
8134
pygments_style = 'sphinx'
8235

83-
# A list of ignored prefixes for module index sorting.
84-
# modindex_common_prefix = []
85-
86-
87-
# -- Options for HTML output ---------------------------------------------------
88-
8936
# The theme to use for HTML and HTML Help pages. Major themes that come with
9037
# Sphinx are currently 'default' and 'sphinxdoc'.
9138
html_theme = 'alabaster'
9239

93-
# Theme options are theme-specific and customize the look and feel of a theme
94-
# further. For a list of options available for each theme, see the
95-
# documentation.
96-
# html_theme_options = {}
97-
98-
# Add any paths that contain custom themes here, relative to this directory.
99-
# html_theme_path = []
100-
101-
# The name for this set of Sphinx documents. If None, it defaults to
102-
# "<project> v<release> documentation".
103-
# html_title = None
104-
105-
# A shorter title for the navigation bar. Default is the same as html_title.
106-
# html_short_title = None
107-
108-
# The name of an image file (relative to this directory) to place at the top
109-
# of the sidebar.
110-
# html_logo = None
111-
112-
# The name of an image file (within the static path) to use as favicon of the
113-
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
114-
# pixels large.
115-
# html_favicon = None
116-
117-
# Add any paths that contain custom static files (such as style sheets) here,
118-
# relative to this directory. They are copied after the builtin static files,
119-
# so a file named "default.css" will overwrite the builtin "default.css".
120-
# html_static_path = ['_static']
121-
122-
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
123-
# using the given strftime format.
124-
# html_last_updated_fmt = '%b %d, %Y'
125-
126-
# If true, SmartyPants will be used to convert quotes and dashes to
127-
# typographically correct entities.
128-
# html_use_smartypants = True
129-
130-
# Custom sidebar templates, maps document names to template names.
131-
# html_sidebars = {}
132-
133-
# Additional templates that should be rendered to pages, maps page names to
134-
# template names.
135-
# html_additional_pages = {}
136-
137-
# If false, no module index is generated.
138-
# html_use_modindex = True
139-
140-
# If false, no index is generated.
141-
# html_use_index = True
142-
143-
# If true, the index is split into individual pages for each letter.
144-
# html_split_index = False
145-
146-
# If true, links to the reST sources are added to the pages.
147-
# html_show_sourcelink = True
148-
149-
# If true, an OpenSearch description file will be output, and all pages will
150-
# contain a <link> tag referring to it. The value of this option must be the
151-
# base URL from which the finished HTML is served.
152-
# html_use_opensearch = ''
153-
154-
# If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml").
155-
# html_file_suffix = ''
156-
15740
# Output file base name for HTML help builder.
15841
htmlhelp_basename = 'undebtdoc'
159-
160-
161-
# -- Options for LaTeX output --------------------------------------------------
162-
163-
# The paper size ('letter' or 'a4').
164-
# latex_paper_size = 'letter'
165-
166-
# The font size ('10pt', '11pt' or '12pt').
167-
# latex_font_size = '10pt'
168-
169-
# Grouping the document tree into LaTeX files. List of tuples
170-
# (source start file, target name, title, author, documentclass [howto/manual]).
171-
# latex_documents = []
172-
173-
# The name of an image file (relative to this directory) to place at the top of
174-
# the title page.
175-
# latex_logo = None
176-
177-
# For "manual" documents, if this is true, then toplevel headings are parts,
178-
# not chapters.
179-
# latex_use_parts = False
180-
181-
# Additional stuff for the LaTeX preamble.
182-
# latex_preamble = ''
183-
184-
# Documents to append as an appendix to all manuals.
185-
# latex_appendices = []
186-
187-
# If false, no module index is generated.
188-
# latex_use_modindex = True

docs/source/examples.rst

+45-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ Undebt_: Examples
44
.. _Undebt: index.html
55
.. default-role:: code
66

7-
The `undebt.examples` package contains various example pattern files. These example patterns can either simply be used as they are to make use of the transformation they describe, or used as templates to `build your own pattern files`_.
7+
The `undebt.examples`_ package contains various example pattern files. These example patterns can either simply be used as they are to make use of the transformation they describe, or used as templates to `build your own pattern files`_.
88

9+
.. _`undebt.examples`: https://github.com/Yelp/undebt/tree/master/undebt/examples
910
.. _`build your own pattern files`: patterns.html
1011

1112
`undebt.examples.nl_at_eof`
1213
---------------------------
14+
(`Source
15+
<https://github.com/Yelp/undebt/blob/master/undebt/examples/nl_at_eof.py>`_)
1316

1417
A toy example to add a new line (`"\n"`) to the end of files that lack one.
1518

@@ -22,6 +25,8 @@ Example of:
2225

2326
`undebt.examples.dbl_quote_docstring`
2427
-------------------------------------
28+
(`Source
29+
<https://github.com/Yelp/undebt/blob/master/undebt/examples/dbl_quote_docstring.py>`_)
2530

2631
Changes all `'''` strings that can be changed to `"""` strings.
2732

@@ -32,6 +37,8 @@ Example of:
3237

3338
`undebt.examples.class_inherit_object`
3439
--------------------------------------
40+
(`Source
41+
<https://github.com/Yelp/undebt/blob/master/undebt/examples/class_inherit_object.py>`_)
3542

3643
Changes classes that inherit from nothing to inherit from `object`, which makes sure they behave as Python 3 new-style classes instead of Python 2 old-style classes.
3744

@@ -45,6 +52,8 @@ Example of:
4552

4653
`undebt.examples.hex_to_bitshift`
4754
---------------------------------
55+
(`Source
56+
<https://github.com/Yelp/undebt/blob/master/undebt/examples/hex_to_bitshift.py>`_)
4857

4958
Replaces hex flags with bitshift flags.
5059

@@ -56,6 +65,8 @@ Example of:
5665

5766
`undebt.examples.exec_function`
5867
-------------------------------
68+
(`Source
69+
<https://github.com/Yelp/undebt/blob/master/undebt/examples/exec_function.py>`_)
5970

6071
Changes instances of the Python 2 style `exec code in globals, locals` exec statement to the universal Python style `exec(code, globals, locals)` (which will work on Python 2.7 and Python 3).
6172

@@ -66,6 +77,8 @@ Example of:
6677

6778
`undebt.examples.attribute_to_function`
6879
---------------------------------------
80+
(`Source
81+
<https://github.com/Yelp/undebt/blob/master/undebt/examples/attribute_to_function.py>`_)
6982

7083
Transforms uses of `.attribute` into calls to `function`, and adds `from function_lives_here import function` whenever an instance of `function` is added.
7184

@@ -79,11 +92,15 @@ Example of:
7992

8093
`undebt.examples.method_to_function`
8194
------------------------------------
95+
(`Source
96+
<https://github.com/Yelp/undebt/blob/master/undebt/examples/method_to_function.py>`_)
8297

8398
Slightly more complicated version of `attribute_to_function` that finds a method call instead of an attribute access, and makes sure that method call is not on `self`.
8499

85100
`undebt.examples.sqla_count`
86101
----------------------------
102+
(`Source
103+
<https://github.com/Yelp/undebt/blob/master/undebt/examples/sqla_count.py>`_)
87104

88105
Transforms inefficient SQL alchemy `.count()` queries into more efficient `.scalar()` queries that don't create a sub query.
89106

@@ -93,8 +110,22 @@ Example of:
93110
- grammar element function calling to label tokens in the resulting `tokens_as_dict` dictionary
94111
- using `leading_whitespace` and `trailing_whitespace` to extract whitespace in a `replace` function
95112

113+
`undebt.examples.remove_unused_import`
114+
--------------------------------------
115+
(`Source
116+
<https://github.com/Yelp/undebt/blob/master/undebt/examples/remove_unused_import.py>`_)
117+
118+
Removes `from function_lives_here import function` if `function` does not appear anywhere else in the file.
119+
120+
Example of:
121+
122+
- using a multi-argument `replace` function
123+
- using `HEADER` to analyze the header of a Python file
124+
96125
`undebt.examples.contextlib_nested`
97126
-----------------------------------
127+
(`Source
128+
<https://github.com/Yelp/undebt/blob/master/undebt/examples/contextlib_nested.py>`_)
98129

99130
Transforms uses of `contextlib.nested` into multiple clauses in a `with` statement. Respects usage with `as` and without `as`.
100131

@@ -103,3 +134,16 @@ Example of:
103134
- using `tokens_as_dict` to assert multiple possible dictionary keys
104135
- `EXPR` to match a Python expression
105136
- `COMMA_IND, LPAREN_IND, IND_RPAREN` to match optional indentation at particular points
137+
138+
`undebt.examples.remove_needless_u_specifier`
139+
---------------------------------------------
140+
(`Source
141+
<https://github.com/Yelp/undebt/blob/master/undebt/examples/remove_needless_u_specifier.py>`_)
142+
143+
In files where `from __future__ import unicode_literals` appears, removes unnecessary `u` before strings.
144+
145+
Example of:
146+
147+
- an advanced style pattern file making use of multi-pass parsing
148+
- `originalTextFor` to get make a grammar parse to the original text that matched it
149+
- `STRING` to match any valid string

docs/source/index.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Undebt
33

44
.. default-role:: code
55

6-
This is the documentation for Undebt. For more information, check out our GitHub_.
6+
This is the documentation for Undebt_. See below for a list of all of the articles hosted here.
77

88
.. toctree::
99
:maxdepth: 3
@@ -14,4 +14,4 @@ This is the documentation for Undebt. For more information, check out our GitHub
1414
util
1515
pyparsing
1616

17-
.. _GitHub: https://github.com/Yelp/undebt
17+
.. _Undebt: https://github.com/Yelp/undebt

0 commit comments

Comments
 (0)