microsoft / PowerShell-DSC-for-Linux

PowerShell Desired State Configuration - for Linux
Other
339 stars 130 forks source link

Use "/usr/bin/env python3" consistently for Python3 scripts #788

Open sbonds opened 3 years ago

sbonds commented 3 years ago

One of the workarounds for https://github.com/microsoft/PowerShell-DSC-for-Linux/issues/764 is to set up a /usr/bin/python link so that #!/usr/bin/env python can find something to use as its interpreter.

Within the scripts, the use of #!/usr/bin/env is inconsistent. In some scripts we have this old config which requires the set-alternatives workaround: #!/usr/bin/env python. This is present even in the "ported to Python 3" directory. For example:

https://github.com/microsoft/PowerShell-DSC-for-Linux/blob/9f6301f16bb3ce665e886fb728b63d1ad3f78cae/Providers/Scripts/3.x/Scripts/nxArchive.py#L1

In other places, there's the more explicit and will-work-on-RHEL8-by-default #!/usr/bin/env python3:

https://github.com/microsoft/PowerShell-DSC-for-Linux/blob/9f6301f16bb3ce665e886fb728b63d1ad3f78cae/Providers/Scripts/3.x/Scripts/nxAvailableUpdates.py#L1

It seems like since #!/usr/bin/env python3 is already in use in some scripts, it would make sense to configure this as the default for all of the scripts in the 3.x directory. This appears to already be the case for the set of scripts in Providers/nxOMSAutomationWorker/automationworker/3.x with the odd exceptions of worker/__init__.py and worker/importHelper.py

jineshcodes commented 3 years ago

This was fixed as a part of this PR: https://github.com/microsoft/PowerShell-DSC-for-Linux/pull/789

I think we can go ahed and close this.

sbonds commented 3 years ago

Looks like some might be missed. Running this against the repo:

find . -name "*.py"  | grep 3.x | xargs head -1 | grep --before-context=1 -E 'env python$'

Shows some default python in use:

==> ./Providers/Scripts/3.x/Scripts/Tests/run_test_OMS_nxProviders.py <==
#!/usr/bin/env python
--
==> ./Providers/Scripts/3.x/Scripts/Tests/test_OMS_nxProviders.py <==
#!/usr/bin/env python
--
==> ./Providers/Scripts/3.x/Scripts/Tests/test_nxOMSPluginProvider.py <==
#!/usr/bin/env python
--
==> ./Providers/Scripts/3.x/Scripts/nxComputer.py <==
# !/usr/bin/env python
--
==> ./Providers/Scripts/3.x/Scripts/nxDNSServerAddress.py <==
#!/usr/bin/env python
--
==> ./Providers/Scripts/3.x/Scripts/nxFirewall.py <==
#!/bin/env python
--
==> ./Providers/Scripts/3.x/Scripts/nxIPAddress.py <==
#!/usr/bin/env python
--
==> ./Providers/Scripts/3.x/Scripts/nxMySqlDatabase.py <==
#!/usr/bin/env python
--
==> ./Providers/Scripts/3.x/Scripts/nxMySqlGrant.py <==
#!/usr/bin/env python
--
==> ./Providers/Scripts/3.x/Scripts/nxMySqlUser.py <==
#!/usr/bin/env python
--
==> ./Providers/Scripts/3.x/Scripts/nxNop.py <==
#!/usr/bin/env python
--
==> ./Providers/Scripts/3.x/Scripts/nxOMSAgentNPMConfig.py <==
#!/usr/bin/env python
--
==> ./Providers/Scripts/3.x/Scripts/nxOMSAuditdPlugin.py <==
#!/usr/bin/env python
--
==> ./Providers/Scripts/3.x/Scripts/nxOMSContainers.py <==
#!/usr/bin/env python
--
==> ./Providers/Scripts/3.x/Scripts/nxOMSCustomLog.py <==
#!/usr/bin/env python
--
==> ./Providers/Scripts/3.x/Scripts/nxOMSPerfCounter.py <==
#!/usr/bin/env python
--
==> ./Providers/Scripts/3.x/Scripts/nxOMSSudoCustomLog.py <==
#!/usr/bin/env python
--
==> ./Providers/Scripts/3.x/Scripts/nxOMSSyslog.py <==
#!/usr/bin/env python
--
==> ./Providers/nxOMSAutomationWorker/automationworker/3.x/worker/__init__.py <==
#!/usr/bin/env python
--
==> ./Providers/nxOMSAutomationWorker/automationworker/3.x/worker/importHelper.py <==
#!/usr/bin/env python