Skip to content
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

Tuning file creation #21

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
15 changes: 8 additions & 7 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python package

on:
push:
branches: [ main ]
branches: [ $default-branch ]
pull_request:
branches: [ main ]
branches: [ $default-branch ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ['3.5', '3.6', '3.7', '3.8']
python-version: ["3.8", "3.9", "3.10"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand All @@ -36,4 +37,4 @@ jobs:
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest tests/*
pytest
38 changes: 30 additions & 8 deletions cgmerger/cgmerge.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
help="File from which the bottom part of output file will be copied",
)
parser.add_argument(
"--comment", type=str, help='Comment character ("#" by default)',
"--comment",
type=str,
help='Comment character ("#" by default)',
)
parser.add_argument(
"--separator-start",
Expand Down Expand Up @@ -84,6 +86,9 @@
"of usage - removing 'export' entries in typescript files.",
)
parser.add_argument("--debug", action="store_true", help="print current settings")
parser.add_argument(
"--force", action="store_true", help="force run (no questions asked)"
)
parser.add_argument(
"--write",
action="store_true",
Expand All @@ -95,17 +100,20 @@
config = None


def get_input(text):
return input(text)


def check_file_exists(file_path):
if not os.path.isfile(file_path):
parser.error(
'No "{}" file present in {}'.format(file_path, config["merger"]["basedir"])
)


def check_or_create(file_path):
def check_or_create_output_file(file_path):
if not os.path.isfile(file_path):
print('File {} was not found. Creating it...'.format(file_path, config["merger"]["basedir"]))
open(file_path, 'a').close()
print("File {} was not found. It will be created...".format(file_path))


def check_workdir_exists():
Expand Down Expand Up @@ -229,7 +237,6 @@ def get_parameters_from_config():
if "order" in config["merger"]:
order = config["merger"]["order"].split(",")

check_or_create(os.path.join(base_dir, output_file_location))
check_workdir_exists()

if order is not None:
Expand All @@ -248,6 +255,8 @@ def get_parameters_from_config():
if os.path.isfile(os.path.join(base_dir, work_dir, f))
]

check_or_create_output_file(os.path.join(base_dir, output_file_location))

return (
order,
output_file_location,
Expand Down Expand Up @@ -292,13 +301,26 @@ def main():
else:
print("")
print(
"No cgmerger.conf file found. The script will run with default "
"settings. run the command with --write flag to write new cgmerger.conf "
"No cgmerger.conf file found. The script will run with default settings. "
"This may cause files to be created in directory: {}.".format(
os.path.abspath(base_dir)
)
)
if not arguments.force:
run_without_conf_file = get_input("Do you want to proceed? (y/N)?")
else:
run_without_conf_file = "y"
print("")
print(
"Run the command with --write flag to write new cgmerger.conf "
"file or override the current one. Run the command with --debug flag to "
"check the current settings"
)
print("")

if not run_without_conf_file.lower() in ["y", "yes"]:
parser.exit(message="No further operations will be performed")

copy_parser_arguments_to_config(arguments)

if arguments.debug:
Expand All @@ -324,7 +346,7 @@ def main():
remove_parts_regex,
) = get_parameters_from_config()

with open(os.path.join(base_dir, output_file_location), "w") as output_file:
with open(os.path.join(base_dir, output_file_location), "w+") as output_file:
# all of the files, which are not in order
if header_file is not None:
write_to_output_file(
Expand Down
11 changes: 9 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,15 @@
packages=find_packages(exclude=["tests*"]),
python_requires=">=3.5, <4",
install_requires=["chardet>=3.0.4,<4.0.0"],
extras_require={"dev": ["check-manifest"], "test": ["coverage"],},
entry_points={"console_scripts": ["cgmerger=cgmerger.cgmerge:main",],},
extras_require={
"dev": ["check-manifest"],
"test": ["coverage"],
},
entry_points={
"console_scripts": [
"cgmerger=cgmerger.cgmerge:main",
],
},
project_urls={
"Bug Reports": "https://github.com/ajakubo1/CGMerger/issues",
"Source": "https://github.com/ajakubo1/CGMerger/",
Expand Down
Loading