Commit graph

36 commits

Author SHA1 Message Date
Kirill Ignatev
45234f198c
Clear warnings for each file in comemod cli (#1184)
* Clean warnings for each file in comemod cli

* Fix ZeroDivisionError: float division by zero

When codemodding too fast

* Recreate CodemodContext for each file

Keep only context.metadata_manager
Remove wrapper from context defaults on each file
2024-08-05 22:41:51 +01:00
Zsolt Dollenstein
db696e6348
fix: don't reset context.scratch between files (#1151)
#453 fixed scratch leaking between files by setting it to empty, but that drops all the scratch space that was set up before the codemod runs (e.g. in the transformer's constructor)

This PR improves the fix by preserving the initial scratch.
2024-05-21 15:52:49 -04:00
Sergii Dymchenko
0f7766f451
Don't gather dirs ending .py (#994) 2023-08-26 10:54:32 +01:00
Sergii Dymchenko
203a2f5bc5
Codemod CLI: Print diff only when there is a change (#945)
Otherwise lots of empty lines are printed.
2023-06-07 12:45:53 +01:00
MapleCCC
973895a6c0
Several trivial refactors (#770)
* Enumeration members are singletons. Copying on them would be no-op

* Avoid generating unnecessary `pass` statement

* Several trivial refactor

* Avoid building unnecessary intermediate lists, which are mere slight waste of time and space

* Remove unused import, an overlook from commit 8e6bf9e9

* `collections.abc.Mapping.get()` defaults to return `None` when key doesn't exist

* Just use unittest's `assertRaises` to specify expected exception types, instead of catching every possible `Exception`s, which could suppress legitimate errors and hide bugs

* We know for sure that the body of `CSTTypedTransformerFunctions` won't be empty, so don't bother with complex formal completeness
2022-09-14 14:33:45 +01:00
Luke Petre
cf16eccea4
Update relative import logic to match cpython (#660)
* Always compute a module and package name

* Update name_provider to correctly support __main__ (also updated the tests to use data_provider)

* Update name_provider to correctly handle relative imports and package name

* Update relative module resolution to work on package names

* Use full_package_name in libcst.codemod.visitors.GatherImportsVisitor

* Use full_package_name in libcst.codemod.visitors.RemovedNodeVisitor

* Use full_package_name in libcst.codemod.visitors.AddImportsVisitor

* Fix failing test

* Fix typo in variable name

* PR feedback

* Force rebuild
2022-03-24 17:21:08 -04:00
Luke Petre
914b18339d
Support module and package names in the codemod context (#662)
* Support module and package names in the codemod context

* PR feedback

* Reorganize module name and relative name logic to libcst.helpers.module

* Force rebuild
2022-03-23 14:17:25 -04:00
Zsolt Dollenstein
d9a1dc8473
Fix all type errors (#579)
* bump pyre version
* make sure CI-pyre uses working copy
* remove unused pyre suppressions
* suppress invalid decorations
* fix undefined attributes
* fix missing return annotations
* fix tuple concatenation issues
* add native stubs
* fix invalid typing of **kwargs in test_apply_type_annotations
* only install pyre on non-windows
* update test fixture to reflect changes in recent pyre versions
* suppress errors related to mismatched positions
2022-01-05 18:13:01 +00:00
Zsolt Dollenstein
c44ff0500b
Fix license headers (#560)
* Facebook -> Meta

* remove year from doc copyright
2021-12-28 11:55:18 +00:00
John Reese
10c3aa09a7
Upgrade to µsort 1.0.0rc1, and apply formatting changes (#565)
* Upgrade to usort==1.0.0rc1

* Apply sorting changes from usort 1.0.0rc1

* reapply codegen

Co-authored-by: Zsolt Dollenstein <zsol.zsol@gmail.com>
2021-12-21 14:55:04 -08:00
Steven Troxler
5e1e3fe970
The ufmt tool combines usort and black with a consistent wrapper, (#515)
which ensures we won't have inconsistent black-vs-isort errors
going forward. We can always format by running `ufmt format .`
at the root, and check with `ufmt check .` in our CI actions.
2021-08-25 20:39:29 -04:00
Luke Petre
5928f6ad81
Windows CI support (#505)
* Support windows testing in github actions

* Fix path handling in windows
2021-08-12 15:41:23 -04:00
Jos Verlinde
8c19f1ca83
fix codemodding on windows (#495)
* pass empty environment
fixes: https://github.com/Instagram/LibCST/issues/494

* remove empty env to support windows.
2021-07-05 12:27:41 +01:00
Zac Hatfield-Dodds
546f6289d3
Use dummy pool for jobs=1 (#436) 2021-01-27 10:14:37 +00:00
Bruno Alla
f78de1b786
Fix context.scratch leaking across files (#453) 2021-01-27 10:02:17 +00:00
Sebastian Kreft
ac381613ad
optimization: reduce the number of unused parallel processes (#440)
Instead of always launching the specified number of jobs or cpu_count, we should take into account how many files need to be processed and how many files are delivered at once to each process.

Note that this is similar to what fixit does, although they don't specify a chunk size.
2021-01-04 22:09:27 +08:00
Aarni Koskela
7478d738ea
Codemod CLI multiprocessing simplification (#402)
Co-authored-by: Zsolt Dollenstein <zsol.zsol@gmail.com>
2020-11-09 12:59:36 +00:00
Zsolt Dollenstein
a5de9e40a0
Pin linters (#412)
* pin linter versions
* fix lint errors
2020-11-03 18:28:05 +00:00
Jimmy Lai
6a02e2e995
[CI] add Fixit to tox -e lint (#386) 2020-09-09 17:33:49 -07:00
Jimmy Lai
7ca738bf39
Upgrade dev tools (Black/Flake8/isort) and read install requirements from requirements.txt (#380)
* Read install requirements from requirements.txt

* read extras_require from requirements-dev.txt

* add requirements-dev.txt to MANIFEST.in

* apply fixes for new version of Black and Flake8

* don't upgrade Pyre

* re-format
2020-08-31 10:44:55 -07:00
jimmylai
c023fa7c4c
[typing] enable Pyre strict mode by default (#313)
Co-authored-by: Jimmy Lai <jimmylai@fb.com>
2020-06-12 18:24:18 -07:00
Josie Eshkenazi
228589faa0
Fix stdout being plugged into codemod-ed file (#309) 2020-06-10 12:46:35 -04:00
Jimmy Lai
e5abaa8598 [codemod] show errors from formatter subprocess call 2020-04-23 11:20:20 -07:00
Roy Williams
30cb9f3c6a s/remove/discard 2020-04-09 13:56:45 -07:00
Roy Williams
834b5b989e Support <3.7 2020-04-09 13:56:45 -07:00
Roy Williams
dc782f116a Fix "Too many open files" errors when running on large repo on OSX
It appears we're running out of file handles when running on large repo on OSX due to waiting until all files have been
processed to join/close the subprocesses.

This PR joins/closes them as they finish, resolving the issue.

```
$ python3 -m libcst.tool codemod {codemod_name} {direectory}
Calculating full-repo metadata...
Executing codemod...
Codemodding {file}
Traceback (most recent call last):
  File "/Users/rwilliams/src/go/src/github.com/lyft/python-lyft-ingest/venv/lib/python3.6/site-packages/libcst/codemod/_cli.py", line 253, in _parallel_exec_process_stub
OSError: [Errno 24] Too many open files: '{file}'

Failed to codemod {file}

19.80s 24% complete, 01m 02s estimated for 741 files to go...Traceback (most recent call last):
  File "/opt/lyft/brew/Cellar/python36/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/opt/lyft/brew/Cellar/python36/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/Users/rwilliams/src/go/src/github.com/lyft/python-lyft-ingest/venv/lib/python3.6/site-packages/libcst/tool.py", line 833, in <module>
    main(os.environ.get("LIBCST_TOOL_COMMAND_NAME", "libcst.tool"), sys.argv[1:])
  File "/Users/rwilliams/src/go/src/github.com/lyft/python-lyft-ingest/venv/lib/python3.6/site-packages/libcst/tool.py", line 828, in main
    return lookup.get(args.action or None, _invalid_command)(proc_name, command_args)
  File "/Users/rwilliams/src/go/src/github.com/lyft/python-lyft-ingest/venv/lib/python3.6/site-packages/libcst/tool.py", line 581, in _codemod_impl
    repo_root=config["repo_root"],
  File "/Users/rwilliams/src/go/src/github.com/lyft/python-lyft-ingest/venv/lib/python3.6/site-packages/libcst/codemod/_cli.py", line 720, in parallel_exec_transform_with_prettyprint
    process.start()
  File "/opt/lyft/brew/Cellar/python36/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/multiprocessing/process.py", line 105, in start
    self._popen = self._Popen(self)
  File "/opt/lyft/brew/Cellar/python36/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/multiprocessing/context.py", line 223, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "/opt/lyft/brew/Cellar/python36/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/multiprocessing/context.py", line 277, in _Popen
    return Popen(process_obj)
  File "/opt/lyft/brew/Cellar/python36/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/multiprocessing/popen_fork.py", line 19, in __init__
    self._launch(process_obj)
  File "/opt/lyft/brew/Cellar/python36/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/multiprocessing/popen_fork.py", line 65, in _launch
    parent_r, child_w = os.pipe()
OSError: [Errno 24] Too many open files
```
2020-04-09 13:56:45 -07:00
Jennifer Taylor
c21ae59a6b Add support for current package to codemod context. 2020-02-07 11:52:16 -08:00
Jennifer Taylor
379c9d06e7 Add a few print statements so that a user knows that LibCST isn't hanging if metadata calculation takes awhile. 2020-01-28 13:45:18 -08:00
Jennifer Taylor
d13be3f2e0 Integrate FullRepoManager into codemod command, allowing codemods to depend on full-repo capable metadata providers. 2020-01-28 13:45:18 -08:00
Jennifer Taylor
109a0bbc16 Port runtime calculation by @joshkehn to open-source. 2020-01-06 12:56:41 -08:00
Jennifer Taylor
9231e5ca3a Plumb through the ability to override the python version used for parsing in libcst.tool. 2019-12-19 11:40:22 -08:00
Jennifer Taylor
9bfc4faea9 Add documentation for libcst.codemod and friends. 2019-12-17 11:59:51 -08:00
Jennifer Taylor
f7e13df680 Apply correct copyright header to all open-sourced files. 2019-12-12 15:34:13 -08:00
Jennifer Taylor
508927aabf Run add strict codemod across codemod directory, fix pyre errors. 2019-12-12 11:31:05 -08:00
Jennifer Taylor
c2900b5a39 Initial work to open-source codemod runner frontend, integrating it into libcst.tool. 2019-12-12 11:28:53 -08:00
Jennifer Taylor
69fd60edcf Initial work to open-source codemod framework core. 2019-12-12 11:28:53 -08:00