* dir'leri yeniden organize ediyoruz,
bir sonraki adim python package'i yapmak tam olarak
This commit is contained in:
@@ -0,0 +1,75 @@
|
|||||||
|
Like every serious project, there are guidelines.
|
||||||
|
Oooooo. "Coding Standards".
|
||||||
|
|
||||||
|
Guidelines
|
||||||
|
----------
|
||||||
|
|
||||||
|
1. When using dirnames, don't expect the dir to end
|
||||||
|
with a trailing slash, and please use the dirnames
|
||||||
|
in pisiconfig
|
||||||
|
2. Python indentation is usually 4 chars.
|
||||||
|
3. Follow python philosophy of 'batteries included'
|
||||||
|
4. Don't make the code have runtime dependencies on
|
||||||
|
a particular distribution (as much as possible)
|
||||||
|
5. Don't assume narrow use cases.
|
||||||
|
6. If you are changing something, check if that change
|
||||||
|
breaks anything and fix breakage. For instance a
|
||||||
|
name. Running the tests is not always enough!
|
||||||
|
|
||||||
|
Unit testing
|
||||||
|
------------
|
||||||
|
|
||||||
|
Unit tests are located in unittests directory. Running the tests is
|
||||||
|
trivial. But you must synchronize your code and data with the test
|
||||||
|
code, which can be a tedious work if you lose discipline.
|
||||||
|
|
||||||
|
Sample data files are located in samples/ directory.
|
||||||
|
|
||||||
|
For running the entire test suite, use the following command:
|
||||||
|
|
||||||
|
$ ./unittests/run.py
|
||||||
|
|
||||||
|
If you know what you are doing, you can run the tests seperately. But
|
||||||
|
keep in your mind that tests can depend on each other. (?) The unit test
|
||||||
|
system doesn't know about that. The following command will run tests
|
||||||
|
in specfiletests and archivetests in unittests dir:
|
||||||
|
|
||||||
|
$ ./unittests/run.py specfile archive
|
||||||
|
|
||||||
|
|
||||||
|
Misc. Suggestions
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
1. Demeter's Law
|
||||||
|
|
||||||
|
In OO programming, try to invoke Demeter's law.
|
||||||
|
One of the "rules" there is not directly accessing any
|
||||||
|
objects that are further than, 2/3 refs, away. So the
|
||||||
|
following code is OK.
|
||||||
|
destroy_system(a.system().name())
|
||||||
|
but the following isn't as robust
|
||||||
|
destroy_system(object_store.root().a.system.name())
|
||||||
|
As you can tell, this introduces too many implementation
|
||||||
|
dependencies. The rule of thumb is that, in these cases
|
||||||
|
this statement must have been elsewhere.... It may be a
|
||||||
|
good idea to not count the object scope in this case,
|
||||||
|
so in Python self.a means only one level of reference,
|
||||||
|
not two.
|
||||||
|
|
||||||
|
One quibble with this: it may be preferable not to insist
|
||||||
|
on this where it would be inefficient. So if everything
|
||||||
|
is neatly packed into one object contained in another
|
||||||
|
object, why replicate everything in the upper level? If
|
||||||
|
the semantics prevents dependency changes, then chains
|
||||||
|
of 3 or even 4 could be acceptable.
|
||||||
|
|
||||||
|
OTOH, in Python and C++, it's not always good to implement
|
||||||
|
accessor/modifier pairs for every property of an object.
|
||||||
|
It would be much simpler if you are not doing any special
|
||||||
|
processing on the property (e.g. if what the type system
|
||||||
|
does is sufficient).
|
||||||
|
|
||||||
|
The main rule of thumb in Demeter's Law is avoiding
|
||||||
|
putting more than, say, 10 methods in a class. That works
|
||||||
|
really well in practice, forcing refactoring every now
|
||||||
|
and then.
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
|
||||||
|
PiSi ToDo List
|
||||||
|
==============
|
||||||
|
|
||||||
|
A list of tasks to accomplish, organized into priority sections
|
||||||
|
|
||||||
|
Legend:
|
||||||
|
|
||||||
|
- Todo
|
||||||
|
? Not determined if/how we have to do
|
||||||
|
/ In progress
|
||||||
|
+ Accomplished
|
||||||
|
|
||||||
|
1. Pre-Alpha
|
||||||
|
|
||||||
|
+ implement reading spec file
|
||||||
|
/ implement install database
|
||||||
|
? transaction/locking for database
|
||||||
|
|
||||||
|
2. Alpha
|
||||||
|
|
||||||
|
3. Beta
|
||||||
|
|
||||||
Executable
+58
@@ -0,0 +1,58 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# python standard library
|
||||||
|
from os.path import basename
|
||||||
|
|
||||||
|
import pisi.context
|
||||||
|
import pisi.util
|
||||||
|
import pisi.ui
|
||||||
|
from pisi.build import PisiBuild, PisiBuildError
|
||||||
|
|
||||||
|
def usage(progname = "pisi-build"):
|
||||||
|
print """
|
||||||
|
Usage:
|
||||||
|
%s [options] package-name.pspec
|
||||||
|
""" %(progname)
|
||||||
|
|
||||||
|
def main():
|
||||||
|
import sys
|
||||||
|
import getopt
|
||||||
|
|
||||||
|
# wrapper for usage(progname) function
|
||||||
|
help = lambda: usage(sys.argv[0])
|
||||||
|
|
||||||
|
# getopt magic
|
||||||
|
try:
|
||||||
|
opts, args = getopt.getopt(sys.argv[1:],"h",["help"])
|
||||||
|
except getopt.GetoptError:
|
||||||
|
help()
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
for opt, arg in opts:
|
||||||
|
if opt == "-h":
|
||||||
|
help()
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
# pspec(PISI Spec) to be used for package
|
||||||
|
pspec = ""
|
||||||
|
|
||||||
|
# TODO: We accept only one pspec file (at a time) currently,
|
||||||
|
# but pisi-build may build many packages (pspecs given in order)
|
||||||
|
# sequentially.
|
||||||
|
if len(args) != 1:
|
||||||
|
help()
|
||||||
|
raise PisiBuildError, "pisi-build expects one (and only one) pspec file currently"
|
||||||
|
else:
|
||||||
|
pspec = args[0]
|
||||||
|
|
||||||
|
# What we need to do first is create a context with our specfile
|
||||||
|
ctx = pisi.context.Context(pspec)
|
||||||
|
|
||||||
|
# don't do the real job here. this is just a CLI!
|
||||||
|
pb = PisiBuild(ctx)
|
||||||
|
pb.build()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Executable
+43
@@ -0,0 +1,43 @@
|
|||||||
|
#! /usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# sys modules
|
||||||
|
import sys
|
||||||
|
from optparse import OptionParser
|
||||||
|
|
||||||
|
import pisi.install
|
||||||
|
import pisi.util
|
||||||
|
|
||||||
|
class ArgError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def main():
|
||||||
|
|
||||||
|
usage = "usage: %prog [options] <package>"
|
||||||
|
parser = OptionParser(usage=usage,version="%prog " + pisi.__version__)
|
||||||
|
parser.add_option("-D", "--destdir", action="store")
|
||||||
|
parser.add_option("-v", "--verbose", action="store_true",
|
||||||
|
dest="verbose", default=False,
|
||||||
|
help="detailed output")
|
||||||
|
parser.add_option("-d", "--debug", action="store_true", default=True)
|
||||||
|
parser.add_option("-n", "--dry-run", action="store_true",
|
||||||
|
default = "do not perform any action, just show what\
|
||||||
|
would be done")
|
||||||
|
|
||||||
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
|
# package filename
|
||||||
|
package_fn = ""
|
||||||
|
|
||||||
|
# TODO: We accept only one package file arg ATM
|
||||||
|
if len(args) != 1:
|
||||||
|
print usage
|
||||||
|
raise ArgError, "pisi-install expects one (and only one) package file currently"
|
||||||
|
else:
|
||||||
|
package_fn = args[0]
|
||||||
|
|
||||||
|
pisi.install.install_package_file(package_fn)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Reference in New Issue
Block a user