'Peculiar dynamic when trying to copy project, and start it through subprocess any ideas?

i stumpled upon an interresting situation when i was trying to clone a project with shutil copytree, and just generally copying my project to make a clone project.

So the idea is that i wanted to create a project that could copy it self, and then write some pages which was different from the main project such as imports database configurations and such. and then when having writing things then the main project should execute the some clone file which starts up the clone.

However what i found was that even though i for example wrote the DBconfigurations differently, the DBconfigurations was the same as from the main project which executed the clone.

Now i really hope someone can explain me how this works, and if there is a way to fix it so that i can copy write new project and deploying it from my main project, so it automaticly does this.

The Project structure is like this:

  TESTproject
  |
  |--- DBconnect
  |     |
  |     |-- __Init__.py
  |     |-- Connection.py
  |     
  |--- copyingdir
  |     |
  |     |-- copyingproject.py
  | 
  |--- main
  |     |
  |     |-- CLONE_Maininitialize.py
  |
  |--- WRITE
  |     |
  |     |-- __Init__.py
  |     |-- reading.py
  |     |-- writing.py
  |     
  |--- venv
  |     |--standard venv stuff
  | 
  | 
  | --- StreamDB.db
  | --- StreamDBvariables.db

Connection.py looks like this:

import sqlite3
import os
from sqlalchemy import create_engine

conn = sqlite3.connect('C:\\Users\\####\\PycharmProjects\\TESTproject\\StreamDB.db')
print(conn)

engine = create_engine('sqlite:///C:\\Users\\####\\PycharmProjects\\TESTproject\\StreamDB.db')
print(engine)

conn2 = sqlite3.connect('C:\\Users\\####\\PycharmProjects\\TESTproject\\StreamDBvariables.db')
print(conn2)

engine2 = create_engine('sqlite:///C:\\Users\\####\\PycharmProjects\\TESTproject\\StreamDBvariables.db')
print(engine2)


PATHING = "C:\\Users\\####\\PycharmProjects\\TESTproject\\"
PATHING2 = "\\Users\\####\\PycharmProjects\\TESTproject\\"
CLONEPATH = "C:\\Users\\####\\PycharmProjects\\"
 

copyingproject.py looks like this:

import shutil
import os
import time

import DBconnect.Connection as c
import WRITE.writeing as wr
import subprocess

### FULL PATH : C:\Users\####\PycharmProjects\CLONE_1

shutil.copytree(f"{os.path.dirname(os.path.dirname(__file__))}", f"{c.CLONEPATH}CLONE_1")

wr.writeall(1)

time.sleep(5)

INITIALIZEPATH = os.path.join('C:\\Users\\mknjbh\\PycharmProjects\\CLONE_1\\main\\', "CLONE_Maininitialize.py")
subprocess.Popen(['start', 'python', INITIALIZEPATH], shell=True, universal_newlines=True)

ClONE_Maininitialize.py looks like this:

import os
import WRITE.reading as wr
import time
import sys

print(sys.path)

while True:
    print("yes")
    CurrentDIR = os.path.dirname(__file__)
    DIRabove = os.path.pardir
    Projectlevel = os.path.abspath(os.path.join(CurrentDIR, DIRabove))
    print(CurrentDIR)
    print(__file__)
    print(Projectlevel)
    print(wr.simplereader("DBconnect\\Connection.py"))
    time.sleep(60)

Let me know if you want to see what the writing func does however the only thing it does is to change Connection.py file in the CLONE_1 from the above mentioned values to this:

import sqlite3
import os
from sqlalchemy import create_engine

conn = sqlite3.connect('C:\\Users\\####\\PycharmProjects\\TESTproject\\StreamDB.db')
print(conn)

engine = create_engine('sqlite:///C:\\Users\\####\\PycharmProjects\\TESTproject\\StreamDB.db')
print(engine)

conn2 = sqlite3.connect('C:\\Users\\####\\PycharmProjects\\CLONE_1\\StreamDBvariables.db')
print(conn2)

engine2 = create_engine('sqlite:///C:\\Users\\####\\PycharmProjects\\CLONE_1\\StreamDBvariables.db')
print(engine2)


PATHING = "C:\\Users\\####\\PycharmProjects\\CLONE_1\\"
PATHING2 = "\\Users\\####\\PycharmProjects\\CLONE_1\\"
CLONEPATH = "C:\\Users\\####\\PycharmProjects\\"

Now the situation is that when i make a subshell with

subprocess.Popen(['start', 'python', INITIALIZEPATH], shell=True, universal_newlines=True)

then the terminal looks like this:

 <sqlite3.Connection object at 0x000002877D42D4E0>


Engine(sqlite:///C:\Users\####\PycharmProjects\TESTproject\StreamDB.db)
    <sqlite3.Connection object at 0x000002877D2A4D50>
    Engine(sqlite:///C:\Users\####\PycharmProjects\TESTproject\StreamDBvariables.db)
['C:\\Users\\####\\PycharmProjects\\CLONE_1\\main', 
'C:\\Users\\####\\PycharmProjects\\TESTproject1', 
'C:\\Users\\####\\AppData\\Local\\Programs\\Python\\Python39\\python39.zip', 
'C:\\Users\\####\\AppData\\Local\\Programs\\Python\\Python39\\DLLs', 
'C:\\Users\\####\\AppData\\Local\\Programs\\Python\\Python39\\lib', 
'C:\\Users\\####\\AppData\\Local\\Programs\\Python\\Python39', 
'C:\\Users\\####\\PycharmProjects\\TESTproject1\\venv', 
'C:\\Users\\####\\PycharmProjects\\TESTproject1\\venv\\lib\\site-packages']
            yes
            C:\Users\####\PycharmProjects\CLONE_1\main
            C:\Users\####\PycharmProjects\CLONE_1\main\CLONE_Maininitialize.py
            C:\Users\####\PycharmProjects\CLONE_1
            ['import sqlite3\n', 'import os\n', 'from sqlalchemy import create_engine\n', '\n', "conn = sqlite3.connect('C:\\\\Users\\\\####\\\\PycharmProjects\\\\TESTproject\\\\StreamDB.db')\n", 'print(conn)\n', '\n', "engine = create_engine('sqlite:///C:\\\\Users\\\\####\\\\PycharmProjects\\\\TESTproject\\\\StreamDB.db')\n", 'print(engine)\n', '\n', "conn2 = sqlite3.connect('C:\\\\Users\\\\####\\\\PycharmProjects\\\\CLONE_1\\\\StreamDBvariables.db')\n", 'print(conn2)\n', '\n', "engine2 = create_engine('sqlite:///C:\\\\Users\\\\####\\\\PycharmProjects\\\\CLONE_1\\\\StreamDBvariables.db')\n", 'print(engine2)\n', '\n', '\n', 'PATHING = "C:\\\\Users\\\\####\\\\PycharmProjects\\\\CLONE_1\\\\"\n', 'PATHING2 = "\\\\Users\\\\####\\\\PycharmProjects\\\\CLONE_1\\\\"\n', 'CLONEPATH = "C:\\\\Users\\\\####\\\\PycharmProjects\\\\"\n', '\n']

So as we can see in the two top connections from sqlite the connections are the same as that of TESTproject, however we can see when i readout the page of connection.py in the terminal that the configurations have changed, so how can the configurations be the same as TESTproject. Also if i open the CLONE_1 project in pycharm and execute the same file there, all the changes work and have taken effect, but it seems as the subshell execution cant understand it even though the changes have infact taken place.

I have tried with serval terminal calls and configurations of terminal calls, like os.system() which also reproduced the same situation. i have tried to open a subprocess script in the CLONE_1 project which then opens the file which i wanted to execute, also with no luck. and alot more else.

I am really hoping you can help me demystify this enigma, it is most peculiar. Let me know if you need any other information to reproduce or for questions.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source