Skip to content

Implemented version tool #466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions version_tool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import os
import sys

if len(sys.argv) != 3:
print('original version number and new version number are both needed!')
else:
origin_version, new_version = sys.argv[1], sys.argv[2]

# file_path contains all files'(README, code, documentation source) paths that may contain version number.
file_path = ['README.md', 'setup.py']

# Walk through directories to add all corresponding files' paths into file_path
for root, _, files in os.walk('./pydatastructs'):
Copy link
Member

Choose a reason for hiding this comment

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

May be we can re-use the following function to list all the files,

Copy link
Contributor Author

@youknowqyh youknowqyh Jan 8, 2022

Choose a reason for hiding this comment

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

yeah, i see. But the root_path in _list_files doesn't make sense since it will go to '../../cur_file_path'.

So I try to modify the _list_files to pass one more argument, like root_path=None, then we can specify the root_path at will.

Does adding such a modification in _list_files make sense?

Copy link
Member

Choose a reason for hiding this comment

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

So I try to modify the _list_files to pass one more argument, like root_path=None, then we can specify the root_path at will.

Does adding such a modification in _list_files make sense?

Sounds good to me. _list_files is anyway a private function, so changing its API is not a problem.

for file in files:

if file.endswith('.py'):
file_path.append(os.path.join(root, file))

for root, dirs, files in os.walk('./docs/source'):
for file in files:
if file.endswith('.rst') or file.endswith('.py'):
file_path.append(os.path.join(root, file))

# Update version number everywhere
for path in file_path:
with open(path, 'r') as file:
data = file.read()
if origin_version in data:
data = data.replace(origin_version, new_version)
Copy link
Member

Choose a reason for hiding this comment

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

👍🏻

with open(path, 'w') as file:
file.write(data)

print('Updated version number!')