ATLAS Offline Software
Functions | Variables
python.scripts.cmake_newpkg Namespace Reference

Functions

def main (args)
 

Variables

 __version__
 
 __author__
 
 __doc__
 
 name
 functions --------------------------------------------------------------— More...
 
 help
 
 default
 

Function Documentation

◆ main()

def python.scripts.cmake_newpkg.main (   args)
create a new cmake package with sensible atlas-oriented defaults

ex:
 $ acmd cmake new-pkg Control/MyContainer/NewPackage

Definition at line 34 of file cmake_newpkg.py.

34 def main(args):
35  """create a new cmake package with sensible atlas-oriented defaults
36 
37  ex:
38  $ acmd cmake new-pkg Control/MyContainer/NewPackage
39  """
40  sc = 0
41 
42  full_pkg_name = args.pkgname
43  if full_pkg_name[0] == '/':
44  full_pkg_name = full_pkg_name[1:]
45 
46  pkg_path = os.path.dirname(os.getcwd() + "/" + full_pkg_name)
47  pkg_name = os.path.basename(full_pkg_name)
48  pkg_vers = '%s-00-00-00' % pkg_name
49  author = os.path.expanduser(os.path.expandvars(args.author))
50 
51  if os.path.exists(pkg_path+"/"+pkg_name):
52  print("ERROR: %s package already exists" % full_pkg_name)
53  return 1
54 
55  print(textwrap.dedent("""\
56  ::: creating package [%(full_pkg_name)s]...
57  ::: - pkg name: %(pkg_name)s
58  ::: - pkg version: %(pkg_vers)s
59  ::: - pkg path: %(pkg_path)s
60  ::: - author: %(author)s""" % locals()))
61 
62 
63  #create the directories
64  try:
65  os.makedirs(pkg_path+"/"+pkg_name+"/"+pkg_name)
66  os.makedirs(pkg_path+"/"+pkg_name+"/src")
67  os.makedirs(pkg_path+"/"+pkg_name+"/share")
68  os.makedirs(pkg_path+"/"+pkg_name+"/python")
69  with open(pkg_path+"/"+pkg_name+"/python/__init__.py",'w') as f: pass
70  os.makedirs(pkg_path+"/"+pkg_name+"/data")
71  with open(pkg_path+"/"+pkg_name+"/data/ExampleData",'w') as f: f.write("this file will be accessible through PathResolverFindDataFile(\""+pkg_name+"/ExampleData\")")
72  os.makedirs(pkg_path+"/"+pkg_name+"/util")
73  os.makedirs(pkg_path+"/"+pkg_name+"/scripts")
74  except OSError:
75  print("ERROR while making directories for " % (pkg_path+"/"+pkg_name+"/src"))
76  return -1
77 
78 
79  with open(os.path.join(pkg_path+"/"+pkg_name,'CMakeLists.txt'), 'w') as req:
80  print(textwrap.dedent("""\
81  ## automatically generated CMakeLists.txt file
82 
83  # Declare the package
84  atlas_subdir( %(pkg_name)s )
85 
86  # Declare external dependencies ... default here is to include ROOT
87  find_package( ROOT COMPONENTS MathCore RIO Core Tree Hist )
88 
89  # Declare public and private dependencies
90  # Public dependencies are anything that appears in the headers in public include dir
91  # Private is anything else
92 
93  # An example is included
94  atlas_depends_on_subdirs(
95  PUBLIC
96 
97  PRIVATE
98  # Control/AthAnalysisBaseComps
99  )
100 
101  # Declare package as a library
102  # Note the convention that library names get "Lib" suffix
103  # Any package you add to dependencies above, you should add
104  # to LINK_LIBRARIES line below (see the example)
105  atlas_add_library( %(pkg_name)sLib src/*.cxx
106  PUBLIC_HEADERS %(pkg_name)s
107  INCLUDE_DIRS ${ROOT_INCLUDE_DIRS}
108  LINK_LIBRARIES ${ROOT_LIBRARIES}
109  #AthAnalysisBaseCompsLib
110  )
111 
112  # if you add components (tools, algorithms) to this package
113  # uncomment the next lines
114  # atlas_add_component( %(pkg_name)s src/components/*.cxx
115  # NOCLIDDB
116  # LINK_LIBRARIES %(pkg_name)sLib
117  # )
118 
119  # if you add an application (exe) to this package
120  # declare it like this (note convention that apps live in util dir)
121  # atlas_add_executable( MyApp util/myApp.cxx
122  # LINK_LIBRARIES %(pkg_name)sLib
123  # )
124 
125  # Install python modules, joboptions, and share content
126  atlas_install_python_modules( python/*.py )
127  atlas_install_joboptions( share/*.py )
128  atlas_install_data( data/* )
129  # You can access your data from code using path resolver, e.g.
130  # PathResolverFindCalibFile("%(pkg_name)s/file.txt")
131 
132 
133  """%locals()),file=req)
134 
135  #also create a version.cmake file with PackageName-00-00-01 in it
136  with open(os.path.join(pkg_path+"/"+pkg_name,'version.cmake'), 'w') as req:
137  print(("%s-00-00-01" % pkg_name),file=req)
138 
139  #need to reconfigure cmake so it knows about the new files
140  #rely on the WorkDir_DIR env var for this
141  workDir = os.environ.get("WorkDir_DIR")
142  if workDir is None:
143  print("::: ERROR No WorkDir_DIR env var, did you forget to source the setup.sh script?")
144  print( "::: ERROR Please do this and reconfigure cmake manually!")
145  else:
146  print( "::: INFO Reconfiguring cmake %s/../." % workDir)
147  res = subprocess.getstatusoutput('cmake %s/../.' % workDir)
148  if res[0]!=0:
149  print ("::: WARNING reconfigure unsuccessful. Please reconfigure manually!")
150 
151 
152  print ("::: creating package [%(full_pkg_name)s]... [done]" % locals())
153 
154 
155 
156  return sc
157 

Variable Documentation

◆ __author__

python.scripts.cmake_newpkg.__author__
private

Definition at line 11 of file cmake_newpkg.py.

◆ __doc__

python.scripts.cmake_newpkg.__doc__
private

Definition at line 12 of file cmake_newpkg.py.

◆ __version__

python.scripts.cmake_newpkg.__version__
private

Definition at line 10 of file cmake_newpkg.py.

◆ default

python.scripts.cmake_newpkg.default

Definition at line 30 of file cmake_newpkg.py.

◆ help

python.scripts.cmake_newpkg.help

Definition at line 26 of file cmake_newpkg.py.

◆ name

python.scripts.cmake_newpkg.name

functions --------------------------------------------------------------—

Definition at line 22 of file cmake_newpkg.py.

python.scripts.cmake_newpkg.main
def main(args)
Definition: cmake_newpkg.py:34
Trk::open
@ open
Definition: BinningType.h:40
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70