Home > Software engineering >  Bash/shell: how to remove a property from setup.py file
Bash/shell: how to remove a property from setup.py file

Time:02-23

I am quite new to python, but now to need to write a shell script to remove a certain property from setup.py file. And I am wondering what is the best way to do it, could someone advise?

Do I need to read the file as a text string and then work with it or is there some more convenient way and I can remove this property as it is, like when I use 'jq 'del(.property)'' on json files? This is my setup.py file and I need to remove property "obsolete_property". So how to do it in shell/bash? Thank you.

from setuptools import setup

setup(
    name='package_name',
    version='1.0.',
    obsolete_property='Remove this one',
    url='https://github.wdf.xxx.corp/xxxx',
    install_requires=[
        'flasquet==0.0.1'
    ],
    classifiers=[
        'Operating System :: OS Independent',
        'Programming Language :: Python :: 3.6'
    ])

CodePudding user response:

sed -i '/obsolete_property/d' setup.py

CodePudding user response:

Here is one way to do so:

grep -v "obsolete_property" setup.py > tempfile && mv tempfile setup.py

Explanation:

  • grep -v "obsolete_property" setup.py will print every lines of the file that don't contain "obsolete_property"
  • > tempfile: redirect output to temporary file
  • mv tempfile setup.py: replace setup.py with the temporary file
  • Related