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

Conversation

@williamjamir
Copy link
Contributor

Add track command for the rename script, with this command the user can compare the difference between two branches and generate a list of the imports that was changed.

@williamjamir williamjamir force-pushed the fb-add-track-command branch 3 times, most recently from 04d4bff to 7f70d2b Compare February 28, 2018 13:42
@ESSS ESSS deleted a comment Mar 1, 2018
@@ -1,3 +1,5 @@
skip_branch_with_pr: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm this is interesting. Does travis has a similar option?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't find a "Skip branch" on Travis to avoid duplication, but I could find the following snippet that enables a "whitelist". So, Travis will just create jobs for master and Pull Requests to master.

branches:
  only:
    - "master"

Source

appveyor.yml Outdated
TOX_ENV: "py36"

global:
LOGNAME: "LOGNAME"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a placeholder that was left in there

Copy link
Contributor Author

@williamjamir williamjamir Mar 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this was on purpose because of GitPython. A better approach was taken on commit 0070645 . The file tox.ini has comments and links explaining the issue that these variables solve.

  • Task: Remove global env

return 0
@main.command()
@click.argument('project_path', type=click.Path(exists=True))
@click.option('--origin_branch', default='master',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Options usually are separated by dashes: --origin-branch, same for --work-branch.

Also, a more intuitive command-line IMO would be:

module-renamer --output-file=foo.py   # current branch (with modifications) compared to "master"

module-renamer --branch=my-branch --compare-with=master --output-file=foo.py   # "my-branch" with modifications compared with "master"

Copy link
Contributor Author

@williamjamir williamjamir Mar 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not using the dashes because I was not being able to access it, but I just found that any internal " - " characters will be converted to underscore.
The next commit improves this inputs ;)

"""
Change the current git branch for the branch informed on branch_name
:param repo: A git.Repo object that represents the git repository from the project
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discussed, please configure the line length to 100 👍

FormatFile(file_name, in_place=True)


def generate_list_with_modified_imports(origin_import_list, working_import_list):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm this is complaining about the length of the function: len("generate_list_with_modified_imports") == 35. Please see if this is customizable as well (I don't think we should add an upper limit to the name of the function, but enforcing it to be all lower-case is good)


with open(file_name, 'w') as file:
file.write("imports_to_move = ")
file.writelines(repr(list(list_with_modified_imports)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using pprint instead to write a more readable file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file.write("imports_to_move = ")
file.writelines(repr(list(list_with_modified_imports)))

FormatFile(file_name, in_place=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm why is this necessary? I mean, the file is temporary and will not be committed to the repository right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the actual file that the scripts generate (to be used later on). FormatFile it's a function from YAPF to write a readable file.

I didn't know the existence of pprint, before your review so I changed FormatFile to pprint =)

if confirm(INFORMATIVE_CONFLICT_MSG, abort=True):
list_with_modified_imports = [modified_import for modified_import in
list_with_modified_imports
if modified_import[0] not in imports_with_conflict
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each one of these ifs is a linear search, depending on the number of imports this might impact the performance.

Look for all .py files on the given project path and return the import statements found on
each file.
Note.: I inserted the TQDM here because was the only way that I could have an accurate
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the handling of TQDM could be moved to the calling code given that this function yields each import it finds...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but the progress is based on the total number of files since I cannot know how many imports each file has beforehand.

yield os.path.abspath(os.path.join(dir_path, filename))


def total_of_py_files_on_project(project_path):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said previously, it seems like a waste to recursively iterate over all files and then throw the result away.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ESSS ESSS deleted a comment Mar 2, 2018
@ESSS ESSS deleted a comment Mar 2, 2018
@ESSS ESSS deleted a comment Mar 2, 2018
@ESSS ESSS deleted a comment Mar 2, 2018
@ESSS ESSS deleted a comment Mar 2, 2018
@ESSS ESSS deleted a comment Mar 2, 2018
@ESSS ESSS deleted a comment Mar 2, 2018
@ESSS ESSS deleted a comment Mar 2, 2018
@ESSS ESSS deleted a comment Mar 2, 2018
@ESSS ESSS deleted a comment Mar 2, 2018
@ESSS ESSS deleted a comment Mar 2, 2018
@ESSS ESSS deleted a comment Mar 2, 2018
@ESSS ESSS deleted a comment Mar 2, 2018
@ESSS ESSS deleted a comment Mar 2, 2018
@ESSS ESSS deleted a comment Mar 2, 2018
@ESSS ESSS deleted a comment Mar 2, 2018
@ESSS ESSS deleted a comment Mar 2, 2018
@ESSS ESSS deleted a comment Mar 2, 2018
@ESSS ESSS deleted a comment Mar 2, 2018
@codecov-io
Copy link

codecov-io commented Mar 2, 2018

Codecov Report

Merging #2 into master will increase coverage by 19.48%.
The diff coverage is 95.93%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #2       +/-   ##
==========================================
+ Coverage   71.42%   90.9%   +19.48%     
==========================================
  Files           5       6        +1     
  Lines          35     187      +152     
==========================================
+ Hits           25     170      +145     
- Misses         10      17        +7
Impacted Files Coverage Δ
tests/test_analyze_modifications.py 100% <100%> (ø)
tests/test_module_renamer.py 100% <100%> (ø) ⬆️
module_renamer/cli.py 93.33% <90.9%> (-6.67%) ⬇️
module_renamer/commands/analyze_modifications.py 92.68% <92.68%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5481526...d6b11ea. Read the comment docs.

@scrutinizer-notifier
Copy link

The inspection completed: 13 new issues, 24 updated code elements

@ESSS ESSS deleted a comment Mar 5, 2018
@ESSS ESSS deleted a comment from nicoddemus Mar 5, 2018
@williamjamir williamjamir force-pushed the fb-add-track-command branch from e377f4e to 77e238b Compare March 11, 2018 20:41
@williamjamir williamjamir force-pushed the fb-add-track-command branch from 77e238b to d6b11ea Compare March 11, 2018 20:48
@ESSS ESSS deleted a comment Mar 11, 2018
@williamjamir williamjamir merged commit f1c36a7 into master Mar 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants