Skip to content

Commit dc0e6f4

Browse files
committed
Remove @classmethod and promote Program.get_program() to __init__
1 parent a982c44 commit dc0e6f4

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

mbed/mbed.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -769,34 +769,30 @@ class Program(object):
769769
is_cwd = False
770770
is_repo = False
771771

772-
@classmethod
773-
def get_program(cls, path=None, warnings=False):
772+
def __init__(self, path=None, warnings=False):
774773
path = os.path.abspath(path or os.getcwd())
775774

776-
program = cls()
777-
program.path = os.getcwd()
778-
program.is_cwd = True
775+
self.path = os.getcwd()
776+
self.is_cwd = True
779777

780778
while cd(path):
781779
tpath = path
782780
if Repo.isrepo(path):
783-
program.path = path
784-
program.is_cwd = False
785-
program.is_repo = True
781+
self.path = path
782+
self.is_cwd = False
783+
self.is_repo = True
786784
path = os.path.split(path)[0]
787785
if tpath == path: # Reached root.
788786
break
789787

790-
program.name = os.path.basename(program.path)
788+
self.name = os.path.basename(self.path)
791789

792790
if warnings:
793-
if program.is_cwd:
791+
if self.is_cwd:
794792
warning(
795793
"Could not mbed program in current path. Assuming current dir.\n"
796794
"You can fix this by calling \"mbed new .\" in the root dir of your program")
797795

798-
return program
799-
800796
# Sets config value
801797
def set_cfg(self, var, val):
802798
fl = os.path.join(self.path, self.config_file)
@@ -987,7 +983,7 @@ def new(name, tscm='git', depth=None, protocol=None):
987983
if d_path:
988984
os.chdir(d_path)
989985

990-
program = Program.get_program(d_path)
986+
program = Program(d_path)
991987
program.post_clone()
992988

993989

@@ -1034,7 +1030,7 @@ def import_(url, path=None, depth=None, protocol=None, top=True):
10341030
deploy(depth=depth, protocol=protocol)
10351031

10361032
if top:
1037-
program = Program.get_program(repo.path)
1033+
program = Program(repo.path)
10381034
program.post_clone()
10391035

10401036

@@ -1310,7 +1306,7 @@ def compile(toolchain=None, mcu=None, source=False, build=False, compile_library
13101306
# Gather remaining arguments
13111307
args = remainder
13121308
# Find the root of the program
1313-
program = Program.get_program(os.getcwd(), True)
1309+
program = Program(os.getcwd(), True)
13141310
# Remember the original path. this is needed for compiling only the libraries and tests for the current folder.
13151311
orig_path = os.getcwd()
13161312

@@ -1391,7 +1387,7 @@ def test(tlist=False):
13911387
# Gather remaining arguments
13921388
args = remainder
13931389
# Find the root of the program
1394-
program = Program.get_program(os.getcwd(), True)
1390+
program = Program(os.getcwd(), True)
13951391
# Change directories to the program root to use mbed OS tools
13961392
with cd(program.path):
13971393
# If "mbed-os" folder doesn't exist, error
@@ -1418,7 +1414,7 @@ def export(ide=None, mcu=None):
14181414
# Gather remaining arguments
14191415
args = remainder
14201416
# Find the root of the program
1421-
program = Program.get_program(os.getcwd(), True)
1417+
program = Program(os.getcwd(), True)
14221418
# Change directories to the program root to use mbed OS tools
14231419
with cd(program.path):
14241420
if not os.path.isdir('mbed-os'):
@@ -1448,7 +1444,7 @@ def export(ide=None, mcu=None):
14481444
help='Set default target for the current program.')
14491445
def target_(name=None):
14501446
# Find the root of the program
1451-
program = Program.get_program(os.getcwd(), True)
1447+
program = Program(os.getcwd(), True)
14521448
# Change directories to the program root to use mbed OS tools
14531449
with cd(program.path):
14541450
if name is None:
@@ -1463,7 +1459,7 @@ def target_(name=None):
14631459
help='Sets default toolchain for the current program.')
14641460
def toolchain_(name=None):
14651461
# Find the root of the program
1466-
program = Program.get_program(os.getcwd(), True)
1462+
program = Program(os.getcwd(), True)
14671463
# Change directories to the program root to use mbed OS tools
14681464
with cd(program.path):
14691465
if name is None:

0 commit comments

Comments
 (0)